| | |
| | | |
| | | 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; |
| | |
| | | private TagService tagService; |
| | | @Autowired |
| | | private NodeService nodeService; |
| | | @Autowired |
| | | private DeptService deptService; |
| | | |
| | | /******************************** 归类树 *********************************/ |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /******************************** 部门树 *********************************/ |
| | | |
| | | /** |
| | | * 获取树图数据结构 |
| | | */ |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | |
| | | // ------------------------------------------------------------------------------------------------------- |
| | | |