Browse Source

实现/rel-manual-calc/add接口

lijie 3 years ago
parent
commit
ef5c02e0f3

+ 4 - 0
src/main/java/com/persagy/proxy/adm/constant/AdmObjectInfoConstant.java

@@ -28,4 +28,8 @@ public interface AdmObjectInfoConstant {
     Set<String> CHECK_SENSOR_CODES= CollUtil.newHashSet("SPVSCM","FFEALS","FFFPSE","FFFASE","SPIASE",
     Set<String> CHECK_SENSOR_CODES= CollUtil.newHashSet("SPVSCM","FFEALS","FFFPSE","FFFASE","SPIASE",
             "WEGMCM","WEOFCM","WEGMPD","FFGASE","OTSESP","OTSESD","OTSETP","OTSEVD","OTSEPS","OTSEPF","OTSERH",
             "WEGMCM","WEOFCM","WEGMPD","FFGASE","OTSESP","OTSESD","OTSETP","OTSEVD","OTSEPS","OTSEPF","OTSERH",
             "OTSEIP","OTSEIL","OTSEHT","OTSECB","OTSECT","OTSEEE","OTSEDP","OTSEFL");
             "OTSEIP","OTSEIL","OTSEHT","OTSECB","OTSECT","OTSEEE","OTSEDP","OTSEFL");
+    /**重复检查主对象的type与从对象的type是否重复*/
+    Set<String> CHECK_SPECIAL_TYPES= CollUtil.newHashSet("sp2sp_RadiationNetwork_2","sp2sp_RadiationNetwork_1",
+            "sp2sp_ConvectionNetwork_2","sp2sp_ConvectionNetwork_3","sp2sp_ConvectionNetwork_1",
+            "sp2sp_TrafficNetwork_3","sp2sp_TrafficNetwork_2","sp2sp_TrafficNetwork_1");
 }
 }

+ 43 - 0
src/main/java/com/persagy/proxy/adm/constant/BusinessErrorRwdCode.java

@@ -0,0 +1,43 @@
+package com.persagy.proxy.adm.constant;
+
+/***
+ * Description: rwd定制的错误返回码
+ * @author : lijie
+ * @date :2021/9/3 14:25
+ * Update By lijie 2021/9/3 14:25
+ */
+public enum BusinessErrorRwdCode {
+    /**
+     * A73XX:代表关系计算的错误码
+     *
+     * */
+	A7301("A7301", ":不存在"),
+    A7302("A7302", ":存在多个实例"),
+    A7303("A7303", ":不存在"),
+    A7304("A7304", ":存在多个实例"),
+    A7305("A7305", ":错误的类型参考:这里的传感器包含车库摄像头,车位检测器,办公摄像头,火灾探测器,燃气探测器,漏电探测器,消防设备电源传感器,监控摄像头,入侵报警探测器,以及传感器系统下所有设备类型"),
+    A7306("A7306", ":不符合主对象条件限制");
+
+    private String code;
+
+    private String desc;
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    private BusinessErrorRwdCode(String code, String desc) {
+        this.desc = desc;
+        this.code = code;
+    }
+
+    @Override
+    public String toString() {
+        return this.code + "_" + this.desc;
+    }
+
+}

+ 11 - 8
src/main/java/com/persagy/proxy/adm/controller/AdmManualRelationCalcController.java

@@ -2,13 +2,11 @@ package com.persagy.proxy.adm.controller;
 
 
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
-import com.persagy.proxy.adm.model.AdmTenant;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
-import com.persagy.proxy.adm.request.AdmQueryCriteria;
-import com.persagy.proxy.adm.request.AdmResponse;
-import com.persagy.proxy.adm.service.AdmManualRelationCalcService;
+import com.persagy.proxy.adm.service.AdmManualRelCalService;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -25,9 +23,11 @@ import javax.ws.rs.QueryParam;
 @RestController
 @RestController
 @RequestMapping("/rel-manual-calc/")
 @RequestMapping("/rel-manual-calc/")
 @RequiredArgsConstructor
 @RequiredArgsConstructor
-public class AdmManualRelationCalcController {
+public class AdmManualRelCalController {
 
 
-    private final AdmManualRelationCalcService admManualRelationCalcService;
+    private final AdmManualRelCalService admManualRelationCalcService;
+    @Value("${middleware.group.code}")
+    private String groupCode;
     
     
     /***
     /***
      * Description: 添加关系
      * Description: 添加关系
@@ -38,8 +38,11 @@ public class AdmManualRelationCalcController {
      * Update By lijie 2021/8/31 12:10
      * Update By lijie 2021/8/31 12:10
      */
      */
     @PostMapping(value = "add")
     @PostMapping(value = "add")
-    public AdmCreateResponse addRels(@RequestBody AdmRelationAddRequest request) throws Exception {
-        return admManualRelationCalcService.addRels(request);
+    public AdmCreateResponse addRels(@QueryParam("projectId") String projectId,
+                                     @RequestBody AdmRelationAddRequest request) throws Exception {
+        // 组装上下文条件
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        return admManualRelationCalcService.addRels(context,request);
     }
     }
 
 
 
 

+ 2 - 1
src/main/java/com/persagy/proxy/adm/model/AdmRelationAddRequest.java

@@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 
 
 @Data
 @Data
 @Builder
 @Builder
@@ -27,7 +28,7 @@ public class AdmRelationAddRequest implements Serializable {
     private String mainContent;
     private String mainContent;
 
 
     /**从对象内容*/
     /**从对象内容*/
-    private List<String> fromContent;
+    private Set<String> fromContent;
 
 
     /**图类型编码*/
     /**图类型编码*/
     @JsonAlias({"graphicType","graphic_type"})
     @JsonAlias({"graphicType","graphic_type"})

+ 4 - 0
src/main/java/com/persagy/proxy/adm/request/AdmCreateResponse.java

@@ -34,6 +34,10 @@ public class AdmCreateResponse {
         return new AdmCreateResponse(SUCCESS, null, null, null);
         return new AdmCreateResponse(SUCCESS, null, null, null);
     }
     }
 
 
+    public static AdmCreateResponse success(String message) {
+        return new AdmCreateResponse(SUCCESS, message, null, null);
+    }
+
     public static AdmCreateResponse failure(String message) {
     public static AdmCreateResponse failure(String message) {
         return new AdmCreateResponse(FAILURE, message, null, new ArrayList<>());
         return new AdmCreateResponse(FAILURE, message, null, new ArrayList<>());
     }
     }

+ 7 - 3
src/main/java/com/persagy/proxy/adm/service/AdmManualRelationCalcService.java

@@ -2,20 +2,24 @@ package com.persagy.proxy.adm.service;
 
 
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+
 /***
 /***
  * Description: 手动关系计算逻辑处理接口
  * Description: 手动关系计算逻辑处理接口
  * @author : lijie
  * @author : lijie
  * @date :2021/8/31 12:14
  * @date :2021/8/31 12:14
  * Update By lijie 2021/8/31 12:14
  * Update By lijie 2021/8/31 12:14
  */
  */
-public interface AdmManualRelationCalcService {
+public interface AdmManualRelCalService {
     /***
     /***
      * Description: 添加关系
      * Description: 添加关系
+     *
+     * @param context: 存储集团编码及项目id的上下文
      * @param request : 请求参数
      * @param request : 请求参数
-     * @return : com.persagy.proxy.adm.request.AdmCreateResponse  
+     * @return : com.persagy.proxy.adm.request.AdmCreateResponse
      * @author : lijie
      * @author : lijie
      * @date :2021/8/31 12:14
      * @date :2021/8/31 12:14
      * Update By lijie 2021/8/31 12:14
      * Update By lijie 2021/8/31 12:14
      */
      */
-    AdmCreateResponse addRels(AdmRelationAddRequest request);
+    AdmCreateResponse addRels(InstanceUrlParam context, AdmRelationAddRequest request);
 }
 }

+ 58 - 19
src/main/java/com/persagy/proxy/adm/service/impl/AbstractAdmManualRelationCalcServiceImpl.java

@@ -2,16 +2,25 @@ package com.persagy.proxy.adm.service.impl;
 
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
+import com.persagy.dmp.basic.dto.RequestData;
 import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.digital.client.DigitalRelationCaclClient;
+import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmObjectInfoConstant;
 import com.persagy.proxy.adm.constant.AdmObjectInfoConstant;
+import com.persagy.proxy.adm.constant.BusinessErrorRwdCode;
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
 import com.persagy.proxy.adm.model.AdmRelationAddRequest;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
 import com.persagy.proxy.adm.request.AdmCreateResponse;
-import com.persagy.proxy.adm.service.AdmManualRelationCalcService;
+import com.persagy.proxy.adm.service.AdmManualRelCalService;
 import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Set;
 
 
 /***
 /***
  * Description: 手动计算逻辑处理类
  * Description: 手动计算逻辑处理类
@@ -21,10 +30,16 @@ import java.util.Map;
  */
  */
 @Service
 @Service
 @Slf4j
 @Slf4j
-public class AbstractAdmManualRelationCalcServiceImpl implements AdmManualRelationCalcService {
+@RequiredArgsConstructor
+public class AdmManualRelCalServiceImpl implements AdmManualRelCalService {
+
+    private final DigitalRelationCaclClient digitalRelationCaclClient;
+
 
 
     /***
     /***
      * Description: 添加关系
      * Description: 添加关系
+     *
+     * @param context
      * @param request : 请求参数
      * @param request : 请求参数
      * @return : com.persagy.proxy.adm.request.AdmCreateResponse
      * @return : com.persagy.proxy.adm.request.AdmCreateResponse
      * @author : lijie
      * @author : lijie
@@ -32,7 +47,7 @@ public class AbstractAdmManualRelationCalcServiceImpl implements AdmManualRelati
      * Update By lijie 2021/8/31 12:14
      * Update By lijie 2021/8/31 12:14
      */
      */
     @Override
     @Override
-    public AdmCreateResponse addRels(AdmRelationAddRequest request) {
+    public AdmCreateResponse addRels(InstanceUrlParam context, AdmRelationAddRequest request) {
         // 获取项目id
         // 获取项目id
         String projectId = AppContext.getContext().getProjectId();
         String projectId = AppContext.getContext().getProjectId();
         if (StrUtil.isBlank(request.getRelType())){
         if (StrUtil.isBlank(request.getRelType())){
@@ -66,14 +81,45 @@ public class AbstractAdmManualRelationCalcServiceImpl implements AdmManualRelati
         if (AdmObjectInfoConstant.CADID.equals(request.getType()) && relationTypeEnum.getHasCheckCadId()){
         if (AdmObjectInfoConstant.CADID.equals(request.getType()) && relationTypeEnum.getHasCheckCadId()){
             return AdmCreateResponse.failure("从对象不存在CADID编码","2");
             return AdmCreateResponse.failure("从对象不存在CADID编码","2");
         }
         }
-
-
-
-
-        // 1.根据项目id和关系类型更新计算时间为当前时间
-        // 2.根据不同关系类型进行处理
-
-
+        // relType为下面几种的从对象不能重复,主对象和从对象不能重复
+        if (AdmObjectInfoConstant.CHECK_SPECIAL_TYPES.contains(request.getRelType())){
+            Set<String> fromContent = request.getFromContent();
+            if (fromContent.contains(request.getMainContent())){
+                return AdmCreateResponse.failure(request.getMainContent()+":从对象不能重复","2");
+            }
+        }
+        RequestData requestData = RequestData.builder()
+                .graphCode(relationTypeEnum.getGraphCode())
+                .relCode(relationTypeEnum.getRelCode())
+                .masterObjType(relationTypeEnum.getMasterObjType())
+                .slaveObjType(relationTypeEnum.getSlaveObjType())
+                .type(request.getType())
+                .hasRelValue(relationTypeEnum.getHasRelValue())
+                .hasFilterMasterId(relationTypeEnum.getHasFilterMasterId())
+                .hasFilterClassCode(relationTypeEnum.getHasFilterClassCode())
+                .hasCheckSensor(relationTypeEnum.getHasCheckSensor())
+                .hasCheckClassCode(relationTypeEnum.getHasCheckClassCode())
+                .checkClassCodes(relationTypeEnum.getCheckClassCodes())
+                .checkSensorCodes(relationTypeEnum.getCheckSensorCodes())
+                .sign("1")
+                .mainContent(request.getMainContent())
+                .fromContent(request.getFromContent())
+                .build();
+        CommonResult<List<ObjectRelation>> commonResult = digitalRelationCaclClient
+                .createObjRelationsByKeywordAndObjType(context.getGroupCode(), context.getProjectId(),
+                        context.getAppId(), "0", requestData);
+        if (BusinessErrorRwdCode.A7301.getCode().equals(commonResult.getResult())
+                || BusinessErrorRwdCode.A7302.getCode().equals(commonResult.getResult())
+                || BusinessErrorRwdCode.A7305.getCode().equals(commonResult.getResult())
+                || BusinessErrorRwdCode.A7306.getCode().equals(commonResult.getResult())){
+            return AdmCreateResponse.failure(commonResult.getMessage(),"1");
+        }
+        if (BusinessErrorRwdCode.A7303.getCode().equals(commonResult.getResult())
+                || BusinessErrorRwdCode.A7304.getCode().equals(commonResult.getResult())){
+            return AdmCreateResponse.failure(commonResult.getMessage(),"2");
+        }
+        return AdmCreateResponse.success("添加成功");
+        // 原数据中心逻辑
         // 2.2 特殊类型的判断
         // 2.2 特殊类型的判断
         // *******
         // *******
         // sp2sp_RadiationNetwork_2,sp2sp_RadiationNetwork_1 && classCode!=LightingZone errorType=1,不是照明分区类型
         // sp2sp_RadiationNetwork_2,sp2sp_RadiationNetwork_1 && classCode!=LightingZone errorType=1,不是照明分区类型
@@ -219,17 +265,10 @@ public class AbstractAdmManualRelationCalcServiceImpl implements AdmManualRelati
         // 传感器类型检查
         // 传感器类型检查
         // eq2sp_SensorRelationship_ss2sp:图类型为SensorRelationship,边类型为Ss2Sp
         // eq2sp_SensorRelationship_ss2sp:图类型为SensorRelationship,边类型为Ss2Sp
         // *****
         // *****
-        // eq2sp_x
+        // eq2sp_x,已经不存在的类型
         // bd2bd_ArchForArch,bd2fl_ArchForArch,bd2sh_ArchForArch,bd2sp_ArchForArch,fl2bd_ArchForArch,fl2fl_ArchForArch
         // bd2bd_ArchForArch,bd2fl_ArchForArch,bd2sh_ArchForArch,bd2sp_ArchForArch,fl2bd_ArchForArch,fl2fl_ArchForArch
         // fl2sh_ArchForArch,fl2sp_ArchForArch,sh2bd_ArchForArch,sh2fl_ArchForArch,sh2sh_ArchForArch,sh2sp_ArchForArch
         // fl2sh_ArchForArch,fl2sp_ArchForArch,sh2bd_ArchForArch,sh2fl_ArchForArch,sh2sh_ArchForArch,sh2sp_ArchForArch
         // sp2bd_ArchForArch,sp2fl_ArchForArch,sp2sh_ArchForArch,sp2sp_ArchForArch
         // sp2bd_ArchForArch,sp2fl_ArchForArch,sp2sh_ArchForArch,sp2sp_ArchForArch
 
 
-
-
-
-
-
-
-        return null;
     }
     }
 }
 }