Browse Source

优化空间对象创建接口

zhangqiankun 3 years ago
parent
commit
a8560c9f70

+ 8 - 1
src/main/java/com/persagy/proxy/adm/utils/AdmEntityTransferUtil.java

@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.utils.JsonNodeUtils;
 
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -66,7 +67,13 @@ public class AdmEntityTransferUtil {
                 resetAdmProperty((ObjectNode) node, projection);
             }
         }
-        return JsonNodeUtils.toEntity(array, clazz, "infos");
+        
+        try {
+			return JSONEntityUtil.toEntity(array, clazz, "infos");
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+        return null;
     }
 
     /**

File diff suppressed because it is too large
+ 208 - 0
src/main/java/com/persagy/proxy/adm/utils/JSONEntityUtil.java


+ 53 - 29
src/main/java/com/persagy/proxy/object/service/impl/AdmSpaceServiceImpl.java

@@ -1,8 +1,17 @@
 package com.persagy.proxy.object.service.impl;
 
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.json.JSONUtil;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -11,31 +20,32 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
-import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
-import com.persagy.proxy.object.service.IAdmEquipmentService;
 import com.persagy.proxy.adm.service.IAdmRelationService;
-import com.persagy.proxy.object.service.IAdmSpaceService;
-import com.persagy.proxy.object.service.IAdmSystemService;
+import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.common.client.DmpRwdClient;
 import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
 import com.persagy.proxy.object.model.AdmEquipment;
-import com.persagy.proxy.object.model.AdmFloor;
 import com.persagy.proxy.object.model.AdmSpace;
 import com.persagy.proxy.object.model.AdmSystem;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+import com.persagy.proxy.object.service.IAdmEquipmentService;
+import com.persagy.proxy.object.service.IAdmSpaceService;
+import com.persagy.proxy.object.service.IAdmSystemService;
 
-import java.util.*;
-import java.util.stream.Collectors;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * ADM 空间 实现类
@@ -68,11 +78,11 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     public List<AdmSpace> doInsertExt(InstanceUrlParam context, Class<AdmSpace> clazz, List<AdmSpace> voList) {
         Map<String, AdmSpace> spaceMapByFlId = CollUtil.fieldValueMap(voList, "floorId");
         //查询空间中floorId 对应的floor
-        DmpResult<JSONArray> floors = queryFloorsByFloorIds(context, spaceMapByFlId.keySet());
-        if(CollUtil.isNotEmpty(floors.getData())){
-            ArrayList<AdmFloor> floorList = CollUtil.newArrayList(JSONUtil.toList(floors.getData().toString(),AdmFloor.class));
+        List<ObjectNode> floors = queryFloorsByFloorIds(context, spaceMapByFlId.keySet());
+        if(CollUtil.isNotEmpty(floors)){
+            //ArrayList<AdmFloor> floorList = CollUtil.newArrayList(JSONUtil.toList(floors.getData().toString(),AdmFloor.class));
             //space.height = floor.infos.height
-            voList = processHeight(spaceMapByFlId, floorList);
+            voList = processHeight(spaceMapByFlId, floors);
         }
         //插入空间
         List<AdmSpace> vosR = doInsert(context, clazz, voList);
@@ -339,6 +349,14 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         }
     }
 
+    private List<ObjectNode> queryObject(InstanceUrlParam context, QueryCriteria criteriaObject){
+        JSONObject paraPe = null;
+    	String groupCode = AppContext.getContext().getGroupCode();
+		String projectId = AppContext.getContext().getProjectId();
+    	List<ObjectNode> query = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteriaObject);
+    	return query;
+    }
+    
     private DmpResult<JSONArray> queryObj(InstanceUrlParam context, QueryCriteria criteriaObject){
         JSONObject paraPe = null;
         try {
@@ -402,7 +420,7 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
      * @param floolIds
      * @return
      */
-    private DmpResult<JSONArray> queryFloorsByFloorIds(InstanceUrlParam context, Collection<String> floolIds){
+    private List<ObjectNode> queryFloorsByFloorIds(InstanceUrlParam context, Collection<String> floolIds){
         QueryCriteria queryCriteria = ensureQueryCommParm(new QueryCriteria(),context, CollUtil.newArrayList("floor"),"floor");
         ObjectNode criteriaPe = queryCriteria.getCriteria();
         if(CollUtil.isNotEmpty(floolIds)){
@@ -414,7 +432,7 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         criteriaPe.putPOJO("height", height);
         queryCriteria.setCriteria(criteriaPe);
         queryCriteria.setWithoutCount(true);
-        return queryObj(context, queryCriteria);
+        return queryObject(context, queryCriteria);
     }
 
     /**
@@ -423,15 +441,21 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
      * @param floorList
      * @return
      */
-    private List<AdmSpace> processHeight(Map<String, AdmSpace> spaceMapByFlId, List<AdmFloor> floorList){
-        floorList.forEach(admFloor -> {
-            if(CollUtil.isNotEmpty(admFloor.getInfos())){
-                Float height = (Float) admFloor.getInfos().get("height");
-                AdmSpace admSpace = spaceMapByFlId.get(admFloor.getId());
-                admSpace.setHeight(height);
-            }
+    private List<AdmSpace> processHeight(Map<String, AdmSpace> spaceMapByFlId, List<ObjectNode> floorList){
+    	List<AdmSpace> resultList = new ArrayList<AdmSpace>();
+    	floorList.forEach(node -> {
+    		try {
+    			if(node.has("height")){
+                	String height = node.get("height").asText();
+                	if (StrUtil.isNotBlank(height)) {
+                		AdmSpace admSpace = spaceMapByFlId.get(node.get("id").asText());
+                        admSpace.setHeight(Float.parseFloat(height));
+                        resultList.add(admSpace);
+					}
+                }
+			} catch (Exception e) {}
         });
-        return (List<AdmSpace>) spaceMapByFlId.values();
+        return resultList;
     }
 
     /**
@@ -442,10 +466,10 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
             List<RelationDTO> relationDTOS = new ArrayList<>(vosR.size());
             vosR.forEach(admSpace -> {
                 if (StrUtil.isNotEmpty(admSpace.getBuildingId())) {
-                    relationDTOS.add(new RelationDTO(null, "ArchSubset", "Bd2Sp", null, admSpace.getBuildingId(), admSpace.getId()));
+                    relationDTOS.add(new RelationDTO("GtArchSubset001", "ArchSubset", "Bd2Sp", null, admSpace.getBuildingId(), admSpace.getId()));
                 }
                 if (StrUtil.isNotEmpty(admSpace.getFloorId())) {
-                    relationDTOS.add(new RelationDTO(null, "ArchSubset", "Fl2Sp", null, admSpace.getFloorId(), admSpace.getId()));
+                    relationDTOS.add(new RelationDTO("GtArchSubset001", "ArchSubset", "Fl2Sp", null, admSpace.getFloorId(), admSpace.getId()));
                 }
             });
             if (CollUtil.isNotEmpty(relationDTOS)) {