中扬CRM客户关系管理系统
#
luxiaotao1123
2022-09-11 c3385cb6fba4f40884df1cfb7f7c84b608cf54bc
src/main/java/com/zy/crm/common/utils/TreeUtils.java
@@ -2,6 +2,8 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.zy.crm.system.entity.Dept;
import com.zy.crm.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
@@ -23,6 +25,8 @@
    private TagService tagService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private DeptService deptService;
    /******************************** 归类树 *********************************/
@@ -116,6 +120,52 @@
        }
    }
    /******************************** 部门树 *********************************/
    /**
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="deptTree",key="#id")
    public ArrayList<Map> getDeptTree(String id, Long hostId){
        ArrayList<Map> result = new ArrayList<>();
        Dept dept = deptService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", dept.getName());
        map.put("id", dept.getId());
        map.put("spread", true);
        List<Map> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealDept(dept, childrens, hostId);
        result.add(map);
        // 开始处理字节点
//        deal(tag, childrens);
        return result;
    }
    /**
     * 递归获取子节点数据
     */
    public void dealDept(Dept parent, List<Map> list, Long hostId) {
        Wrapper<Dept> wrapper = new EntityWrapper<Dept>()
                .eq("parent_id", parent.getId())
                .eq("status", "1");
        if (hostId != null) {
            wrapper.eq("host_id", hostId);
        }
        List<Dept> depts = deptService.selectList(wrapper);
        for (Dept dept : depts) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", dept.getName());
            map.put("id", dept.getId());
            map.put("spread", true);
            List<Map> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealDept(dept, childrens, hostId);
            list.add(map);
        }
    }
    // -------------------------------------------------------------------------------------------------------