package com.jpsoft.shinestar.modules.sys.service.impl;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.sys.dao.RolePermissionDAO;
import com.jpsoft.shinestar.modules.sys.entity.RolePermission;
import com.jpsoft.shinestar.modules.sys.service.RolePermissionService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="rolePermissionService")
public class RolePermissionServiceImpl implements RolePermissionService {
	@Resource(name="rolePermissionDAO")
	private RolePermissionDAO rolePermissionDAO;

	@Override
	public RolePermission get(String id) {
		// TODO Auto-generated method stub
		return rolePermissionDAO.get(id);
	}

	@Override
	public int insert(RolePermission model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return rolePermissionDAO.insert(model);
	}

	@Override
	public int update(RolePermission model) {
		// TODO Auto-generated method stub
		return rolePermissionDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return rolePermissionDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = rolePermissionDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<RolePermission> list() {
		// TODO Auto-generated method stub
		return rolePermissionDAO.list();
	}
		
	@Override
	public Page<RolePermission> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<RolePermission> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            rolePermissionDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<RolePermission> findByRoleId(String roleId) {
		return rolePermissionDAO.findByRoleId(roleId);
	}

	@Override
	public int deleteByRoleId(String roleId) {
		return rolePermissionDAO.deleteByRoleId(roleId);
	}
}