liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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;
//    }
}