|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | private DeptService deptService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RoleService roleService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /******************************** 归类树 *********************************/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 获取树图数据结构 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | // 主节点 | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("title", dept.getName()); | 
|---|
|  |  |  | map.put("id", dept.getId()); | 
|---|
|  |  |  | map.put("spread", true); | 
|---|
|  |  |  | //        map.put("icon", "layui-icon layui-icon-star-fill"); | 
|---|
|  |  |  | List<Map<String, Object>> childrens = new ArrayList<>(); | 
|---|
|  |  |  | map.put("children", childrens); | 
|---|
|  |  |  | dealUserDept(dept, childrens, hostId); | 
|---|
|  |  |  | result.add(map); | 
|---|
|  |  |  | User user = userService.selectById(userId); | 
|---|
|  |  |  | Role role = roleService.selectById(user.getRoleId()); | 
|---|
|  |  |  | if (role.getCode().equals("salesman")) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("title", user.getNickname()); | 
|---|
|  |  |  | map.put("id", user.getId()); | 
|---|
|  |  |  | map.put("key", "user_id"); | 
|---|
|  |  |  | map.put("icon", "layui-icon layui-icon-friends"); | 
|---|
|  |  |  | result.add(map); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (role.getId()==1){ | 
|---|
|  |  |  | id="19"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | map.put("key", "dept_id"); | 
|---|
|  |  |  | List<Map<String, Object>> childrens = new ArrayList<>(); | 
|---|
|  |  |  | map.put("children", childrens); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | // 人员 | 
|---|
|  |  |  | List<User> users = roleService.getUserByRoleCode(hostId, parent.getId(), userId); | 
|---|
|  |  |  | for (User user : users) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("title", user.getNickname()); | 
|---|
|  |  |  | map.put("id", user.getId()); | 
|---|
|  |  |  | map.put("key", "user_id"); | 
|---|
|  |  |  | map.put("icon", "layui-icon layui-icon-friends"); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 部门 | 
|---|
|  |  |  | Wrapper<Dept> wrapper = new EntityWrapper<Dept>() | 
|---|
|  |  |  | .eq("parent_id", parent.getId()) | 
|---|
|  |  |  | .eq("status", 1); | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.eq("host_id", hostId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dept> depts = deptService.selectList(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<User> 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("icon", "layui-icon layui-icon-friends"); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Dept dept : depts) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("title", dept.getName()); | 
|---|
|  |  |  | map.put("id", dept.getId()); | 
|---|
|  |  |  | map.put("spread", true); | 
|---|
|  |  |  | //            map.put("icon", "layui-icon layui-icon-star-fill"); | 
|---|
|  |  |  | map.put("key", "dept_id"); | 
|---|
|  |  |  | List<Map<String, Object>> childrens = new ArrayList<>(); | 
|---|
|  |  |  | map.put("children", childrens); | 
|---|
|  |  |  | dealUserDept(dept, childrens, hostId); | 
|---|
|  |  |  | dealUserDept(dept, childrens, hostId, userId); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|