package com.basic.x01.helper;
|
|
import java.util.LinkedList;
|
import java.util.List;
|
|
import com.basic.x01.system.mapper.SystemMapper;
|
import com.basic.x01.system.model.TSysOrg;
|
import com.basic.x01.system.model.TSysUser;
|
|
/**
|
* 通用的用户操作类
|
*
|
* @company 北京贝思科技术有限公司
|
* @author liuyajun, 8384503@qq.com
|
* @date 2016年1月26日
|
* @time 下午5:02:30
|
*/
|
public class UserHelper {
|
|
public static boolean isAdmin(TSysUser user){
|
return user.getRole()!=null && "1".equals(user.getRole().getIsAdmin());
|
}
|
|
public static boolean isSchoolUser(TSysUser user){
|
return TSysOrg.ORG_TYPE_SCHOOL.equals(user.getOrg().getOrgType());
|
}
|
|
/**
|
* 查询指定用户的组织,包括下级全部的下级组织
|
* @param userMapper
|
* @param userId
|
* @return
|
*/
|
public static List<TSysOrg> getOrgListByUserId(SystemMapper userMapper, String userId){
|
TSysUser user = userMapper.getUserByUserId(userId);
|
|
return getOrgListTreeByRootOrgId(userMapper, user.getOrgId());
|
}
|
|
/**
|
*
|
* @param userMapper
|
* @param rootOrgId
|
* @return 包含 rootOrg
|
*/
|
public static List<TSysOrg> getOrgListTreeByRootOrgId(
|
SystemMapper userMapper, String rootOrgId){
|
TSysOrg rootOrg = userMapper.getOrgByOrgId(rootOrgId);
|
List<TSysOrg> list = new LinkedList<TSysOrg>();
|
|
List<TSysOrg> tmpList = new LinkedList<TSysOrg>();
|
tmpList.add(rootOrg);
|
|
while(tmpList!=null && tmpList.size()>0){
|
list.addAll(tmpList);
|
tmpList = userMapper.getOrgListByParOrgList(tmpList,
|
tmpList.get(0).getOrgType());
|
}
|
|
return list;
|
}
|
|
// /**
|
// * 获取用户所属的学校
|
// * @param userMapper
|
// * @param schoolMapper
|
// * @param userId
|
// * @return 如果为null,则不是学校用户
|
// */
|
// public static TSchool getUserSchool(
|
// UserMapper userMapper,
|
// SchoolMapper schoolMapper,
|
// String userId){
|
// TSysUser user = userMapper.getUserByUserId(userId);
|
// if(user==null){
|
// return null;
|
// }
|
// if(! ORG_TYPE_SCHOOL.equals(user.getOrgType())){
|
// return null;
|
// }
|
// String orgId = user.getOrgId();
|
// TSchool school = schoolMapper.getSchoolBySchoolId(orgId);
|
//
|
// return school;
|
// }
|
//
|
// /**
|
// * 获取指用定用户可以管理的行政区域
|
// * @param mapper
|
// * @param userId
|
// * @return
|
// */
|
// public static List<TRegion> getUserRegions(UserMapper mapper, String userId) {
|
// List<TRegion> pars = mapper.getUserDiectRegions(userId);
|
//
|
// List<TRegion> list = new LinkedList<TRegion>();
|
//
|
// while(pars!=null && pars.size()>0){
|
// list.addAll(pars);
|
//
|
// pars = mapper.getRegionByParent(pars);
|
// }
|
//
|
// return list;
|
// }
|
}
|