Browse Source

优化:/rwd/instance/object/queryObjectListSuperiorId接口查询慢

lijie 3 years ago
parent
commit
f6402ab13a

+ 34 - 16
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/basic/constant/DigitalRelCode.java

@@ -1,7 +1,11 @@
 package com.persagy.dmp.rwd.basic.constant;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.EnumUtil;
 import lombok.Getter;
 
+import java.util.List;
+
 /**
  * 对象类型
  * @author Charlie Yu
@@ -10,27 +14,41 @@ import lombok.Getter;
 @Getter
 public enum DigitalRelCode {
     /** 对象类型 */
-    BD_2_FL("Bd2Fl", "建筑下的楼层"),
-    BD_2_SH("Bd2Sh", "建筑下的竖井"),
-    BD_2_SP("Bd2Sp", "建筑下的业务空间"),
-    FL_2_SP("Fl2Sp", "楼层下的业务空间"),
-    SH_2_SP("Sh2Sp", "竖井下的业务空间"),
-    SY_2_BD("Sy2Bd", "系统所在建筑"),
-    SY_2_FL("Sy2Fl", "系统所在楼层"),
-    SY_2_SH("Sy2Sh", "系统所在竖井"),
-    SY_2_SP("Sy2Sp", "系统所在空间"),
-    EQ_2_BD("Eq2Bd", "设备所在建筑"),
-    EQ_2_FL("Eq2Fl", "设备所在楼层"),
-    EQ_2_SH("Eq2Sh", "设备所在竖井"),
-    EQ_2_SP("Eq2Sp", "设备所在空间"),
-    SY_2_EQ("Sy2Eq", "系统下的设备"),
-    EQ_2_EC("Eq2Ec", "设备下的部件");
+    BD_2_FL("Bd2Fl", "建筑下的楼层","building","floor"),
+    BD_2_SH("Bd2Sh", "建筑下的竖井","building","shaft"),
+    BD_2_SP("Bd2Sp", "建筑下的业务空间","building","space"),
+    FL_2_SP("Fl2Sp", "楼层下的业务空间","floor","space"),
+    SH_2_SP("Sh2Sp", "竖井下的业务空间","shaft","space"),
+    SY_2_BD("Sy2Bd", "系统所在建筑","system","building"),
+    SY_2_FL("Sy2Fl", "系统所在楼层","system","floor"),
+    SY_2_SH("Sy2Sh", "系统所在竖井","system","shaft"),
+    SY_2_SP("Sy2Sp", "系统所在空间","system","space"),
+    EQ_2_BD("Eq2Bd", "设备所在建筑","equipment","building"),
+    EQ_2_FL("Eq2Fl", "设备所在楼层","equipment","floor"),
+    EQ_2_SH("Eq2Sh", "设备所在竖井","equipment","shaft"),
+    EQ_2_SP("Eq2Sp", "设备所在空间","equipment","space"),
+    SY_2_EQ("Sy2Eq", "系统下的设备","system","equipment"),
+    EQ_2_EC("Eq2Ec", "设备下的部件","equipment","component");
 
     private String index;
     private String name;
+    private String fromType;
+    private String toType;
 
-    DigitalRelCode(String index, String name) {
+    DigitalRelCode(String index, String name,String fromType,String toType) {
         this.index = index;
         this.name = name;
+        this.fromType = fromType;
+        this.toType = toType;
+    }
+    /**
+     * 获取枚举对象列表
+     * @return : java.util.List<com.persagy.dmp.rwd.basic.constant.DigitalRelCode>
+     * @author : lijie
+     * Update By 2022/1/10 12:58
+     */
+    public static List<DigitalRelCode> getDigitalRelCodeList(){
+        return CollUtil.newArrayList(EnumUtil.getEnumMap(DigitalRelCode.class).values());
     }
+
 }

+ 1 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/config/DigitalRabbitConfig.java

@@ -6,6 +6,7 @@ import org.springframework.amqp.core.Binding;
 import org.springframework.amqp.core.BindingBuilder;
 import org.springframework.amqp.core.Queue;
 import org.springframework.amqp.core.TopicExchange;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 

+ 45 - 14
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/ObjectDigitalServiceImpl.java

@@ -41,6 +41,7 @@ import com.persagy.dmp.rwd.parser.service.InfoDataFactory;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -534,6 +535,20 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
      * Update By lijie 2021/8/24 21:20
      */
     private void fillSubordinateRelCode(RequestData requestData) {
+        Set<String> validRelCodes = new HashSet<>();
+        if (CollUtil.isNotEmpty(requestData.getObjTypes())){
+            // 如果objTypes不为空,则根据objTypes进行关系设置
+            List<DigitalRelCode> list = DigitalRelCode.getDigitalRelCodeList();
+            Set<String> objTypes = requestData.getObjTypes();
+            for (String objType : objTypes) {
+                for (DigitalRelCode code:list){
+                    if (code.getFromType().equals(objType)
+                            || code.getToType().equals(objType)){
+                        validRelCodes.add(code.getIndex());
+                    }
+                }
+            }
+        }
         if (StrUtil.isNotBlank(requestData.getEquipmentId())){
             // 设备下的部件
             requestData.setRelCodes(CollUtil.newHashSet(DigitalRelCode.EQ_2_EC.getIndex()));
@@ -542,24 +557,40 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
         }
         if (StrUtil.isNotBlank(requestData.getFloorId())){
             // 楼层下的空间,设备,系统
-            requestData.setRelCodes(CollUtil.newHashSet(DigitalRelCode.FL_2_SP.getIndex(),
-                    DigitalRelCode.EQ_2_FL.getIndex(),DigitalRelCode.SY_2_FL.getIndex()));
-            // 设置设备查询部件
-            requestData.setQueryEcFlag(true);
-            requestData.setEcRelCodes(CollUtil.newHashSet(DigitalRelCode.EQ_2_EC.getIndex()));
-            requestData.setFilterObjId(requestData.getFloorId());
+            Set<String> queryRels = CollUtil.newHashSet(DigitalRelCode.FL_2_SP.getIndex(),
+                    DigitalRelCode.EQ_2_FL.getIndex(), DigitalRelCode.SY_2_FL.getIndex());
+            commonFillRelCode(requestData,queryRels,validRelCodes,requestData.getFloorId());
             return;
         }
         if (StrUtil.isNotBlank(requestData.getBuildingId())){
-            // 建筑下的楼层,空间,设备,系统
-            requestData.setRelCodes(CollUtil.newHashSet(DigitalRelCode.BD_2_FL.getIndex(),
-                    DigitalRelCode.BD_2_SP.getIndex(),DigitalRelCode.SY_2_BD.getIndex(),
-                    DigitalRelCode.EQ_2_BD.getIndex(),DigitalRelCode.BD_2_SH.getIndex()));
-            // 设置设备查询部件
-            requestData.setQueryEcFlag(true);
-            requestData.setEcRelCodes(CollUtil.newHashSet(DigitalRelCode.EQ_2_EC.getIndex()));
-            requestData.setFilterObjId(requestData.getBuildingId());
+            Set<String> queryRels = CollUtil.newHashSet(DigitalRelCode.BD_2_FL.getIndex(),
+                    DigitalRelCode.BD_2_SP.getIndex(), DigitalRelCode.SY_2_BD.getIndex(),
+                    DigitalRelCode.EQ_2_BD.getIndex(), DigitalRelCode.BD_2_SH.getIndex());
+            commonFillRelCode(requestData,queryRels,validRelCodes,requestData.getBuildingId());
+        }
+    }
+    /**
+     * 公共注入关系的方法
+     * @param requestData : 请求参数
+     * @param queryRels : 查询关系
+     * @param validRelCodes : 校验关系列表
+     * return : void
+     * @author : lijie
+     * Update By 2022/1/10 14:43
+     */
+    private void commonFillRelCode(RequestData requestData, Set<String> queryRels,Set<String> validRelCodes,String filterObjId) {
+        if (CollUtil.isNotEmpty(validRelCodes)){
+            queryRels = CollUtil.intersectionDistinct(queryRels,validRelCodes);
+        }
+        requestData.setRelCodes(queryRels);
+        requestData.setFilterObjId(filterObjId);
+        if (CollUtil.isNotEmpty(validRelCodes)
+                && !validRelCodes.contains(DigitalRelCode.EQ_2_EC.getIndex())){
+            return;
         }
+        // 设置设备查询部件
+        requestData.setQueryEcFlag(true);
+        requestData.setEcRelCodes(CollUtil.newHashSet(DigitalRelCode.EQ_2_EC.getIndex()));
     }
 
     /***

+ 1 - 1
dmp-business/dmp-rwd/src/main/resources/mapper/ObjectDigitalMapper.xml

@@ -143,7 +143,7 @@
         </include>
     </sql>
     <sql id="queryObjDataUnionEcData">
-        <if test="param.queryEcFlag!=null and param.queryEcFlag='true'">
+        <if test="param.queryEcFlag!=null and param.queryEcFlag==true">
             UNION
             (<include refid="commonQueryObjByRelSubTo">
                 <property name="param" value="#{param}"/>