瀏覽代碼

优化创建竖井下的业务空间

zhangqiankun 3 年之前
父節點
當前提交
40c6d70ca9
共有 1 個文件被更改,包括 31 次插入29 次删除
  1. 31 29
      src/main/java/com/persagy/proxy/relation/controller/RelationShContainSpBaseController.java

+ 31 - 29
src/main/java/com/persagy/proxy/relation/controller/RelationShContainSpBaseController.java

@@ -218,13 +218,10 @@ public class RelationShContainSpBaseController {
                                    @RequestBody JSONObject param) throws Exception {
         String shaftId = param.getString("shaftId");
         JSONArray spaceIdList = param.getJSONArray("spaceIdList");
-        if(StrUtil.isBlank(shaftId) || CollUtil.isEmpty(spaceIdList)) {
-            return AdmResponse.failure("必填项:SpaceIdList(业务空间id列表)、ShaftID(竖井id),此方法会覆盖以前的记录");
-        }
-        // 创建关系对象.先删除,后添加
+
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
-        RequestData requestData = RequestData.builder().buildingId(buildingId).classCode(type)
-                .floorId(floorId).projectId(context.getProjectId()).objType(AdmDictCategoryEnum.SPACE.getValue()).build();
+        
+        // 查出和当前竖井关联并为当前空间类型的的业务空间id
         QueryCriteria queryRequestTmp = new QueryCriteria();
         ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
         nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
@@ -232,12 +229,15 @@ public class RelationShContainSpBaseController {
         nodeTmp.put("relValue", type);
         nodeTmp.put("objFrom", shaftId);
         queryRequestTmp.setCriteria(nodeTmp);
-        //关系查询空间id
-        Set<String> oldSpaceIds = service.queryByCondition(context,queryRequestTmp).stream().map(ObjectRelation::getObjTo).collect(Collectors.toSet());
+        Set<String> oldSpaceIds = service.queryByCondition(context, queryRequestTmp).stream().map(ObjectRelation::getObjTo).collect(Collectors.toSet());
+        
+        // 楼层、建筑、对象类查询的空间id
+        RequestData requestData = RequestData.builder().buildingId(buildingId).classCode(type)
+                .floorId(floorId).projectId(context.getProjectId()).objType(AdmDictCategoryEnum.SPACE.getValue()).build();
         List<ObjectDigital> objectDigitals = DigitalObjectFacade.queryObjectListSuperiorId(context.getGroupCode(),
                 context.getProjectId(), AdmCommonConstant.APP_ID, context.getUserId(), requestData);
-        //楼层、建筑、对象类查询的空间id
         Set<String> spaceIdSet = objectDigitals.stream().map(ObjectDigital::getId).collect(Collectors.toSet());
+        
         //空间id取交集
         if(ObjectUtil.isNotEmpty(oldSpaceIds)){
             spaceIdSet.retainAll(oldSpaceIds);
@@ -255,26 +255,28 @@ public class RelationShContainSpBaseController {
             service.doDelete(context,queryRequest);
         }
         //替换空间关系
-        List<RelationDTO> voList = new ArrayList<>();
-        for(int i = 0;i < spaceIdList.size();i++) {
-            String spaceId = spaceIdList.getString(i);
-            if(StrUtil.isBlank(spaceId)) {
-                continue;
-            }
-            QueryCriteria queryRequest = new QueryCriteria();
-            ObjectNode node = JsonNodeFactory.instance.objectNode();
-            node.put("graphCode", DEFAULT_GRAPH_CODE);
-            node.put("relCode", DEFAULT_REL_CODE);
-            node.put("relValue", type);
-            node.put("objFrom", shaftId);
-            node.put("objTo", spaceId);
-            queryRequest.setCriteria(node);
-            service.doDelete(context,queryRequest);
-            // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
-            voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, type, shaftId, spaceId));
-        }
-        // 组装上下文条件
-        service.doSave(context, voList);
+        if (CollectionUtil.isNotEmpty(spaceIdList)) {
+        	 List<RelationDTO> voList = new ArrayList<>();
+             for(int i = 0;i < spaceIdList.size();i++) {
+                 String spaceId = spaceIdList.getString(i);
+                 if(StrUtil.isBlank(spaceId)) {
+                     continue;
+                 }
+                 QueryCriteria queryRequest = new QueryCriteria();
+                 ObjectNode node = JsonNodeFactory.instance.objectNode();
+                 node.put("graphCode", DEFAULT_GRAPH_CODE);
+                 node.put("relCode", DEFAULT_REL_CODE);
+                 node.put("relValue", type);
+                 node.put("objFrom", shaftId);
+                 node.put("objTo", spaceId);
+                 queryRequest.setCriteria(node);
+                 service.doDelete(context,queryRequest);
+                 // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
+                 voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, type, shaftId, spaceId));
+             }
+             // 组装上下文条件
+             service.doSave(context, voList);
+		}
         return AdmResponse.success();
     }