Forráskód Böngészése

设备查询bug修复

linhuili 2 éve
szülő
commit
ef47a7b963

+ 84 - 18
src/main/java/com/persagy/dmp/middleware/controller/EquipController.java

@@ -2,20 +2,23 @@ package com.persagy.dmp.middleware.controller;
 
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.dmp.common.constant.CommonConstant;
 import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.middleware.constant.CommonConsant;
+import com.persagy.dmp.middleware.constant.enums.RelationTypeEnum;
 import com.persagy.dmp.middleware.entity.dto.CommonRequestDTO;
 import com.persagy.dmp.middleware.entity.dto.InstanceUrlParam;
+import com.persagy.dmp.middleware.entity.dto.ObjRelationDTO;
 import com.persagy.dmp.middleware.entity.response.CommonResult;
 import com.persagy.dmp.middleware.entity.vo.WdConstructDescription;
+import com.persagy.dmp.middleware.service.IBaseService;
 import com.persagy.dmp.middleware.service.IConstructDescriptionService;
 import com.persagy.dmp.middleware.service.IEquipService;
 import com.persagy.dmp.middleware.utils.EntityTransferUtil;
 import com.persagy.dmp.middleware.utils.SortUtil;
 import org.apache.commons.lang.StringUtils;
-import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -23,9 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.ws.rs.QueryParam;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -45,6 +46,9 @@ public class EquipController {
     @Autowired
     private IConstructDescriptionService constructDescriptionService;
 
+    @Autowired
+    private IBaseService baseService;
+
     /**
      * 查询/统计设备设施下的设备/阀门
      * @param projectId
@@ -67,6 +71,8 @@ public class EquipController {
         content = EntityTransferUtil.combineData(content);
         //按首字母,对象数量为0放后的规则进行排序
         content = SortUtil.sortByCharacter(content,CommonConsant.OBJ_TYPE, CommonConsant.CLASS_NAME);
+        //设置关系id
+        setRelId(context,content, request);
         //设置返回值
         CommonResult<List<JSONObject>> response = CommonResult.success(content);
         response.setCount(content == null ? 0 : Long.valueOf(content.size()));
@@ -74,20 +80,6 @@ public class EquipController {
     }
 
 
-    private void setFloorId(List<JSONObject> content,CommonRequestDTO requestDTO){
-        if(CollUtil.isEmpty(content)){
-            return;
-        }
-        if(StringUtils.isNotEmpty(requestDTO.getFloorId())){
-            //直接设置对象所属楼层id
-            content.forEach(item->{
-                item.put("floorId",requestDTO.getFloorId());
-            });
-            return;
-        }
-        Set<String> spaceIds = content.stream().map(k->k.getString("id")).collect(Collectors.toSet());
-
-    }
     /**
      *  查询设备设施-暖通系统-全局-3D原理图相关的设备/阀门
      * @param projectId
@@ -282,4 +274,78 @@ public class EquipController {
     }
 
 
+    /**
+     * 设置关系id
+     * @param context
+     * @param content
+     * @param requestDTO
+     */
+    private void setRelId(InstanceUrlParam context,List<JSONObject> content,CommonRequestDTO requestDTO){
+        if(CollUtil.isEmpty(content)){
+            return;
+        }
+        if(StringUtils.isNotEmpty(requestDTO.getFloorId())){
+            //直接设置对象所属楼层id
+            content.forEach(item->{
+                item.put("floorId",requestDTO.getFloorId());
+            });
+            return;
+        }
+        setEquipInFloorId(context,content,requestDTO);
+
+    }
+
+
+    /**
+     * 设置设备所在楼层id
+     * @param content
+     * @param requestDTO
+     */
+    private void setEquipInFloorId(InstanceUrlParam context,List<JSONObject> content,CommonRequestDTO requestDTO){
+        if(CollUtil.isEmpty(content)){
+            return ;
+        }
+        //获取所有的设备id
+        Set<String> equipId = getEquipId(content);
+        //获取设备所在楼层id
+        List<ObjRelationDTO> objTo = baseService.queryRelations(context, equipId, RelationTypeEnum.MECHINARCH_EQ2FL.getGraphCode(), RelationTypeEnum.MECHINARCH_EQ2FL.getRelCode(), "objTo");
+        if(CollUtil.isEmpty(objTo)){
+            return;
+        }
+        Map<String, String> map = objTo.stream().collect(Collectors.toMap(ObjRelationDTO::getObjFrom, ObjRelationDTO::getObjTo));
+        for (JSONObject object : content) {
+            JSONArray array = object.getJSONArray("objects");
+            if(CollUtil.isEmpty(array)){
+                continue;
+            }
+            array.forEach(item->{
+                JSONObject equip = (JSONObject) item;
+                equip.put("floorId",map.get(equip.getString("id")));
+            });
+        }
+    }
+
+    /**
+     * 获取设备id
+     * @param content
+     * @return
+     */
+    private Set<String> getEquipId(List<JSONObject> content){
+        if(CollUtil.isEmpty(content)){
+            return null;
+        }
+        Set<String> equipIds = new HashSet<>();
+        for (JSONObject object : content) {
+            JSONArray array = object.getJSONArray("objects");
+            if(CollUtil.isEmpty(array)){
+                continue;
+            }
+            array.forEach(item->{
+                JSONObject equip = (JSONObject) item;
+                equipIds.add(equip.getString("id"));
+            });
+        }
+        return equipIds;
+    }
+
 }

+ 13 - 0
src/main/java/com/persagy/dmp/middleware/service/IBaseService.java

@@ -2,9 +2,11 @@ package com.persagy.dmp.middleware.service;
 
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.middleware.entity.dto.InstanceUrlParam;
+import com.persagy.dmp.middleware.entity.dto.ObjRelationDTO;
 import com.persagy.dmp.middleware.entity.response.CommonResult;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 通用接口
@@ -45,4 +47,15 @@ public interface IBaseService<T> {
      * @return
      */
     void doDelete(InstanceUrlParam context, List<T> voList);
+
+    /**
+     * 关系查询
+     * @param context
+     * @param idList
+     * @param graphCode
+     * @param relCode
+     * @param isSelectTo
+     * @return
+     */
+    List<ObjRelationDTO> queryRelations(InstanceUrlParam context, Set<String> idList, String graphCode, String relCode, String isSelectTo);
 }

+ 20 - 11
src/main/java/com/persagy/dmp/middleware/service/impl/AbstractBaseServiceImpl.java

@@ -8,10 +8,16 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
 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.constant.ValidEnum;
+import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
+import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.dmp.middleware.entity.dto.InstanceUrlParam;
+import com.persagy.dmp.middleware.entity.dto.ObjRelationDTO;
 import com.persagy.dmp.middleware.entity.response.CommonResult;
 import com.persagy.dmp.middleware.entity.response.DmpResult;
 import com.persagy.dmp.middleware.service.IBaseService;
@@ -100,27 +106,30 @@ public class AbstractBaseServiceImpl<T> implements IBaseService<T> {
      * 查询关系
      * @param context
      * @param idList
-     * @param anno
+     * @param graphCode
+     * @param relCode
+     * @param isSelectTo
      * @return
      */
-  /*  private List<ObjectRelation> queryRelations(InstanceUrlParam context, Set<String>idList, CascadeColumn anno) {
+    @Override
+    public List<ObjRelationDTO> queryRelations(InstanceUrlParam context, Set<String>idList, String graphCode,String relCode,String isSelectTo) {
         // 如果没有任何配置,不处理
-        if(StrUtil.isBlank(anno.graphCode()) && StrUtil.isBlank(anno.relCode()) &&
-                StrUtil.isBlank(anno.relValue())) {
+        if(StrUtil.isBlank(graphCode) && StrUtil.isBlank(relCode) &&
+                CollUtil.isEmpty(idList)) {
             return null;
         }
         // 查询关系
         QueryCriteria queryRequest = new QueryCriteria();
         ObjectNode criteria = JsonNodeFactory.instance.objectNode();
         queryRequest.setCriteria(criteria);
-        boolean isSelectTo = anno.selectToObj();
-        putString(criteria, "graphCode", anno.graphCode());
-        putString(criteria, "relCode", anno.relCode());
-        putString(criteria, "relValue", anno.relValue());
-        ArrayNode array = criteria.putObject(isSelectTo?"objFrom":"objTo").putArray("$in");
+        criteria.put(BaseEntity.PROP_VALID, ValidEnum.TRUE.getType());
+        putString(criteria, "graphCode",graphCode);
+        putString(criteria, "relCode", relCode);
+        ArrayNode array = criteria.putObject(isSelectTo).putArray("$in");
         idList.forEach(id -> array.add(id));
-        return SpringHelper.getBean(IAdmRelationService.class).queryByCondition(context, queryRequest);
-    }*/
+        DmpResult<List<ObjRelationDTO>> listDmpResult = rwdClient.queryRelation(context, queryRequest);
+        return listDmpResult.getData();
+    }
 
     /**
      * 添加字符串条件

+ 14 - 44
src/main/resources/db.init/schema.sql

@@ -23,49 +23,19 @@ CREATE TABLE IF NOT EXISTS  "wd_define_type_rel" (
 PRIMARY KEY ("id")
 ) ENGINE=InnoDB AUTO_INCREMENT=1219 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
 
-CREATE TABLE IF NOT EXISTS "wd_equip_type_rel" (
-"id" int NOT NULL AUTO_INCREMENT,
-"system_code" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '系统编码',
-"system_name" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '系统名称',
-"bim_type_id" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'BIM构建编码',
-"class_name" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '类型名称',
-PRIMARY KEY ("id")
-) ENGINE=InnoDB AUTO_INCREMENT=731 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
-
-
-CREATE TABLE  IF NOT EXISTS "wd_materia_type_rel" (
-"id" int NOT NULL AUTO_INCREMENT,
-"system_code" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '系统编码',
-"bim_type_id" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'BIM构建编码',
-"class_name" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '类型名称',
-"class_code" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
-PRIMARY KEY ("id")
-) ENGINE=InnoDB AUTO_INCREMENT=4681 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
-
-CREATE TABLE  IF NOT EXISTS "wd_space_type_rel" (
-"id" int NOT NULL AUTO_INCREMENT,
-"model_code" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '所属功能模块编码',
-"system_code" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '系统编码',
-"system_name" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '系统名称',
-"bim_type_id" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'BIM构建编码',
-"class_name" varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '类型名称',
+CREATE TABLE IF NOT EXISTS "wd_object_count" (
+"id" int NOT NULL AUTO_INCREMENT COMMENT 'id',
+"group_code" varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '集团编码',
+"project_id" varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '项目id',
+"build_id" varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '建筑id',
+"floor_id" varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '楼层id',
+"system_code" varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '系统编码',
+"bim_type_id" varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'BIM构建编码',
+"class_name" varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '类型名称',
+"count" int DEFAULT NULL COMMENT '对象数量',
+"area" double(10,2) DEFAULT NULL,
+"valid" int DEFAULT '1',
+"create_time" datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+"update_time" datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY ("id")
-) ENGINE=InnoDB AUTO_INCREMENT=626 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
-
-
-CREATE TABLE  IF NOT EXISTS "wd_object_count" (
-    "id" int NOT NULL AUTO_INCREMENT COMMENT 'id',
-     "group_code" varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '集团编码',
-    "project_id" varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '项目id',
-    "build_id" varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '建筑id',
-    "floor_id" varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '楼层id',
-    "system_code" varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '系统编码',
-    "bim_type_id" varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'BIM构建编码',
-    "class_name" varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '类型名称',
-    "count" int DEFAULT NULL COMMENT '对象数量',
-    "area" double(10,2) DEFAULT NULL,
-    "valid" int DEFAULT '1',
-    "create_time" datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-    "update_time" datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-    PRIMARY KEY ("id")
 ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;