Selaa lähdekoodia

fix bug:修改楼层及空间逻辑附带的关系计算逻辑,改为异步执行

lijie 3 vuotta sitten
vanhempi
commit
5b05befa7b

+ 2 - 0
src/main/java/com/persagy/proxy/common/config/AdmMiddlewareWebConfigurer.java

@@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.Order;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@@ -19,6 +20,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  */
 @Configuration
 @Order(1)
+@EnableAsync
 public class AdmMiddlewareWebConfigurer implements WebMvcConfigurer {
 
     @Bean

+ 4 - 1
src/main/java/com/persagy/proxy/object/controller/AdmFloorController.java

@@ -11,6 +11,7 @@ import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.adm.utils.ObjectNameUtil;
 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;
@@ -219,8 +220,10 @@ public class AdmFloorController {
         // 组装上下文条件
         AdmResponse admResponse = update(admFloor);
 
+        InstanceUrlParam context = AdmContextUtil.toDmpContext();
+
         /** 处理关系标记 */
-        service.processRelationType((List<AdmFloor>) admResponse.getContent());
+        service.processRelationType(context,(List<AdmFloor>) admResponse.getContent());
         return admResponse;
     }
 

+ 3 - 2
src/main/java/com/persagy/proxy/object/service/IAdmFloorService.java

@@ -49,7 +49,8 @@ public interface IAdmFloorService extends IAdmBaseService<AdmFloor> {
 
     /**
      * 关系计算处理
-     * @param vos
+     * @param context: 上下文数据,因方法为异步方法,ThreadLocal无法多线程之间共享变量.暂时使用Spring的异步
+     * @param vos: 楼层数据
      */
-    void processRelationType(List<AdmFloor> vos);
+    void processRelationType(InstanceUrlParam context,List<AdmFloor> vos);
 }

+ 1 - 1
src/main/java/com/persagy/proxy/object/service/IAdmSpaceService.java

@@ -110,5 +110,5 @@ public interface IAdmSpaceService extends IAdmBaseService<AdmSpace> {
     /**
      * 处理关系计算
      */
-    void processRelationType(List<AdmSpace> vos);
+    void processRelationType(InstanceUrlParam context,List<AdmSpace> vos);
 }

+ 11 - 4
src/main/java/com/persagy/proxy/object/service/impl/AdmFloorServiceImpl.java

@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.helper.SpringHelper;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.constant.GraphCodeEnum;
 import com.persagy.proxy.adm.constant.RelCodeEnum;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
@@ -22,6 +23,7 @@ import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.object.model.AdmFloor;
 import com.persagy.proxy.object.service.IAdmFloorService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -79,9 +81,14 @@ public class AdmFloorServiceImpl extends AbstractAdmBaseServiceImpl<AdmFloor> im
         ensureSpecialValues(context, admFloors, QUERY);
         return response;
     }
-
+    /**
+     * 关系计算处理
+     * @param context: 上下文数据,因方法为异步方法,ThreadLocal无法多线程之间共享变量.暂时使用Spring的异步
+     * @param vos: 楼层数据
+     */
+    @Async
     @Override
-    public void processRelationType(List<AdmFloor> vos) {
+    public void processRelationType(InstanceUrlParam context,List<AdmFloor> vos) {
         /**
          isttype.add("sh2bd")
          listtype.add("bd2sp")
@@ -92,7 +99,7 @@ public class AdmFloorServiceImpl extends AbstractAdmBaseServiceImpl<AdmFloor> im
          listtype.add("pe2bd")
          listtype.add("pe2fl")
          */
-        /*admRelCalService.calcRelation(AdmContextUtil.toDmpContext(),
+        admRelCalService.calcRelation(AdmContextUtil.toDmpContext(),
                 //暂不支持资产的关系计算
                 CollUtil.newArrayList(
                         AdmRelationTypeEnum.SH2BD,
@@ -104,7 +111,7 @@ public class AdmFloorServiceImpl extends AbstractAdmBaseServiceImpl<AdmFloor> im
                         //AdmRelationTypeEnum.PE2BD,
                         //AdmRelationTypeEnum.PE2FL
                 ),
-                null);*/
+                null);
     }
 
     /***

+ 9 - 6
src/main/java/com/persagy/proxy/object/service/impl/AdmSpaceServiceImpl.java

@@ -22,6 +22,7 @@ import com.persagy.dmp.digital.client.DigitalObjectFacade;
 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.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.constant.GraphCodeEnum;
 import com.persagy.proxy.adm.constant.RelCodeEnum;
 import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
@@ -47,6 +48,7 @@ import com.persagy.proxy.report.service.IRelationReportService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
@@ -101,7 +103,7 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         //添加绑定关系
         processRelations(vosR);
         //处理关系标记
-        processRelationType(vosR);
+        SpringHelper.getBean(IAdmSpaceService.class).processRelationType(context,vosR);
         return vosR;
     }
 
@@ -337,7 +339,7 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     public AdmResponse updateOutLine(List<AdmSpace> vos) {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
         vos = super.doUpdate(context,  AdmSpace.class, vos);
-        processRelationType(vos);
+        SpringHelper.getBean(IAdmSpaceService.class).processRelationType(context,vos);
         return AdmResponse.success(vos);
     }
 
@@ -345,9 +347,10 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
      * 触发关系计算
      * @param vos
      */
+    @Async
     @Override
-    public void processRelationType(List<AdmSpace> vos) {
-       /* admRelCalService.calcRelation(AdmContextUtil.toDmpContext(),
+    public void processRelationType(InstanceUrlParam context,List<AdmSpace> vos) {
+        admRelCalService.calcRelation(context,
                 CollUtil.newArrayList(
                         AdmRelationTypeEnum.SP2SP_SPACENEIGHBORHOOD_5,
                         AdmRelationTypeEnum.SP2SP_TRAFFICNETWORK_3,
@@ -355,9 +358,9 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
                         AdmRelationTypeEnum.SP2SP_RADIATIONNETWORK_1),null);
 
         vos.forEach(admSpace -> {
-            admRelCalService.calcRelation(AdmContextUtil.toDmpContext(),
+            admRelCalService.calcRelation(context,
                     CollUtil.newArrayList(AdmRelationTypeEnum.EQ2SP_IN),admSpace.getClassCode());
-        });*/
+        });
     }
 
     /***