/*
 * 该Dao主要负责该类同名表或其他与之关联表的操作
 * 如增删改查等操作,该类不负责系统业务逻辑的处理,主要业务逻辑的实现在对应的Manager中
 */

package com.blueland.bpm.identity.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.blueland.bpm.common.base.BaseIbatis3Dao;
import com.blueland.bpm.identity.model.Role;
import com.blueland.bpm.identity.model.User;


/**
 * @author lw
 * @version 1.0
 * @since
 */

@Repository
public class RoleQueryDao extends BaseIbatis3Dao<Role, String> {
	@Override
	public String getIbatisMapperNamesapce() {
		return "WFRole";
	}
	
	public List<Role> findRoleByUser(User user) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findRoleByUser", user);
	}
	public List<Role> findRoleByUserCode(String userCode) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findRoleByUserCode", userCode);
	}
	public List<Role> findRoleByUser(String userId) {
		User user=new User();
		user.setUserId(userId);
		return findRoleByUser(user);
	}
	public boolean isUserInRole(String roleId, String userId) {
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("roleId", roleId);
		params.put("userId", userId);
		Object obj=getSqlSessionTemplate().selectOne(getIbatisMapperNamesapce()+".isUserInRole", params);
		return obj!=null;
	}
}
