/*
 * 该Dao主要负责该类同名表或其他与之关联表的操作
 * 如增删改查等操作,该类不负责系统业务逻辑的处理,主要业务逻辑的实现在对应的Manager中
 */
 
package com.blueland.bpm.identity.dao;
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.Org;
import com.blueland.bpm.identity.model.Role;
import com.blueland.bpm.identity.model.User;


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

@Repository
public class UserQueryDao extends BaseIbatis3Dao<User,String>{
	@Override
	public String getIbatisMapperNamesapce() {
		return "WFUser";
	}
	public List<User> findUserByRole(Role role) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserByRole", role);
	}
	public List<String> findUserIdByRole(String roleId) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserIdByRole", roleId);
	}
	public List<User> findUserIdByRoleCascade(Role role) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserIdByRoleCascade", role);
	}
	/**
	 * 根据map中传递的参数查询
	 * @param params
	 * @return
	 */
	public List<User> findUserByRoleCascade(Map<String,Object> params) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserByRoleCascade", params);
	}
	
	public List<User> findAllUserByRole(Role role) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findAllUserByRole", role);
	}
	public List<User> findUserTree(Org org) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserTreeByOrgId", org);
	}
	
	public List<User> findUserByOrg(Org org) {
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".findUserByOrg", org);
	}
	
	public List<User> getUserByUserNameOrUserCode(String userName,String userCode){
		return getSqlSessionTemplate().selectList(getIbatisMapperNamesapce()+".getUserByUserNameOrUserCode", userName);
	}
	
	public long findUserCount(User user) {
		Number totalCount = (Number) getSqlSessionTemplate().selectOne(getIbatisMapperNamesapce()+".findUserCount",user);
		if(totalCount == null || totalCount.longValue() <= 0) {
			return 0;
		}
		return totalCount.longValue();
	}
}
