Browse Source

feature(机构树节点查询修改): 机构树节点查询修改

机构树节点查询修改
mazq 3 years ago
parent
commit
639f6bded3

+ 33 - 0
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/sub/facade/IAuthOrgInfoFacade.java

@@ -1,6 +1,7 @@
 package com.dragoninfo.dcuc.auth.sub.facade;
 
 import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
+import com.dragoninfo.dcuc.auth.sub.dto.OrgQuotaNumDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
@@ -108,4 +109,36 @@ public interface IAuthOrgInfoFacade {
      */
     @GetMapping("getChildById")
     List<OrgTreeNodeDTO> getChildById(@RequestParam(value = "id", required = false) String id);
+
+    /**
+     * 获取满足条件的子级机构和数量
+     * 子级机构为orgId的满足条件的下一级机构
+     * 数量为所有满足条件的机构数量
+     *
+     * @param userId    人员id
+     * @param orgId     机构id
+     * @param unitClass 机构类别
+     * @param roleLevel 角色层级
+     * @return
+     */
+    @GetMapping("searchOrgForQuota")
+    OrgQuotaNumDTO searchOrgForQuota(@RequestParam("userId") String userId,
+                                     @RequestParam("orgId") String orgId,
+                                     @RequestParam("unitClass") String unitClass,
+                                     @RequestParam("roleLevel") String roleLevel);
+
+
+    /**
+     *
+     * @param userId    人员id
+     * @param orgId     机构id
+     * @param unitClass 机构类别
+     * @param roleLevel 角色层级
+     * @return
+     */
+    @GetMapping("getCalQuotaTree")
+    List<OrgTreeNodeDTO> getCalQuotaTree(@RequestParam("userId") String userId,
+                                         @RequestParam("orgId") String orgId,
+                                         @RequestParam("unitClass") String unitClass,
+                                         @RequestParam("roleLevel") String roleLevel);
 }

+ 30 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/sub/dto/OrgQuotaNumDTO.java

@@ -0,0 +1,30 @@
+package com.dragoninfo.dcuc.auth.sub.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author mazq
+ * @date 2021/9/29
+ */
+@Data
+public class OrgQuotaNumDTO {
+
+    /**
+     * 满足过滤条件的树节点集合
+     */
+    private List<OrgTreeNodeDTO> resultTreeNodes;
+
+    /**
+     * 所有子节点集合
+     */
+    private List<OrgTreeNodeDTO> allTreeNodes;
+
+    /**
+     * 总数量
+     */
+    private Integer count;
+
+
+}

+ 1 - 5
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/admin/service/impl/ManageInfoService.java

@@ -15,7 +15,6 @@ import com.dragoninfo.dcuc.auth.admin.vo.AdminAuditVO;
 import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
-import com.dragoninfo.dcuc.auth.sub.service.IAuthOrgInfoService;
 import com.dragoninfo.dcuc.auth.sub.service.IAuthOrgTreeService;
 import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
 import com.dragoninfo.dcuc.duceap.facade.ICodeListResourceFacade;
@@ -68,9 +67,6 @@ public class ManageInfoService implements IManageInfoService {
     @Autowired
     private IMgeLogService iMgeLogService;
 
-    @Autowired
-    private IAuthOrgInfoService authOrgInfoService;
-
     @Autowired
     private IAuthOrgTreeService authOrgTreeService;
 
@@ -288,7 +284,7 @@ public class ManageInfoService implements IManageInfoService {
         AuthUserInfo userInfo = authUserInfoService.findById(userId);
         String orgId = userInfo.getOrgId();
         //  TODO
-        List<OrgTreeNodeDTO> list = authOrgTreeService.getChildById(orgId);
+        List<OrgTreeNodeDTO> list = authOrgTreeService.getOneLevelChildById(orgId);
         if (CollectionUtils.isEmpty(list)) {
             return false;
         }

+ 29 - 27
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/OrgQuotaAuthService.java

@@ -10,10 +10,11 @@ import com.dragoninfo.dcuc.auth.auth.dto.OrgQuotaOpeDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.OrgQuotaAuthInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.OrgQuotaAuthLog;
 import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
-import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
 import com.dragoninfo.dcuc.auth.auth.service.IOrgQuotaAuthLogService;
 import com.dragoninfo.dcuc.auth.auth.service.IOrgQuotaAuthService;
 import com.dragoninfo.dcuc.auth.auth.service.IStaffAssignAuthInfoService;
+import com.dragoninfo.dcuc.auth.sub.business.IAuthOrgBusiness;
+import com.dragoninfo.dcuc.auth.sub.dto.OrgQuotaNumDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthOrgInfo;
 import com.dragoninfo.dcuc.auth.sub.service.IAuthOrgInfoService;
@@ -23,7 +24,6 @@ import com.dragoninfo.duceap.commons.util.server.OrgInfoUtil;
 import com.dragoninfo.duceap.core.service.impl.BaseService;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
-import com.dragonsoft.duceap.base.entity.security.BaseSecurityUser;
 import com.dragonsoft.duceap.base.entity.security.SecurityUser;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.base.utils.UserContextUtils;
@@ -65,6 +65,9 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
     @Autowired
     private IAuthOrgTreeService authOrgTreeService;
 
+    @Autowired
+    private IAuthOrgBusiness authOrgBusiness;
+
     @Autowired
     private IAppMtAuthFacade appMtAuthFacade;
 
@@ -169,7 +172,7 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
         long time2 = System.currentTimeMillis();
         logger.info("authCancelChild:orgInfoFacade.detail耗时:{} ms", (time2 - time1));
         //  TODO
-        List<String> childIds = authOrgTreeService.getChildById(orgId)
+        List<String> childIds = authOrgTreeService.getOneLevelChildById(orgId)
                 .stream().map(OrgTreeNodeDTO::getId).collect(Collectors.toList());
         long time3 = System.currentTimeMillis();
         logger.info("authCancelChild:orgInfoFacade.getChildrenIds耗时:{} ms", (time3 - time2));
@@ -223,7 +226,7 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
     private int cancelQuota(String orgId, String appMtAuths, List<OrgQuotaAuthInfo> updateList, Map<String, OrgQuotaAuthInfo> orgQuotaAuthInfoMap) {
         int count = 0;
         //  TODO
-        List<String> childrenIds = authOrgTreeService.getChildById(orgId)
+        List<String> childrenIds = authOrgTreeService.getOneLevelChildById(orgId)
                 .stream().map(OrgTreeNodeDTO::getId).collect(Collectors.toList());
 
         if (CollectionUtils.isNotEmpty(childrenIds)) {
@@ -241,7 +244,7 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
             return count;
         }
         //  TODO
-        List<OrgTreeNodeDTO> list = authOrgTreeService.getChildById(orgId);
+        List<OrgTreeNodeDTO> list = authOrgTreeService.getOneLevelChildById(orgId);
         if (CollectionUtils.isEmpty(list)) {
             return count;
         }
@@ -374,7 +377,6 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
      *
      * @param
      */
-//    SecurityUser userInfo, String appId, String roleId, String rootId, String unitClass, String roleLevel, String targetOrgLevel, int addNum
     @Override
     public ResponseStatus orgQutaInfoCalSave(OrgQuotaOpeDTO orgQuotaOpeDTO) {
         SecurityUser userInfo = orgQuotaOpeDTO.getSecurityUser();
@@ -388,32 +390,28 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
 
         String userId = userInfo.getId();
 
-        //  TODO
-        Map<String, Object> resultMap = null/*orgInfoFacade.searchOrg(userId, rootId, unitClass, roleLevel)*/;
+        OrgQuotaNumDTO orgQuotaNumDTO = authOrgBusiness.searchOrg(userId, rootId, unitClass, roleLevel);
 
         ApplyInfo applyInfo = applyInfoFacade.applyDetail(appId);
 
         AuthOrgInfo rootOrg = authOrgInfoService.findById(rootId);
-        int count = (Integer) resultMap.get("count");
+        int count = orgQuotaNumDTO.getCount();
         OrgQuotaAuthInfo rootOrgQuota = orgQuotaAuthInfoBpo.getOrgQuotoAuthInfo(appId, roleId, rootId);//获取当前本级机构配额信息
         //判断空闲名额是否足够
         if (!rootId.equals(applyInfo.getOrgId()) && (rootOrgQuota == null || rootOrgQuota.getDfpNum() < count * addNum)) {
             int kxme = rootOrgQuota == null ? 0 : rootOrgQuota.getDfpNum();
             return ResponseStatus.fail("机构【" + rootOrg.getFullName() + "】空闲名额不足,当前空闲名额为:" + kxme + ",所需下发名额为:" + addNum * count);
         }
-        List<Map> allList = (List<Map>) resultMap.get("allList");
+        List<OrgTreeNodeDTO> resultTreeNodes = orgQuotaNumDTO.getResultTreeNodes();
         Map<String, OrgQuotaAuthInfo> orgQuotaMap = getOrgQuotaAuthInfoMap(roleId);
         final List<OrgQuotaAuthInfo> orgQuotaAuthInfos = new ArrayList<OrgQuotaAuthInfo>();
-        for (Map orgTreeNode : allList) {
-            if (!(Boolean) orgTreeNode.get("treeNode") && (int) orgTreeNode.get("count") == 0) {    //没有变化的节点
-                continue;
-            }
+        for (OrgTreeNodeDTO orgTreeNode : resultTreeNodes) {
             if (StringUtils.isNotBlank(targetOrgLevel)) {
                 //有配额但不下发
-                if (StringUtils.isBlank((String) orgTreeNode.get("orgLevel")) || Integer.parseInt((String) orgTreeNode.get("orgLevel")) > Integer.parseInt(targetOrgLevel)) {
+                if (StringUtils.isBlank(orgTreeNode.getOrgLevel()) || Integer.parseInt(orgTreeNode.getOrgLevel()) > Integer.parseInt(targetOrgLevel)) {
                     continue;
                 } else {
-                    boolean flag = Integer.parseInt((String) orgTreeNode.get("orgLevel")) == Integer.parseInt(targetOrgLevel);  //机构层级与分配范围的层级相等
+                    boolean flag = Integer.parseInt(orgTreeNode.getOrgLevel()) == Integer.parseInt(targetOrgLevel);  //机构层级与分配范围的层级相等
                     OrgQuotaAuthInfo orgQuotaAuthInfo = newOrUpdateOrgQuota(orgQuotaMap, orgTreeNode, flag, addNum, userInfo, appId, roleId);
                     orgQuotaAuthInfos.add(orgQuotaAuthInfo);
                 }
@@ -427,10 +425,14 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
         boolean flag = StringUtils.isNotBlank(targetOrgLevel) && StringUtils.isNotBlank(orgLevel)
                 && Integer.parseInt(orgLevel) == Integer.parseInt(targetOrgLevel); //根节点机构层级与分配范围的层级相等
         if (rootId.equals(applyInfo.getOrgId())) {   //根节点为应用所属机构
-            Map rootOrgTreeNode = new HashMap();
-            rootOrgTreeNode.put("value", rootId);
-            rootOrgTreeNode.put("count", count);
-            rootOrgTreeNode.put("treeNode", false);
+            OrgTreeNodeDTO rootOrgTreeNode = new OrgTreeNodeDTO();
+            rootOrgTreeNode.setIsParent(false);
+            rootOrgTreeNode.setId(rootId);
+            List<String> childIds = new ArrayList<>();
+            for (int i = 0; i < count; i++) {
+                childIds.add("0");
+            }
+            rootOrgTreeNode.setChildIds(childIds);
             OrgQuotaAuthInfo orgQuotaAuthInfo = newOrUpdateOrgQuota(orgQuotaMap, rootOrgTreeNode, false, addNum, userInfo, appId, roleId);
             orgQuotaAuthInfos.add(orgQuotaAuthInfo);
         } else {
@@ -445,9 +447,9 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
         return ResponseStatus.success("保存成功!");
     }
 
-    private OrgQuotaAuthInfo newOrUpdateOrgQuota(Map<String, OrgQuotaAuthInfo> orgQuotaMap, Map orgTreeNode, boolean flag, int addNum, SecurityUser userInfo, String appId, String roleId) {
-        OrgQuotaAuthInfo orgQuotaAuthInfo = orgQuotaMap.get(orgTreeNode.get("value"));
-        int ownAddNum = (Boolean) orgTreeNode.get("treeNode") ? addNum : 0;  //本机构新增的空闲名额
+    private OrgQuotaAuthInfo newOrUpdateOrgQuota(Map<String, OrgQuotaAuthInfo> orgQuotaMap, OrgTreeNodeDTO orgTreeNode, boolean flag, int addNum, SecurityUser userInfo, String appId, String roleId) {
+        OrgQuotaAuthInfo orgQuotaAuthInfo = orgQuotaMap.get(orgTreeNode.getId());
+        int ownAddNum =  orgTreeNode.getIsParent() ? addNum : 0;  //本机构新增的空闲名额
         if (orgQuotaAuthInfo != null) {
             int dfp = 0;
             int yxf = 0;
@@ -458,16 +460,16 @@ public class OrgQuotaAuthService extends BaseService<OrgQuotaAuthInfo, String> i
                 yxf = orgQuotaAuthInfo.getYxfNum();
             }
             if (flag) { //如果机构层级与分配范围的层级相等,则把下级的分配的总数加到本机构的空闲名额中
-                orgQuotaAuthInfo.setDfpNum(dfp + ownAddNum + (int) orgTreeNode.get("count") * addNum);
+                orgQuotaAuthInfo.setDfpNum(dfp + ownAddNum +  orgTreeNode.getChildIds().size() * addNum);
             } else {
-                orgQuotaAuthInfo.setYxfNum(yxf + (int) orgTreeNode.get("count") * addNum);
+                orgQuotaAuthInfo.setYxfNum(yxf + orgTreeNode.getChildIds().size() * addNum);
                 orgQuotaAuthInfo.setDfpNum(dfp + ownAddNum);
             }
         } else {
             if (flag) {  //如果机构层级与分配范围的层级相等,则把下级的分配的总数加到本机构的空闲名额中
-                orgQuotaAuthInfo = setOrgQuotaAuthInfo(appId, roleId, (String) orgTreeNode.get("value"), 0, 0, ownAddNum + (int) orgTreeNode.get("count") * addNum, "10", userInfo.getUserName(), userInfo.getDeptId());
+                orgQuotaAuthInfo = setOrgQuotaAuthInfo(appId, roleId, orgTreeNode.getId(), 0, 0, ownAddNum + orgTreeNode.getChildIds().size() * addNum, "10", userInfo.getUserName(), userInfo.getDeptId());
             } else {
-                orgQuotaAuthInfo = setOrgQuotaAuthInfo(appId, roleId, (String) orgTreeNode.get("value"), 0, (int) orgTreeNode.get("count") * addNum, ownAddNum, "10", userInfo.getUserName(), userInfo.getDeptId());
+                orgQuotaAuthInfo = setOrgQuotaAuthInfo(appId, roleId, orgTreeNode.getId(), 0, orgTreeNode.getChildIds().size() * addNum, ownAddNum, "10", userInfo.getUserName(), userInfo.getDeptId());
             }
         }
         return orgQuotaAuthInfo;

+ 7 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/config/DcucAuthConfig.java

@@ -1,6 +1,8 @@
 package com.dragoninfo.dcuc.auth.config;
 
 import lombok.Data;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
@@ -91,4 +93,9 @@ public class DcucAuthConfig {
      */
     private String rootUserId;
 
+    /**
+     * 顶级机构id
+     */
+    private String rootOrgId;
+
 }

+ 38 - 5
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/business/IAuthOrgBusiness.java

@@ -1,11 +1,9 @@
 package com.dragoninfo.dcuc.auth.sub.business;
 
 import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
+import com.dragoninfo.dcuc.auth.sub.dto.OrgQuotaNumDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
-/**
- *
- */
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.core.search.Searchable;
 import org.springframework.data.domain.Page;
@@ -72,7 +70,7 @@ public interface IAuthOrgBusiness {
     OrgTreeNodeDTO getOrgTreeNode(String id);
 
     /**
-     *
+     * 批量获取树节点
      * @param ids
      * @return
      */
@@ -86,9 +84,44 @@ public interface IAuthOrgBusiness {
     String changeIdsToNames(String ids);
 
     /**
-     *
+     * 根据code获取机构信息
      * @param orgCode
      * @return
      */
     AuthOrgDTO getOrgByCode(String orgCode);
+
+    /**
+     * 获取满足条件的子级机构和数量
+     * 子级机构为orgId的满足条件的下一级机构
+     * 子级机构的childIds字段中只有权限范围内的id
+     * 数量为所有满足条件的机构数量
+     * @param userId
+     * @param orgId
+     * @param unitClass
+     * @param roleLevel
+     * @return
+     */
+    OrgQuotaNumDTO searchOrgForQuota(String userId, String orgId, String unitClass, String roleLevel);
+
+    /**
+     * 获取满足条件的子级机构和数量
+     * 子级机构为orgId的满足条件的下一级机构
+     * 数量为所有满足条件的机构数量
+     * @param userId
+     * @param orgId
+     * @param unitClass
+     * @param roleLevel
+     * @return
+     */
+    OrgQuotaNumDTO searchOrg(String userId, String orgId, String unitClass, String roleLevel);
+
+    /**
+     *
+     * @param userId
+     * @param orgId
+     * @param unitClass
+     * @param roleLevel
+     * @return
+     */
+    List<OrgTreeNodeDTO> getCalQuotaTree(String userId, String orgId, String unitClass, String roleLevel);
 }

+ 113 - 3
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/business/impl/AuthOrgBusinessImpl.java

@@ -1,10 +1,12 @@
 package com.dragoninfo.dcuc.auth.sub.business.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.dragoninfo.dcuc.auth.admin.service.IAppMtAuthService;
 import com.dragoninfo.dcuc.auth.auth.constance.CommonCons;
 import com.dragoninfo.dcuc.auth.sub.business.IAuthOrgBusiness;
 import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.ExcelImpOrgInfo;
+import com.dragoninfo.dcuc.auth.sub.dto.OrgQuotaNumDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthOrgInfo;
 import com.dragoninfo.dcuc.auth.sub.service.IAuthOrgInfoService;
@@ -15,6 +17,8 @@ import com.dragoninfo.dcuc.duceap.enums.OrgKindEnum;
 import com.dragoninfo.dcuc.duceap.facade.ICodeListResourceFacade;
 import com.dragoninfo.dcuc.duceap.facade.IDuceapUploadFacade;
 import com.dragoninfo.dcuc.duceap.upload.dto.DocContentDTO;
+import com.dragoninfo.duceap.commons.util.server.OrgInfoUtil;
+import com.dragoninfo.duceap.core.enums.RoleLevelEnum;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.metadata.CodeRecord;
@@ -23,6 +27,7 @@ import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
 import com.dragonsoft.duceap.core.search.Searchable;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.ListUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
@@ -33,7 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.stereotype.Component;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -82,6 +86,9 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
     @Autowired
     private IAuthOrgTreeService authOrgTreeService;
 
+    @Autowired
+    private IAppMtAuthService appMtAuthService;
+
     @Autowired
     private IDuceapUploadFacade uploadFacade;
 
@@ -169,7 +176,7 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
 
     @Override
     public List<OrgTreeNodeDTO> getChildById(String id) {
-        return authOrgTreeService.getChildById(id);
+        return authOrgTreeService.getOneLevelChildById(id);
     }
 
     @Override
@@ -182,6 +189,109 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
         return authOrgTreeService.getOrgTreeNodeByIds(ids);
     }
 
+    @Override
+    public OrgQuotaNumDTO searchOrgForQuota(String userId, String orgId, String unitClass, String roleLevel) {
+        OrgQuotaNumDTO orgQuotaNumDTO = new OrgQuotaNumDTO();
+        OrgTreeNodeDTO orgTreeNode = authOrgTreeService.getOrgTreeNode(orgId);
+        if(null == orgTreeNode) {
+            return orgQuotaNumDTO;
+        }
+        orgQuotaNumDTO = searchOrg(userId, orgId, unitClass, roleLevel);
+        List<OrgTreeNodeDTO> resultTreeNodes = orgQuotaNumDTO.getResultTreeNodes();
+        if (orgQuotaNumDTO.getCount() == null || orgQuotaNumDTO.getCount() == 0) {
+            return orgQuotaNumDTO;
+        }
+
+        orgQuotaNumDTO.setAllTreeNodes(null);
+
+        //获取下一级有权限的子节点
+        Map<String, OrgTreeNodeDTO> idMap = resultTreeNodes
+                .stream()
+                .collect(Collectors.toMap(OrgTreeNodeDTO::getId, e->e));
+        List<String> childIds = orgTreeNode.getChildIds();
+        List<OrgTreeNodeDTO> collect = childIds.stream()
+                .filter(e -> idMap.keySet().contains(e))
+                .map(idMap::get).collect(Collectors.toList());
+        orgQuotaNumDTO.setResultTreeNodes(collect);
+        orgQuotaNumDTO.setCount(collect.size());
+        return orgQuotaNumDTO;
+    }
+
+    @Override
+    public OrgQuotaNumDTO searchOrg(String userId, String orgId, String unitClass, String roleLevel) {
+        OrgQuotaNumDTO orgQuotaNumDTO = new OrgQuotaNumDTO();
+        List<OrgTreeNodeDTO> allList = authOrgTreeService.getAllChildNodes(orgId);
+        if(CollectionUtils.isEmpty(allList)) {
+            return orgQuotaNumDTO;
+        }
+        String mts = appMtAuthService.mgeAppRightRangeStr(userId);
+
+        //筛选满足条件的子级机构
+        Map<Boolean, List<OrgTreeNodeDTO>> collect = allList.stream()
+                .collect(Collectors.partitioningBy(el -> filterChildNode(el, mts, unitClass, roleLevel)));
+        List<OrgTreeNodeDTO> resultList = collect.get(Boolean.TRUE);
+
+        //重新构建树节点和子节点关系
+        //有权限的节点
+        Map<String, List<String>> pidMap = resultList
+                .stream()
+                .collect(Collectors.groupingBy(OrgTreeNodeDTO::getPid,
+                        Collectors.mapping(OrgTreeNodeDTO::getId, Collectors.toList())));
+        resultList.forEach(node -> {
+            String id = node.getId();
+            List<String> nodeChildIds = pidMap.get(id);
+            if (CollectionUtils.isEmpty(nodeChildIds)) {
+                node.setIsParent(false);
+                node.setChildIds(ListUtils.EMPTY_LIST);
+            } else {
+                node.setIsParent(true);
+                node.setChildIds(nodeChildIds);
+            }
+        });
+
+        //没权限的节点
+        collect.get(Boolean.FALSE).forEach(e->{
+            e.setIsParent(false);
+            e.setChildIds(ListUtils.EMPTY_LIST);
+        });
+        orgQuotaNumDTO.setCount(resultList.size());
+        orgQuotaNumDTO.setResultTreeNodes(resultList);
+        orgQuotaNumDTO.setAllTreeNodes(allList);
+        return orgQuotaNumDTO;
+    }
+
+    @Override
+    public List<OrgTreeNodeDTO> getCalQuotaTree(String userId, String orgId, String unitClass, String roleLevel) {
+        OrgQuotaNumDTO orgQuotaNumDTO = searchOrgForQuota(userId, orgId, unitClass, roleLevel);
+        List<OrgTreeNodeDTO> resultTreeNodes = orgQuotaNumDTO.getResultTreeNodes();
+        if(null == resultTreeNodes) {
+            return new ArrayList<>();
+        }
+        return resultTreeNodes;
+    }
+
+    private boolean filterChildNode(OrgTreeNodeDTO node, String mts, String unitClass, String roleLevel) {
+        //权限过滤
+        if(!OrgInfoUtil.isHaveAuth(node.getId(), node.getPath(), mts)) {
+            return false;
+        }
+        //单位类别过滤
+        if(StringUtils.isNotBlank(unitClass)) {
+            String nodeUnitClass = node.getUnitClass();
+            if(!unitClass.contains(nodeUnitClass)) {
+                return false;
+            }
+        }
+        //角色层级过滤
+        if(StringUtils.isNotBlank(roleLevel)
+            && !RoleLevelEnum.TY.getValue().equals(roleLevel)) {
+            String nodeOrgLevel = node.getOrgLevel();
+            if(!roleLevel.contains(nodeOrgLevel)) {
+                return false;
+            }
+        }
+        return true;
+    }
 
     private void verifyOrgInfo(List<ExcelImpOrgInfo> list) {
         if(list.size() > 1000) {
@@ -400,7 +510,7 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
         }
     }
 
-    public void codeListCache() {
+    private void codeListCache() {
         try {
             log.info("-------------codeListCache START--------------");
             //T_MD_ORGTYPE 机构类别

+ 11 - 1
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/facade/AuthOrgInfoFacade.java

@@ -2,6 +2,7 @@ package com.dragoninfo.dcuc.auth.sub.facade;
 
 import com.dragoninfo.dcuc.auth.sub.business.IAuthOrgBusiness;
 import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
+import com.dragoninfo.dcuc.auth.sub.dto.OrgQuotaNumDTO;
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
@@ -73,10 +74,19 @@ public class AuthOrgInfoFacade implements IAuthOrgInfoFacade {
         return authOrgBusiness.getChildById(id);
     }
 
-
     @Override
     public String changeIdsToNames(String ids) {
         return authOrgBusiness.changeIdsToNames(ids);
     }
 
+    @Override
+    public OrgQuotaNumDTO searchOrgForQuota(String userId, String orgId, String unitClass, String roleLevel) {
+        return authOrgBusiness.searchOrgForQuota(userId, orgId, unitClass, roleLevel);
+    }
+
+    @Override
+    public List<OrgTreeNodeDTO> getCalQuotaTree(String userId, String orgId, String unitClass, String roleLevel) {
+        return authOrgBusiness.getCalQuotaTree(userId, orgId, unitClass, roleLevel);
+    }
+
 }

+ 11 - 2
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/service/IAuthOrgTreeService.java

@@ -2,6 +2,7 @@ package com.dragoninfo.dcuc.auth.sub.service;
 
 import com.dragoninfo.dcuc.auth.sub.dto.OrgTreeNodeDTO;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
@@ -14,10 +15,18 @@ public interface IAuthOrgTreeService {
 
     /**
      * 机构数据懒加载获取子节点
+     * 只获取下一级节点
      * @param id 本级节点id
      * @return 子级机构数据
      */
-    List<OrgTreeNodeDTO> getChildById(String id);
+    List<OrgTreeNodeDTO> getOneLevelChildById(String id);
+
+    /**
+     * 获取所有子机构树节点
+     * @param orgId
+     * @return
+     */
+    List<OrgTreeNodeDTO> getAllChildNodes(String orgId);
 
     /**
      * 根据id获取机构树节点
@@ -31,7 +40,7 @@ public interface IAuthOrgTreeService {
      * @param ids
      * @return
      */
-    List<OrgTreeNodeDTO> getOrgTreeNodeByIds(List<String> ids);
+    List<OrgTreeNodeDTO> getOrgTreeNodeByIds(Collection<String> ids);
 
     /**
      * 把管理范围转换成所以的机构集合

+ 11 - 6
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/service/impl/AuthOrgInfoService.java

@@ -1,5 +1,6 @@
 package com.dragoninfo.dcuc.auth.sub.service.impl;
 
+import com.dragoninfo.dcuc.auth.config.DcucAuthConfig;
 import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthOrgInfo;
 import com.dragoninfo.dcuc.auth.sub.repo.AuthOrgInfoRepository;
@@ -11,17 +12,17 @@ import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
 import com.dragonsoft.duceap.core.search.Searchable;
 import com.dragonsoft.duceap.core.search.enums.SearchOperator;
-import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -33,9 +34,8 @@ import java.util.stream.Collectors;
 @Transactional(rollbackFor = RuntimeException.class)
 public class AuthOrgInfoService implements IAuthOrgInfoService {
 
-    @Value("${dcuc.org.root-org-id}")
-    @Getter
-    private String rootOrgId;
+    @Autowired
+    private DcucAuthConfig dcucAuthConfig;
 
     @Autowired
     private AuthOrgInfoRepository orgInfoRepository;
@@ -166,4 +166,9 @@ public class AuthOrgInfoService implements IAuthOrgInfoService {
         return ResponseDTO.success("" + list.size(), collect);
     }
 
+    @Override
+    public String getRootOrgId() {
+        return dcucAuthConfig.getRootOrgId();
+    }
+
 }

+ 25 - 17
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/service/impl/AuthOrgTreeServiceImpl.java

@@ -32,7 +32,8 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
     /**
      * holder不能对外暴露
      * 通过holder获取的树节点不允许调用set方法修改树节点的属性值
-     * 接口给出去的对象最好使用拷贝后的对象,不要破坏树节点的内部结构
+     * 接口给出去的对象使用拷贝后的对象,不要破坏树节点的内部结构
+     * 在使用holder时尽量只获取一次,然后都使用获取到的引用。可以避免在一个方法中多次获取树结构,而树结构又被重新构建导致数据不一致的情况
      */
     private AuthOrgTreeHolder holder;
 
@@ -44,7 +45,7 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
     }
 
     @Override
-    public List<OrgTreeNodeDTO> getChildById(String id) {
+    public List<OrgTreeNodeDTO> getOneLevelChildById(String id) {
         List<OrgTreeNodeDTO> child;
         if(StringUtils.isBlank(id)) {
             child = deepCopy(holder.getTopNodesList());
@@ -67,6 +68,16 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
         return child;
     }
 
+    @Override
+    public List<OrgTreeNodeDTO> getAllChildNodes(String orgId) {
+        if(StringUtils.isBlank(orgId)) {
+            return new ArrayList<>();
+        }
+        Map<String, OrgTreeNodeDTO> treeNodeMap = holder.getTreeNodeMap();
+        Set<String> allChildIds = getAllChildIds(orgId, treeNodeMap);
+        return getOrgTreeNodeByIds(allChildIds);
+    }
+
     @Override
     public OrgTreeNodeDTO getOrgTreeNode(String id) {
         if(StringUtils.isBlank(id)) {
@@ -81,7 +92,7 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
     }
 
     @Override
-    public List<OrgTreeNodeDTO> getOrgTreeNodeByIds(List<String> ids) {
+    public List<OrgTreeNodeDTO> getOrgTreeNodeByIds(Collection<String> ids) {
         if(CollectionUtils.isEmpty(ids)) {
             return new ArrayList<>();
         }
@@ -97,6 +108,7 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
     public Set<String> getAllMtOrgIds(String mtIds) {
         Set<String> resultSet = new HashSet<>();
         String[] mtIdStrs = mtIds.split(",");
+        Map<String, OrgTreeNodeDTO> treeNodeMap = holder.getTreeNodeMap();
         for (String mtIdStr : mtIdStrs) {
             if (mtIdStr.contains(":")) {
                 String[] split = mtIdStr.split(":");
@@ -105,7 +117,7 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
                 int rang = Integer.parseInt(split[1]);
                 //1 半选 2 全选
                 if (rang == 2) {
-                    Set<String> allChildIds = getAllChildIds(orgId);
+                    Set<String> allChildIds = getAllChildIds(orgId, treeNodeMap);
                     resultSet.addAll(allChildIds);
                 }
             } else {
@@ -115,9 +127,8 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
         return resultSet;
     }
 
-    private Set<String> getAllChildIds(String orgId) {
+    private Set<String> getAllChildIds(String orgId, Map<String, OrgTreeNodeDTO> treeNodeMap) {
         Set<String> childIds = new HashSet<>();
-        Map<String, OrgTreeNodeDTO> treeNodeMap = holder.getTreeNodeMap();
         OrgTreeNodeDTO orgTreeNodeDTO = treeNodeMap.get(orgId);
         if(null == orgTreeNodeDTO) {
             return childIds;
@@ -147,7 +158,7 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
 
     @Override
     public void reInitTrees() {
-        holder.reInit();
+        holder.init();
     }
 
     private OrgTreeNodeDTO deepCopy(OrgTreeNodeDTO orgTreeNodeDTO) {
@@ -171,25 +182,19 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
          * childIds字段只存子节点id
          * key:机构id
          */
-        private Map<String, OrgTreeNodeDTO> treeNodeMap = new HashMap<>();
+        private volatile Map<String, OrgTreeNodeDTO> treeNodeMap;
 
         /**
          * 所有顶级节点
          */
-        private List<OrgTreeNodeDTO> topNodesList = new ArrayList<>();
+        private volatile List<OrgTreeNodeDTO> topNodesList;
 
         /**
          * 当机构发生增量变化时需要用到锁
+         * 全量构建树,一次替换引用时不需要用到锁
          */
         private ReadWriteLock lock = new ReentrantReadWriteLock();
 
-        /**
-         * 初始化
-         */
-        public void init() {
-            constructTrees(treeNodeMap, topNodesList);
-        }
-
         /**
          * 构建树结构
          * @param treeNodeMap
@@ -296,7 +301,10 @@ public class AuthOrgTreeServiceImpl implements IAuthOrgTreeService {
             }
         }
 
-        void reInit() {
+        /**
+         * 初始化
+         */
+        void init() {
             Map<String, OrgTreeNodeDTO> orgMap = new HashMap<>();
             List<OrgTreeNodeDTO> orgList = new ArrayList<>();
             constructTrees(orgMap, orgList);

+ 1 - 2
dcuc-auth-service/src/main/resources/application-auth.yml

@@ -1,6 +1,4 @@
 dcuc:
-  org:
-    root-org-id: 7F08CCC3C4984A2586C9D3F0A6B804E5
   auth:
     app-code: QXXT0000000000000001
     menu-noclear: true
@@ -51,6 +49,7 @@ dcuc:
     approval-center-url: http://10.254.11.185:8866/approve-gateway
     user-center-url: http://10.11.1.237:8860/dcuc
     root-user-id: 402881cb4era66f4014b0ghd0b875485
+    root-org-id: 7F08CCC3C4984A2586C9D3F0A6B804E5
 app:
   audit:
     qmtj: