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.RoleDAO;
import com.jpsoft.shinestar.modules.sys.entity.Role;
import com.jpsoft.shinestar.modules.sys.service.RoleService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="roleService")
public class RoleServiceImpl implements RoleService {
	@Resource(name="roleDAO")
	private RoleDAO roleDAO;

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

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

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

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

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

	@Override
	public Role findByName(String name){
		return roleDAO.findByName(name);
	}
}