Browse Source

完成calculatingObjRelation接口(暂时只完成两种计算器)

lijie 3 năm trước cách đây
mục cha
commit
9fe8e94689

+ 5 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/domain/CalculatingDTO.java

@@ -67,6 +67,11 @@ public class CalculatingDTO {
     @JsonProperty("calBeforeRelFlag")
     @JSONField(name = "calBeforeRelFlag",alternateNames = {"calBeforeRelFlag","cal_before_rel_flag"})
     private Boolean calBeforeRelFlag=false;
+    /** 是否根据关系id过滤,true-过滤,false-不过滤.默认过滤 */
+    @JsonAlias({"filterRelFlag","filter_rel_flag"})
+    @JsonProperty("filterRelFlag")
+    @JSONField(name = "filterRelFlag",alternateNames = {"filterRelFlag","filter_rel_flag"})
+    private Boolean filterRelFlag=true;
     /** 关系定义映射 */
     @JsonAlias({"relationDefineMap","relation_define_map"})
     @JsonProperty("relationDefineMap")

+ 9 - 10
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/CoordinateCalculateServiceImpl.java

@@ -26,10 +26,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /***
  * Description: 根据坐标计算关系的策略类
@@ -65,8 +62,6 @@ public class CoordinateCalculateServiceImpl implements CalculateService {
             throw new BusinessException(BusinessErrorRwdCode.A7312.getCode(),BusinessErrorRwdCode.A7312.getDesc());
         }
         // 试验过sql计算后,发现效率低下.先暂时使用java实现
-        String fromObjType = relationDefine.getFromObjType();
-        String toObjType = relationDefine.getToObjType();
         // 1.先分页查询from对象,在分页处理to对象
         Boolean calRelFromFileRelFlag = graphCalInfo.getCalRelFromFileRelFlag();
         if (null!=calRelFromFileRelFlag && calRelFromFileRelFlag){
@@ -77,14 +72,18 @@ public class CoordinateCalculateServiceImpl implements CalculateService {
         if (graphCalInfo.getFromIsPointFlag()){
             // 左侧为点,则对左侧点做分页操作
             calculateRelationInternal(graphCalInfo,calculatingDTO,
-                    calculatingDTO.getFromIds(),relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode(),
-                    calculatingDTO.getToIds(),relationDefine.getToObjType(),graphCalInfo.getToInfoCode());
+                    calculatingDTO.getFilterRelFlag()?calculatingDTO.getFromIds():new HashSet<>(),
+                    relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode(),
+                    calculatingDTO.getFilterRelFlag()?calculatingDTO.getToIds():new HashSet<>(),
+                    relationDefine.getToObjType(),graphCalInfo.getToInfoCode());
             return;
         }
         // 右侧为点
         calculateRelationInternal(graphCalInfo,calculatingDTO,
-                calculatingDTO.getToIds(),relationDefine.getToObjType(),graphCalInfo.getToInfoCode(),
-                calculatingDTO.getFromIds(),relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode());
+                calculatingDTO.getFilterRelFlag()?calculatingDTO.getToIds():new HashSet<>(),
+                relationDefine.getToObjType(),graphCalInfo.getToInfoCode(),
+                calculatingDTO.getFilterRelFlag()?calculatingDTO.getFromIds():new HashSet<>(),
+                relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode());
     }
     /***
      * Description: 内部的计算关系

+ 20 - 7
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/RelationCalServiceImpl.java

@@ -1,5 +1,6 @@
 package com.persagy.dmp.rwd.digital.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.NumberUtil;
@@ -246,10 +247,20 @@ public class RelationCalServiceImpl implements RelationCalService {
         calculatingDTO.setRelationDefineMap(relationDefineMap);
         // 2.1 前置关系是否存在,如果存在先处理前置关系
         handlePreRelation(currentRelationDefine,calculatingDTO);
-
-
-
-
+        // 2.2 计算自身关系
+        // 因为根据空间坐标计算关系需要知道关系两侧对应的对象分类,所以这里直接冗余存储一下关系定义对象
+        calculatingDTO.setRelationDefine(currentRelationDefine);
+        String calRuleType = currentRelationDefine.getCalRules().getCalRuleType();
+        // {规则索引值:对应的算法类名称},用枚举记录计算策略实体类名称
+        Map<String, String> calRuleTypeMap = CalRuleTypeEnum.getCalRuleTypeMap();
+        if (!calRuleTypeMap.containsKey(calRuleType)) {
+            throw new BusinessException(BusinessErrorRwdCode.A7308.getCode(), BusinessErrorRwdCode.A7308.getDesc());
+        }
+        // 获取策略类的bean
+        CalculateService calculateService = SpringHelper
+                .getBean(calRuleTypeMap.get(calRuleType), CalculateService.class);
+        // 根据计算规则和参数计算关系
+        calculateService.calculateRelation(currentRelationDefine.getCalRules(), calculatingDTO);
         return ResultHelper.multi(new ArrayList<>(),0L);
     }
     /***
@@ -305,10 +316,12 @@ public class RelationCalServiceImpl implements RelationCalService {
         if (!calculatingDTO.getCalBeforeRelFlag()){
             return;
         }
+        CalculatingDTO preCalculatingDTO = BeanUtil.toBean(calculatingDTO, CalculatingDTO.class);
+        preCalculatingDTO.setFilterRelFlag(false);
         // 关系定义中的必须计算的前置关系
         List<RelationCalDTO> beforeCalRels = currentRelationDefine.getBeforeCalRels();
         // {图编码_关系编码:关系定义对象}
-        Map<String, RelationDefine> relationDefineMap = calculatingDTO.getRelationDefineMap();
+        Map<String, RelationDefine> relationDefineMap = preCalculatingDTO.getRelationDefineMap();
         // {规则索引值:对应的算法类名称},用枚举记录计算策略实体类名称
         Map<String, String> calRuleTypeMap = CalRuleTypeEnum.getCalRuleTypeMap();
         for (RelationCalDTO relationCalDTO : beforeCalRels) {
@@ -329,12 +342,12 @@ public class RelationCalServiceImpl implements RelationCalService {
                 throw new BusinessException(BusinessErrorRwdCode.A7308.getCode(), BusinessErrorRwdCode.A7308.getDesc());
             }
             // 因为根据空间坐标计算关系需要知道关系两侧对应的对象分类,所以这里直接冗余存储一下关系定义对象
-            calculatingDTO.setRelationDefine(relationDefine);
+            preCalculatingDTO.setRelationDefine(relationDefine);
             // 获取策略类的bean
             CalculateService calculateService = SpringHelper
                     .getBean(calRuleTypeMap.get(calRules.getCalRuleType()), CalculateService.class);
             // 根据计算规则和参数计算关系
-            calculateService.calculateRelation(calRules, calculatingDTO);
+            calculateService.calculateRelation(calRules, preCalculatingDTO);
         }
     }