|
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.R;
|
|
@@ -812,10 +813,17 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserRoleMapper companyUserRoleMapper;
|
|
|
@Override
|
|
|
public List<DeptDataVO> getDeptData(Long companyId, Long currentCompanyUserId, Long currentDeptId) {
|
|
|
List<DeptDataVO> result = new ArrayList<>();
|
|
|
|
|
|
+ Long isAdmin = companyUserRoleMapper.companyUserIsAdmin(currentCompanyUserId);
|
|
|
+ logger.info("当前用户 {} 是公司admin 返回公司所有部门树",currentDeptId);
|
|
|
+ if(isAdmin!=null){
|
|
|
+ return getDeptData(companyId);
|
|
|
+ }
|
|
|
// 1. 获取所有部门数据
|
|
|
List<CompanyDept> allCompanyDepts = companyDeptMapper.queryDeptDataAll();
|
|
|
|
|
@@ -1054,34 +1062,6 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
return companyNode;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建公司节点,包含其下属多级部门和用户
|
|
|
- */
|
|
|
- private DeptDataVO buildCompanyNode(Company company,
|
|
|
- Map<Long, List<CompanyUser>> companyUserGroupByDeptId,
|
|
|
- Map<Long, List<CompanyDept>> companyDeptGroupByCompanyId,
|
|
|
- Map<Long, List<CompanyDept>> deptGroupByParentId,
|
|
|
- Long currentDeptId,
|
|
|
- Long currentCompanyUserId
|
|
|
- ) {
|
|
|
- DeptDataVO companyNode = new DeptDataVO();
|
|
|
- companyNode.setLabel(company.getCompanyName());
|
|
|
- companyNode.setId("company_"+company.getCompanyId());
|
|
|
-
|
|
|
- // 获取公司下的顶级部门(parentId为null或为公司ID的部门)
|
|
|
- List<CompanyDept> topLevelDepts = companyDeptGroupByCompanyId.get(company.getCompanyId());
|
|
|
- if (topLevelDepts != null) {
|
|
|
- topLevelDepts = topLevelDepts.stream()
|
|
|
- .filter(dept -> dept.getParentId() == null || dept.getParentId().equals(0L))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- List<DeptDataVO> deptDataList = buildDeptTree(topLevelDepts, companyUserGroupByDeptId, deptGroupByParentId,currentDeptId,currentCompanyUserId);
|
|
|
- companyNode.setChildren(deptDataList.isEmpty() ? null : deptDataList);
|
|
|
-
|
|
|
- return companyNode;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 递归构建部门树
|
|
|
*/
|
|
@@ -1126,72 +1106,6 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
- /**
|
|
|
- * 递归构建部门树
|
|
|
- */
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param depts
|
|
|
- * @param companyUserGroupByDeptId
|
|
|
- * @param deptGroupByParentId
|
|
|
- * @param currentDeptId 当前部门id
|
|
|
- * @param currentCompanyUserId 当前销售id
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<DeptDataVO> buildDeptTree(List<CompanyDept> depts,
|
|
|
- Map<Long, List<CompanyUser>> companyUserGroupByDeptId,
|
|
|
- Map<Long, List<CompanyDept>> deptGroupByParentId,
|
|
|
- Long currentDeptId,
|
|
|
- Long currentCompanyUserId) {
|
|
|
- if (depts == null || depts.isEmpty()) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- List<DeptDataVO> result = new ArrayList<>();
|
|
|
-
|
|
|
- for (CompanyDept dept : depts) {
|
|
|
- DeptDataVO deptNode = new DeptDataVO();
|
|
|
- deptNode.setLabel(dept.getDeptName());
|
|
|
- deptNode.setId("dept_"+dept.getDeptId());
|
|
|
-
|
|
|
- List<DeptDataVO> children = new ArrayList<>();
|
|
|
-
|
|
|
- // 1. 添加子部门(递归)
|
|
|
- List<CompanyDept> childDepts = deptGroupByParentId.get(dept.getDeptId());
|
|
|
- if (childDepts != null && !childDepts.isEmpty()) {
|
|
|
- List<DeptDataVO> childDeptNodes = buildDeptTree(childDepts, companyUserGroupByDeptId, deptGroupByParentId);
|
|
|
- children.addAll(childDeptNodes);
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 添加部门下的用户
|
|
|
- List<CompanyUser> deptUsers = companyUserGroupByDeptId.get(dept.getDeptId());
|
|
|
- if (deptUsers != null && !deptUsers.isEmpty()) {
|
|
|
- for (CompanyUser user : deptUsers) {
|
|
|
- // 如果是销售当前部门,不显示同级其他销售
|
|
|
- if(ObjectUtils.equals(dept.getDeptId(),currentDeptId)) {
|
|
|
- if(ObjectUtils.equals(user.getUserId(),currentCompanyUserId)) {
|
|
|
- DeptDataVO userNode = new DeptDataVO();
|
|
|
- userNode.setLabel(user.getNickName()+"_"+user.getUserName());
|
|
|
- userNode.setId("user_"+user.getUserId());
|
|
|
- userNode.setChildren(null);
|
|
|
- children.add(userNode);
|
|
|
- }
|
|
|
- } else {
|
|
|
- DeptDataVO userNode = new DeptDataVO();
|
|
|
- userNode.setLabel(user.getNickName()+"_"+user.getUserName());
|
|
|
- userNode.setId("user_"+user.getUserId());
|
|
|
- userNode.setChildren(null);
|
|
|
- children.add(userNode);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- deptNode.setChildren(children.isEmpty() ? null : children);
|
|
|
- result.add(deptNode);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|