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

@Transactional
@Component(value="roleMenuService")
public class RoleMenuServiceImpl implements RoleMenuService {
	@Resource(name="roleMenuDAO")
	private RoleMenuDAO roleMenuDAO;

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

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

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

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

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

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

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