|
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
@@ -812,10 +813,14 @@ public class CompanyServiceImpl implements ICompanyService
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyUserRoleMapper companyUserRoleMapper;
|
|
@Override
|
|
@Override
|
|
public List<DeptDataVO> getDeptData(Long companyId, Long currentCompanyUserId, Long currentDeptId) {
|
|
public List<DeptDataVO> getDeptData(Long companyId, Long currentCompanyUserId, Long currentDeptId) {
|
|
List<DeptDataVO> result = new ArrayList<>();
|
|
List<DeptDataVO> result = new ArrayList<>();
|
|
|
|
|
|
|
|
+ Long isAdmin = companyUserRoleMapper.companyUserIsAdmin(currentCompanyUserId);
|
|
|
|
+
|
|
// 1. 获取所有部门数据
|
|
// 1. 获取所有部门数据
|
|
List<CompanyDept> allCompanyDepts = companyDeptMapper.queryDeptDataAll();
|
|
List<CompanyDept> allCompanyDepts = companyDeptMapper.queryDeptDataAll();
|
|
|
|
|
|
@@ -840,7 +845,7 @@ public class CompanyServiceImpl implements ICompanyService
|
|
}
|
|
}
|
|
|
|
|
|
// 6. 如果没有可见部门,直接返回空列表
|
|
// 6. 如果没有可见部门,直接返回空列表
|
|
- if (visibleDeptIds.isEmpty()) {
|
|
|
|
|
|
+ if (isAdmin == null && visibleDeptIds.isEmpty()) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -888,7 +893,7 @@ public class CompanyServiceImpl implements ICompanyService
|
|
visibleDeptIds,
|
|
visibleDeptIds,
|
|
deptPath,
|
|
deptPath,
|
|
currentDeptId,
|
|
currentDeptId,
|
|
- currentCompanyUserId);
|
|
|
|
|
|
+ currentCompanyUserId,isAdmin);
|
|
|
|
|
|
companyNode.setChildren(deptTree.isEmpty() ? null : deptTree);
|
|
companyNode.setChildren(deptTree.isEmpty() ? null : deptTree);
|
|
result.add(companyNode);
|
|
result.add(companyNode);
|
|
@@ -921,7 +926,8 @@ public class CompanyServiceImpl implements ICompanyService
|
|
Set<Long> visibleDeptIds,
|
|
Set<Long> visibleDeptIds,
|
|
List<Long> deptPath,
|
|
List<Long> deptPath,
|
|
Long currentDeptId,
|
|
Long currentDeptId,
|
|
- Long currentCompanyUserId) {
|
|
|
|
|
|
+ Long currentCompanyUserId,
|
|
|
|
+ Long isAdmin) {
|
|
|
|
|
|
if (depts == null || depts.isEmpty()) {
|
|
if (depts == null || depts.isEmpty()) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
@@ -929,7 +935,7 @@ public class CompanyServiceImpl implements ICompanyService
|
|
List<DeptDataVO> result = new ArrayList<>();
|
|
List<DeptDataVO> result = new ArrayList<>();
|
|
for (CompanyDept dept : depts) {
|
|
for (CompanyDept dept : depts) {
|
|
// 如果当前部门不在用户可见范围内,且不在部门路径中,则跳过
|
|
// 如果当前部门不在用户可见范围内,且不在部门路径中,则跳过
|
|
- if (!visibleDeptIds.contains(dept.getDeptId()) && !deptPath.contains(dept.getDeptId())) {
|
|
|
|
|
|
+ if (isAdmin == null && !visibleDeptIds.contains(dept.getDeptId()) && !deptPath.contains(dept.getDeptId())) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -945,14 +951,14 @@ public class CompanyServiceImpl implements ICompanyService
|
|
visibleDeptIds,
|
|
visibleDeptIds,
|
|
deptPath,
|
|
deptPath,
|
|
currentDeptId,
|
|
currentDeptId,
|
|
- currentCompanyUserId);
|
|
|
|
|
|
+ currentCompanyUserId,isAdmin);
|
|
if (!childDeptNodes.isEmpty()) {
|
|
if (!childDeptNodes.isEmpty()) {
|
|
children.addAll(childDeptNodes);
|
|
children.addAll(childDeptNodes);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 添加部门下的用户(需要权限控制)
|
|
// 添加部门下的用户(需要权限控制)
|
|
List<DeptDataVO> userNodes = new ArrayList<>();
|
|
List<DeptDataVO> userNodes = new ArrayList<>();
|
|
- if (visibleDeptIds.contains(dept.getDeptId())) {
|
|
|
|
|
|
+ if (visibleDeptIds.contains(dept.getDeptId()) || ObjectUtil.isNotNull(isAdmin)) {
|
|
List<CompanyUser> deptUsers = allUsersByDeptIdMap.get(dept.getDeptId());
|
|
List<CompanyUser> deptUsers = allUsersByDeptIdMap.get(dept.getDeptId());
|
|
if (deptUsers != null && !deptUsers.isEmpty()) {
|
|
if (deptUsers != null && !deptUsers.isEmpty()) {
|
|
for (CompanyUser user : deptUsers) {
|
|
for (CompanyUser user : deptUsers) {
|
|
@@ -1054,34 +1060,6 @@ public class CompanyServiceImpl implements ICompanyService
|
|
return companyNode;
|
|
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 +1104,6 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
|
|
|
return result;
|
|
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
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|