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

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import com.jpsoft.shinestar.modules.sys.entity.Role;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.sys.dao.UserRoleDAO;
import com.jpsoft.shinestar.modules.sys.entity.UserRole;
import com.jpsoft.shinestar.modules.sys.service.UserRoleService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="userRoleService")
public class UserRoleServiceImpl implements UserRoleService {
	@Resource(name="userRoleDAO")
	private UserRoleDAO userRoleDAO;

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

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

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

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

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

	@Override
	public List<Role> findRoleByUserId(String userId) {
		return userRoleDAO.findRoleByUserId(userId);
	}

	@Override
	public int deleteByUserId(String userId) {
		return userRoleDAO.deleteByUserId(userId);
	}
}