中扬CRM客户关系管理系统
#
luxiaotao1123
2022-09-19 f91e3a2507c6972fb15d7d91f0d0380dd4be0bef
src/main/java/com/zy/crm/common/utils/TreeUtils.java
@@ -7,8 +7,10 @@
import com.zy.crm.manager.service.NodeService;
import com.zy.crm.manager.service.TagService;
import com.zy.crm.system.entity.Dept;
import com.zy.crm.system.entity.Role;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.DeptService;
import com.zy.crm.system.service.RoleService;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
@@ -31,6 +33,8 @@
    private DeptService deptService;
    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    /******************************** 归类树 *********************************/
@@ -176,7 +180,7 @@
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="deptUserTree",key="#id")
    public ArrayList<Map<String, Object>> getDeptUserTree(String id, Long hostId){
    public ArrayList<Map<String, Object>> getDeptUserTree(String id, Long hostId, Long userId){
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        Dept dept = deptService.selectById(id);
        // 主节点
@@ -184,15 +188,16 @@
        map.put("title", dept.getName());
        map.put("id", dept.getId());
        map.put("spread", true);
        map.put("type", 0);
        map.put("key", "dept_id");
//        map.put("icon", "layui-icon layui-icon-star-fill");
        List<Map<String, Object>> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealUserDept(dept, childrens, hostId);
        dealUserDept(dept, childrens, hostId, userId);
        result.add(map);
        return result;
    }
    public void dealUserDept(Dept parent, List<Map<String, Object>> list, Long hostId) {
    public void dealUserDept(Dept parent, List<Map<String, Object>> list, Long hostId, Long userId) {
        Wrapper<Dept> wrapper = new EntityWrapper<Dept>()
                .eq("parent_id", parent.getId())
                .eq("status", 1);
@@ -201,12 +206,20 @@
        }
        List<Dept> depts = deptService.selectList(wrapper);
        List<User> users = userService.getUserByDept(hostId, parent.getId());
        List<User> users = new ArrayList<>();
        Role role = roleService.selectById(userService.selectById(userId).getRoleId());
        if (role.getCode().equals("salesman")) {
            users.add(userService.selectById(userId));
        } else {
            users = userService.getUserByDept(hostId, parent.getId());
        }
        for (User user : users) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", user.getNickname());
            map.put("id", user.getId());
            map.put("type", 1);
            map.put("key", "user_id");
            map.put("icon", "layui-icon layui-icon-friends");
            list.add(map);
        }
@@ -215,9 +228,11 @@
            map.put("title", dept.getName());
            map.put("id", dept.getId());
            map.put("spread", true);
            map.put("key", "dept_id");
//            map.put("icon", "layui-icon layui-icon-star-fill");
            List<Map<String, Object>> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealUserDept(dept, childrens, hostId);
            dealUserDept(dept, childrens, hostId, userId);
            list.add(map);
        }
    }