Browse Source

修复用户可选分区和可选项目树的bug

lixing 3 years ago
parent
commit
594a7d9865

+ 45 - 8
src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java

@@ -404,18 +404,23 @@ public class SaasWebServiceImpl implements ISaasWebService {
         if (CollectionUtils.isEmpty(availableProjectTree)) {
             return Lists.newArrayList();
         }
-        // 遍历用户所有可选分区树,标记分区父节点及分区拥有的项目
-        List<FilterPartitionVO> partitions = partitionProjectTree2FilterPartitionList();
-        // 根据建筑业态筛选分区
-        Map<String, FilterPartitionVO> filterPartitionMap = filterPartitions(partitions, buildingType);
-        if (CollectionUtils.isEmpty(filterPartitionMap)) {
-            return Lists.newArrayList();
-        }
+
         // 根据建筑业态筛选用户权限范围内的项目
         List<SimpleProjectVO> availableProjects = getAvailableProjects(buildingType);
         if (CollectionUtils.isEmpty(availableProjects)) {
             return Lists.newArrayList();
         }
+
+        /* 根据用户可选项目筛选分区 */
+        Set<String> availableProjectIds = availableProjects.stream().
+                map(SimpleProjectVO::getProjectId).collect(Collectors.toSet());
+        // 遍历用户所有可选分区树,标记分区父节点及分区拥有的项目
+        List<FilterPartitionVO> partitions = partitionProjectTree2FilterPartitionList();
+        Map<String, FilterPartitionVO> filterPartitionMap = filterPartitions(partitions, availableProjectIds);
+        if (CollectionUtils.isEmpty(filterPartitionMap)) {
+            return Lists.newArrayList();
+        }
+
         Map<String, String> filterProjectMap = availableProjects.stream().collect(
                 Collectors.toMap(SimpleProjectVO::getProjectId, SimpleProjectVO::getProjectName, (k1, k2) -> k1));
 
@@ -499,7 +504,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
         for (String areaId : filterPartitionMap.keySet()) {
             FilterPartitionVO filterPartitionVO = filterPartitionMap.get(areaId);
             String parentId = filterPartitionVO.getParentId();
-            if (StringUtils.isNotBlank(parentId)) {
+            if (StringUtils.isNotBlank(parentId) && filterPartitionMap.containsKey(parentId)) {
                 List<FilterPartitionVO> filterPartitionVOList = parentIdMap.get(parentId);
                 if (filterPartitionVOList == null) {
                     filterPartitionVOList = new ArrayList<>();
@@ -630,6 +635,38 @@ public class SaasWebServiceImpl implements ISaasWebService {
         }
     }
 
+    /**
+     * 根据项目,筛选分区
+     *
+     * @param partitions   用户所有可选分区列表
+     * @param projectIds 用户可用项目id列表
+     * @return 处理后的分区map 分区编码 -> 分区对象
+     * @author lixing
+     * @version V1.0 2021/5/21 3:59 下午
+     */
+    private Map<String, FilterPartitionVO> filterPartitions(
+            List<FilterPartitionVO> partitions, Set<String> projectIds) {
+        Map<String, FilterPartitionVO> result = Maps.newHashMap();
+
+        if (CollectionUtils.isEmpty(partitions)) {
+            return result;
+        }
+
+        for (FilterPartitionVO partition : partitions) {
+            List<SimpleProjectVO> projects = partition.getProjects();
+            if (CollectionUtils.isEmpty(projects)) {
+                continue;
+            }
+            Set<String> projectIdsInArea = projects.stream().
+                    map(SimpleProjectVO::getProjectId).collect(Collectors.toSet());
+            // 取用户可选项目和分区下项目的交集,projectIds会被更新为两个集合的交集 projectIds是用户在分区下可选的项目
+            projectIdsInArea.retainAll(projectIds);
+            if (projectIdsInArea.size() > 0) {
+                result.put(partition.getAreaId(), partition);
+            }
+        }
+        return result;
+    }
 
     /**
      * 根据业态,筛选分区

+ 3 - 2
src/main/resources/bootstrap.yml

@@ -2,8 +2,9 @@ spring:
   application:
     name: energy-report
 
-EUREKA_CLIENT_DEFAULT_ZONE: http://frame:123456@develop.persagy.com/integrated-eureka/eureka/
-#EUREKA_CLIENT_DEFAULT_ZONE: http://pbsage:123456@hr.persagy.com/poems-eureka/eureka/
+#EUREKA_CLIENT_DEFAULT_ZONE: http://frame:123456@develop.persagy.com/integrated-eureka/eureka/
+EUREKA_CLIENT_DEFAULT_ZONE: http://pbsage:123456@hr.persagy.com/poems-eureka/eureka/
+CONFIG_SERVER_ID: poems-config
 
 mybatis-plus:
   configuration: