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

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.PersonRoleInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.PersonRoleInfo;
import com.jpsoft.shinestar.modules.base.service.PersonRoleInfoService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="personRoleInfoService")
public class PersonRoleInfoServiceImpl implements PersonRoleInfoService {
	@Resource(name="personRoleInfoDAO")
	private PersonRoleInfoDAO personRoleInfoDAO;

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

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

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = personRoleInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<PersonRoleInfo> list() {
		// TODO Auto-generated method stub
		return personRoleInfoDAO.list();
	}

	@Override
	public List<PersonRoleInfo> findParentId(String parentId){
		return personRoleInfoDAO.findParentId(parentId);
	}
		
	@Override
	public Page<PersonRoleInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<PersonRoleInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            personRoleInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<PersonRoleInfo> findBySceneId(String sceneId) {
		return personRoleInfoDAO.findBySceneId(sceneId);
	}

	@Override
	public PersonRoleInfo findByRoleNameAndSceneId(String roleName,String sceneId){
		return personRoleInfoDAO.findByRoleNameAndSceneId(roleName,sceneId);
	}

	@Override
	public List<PersonRoleInfo> findAll() {
		return personRoleInfoDAO.findAll();
	}
}