|
@@ -1,10 +1,8 @@
|
|
|
package com.fs.company.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -18,22 +16,20 @@ import com.fs.company.service.ICompanyProfitService;
|
|
|
import com.fs.company.vo.CompanyCrmVO;
|
|
|
import com.fs.company.vo.CompanyNameVO;
|
|
|
import com.fs.company.vo.CompanyVO;
|
|
|
+import com.fs.company.vo.DeptDataVO;
|
|
|
import com.fs.his.config.StoreConfig;
|
|
|
import com.fs.his.domain.FsInquiryOrder;
|
|
|
-import com.fs.his.domain.FsPayConfig;
|
|
|
import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.domain.FsStorePayment;
|
|
|
import com.fs.his.dto.InquiryConfigDTO;
|
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
|
-import com.fs.his.service.IFsInquiryOrderService;
|
|
|
-import com.fs.his.service.impl.FsInquiryOrderServiceImpl;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.google.gson.Gson;
|
|
|
-import io.swagger.models.auth.In;
|
|
|
-import lombok.Synchronized;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang.ObjectUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -77,6 +73,13 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
private ICompanyProfitService companyProfitService;
|
|
|
@Autowired
|
|
|
private SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyDeptMapper companyDeptMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<OptionsVO> selectAllCompanyList() {
|
|
|
return companyMapper.selectAllCompanyList();
|
|
@@ -528,6 +531,427 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
return companyMapper.selectCompanyIds() ;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String selectCompanyByIds(String companyIds) {
|
|
|
+ return companyMapper.selectCompanyNameCompanyByIds(companyIds);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DeptDataVO> getDeptData(Long companyId) {
|
|
|
+ List<DeptDataVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取用户按部门分组的数据
|
|
|
+ Map<Long, List<CompanyUser>> companyUserGroupByDeptId = getCompanyUserGroupByDeptId();
|
|
|
+ // 获取部门按公司分组的数据
|
|
|
+ Map<Long, List<CompanyDept>> companyDeptGroupByCompanyId = getCompanyDeptGroupByCompanyId();
|
|
|
+ // 获取子部门按父部门分组的数据
|
|
|
+ Map<Long, List<CompanyDept>> deptGroupByParentId = getDeptGroupByParentId();
|
|
|
+
|
|
|
+ if (companyId != null) {
|
|
|
+ Company company = companyMapper.selectCompanyById(companyId);
|
|
|
+ if (company != null) {
|
|
|
+ DeptDataVO companyNode = buildCompanyNode(company, companyUserGroupByDeptId,
|
|
|
+ companyDeptGroupByCompanyId, deptGroupByParentId);
|
|
|
+ result.add(companyNode);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<Company> companies = companyMapper.selectCompanyAllList();
|
|
|
+ if (companies != null && !companies.isEmpty()) {
|
|
|
+ for (Company company : companies) {
|
|
|
+ DeptDataVO companyNode = buildCompanyNode(company, companyUserGroupByDeptId,
|
|
|
+ companyDeptGroupByCompanyId, deptGroupByParentId);
|
|
|
+ result.add(companyNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result.stream()
|
|
|
+ .filter(e -> CollectionUtils.isNotEmpty(e.getChildren()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DeptDataVO> getDeptData(Long companyId, Long currentCompanyUserId, Long currentDeptId) {
|
|
|
+ List<DeptDataVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 1. 获取所有部门数据
|
|
|
+ List<CompanyDept> allCompanyDepts = companyDeptMapper.queryDeptDataAll();
|
|
|
+
|
|
|
+ // 2. 按部门ID分组,方便直接获取部门信息
|
|
|
+ Map<Long, CompanyDept> deptMapById = allCompanyDepts.stream()
|
|
|
+ .filter(e -> e.getDeptId() != null)
|
|
|
+ .collect(Collectors.toMap(CompanyDept::getDeptId, dept -> dept, (a, b) -> a));
|
|
|
+
|
|
|
+ // 3. 按父部门ID分组,用于构建树结构
|
|
|
+ Map<Long, List<CompanyDept>> deptsByParentIdMap = allCompanyDepts.stream()
|
|
|
+ .filter(e -> e.getParentId() != null && e.getDeptId() != null)
|
|
|
+ .collect(Collectors.groupingBy(CompanyDept::getParentId));
|
|
|
+
|
|
|
+ // 4. 获取所有用户数据并按部门分组
|
|
|
+ Map<Long, List<CompanyUser>> allUsersByDeptIdMap = getCompanyUserGroupByDeptId();
|
|
|
+
|
|
|
+ // 5. 获取当前用户可见的部门ID集合(本部门及下级部门)
|
|
|
+ Set<Long> visibleDeptIds = new HashSet<>();
|
|
|
+ if (currentDeptId != null) {
|
|
|
+ visibleDeptIds.add(currentDeptId); // 添加当前部门
|
|
|
+ collectSubDepartments(currentDeptId, visibleDeptIds, deptsByParentIdMap); // 添加所有下级部门
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 如果没有可见部门,直接返回空列表
|
|
|
+ if (visibleDeptIds.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 获取公司信息
|
|
|
+ Company company = companyMapper.selectCompanyById(companyId);
|
|
|
+ if (company == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8. 构建公司节点
|
|
|
+ DeptDataVO companyNode = new DeptDataVO();
|
|
|
+ companyNode.setLabel(company.getCompanyName());
|
|
|
+ companyNode.setId("company_"+company.getCompanyId());
|
|
|
+
|
|
|
+ // 9. 构建部门树(仅包含可见部门)
|
|
|
+ // 先找到当前部门对象
|
|
|
+ CompanyDept currentDept = deptMapById.get(currentDeptId);
|
|
|
+ if (currentDept == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前部门的所有上级部门路径
|
|
|
+ List<Long> deptPath = new ArrayList<>();
|
|
|
+ Long tempDeptId = currentDeptId;
|
|
|
+ while (tempDeptId != null && tempDeptId > 0) {
|
|
|
+ CompanyDept dept = deptMapById.get(tempDeptId);
|
|
|
+ if (dept == null) break;
|
|
|
+ deptPath.add(tempDeptId);
|
|
|
+ tempDeptId = dept.getParentId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建以公司为根的树形结构
|
|
|
+ // 找出顶级部门(parentId为null或0的部门)
|
|
|
+ List<CompanyDept> rootDepts = allCompanyDepts.stream()
|
|
|
+ .filter(dept -> dept.getCompanyId() != null &&
|
|
|
+ dept.getCompanyId().equals(companyId) &&
|
|
|
+ (dept.getParentId() == null || dept.getParentId().equals(0L)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 递归构建带权限的树
|
|
|
+ List<DeptDataVO> deptTree = buildDeptTreeWithPermission(
|
|
|
+ rootDepts,
|
|
|
+ allUsersByDeptIdMap,
|
|
|
+ deptsByParentIdMap,
|
|
|
+ visibleDeptIds,
|
|
|
+ deptPath,
|
|
|
+ currentDeptId,
|
|
|
+ currentCompanyUserId);
|
|
|
+
|
|
|
+ companyNode.setChildren(deptTree.isEmpty() ? null : deptTree);
|
|
|
+ result.add(companyNode);
|
|
|
+
|
|
|
+ // 过滤掉空公司节点
|
|
|
+ return result.stream()
|
|
|
+ .filter(node -> node.getChildren() != null && !node.getChildren().isEmpty())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 递归收集所有下级部门ID
|
|
|
+ */
|
|
|
+ private void collectSubDepartments(Long parentDeptId, Set<Long> deptIds, Map<Long, List<CompanyDept>> deptsByParentIdMap) {
|
|
|
+ List<CompanyDept> childDepts = deptsByParentIdMap.get(parentDeptId);
|
|
|
+ if (childDepts != null && !childDepts.isEmpty()) {
|
|
|
+ for (CompanyDept childDept : childDepts) {
|
|
|
+ if (childDept.getDeptId() != null && deptIds.add(childDept.getDeptId())) {
|
|
|
+ collectSubDepartments(childDept.getDeptId(), deptIds, deptsByParentIdMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 递归构建带权限控制的部门树
|
|
|
+ */
|
|
|
+ private List<DeptDataVO> buildDeptTreeWithPermission(
|
|
|
+ List<CompanyDept> depts,
|
|
|
+ Map<Long, List<CompanyUser>> allUsersByDeptIdMap,
|
|
|
+ Map<Long, List<CompanyDept>> deptsByParentIdMap,
|
|
|
+ Set<Long> visibleDeptIds,
|
|
|
+ List<Long> deptPath,
|
|
|
+ Long currentDeptId,
|
|
|
+ Long currentCompanyUserId) {
|
|
|
+
|
|
|
+ if (depts == null || depts.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<DeptDataVO> result = new ArrayList<>();
|
|
|
+ for (CompanyDept dept : depts) {
|
|
|
+ // 如果当前部门不在用户可见范围内,且不在部门路径中,则跳过
|
|
|
+ if (!visibleDeptIds.contains(dept.getDeptId()) && !deptPath.contains(dept.getDeptId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先递归构建子部门
|
|
|
+ List<CompanyDept> childDepts = deptsByParentIdMap.get(dept.getDeptId());
|
|
|
+ List<DeptDataVO> children = new ArrayList<>();
|
|
|
+
|
|
|
+ if (childDepts != null && !childDepts.isEmpty()) {
|
|
|
+ List<DeptDataVO> childDeptNodes = buildDeptTreeWithPermission(
|
|
|
+ childDepts,
|
|
|
+ allUsersByDeptIdMap,
|
|
|
+ deptsByParentIdMap,
|
|
|
+ visibleDeptIds,
|
|
|
+ deptPath,
|
|
|
+ currentDeptId,
|
|
|
+ currentCompanyUserId);
|
|
|
+ if (!childDeptNodes.isEmpty()) {
|
|
|
+ children.addAll(childDeptNodes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加部门下的用户(需要权限控制)
|
|
|
+ List<DeptDataVO> userNodes = new ArrayList<>();
|
|
|
+ if (visibleDeptIds.contains(dept.getDeptId())) {
|
|
|
+ List<CompanyUser> deptUsers = allUsersByDeptIdMap.get(dept.getDeptId());
|
|
|
+ if (deptUsers != null && !deptUsers.isEmpty()) {
|
|
|
+ for (CompanyUser user : deptUsers) {
|
|
|
+ // 如果是当前部门,只显示当前用户
|
|
|
+ if (dept.getDeptId().equals(currentDeptId)) {
|
|
|
+ if (user.getUserId().equals(currentCompanyUserId)) {
|
|
|
+ DeptDataVO userNode = new DeptDataVO();
|
|
|
+ userNode.setLabel(user.getNickName() + "_" + user.getUserName());
|
|
|
+ userNode.setId("user_"+user.getUserId());
|
|
|
+ userNode.setChildren(null);
|
|
|
+ userNodes.add(userNode);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 非当前部门,显示所有用户
|
|
|
+ DeptDataVO userNode = new DeptDataVO();
|
|
|
+ userNode.setLabel(user.getNickName() + "_" + user.getUserName());
|
|
|
+ userNode.setId("user_"+user.getUserId());
|
|
|
+ userNode.setChildren(null);
|
|
|
+ userNodes.add(userNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将用户节点添加到子节点列表
|
|
|
+ if (!userNodes.isEmpty()) {
|
|
|
+ children.addAll(userNodes);
|
|
|
+ }
|
|
|
+ // 只有当下面有子部门或者有用户时,才添加此部门
|
|
|
+ if (!children.isEmpty()) {
|
|
|
+ DeptDataVO deptNode = new DeptDataVO();
|
|
|
+ deptNode.setLabel(dept.getDeptName());
|
|
|
+ deptNode.setId("dept_"+dept.getDeptId());
|
|
|
+ deptNode.setChildren(children);
|
|
|
+ result.add(deptNode);
|
|
|
+ } else if (deptPath.contains(dept.getDeptId())) {
|
|
|
+ // 即使没有子部门和用户,如果是部门路径上的节点,仍然需要添加
|
|
|
+ DeptDataVO deptNode = new DeptDataVO();
|
|
|
+ deptNode.setLabel(dept.getDeptName());
|
|
|
+ deptNode.setId("dept_"+dept.getDeptId());
|
|
|
+ deptNode.setChildren(null);
|
|
|
+ result.add(deptNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取用户按部门ID分组
|
|
|
+ */
|
|
|
+ public Map<Long, List<CompanyUser>> getCompanyUserGroupByDeptId() {
|
|
|
+ List<CompanyUser> userList = companyUserMapper.selectAllCompanyUserList();
|
|
|
+ return userList.stream()
|
|
|
+ .filter(user -> user.getDeptId() != null)
|
|
|
+ .collect(Collectors.groupingBy(CompanyUser::getDeptId));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门按公司ID分组
|
|
|
+ */
|
|
|
+ public Map<Long, List<CompanyDept>> getCompanyDeptGroupByCompanyId() {
|
|
|
+ List<CompanyDept> companyDepts = companyDeptMapper.queryDeptDataAll();
|
|
|
+ return companyDepts.stream()
|
|
|
+ .collect(Collectors.groupingBy(CompanyDept::getCompanyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门按父部门ID分组(新增方法)
|
|
|
+ */
|
|
|
+ public Map<Long, List<CompanyDept>> getDeptGroupByParentId() {
|
|
|
+ List<CompanyDept> companyDepts = companyDeptMapper.queryDeptDataAll();
|
|
|
+ return companyDepts.stream()
|
|
|
+ .filter(dept -> dept.getParentId() != null) // 过滤掉顶级部门
|
|
|
+ .collect(Collectors.groupingBy(CompanyDept::getParentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建公司节点,包含其下属多级部门和用户
|
|
|
+ */
|
|
|
+ private DeptDataVO buildCompanyNode(Company company,
|
|
|
+ Map<Long, List<CompanyUser>> companyUserGroupByDeptId,
|
|
|
+ Map<Long, List<CompanyDept>> companyDeptGroupByCompanyId,
|
|
|
+ Map<Long, List<CompanyDept>> deptGroupByParentId) {
|
|
|
+ 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);
|
|
|
+ companyNode.setChildren(deptDataList.isEmpty() ? null : deptDataList);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归构建部门树
|
|
|
+ */
|
|
|
+ private List<DeptDataVO> buildDeptTree(List<CompanyDept> depts,
|
|
|
+ Map<Long, List<CompanyUser>> companyUserGroupByDeptId,
|
|
|
+ Map<Long, List<CompanyDept>> deptGroupByParentId) {
|
|
|
+ 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) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 递归构建部门树
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @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
|
|
|
public void refundCompanyMoney(FsStoreOrder order) {
|