package com.qmth.qrzk.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.qmth.qrzk.dao.IRoleDao;
import com.qmth.qrzk.repository.common.mapper.RoleMapper;
import com.qmth.qrzk.repository.common.mapper.UserRoleMapper;
import com.qmth.qrzk.repository.service.query.UserQueryParams;
import com.qmth.qrzk.repository.user.model.Role;
import com.qmth.qrzk.repository.user.model.UserRole;

/**
 * 角色接口的实现类
 * @author 钟辉
 *
 */
@Repository("roleDaoImpl")
@Transactional
public class RoleDaoImpl implements IRoleDao {

	//注入roleMapper提供操作数据库的sql语句
	@Autowired
	@Qualifier("roleMapper")
	private RoleMapper roleMapper;
	
	@Autowired
	@Qualifier("userRoleMapper")
	private UserRoleMapper userRoleMapper;
	
	/**
	 * 根据用户id从s_user_role表查出所有对应的UserRole对象集合
	 */
	@Override
	public List<UserRole> selectRoleIdsByUserId(int user_id) {
		return userRoleMapper.findByUserId(user_id);
	}
	
	/**
	 * 通过角色id集合查询出所有角色集合对象
	 */
	@Override
	public List<Role> getRoleIds(List<Integer> ls) {
		List<Role> list=roleMapper.getRoleNamesByRoleIds(ls);
		return list;
	}
	@Override
	public List<Role> getRolesByUserId(int userId) throws SQLException {
		List<Role> list=roleMapper.getRolesByUserId(userId);
		return list;
	}

	@Override
	public List<Role> getAllRoles(UserQueryParams params) throws SQLException {
		List<Role> list=roleMapper.getAllRoles(params);
		return list;
	}

	@Override
	public void insert(UserRole userRole) {
		userRoleMapper.insert(userRole);
	}

	@Override
	public void delUserRoleByUserId(int user_id) {
		userRoleMapper.delUserRoleByUserId(user_id);
	}

	@Override
	public List<UserRole> findSECRETARYUserId() {
		// TODO Auto-generated method stub
		return userRoleMapper.findSECRETARYUserId();
	}

	@Override
	public int getAllRolesCount(UserQueryParams params) {
		// TODO Auto-generated method stub
		return roleMapper.getAllRolesCount(params);
	}

	@Override
	public void addLinkRole(List<UserRole> list) {
		// TODO Auto-generated method stub
		userRoleMapper.addLinkRole(list);
	}
}
