中扬CRM客户关系管理系统
#
lsh
2024-04-19 30350cae29ec19082a9810080e32fcddd4d9df17
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
package com.zy.crm.manager.utils;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.zy.crm.manager.entity.param.UserChildrenParam;
import com.zy.crm.system.entity.Dept;
import com.zy.crm.system.entity.Host;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.DeptService;
import com.zy.crm.system.service.HostService;
import com.zy.crm.system.service.UserService;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
public class UserChildrenParamUtils {
    private static Long id = 0L;
 
    public static UserChildrenParam getUserChildrenParamList(User user) {
        id = 1L;
        switch (user.getRoleId().intValue()){
            case 1:
            case 2:
                return getUserChildrenParamListDept(user.getDeptId());
            case 3:
                return getUserChildrenParam(user);
            default:
                return null;
        }
    }
 
    public static UserChildrenParam getUserChildrenParamListDept(Long deptId) {
        DeptService deptService = SpringUtils.getBean(DeptService.class);
        Dept dept = deptService.selectById(deptId);
        if (Cools.isEmpty(dept) || Cools.isEmpty(dept.getName())){
            return null;
        }
 
        UserService userService = SpringUtils.getBean(UserService.class);
        List<User> users = userService.selectList(new EntityWrapper<User>().eq("dept_id", dept.getId()));
 
        List<UserChildrenParam> list = new ArrayList<>();
 
        for (User userNow:users){
            id++;
            UserChildrenParam userChildrenParam = getUserChildrenParam(userNow);
            list.add(userChildrenParam);
        }
        if (dept.getLevel()!=2){
            List<Dept> deptList = deptService.selectList(new EntityWrapper<Dept>().eq("parent_id", dept.getId()));
            for (Dept dept1:deptList){
                UserChildrenParam userChildrenParamListDept = getUserChildrenParamListDept(dept1.getId());
                list.add(userChildrenParamListDept);
            }
        }
        id++;
        UserChildrenParam userChildrenParam = new UserChildrenParam(id,0L,dept.getId(),dept.getName(),list);
        return userChildrenParam;
    }
 
    public static UserChildrenParam getUserChildrenParam(User user) {
        UserChildrenParam userChildrenParam = new UserChildrenParam();
        userChildrenParam.setId(id);
        userChildrenParam.setUserId(user.getId());
        userChildrenParam.setDeptId(user.getDeptId());
        userChildrenParam.setLabel(user.getNickname());
        return userChildrenParam;
    }
 
}