| | |
| | | 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.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); |
| | |
| | | } |
| | | 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("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); |
| | | } |
| | | } |