Browse Source

Merge remote-tracking branch 'origin/develop' into develop

lijie 3 years ago
parent
commit
a338f34643

+ 19 - 2
src/main/java/com/persagy/proxy/adm/utils/AdmEntityTransferUtil.java

@@ -3,10 +3,12 @@ package com.persagy.proxy.adm.utils;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ArrayUtil;
 import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.utils.JsonNodeUtils;
-import com.persagy.dmp.common.utils.JsonHelper;
+import com.persagy.dmp.common.exception.BusinessException;
+import com.persagy.dmp.common.helper.SpringHelper;
 
 import java.io.IOException;
 import java.util.Iterator;
@@ -139,13 +141,28 @@ public class AdmEntityTransferUtil {
         JsonNode outLine = node.get("outline");
         if(outLine != null && outLine.isTextual()) {
             node.remove("outline");
-            ArrayNode arrayNode = JsonHelper.toSingleEntityQuietly(outLine.textValue(), ArrayNode.class);
+            ArrayNode arrayNode = toSingleEntityQuietly(outLine.textValue(), ArrayNode.class);
             node.set("outline", arrayNode);
         }
         removeProperty(node, projection);
     }
 
     /**
+     * 转换为指定对象
+     * @param jsonStr
+     * @param clazz
+     * @param <T>
+     * @return
+     */
+    public static <T> T toSingleEntityQuietly(String jsonStr, Class<T> clazz) {
+        try {
+            return SpringHelper.getBean(ObjectMapper.class).readValue(jsonStr, clazz);
+        } catch (IOException e) {
+            throw new BusinessException("outline格式解析失败");
+        }
+    }
+
+    /**
      * 拷贝属性
      * @param dmpData 数据中台对象
      * @param srcProp 数据中台属性名

+ 42 - 1
src/main/java/com/persagy/proxy/object/controller/AdmSpaceController.java

@@ -8,6 +8,8 @@ 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.basic.utils.JsonNodeUtils;
+import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.handler.SpaceRelationInfoHandler;
 import com.persagy.proxy.adm.request.*;
 import com.persagy.proxy.adm.service.IAdmRelationService;
@@ -29,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.ws.rs.QueryParam;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Adm 空间 API
@@ -118,7 +121,45 @@ public class AdmSpaceController {
     @PostMapping("/update")
     public AdmResponse update(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
         List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doUpdate( AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
+        if(CollUtil.isNotEmpty(vos)) {
+            Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
+            AdmRelationTypeEnum typeEnumBd = AdmRelationTypeEnum.BD2SP;
+
+            AdmRelationTypeEnum typeEnumFl = AdmRelationTypeEnum.FL2SP;
+            QueryCriteria criteria = new QueryCriteria();
+            ObjectNode node = JsonNodeFactory.instance.objectNode();
+
+            admSpaceMap.keySet().stream().forEach(spId -> {
+                node.put("relCode", typeEnumBd.getRelCode());
+                node.put("objTo", spId);
+                node.put("graphCode", typeEnumBd.getGraphCode());
+                criteria.setCriteria(node);
+                relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
+
+                node.put("relCode", typeEnumFl.getRelCode());
+                node.put("objTo", spId);
+                node.put("graphCode", typeEnumFl.getGraphCode());
+                criteria.setCriteria(node);
+                relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
+            });
+
+            List<RelationDTO> relationDTOList = new ArrayList<>(vos.size());
+            admSpaceMap.keySet().stream().forEach(spaceId -> {
+                if (StrUtil.isNotEmpty(admSpaceMap.get(spaceId).getBuildingId())) {
+                    RelationDTO relationBd = new RelationDTO(null, typeEnumBd.getGraphCode(), typeEnumBd.getRelCode(), null, admSpaceMap.get(spaceId).getBuildingId(), spaceId);
+                    relationDTOList.add(relationBd);
+                }
+                if (StrUtil.isNotEmpty(admSpaceMap.get(spaceId).getFloorId())) {
+                    RelationDTO relationFl = new RelationDTO(null, typeEnumFl.getGraphCode(), typeEnumFl.getRelCode(), null, admSpaceMap.get(spaceId).getFloorId(), spaceId);
+                    relationDTOList.add(relationFl);
+                }
+            });
+
+            if (CollUtil.isNotEmpty(relationDTOList)) {
+                relationService.doSave(AdmContextUtil.toDmpContext(), relationDTOList);
+            }
+            vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
+        }
         return AdmResponse.success(vos);
     }
 

+ 1 - 1
src/main/java/com/persagy/proxy/object/model/AdmSpace.java

@@ -44,7 +44,7 @@ public class AdmSpace extends AdmBaseEntity<AdmSpace> {
     /** 轮廓线2 未使用*/
     private ArrayList<ArrayList<ArrayList<AdmPoint>>> outline2;
     /** 图片 - 信息点里已存在的信息点不应在实体中重复定义为其他格式 */
-   private ArrayNode pic;
+    private ArrayNode pic;
     /** 空间是否受影响 */
     private String state;
     /** 空间常驻人数 */

+ 74 - 57
src/main/java/com/persagy/proxy/report/controller/AdmReportEquipController.java

@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.dto.RequestData;
 import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.basic.utils.JsonNodeUtils;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
@@ -21,21 +22,20 @@ import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
-import com.persagy.proxy.object.model.EquipUpDateEnclosure;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.request.AdmZoneEquipQueryRequest;
-import com.persagy.proxy.object.service.IAdmComponentService;
-import com.persagy.proxy.dictionary.service.IAdmDictService;
-import com.persagy.proxy.object.service.IAdmEquipmentService;
-import com.persagy.proxy.object.service.IAdmSystemService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
 import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.dictionary.model.AdmDict;
 import com.persagy.proxy.dictionary.model.AdmObjectType;
+import com.persagy.proxy.dictionary.service.IAdmDictService;
 import com.persagy.proxy.object.model.*;
+import com.persagy.proxy.object.service.IAdmComponentService;
+import com.persagy.proxy.object.service.IAdmEquipmentService;
+import com.persagy.proxy.object.service.IAdmSystemService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -837,13 +837,14 @@ public class AdmReportEquipController {
     /**
      * 计算动态、静态信息点
      */
-    private Map<String, Integer> calculate(List<ObjectInfoDefine> dynamicInfoPointCodes, List<ObjectInfoDefine> staticInfoPointCodes, List<ObjectNode> objectNodeList, Integer num) {
-        Map<String, Integer> hashMap = new HashMap<String, Integer>();
-        int dynamicInfoPoint = 0;
-        int staticInfoPoint = 0;
-        int customInfoPoint=0;
+    private Map<String, Integer> calculate(List<ObjectInfoDefine> dynamicInfoPointCodes, List<ObjectInfoDefine> staticInfoPointCodes, List objList, Integer num,Map<String, Integer> hashMap) {
+        int dynamicInfoPoint = hashMap.get("dynamicInfoPoint");
+        int staticInfoPoint = hashMap.get("staticInfoPoint");
+        int customInfoPoint = hashMap.get("customInfoPoint");
+
         Iterator<ObjectInfoDefine> iterator1 = staticInfoPointCodes.iterator();
-        for (ObjectNode objectNode : objectNodeList) {
+        for (int i=0;i<objList.size();i++) {
+            JsonNode objectNode = JsonNodeUtils.toObjectNode(objList.get(i),null,null);
             while (iterator1.hasNext()) {
                 ObjectInfoDefine infoDefine = iterator1.next();
                 if (objectNode.get("id") != null && "id" == infoDefine.getCode() && objectNode.get("classCode").textValue() == infoDefine.getClassCode()) {
@@ -898,7 +899,8 @@ public class AdmReportEquipController {
             }
         }
 
-        for (ObjectNode objectNode : objectNodeList) {
+        for (int i=0;i<objList.size();i++) {
+            JsonNode objectNode = JsonNodeUtils.toObjectNode(objList.get(i),null,null);
             if (objectNode.get("infos") != null) {
                 Map<String,Object> dynamic = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), dynamicInfoPointCodes);
                 Map<String,Object> staticMap = calculateInfoPoints(objectNode.get("infos").toString(), objectNode.get("classCode").textValue().toString(), staticInfoPointCodes);
@@ -938,88 +940,103 @@ public class AdmReportEquipController {
     }
 
     private JSONObject calInfoPointByObjType(String objType, Boolean visible, Boolean getInfoCounts){
-        //1 查询项目下所有现有的系统
-        AdmQueryCriteria admQueryCriteriaObj =  new AdmQueryCriteria();
-        if(objType.equals(AdmEquipment.OBJ_TYPE)){
-            admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","bimLocation","infos","classCode","equipSerial","bimFamilyName","bimFamilySymbol"));
-        }else{
-            admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","infos","classCode"));
-        }
-        admQueryCriteriaObj.setName(objType);
-        QueryCriteria queryCriteriaSys = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteriaObj);
-        List<ObjectNode> admObjList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteriaSys);
-
-        //2 获取动态 静态 信息点
-        // 2.1 根据objType获取定义
+        JSONObject gatherInfoPoint = new JSONObject();
+        gatherInfoPoint.put("gatherInfoPointCounts", 0);
+        gatherInfoPoint.put("gatherCustomInfoPointCounts",0);
+        gatherInfoPoint.put("gatherDynamicInfoPointCounts",0);
+        gatherInfoPoint.put("gatherStaticInfoPointCounts",0);
+
+        Map<String, Integer> hashMap = new HashMap<>(16);
+        hashMap.put("dynamicInfoPoint", 0);
+        hashMap.put("staticInfoPoint", 0);
+        hashMap.put("customInfoPoint", 0);
+        //查询当前实例所有信息点总数
+        long controlInfoCounts = 0L;
         Set<String> classCodeSet = new HashSet<>();
-        if(AdmSystem.OBJ_TYPE.equals(objType)){
-            QueryCriteria queryCriteriaType = new QueryCriteria();
-            ObjectNode criteria = JsonNodeFactory.instance.objectNode();
-            criteria.put("objType", objType);
-            queryCriteriaType.setCriteria(criteria);
-            AdmResponse admResponseType = dictService.doQueryObjectType(AdmContextUtil.toDmpContext(), queryCriteriaType, AdmObjectType.class);
-            if(CollUtil.isEmpty(admResponseType.getContent())){
-                return null;
+        //2 获取动态 静态 信息点
+        // 2.1 根据objType获取定义 获取采集的设备的classcode
+        Set<String> objTypes = new HashSet<>(1);
+        objTypes.add(objType);
+        List<Map<String, Object>> codes = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null, RequestData.builder().objTypes(objTypes).build());
+        if(CollUtil.isEmpty(codes)){
+            return gatherInfoPoint;
+        }else{
+            codes.stream().forEach(stringObjectMap -> classCodeSet.add(stringObjectMap.get("code").toString()));
+            //1 查询项目下所有现有的系统
+            AdmQueryCriteria admQueryCriteriaObj =  new AdmQueryCriteria();
+            admQueryCriteriaObj.setPageNumber(1);
+            admQueryCriteriaObj.setPageSize(500);
+            admQueryCriteriaObj.setName(objType);
+            AdmResponse admResponse = new AdmResponse();
+            if(objType.equals(AdmEquipment.OBJ_TYPE)){
+                admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","bimLocation","infos","classCode","equipSerial","bimFamilyName","bimFamilySymbol"));
+                admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteriaObj, AdmEquipment.class);
+            }else{
+                admQueryCriteriaObj.setProjection(Arrays.asList("id","name","localId","localName","cadId","bimId","infos","classCode"));
+                admResponse = systemService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteriaObj, AdmSystem.class);
             }
-            List<AdmObjectType> admObjectTypes = (List<AdmObjectType>) admResponseType.getContent();
-            Map<String, AdmObjectType> admObjectTypeMap = CollUtil.fieldValueMap(admObjectTypes, "code");
-            classCodeSet = admObjectTypeMap.keySet();
-        }else {
-            List<AdmEquipment> equipmentList = JSONUtil.toList(admObjList.toString(), AdmEquipment.class);
-            Map<String, AdmEquipment> admObjectTypeMap = CollUtil.fieldValueMap(equipmentList, "classCode");
-            classCodeSet = admObjectTypeMap.keySet();
-        }
 
-        JSONObject gatherInfoPoint = new JSONObject();
-        if(CollUtil.isEmpty(admObjList)){
-            gatherInfoPoint.put("gatherInfoPointCounts", 0);
-            gatherInfoPoint.put("gatherCustomInfoPointCounts",0);
-            gatherInfoPoint.put("gatherDynamicInfoPointCounts",0);
-            gatherInfoPoint.put("gatherStaticInfoPointCounts",0);
-        } else {
-            // 2.2 根据定义获取信息点
-            //查询当前实例所有信息点总数
-            long controlInfoCounts = 0L;
+            //获取信息点
             QueryCriteria queryCriteria = new QueryCriteria();
             ObjectNode criteria = JsonNodeFactory.instance.objectNode();
             criteria = JsonNodeFactory.instance.objectNode();
             ArrayNode arrayNode = criteria.putObject("classCode").putArray("$in");
             classCodeSet.stream().forEach(classCode -> arrayNode.add(classCode));
+
+            //查询当前实例所有信息点总数
             if(getInfoCounts){
                 queryCriteria.setCriteria(criteria);
                 queryCriteria.setOnlyCount(true);
                 List<ObjectInfoDefine> totalInfo = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
                 controlInfoCounts = totalInfo.size();
             }
+
             //静态信息点
+            criteria.put("groupCode","0");
+            criteria.put("projectId","0");
             criteria.put("category","STATIC");
             if(visible){
                 criteria.put("valid", "1");
             }else{
                 criteria.remove("valid");
             }
+
+            queryCriteria.setOnlyCount(false);
             queryCriteria.setCriteria(criteria);
             List<ObjectInfoDefine> staticInfoCode = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
+
             criteria.remove("category");
 
-            //动态信息点
+            //动态信息点9
             JSONObject category = new JSONObject();
             category.put("$ne","STATIC");
             criteria.putPOJO("category", category);
             queryCriteria.setCriteria(criteria);
             List<ObjectInfoDefine> dynamicInfoCode = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
+
+            // 2.2 根据定义获取信息点
             //4 计算已采集的和需要采集的信息点占比
             //return customSqlService.systemInfoPoins()
-            Map<String, Integer> hashMap = calculate(dynamicInfoCode, staticInfoCode, admObjList, 1);
-            gatherInfoPoint.put("gatherCustomInfoPointCounts",hashMap.get("customInfoPoint"));
-            gatherInfoPoint.put("gatherDynamicInfoPointCounts",hashMap.get("dynamicInfoPoint"));
-            gatherInfoPoint.put("gatherStaticInfoPointCounts",hashMap.get("staticInfoPoint"));
-            gatherInfoPoint.put("gatherInfoPointCounts", controlInfoCounts);
+            List admObjList = admResponse.getContent();
+            hashMap = calculate(dynamicInfoCode, staticInfoCode, admObjList, 1, hashMap);
+            long totalPage = admResponse.getTotal() / admResponse.getPageSize();
+            if(totalPage > 0l){
+                for (long page = admResponse.getPageSize() +1; page <= totalPage; page++){
+                    hashMap = calculate(dynamicInfoCode, staticInfoCode, admObjList, 1, hashMap);
+                }
+            }
+            if(CollUtil.isNotEmpty(hashMap)){
+                gatherInfoPoint.put("gatherCustomInfoPointCounts",hashMap.get("customInfoPoint"));
+                gatherInfoPoint.put("gatherDynamicInfoPointCounts",hashMap.get("dynamicInfoPoint"));
+                gatherInfoPoint.put("gatherStaticInfoPointCounts",hashMap.get("staticInfoPoint"));
+            }
         }
+        gatherInfoPoint.put("gatherInfoPointCounts", controlInfoCounts);
         return gatherInfoPoint;
     }
 
 
+
     /**
      * 处理设备属性文件 -> 设备的信息点
      * @param equip