浏览代码

增加系统下的设备设施接口

luoguangyi 3 年之前
父节点
当前提交
6dd5ca1d45

+ 4 - 4
src/main/java/com/persagy/proxy/adm/controller/REqForSpConreoller.java

@@ -27,7 +27,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping("/rel/eq-for-sp-base")
-public class REqForSpConreoller {
+public class RelationEqForSpConreoller {
 
     @Autowired
     private IAdmRelationService service;
@@ -62,7 +62,7 @@ public class REqForSpConreoller {
                 return AdmResponse.failure("必填项:EquipId(设备id)、SpaceId(业务空间id)");
             }
             // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
-            voList.add(new RelationDTO(null, "EquipforSpace", "Eq2Sp", type, equipId, spaceId));
+            voList.add(new RelationDTO(null, "MechForArch", "Eq2Sp", type, equipId, spaceId));
         }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
@@ -96,7 +96,7 @@ public class REqForSpConreoller {
                 continue;
             }
             // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
-            voList.add(new RelationDTO(null, "EquipforSpace", "Eq2Sp", type, equipId, spaceId));
+            voList.add(new RelationDTO(null, "MechForArch", "Eq2Sp", type, equipId, spaceId));
         }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
@@ -131,7 +131,7 @@ public class REqForSpConreoller {
                 return AdmResponse.failure("必填项:EquipId(设备id)、SpaceId(业务空间id)");
             }
             ObjectNode node = JsonNodeFactory.instance.objectNode();
-            node.put("graphCode", "EquipforSpace");
+            node.put("graphCode", "MechForArch");
             node.put("relCode", "Eq2Sp");
             node.put("relValue", type);
             node.put("objFrom", equipId);

+ 189 - 0
src/main/java/com/persagy/proxy/adm/controller/RelationSyEqController.java

@@ -0,0 +1,189 @@
+package com.persagy.proxy.adm.controller;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.proxy.adm.constant.AdmCommonConstant;
+import com.persagy.proxy.adm.request.AdmResponse;
+import com.persagy.proxy.adm.service.IAdmRelationService;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+import com.persagy.proxy.common.entity.RelationDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @description:系统下的设备设施
+ * @author:lgy
+ * @data:2021/9/3 15:25
+ */
+@RestController
+@RequestMapping("/rel/sy-in-eq")
+public class RelationSyEqController {
+
+    @Autowired
+    private IAdmRelationService service;
+    @Value("${middleware.group.code}")
+    private String groupCode;
+
+
+    /**
+     * 创建系统下的设备关系,数据叠加,不会覆盖以前的数据
+     * 必填项:EquipID(设备id)、SysID(系统id)
+     * @param param
+     * @return
+     * @throws Exception
+     */
+    @PostMapping(value = {"/link-sy-eq","/link"})
+    public AdmResponse create(@RequestParam("projectId") String projectId,
+                                @RequestBody JSONObject param) throws Exception {
+        String equipId = param.getString("equipId");
+        String sysID = param.getString("sysId");
+        if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
+            return AdmResponse.failure("必填项:EquipID(设备id)、SysID(系统id)");
+        }
+        // 创建关系对象
+        List<RelationDTO> voList = new ArrayList<>();
+        voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysID , equipId));
+        // 组装上下文条件
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        service.doSave(context, voList);
+        return AdmResponse.success();
+    }
+
+    /**
+     * 根据对象删除系统和设备的关系,只针对一个对象
+     *必填项:EquipID(设备id)、SysID(系统id)
+     * @param   param      对象
+     * @return             删除的结果信息
+     */
+
+    @PostMapping("/unlink")
+    public AdmResponse delete(@RequestParam String projectId,
+                              @RequestBody JSONObject param) throws Exception {
+        if(CollUtil.isEmpty(param)) {
+            return AdmResponse.success();
+        }
+        // 组装上下文条件
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        // 组装条件
+        QueryCriteria criteria = new QueryCriteria();
+        String equipId = param.getString("equipId");
+        String sysID = param.getString("sysId");
+        if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
+            return AdmResponse.failure("必填项:EquipID(设备id)、SysID(系统id)");
+        }
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        node.put("graphCode", "MechSubset");
+        node.put("relCode", "Sy2Eq");
+        node.put("objFrom", sysID);
+        node.put("objTo", equipId);
+        criteria.setCriteria(node);
+        service.doDelete(context, criteria);
+        return AdmResponse.success();
+    }
+
+    /**
+     * 创建系统下的设备关系
+     *
+     * @param   syEqList           系统和设备的关系对象
+     * @return                  创建结果信息
+     */
+    @PostMapping("/link-eq")
+    public AdmResponse createBatchWithDeleteOldsysIdRelation(@RequestParam("projectId") String projectId,
+                              @RequestBody JSONObject syEqList) throws Exception {
+        JSONArray equipIdList = syEqList.getJSONArray("equipIdList");
+        String sysId = syEqList.getString("sysId");
+        if(StrUtil.isBlank(sysId) || CollUtil.isEmpty(equipIdList)) {
+            return AdmResponse.failure("必填项:EquipIdList(设备id列表)、SysID(系统id)");
+        }
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        QueryCriteria queryRequest = new QueryCriteria();
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        node.put("graphCode", "MechSubset");
+        node.put("relCode", "Sy2Eq");
+        node.put("objFrom", sysId);
+        queryRequest.setCriteria(node);
+        service.doDelete(context,queryRequest);
+        // 创建关系对象
+        List<RelationDTO> voList = new ArrayList<>();
+        for (int i = 0; i < equipIdList.size(); i++) {
+            voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysId , equipIdList.getString(i)));
+        }
+        // 组装上下文条件
+        service.doSave(context, voList);
+        return AdmResponse.success();
+    }
+
+    /**
+     * 创建系统下的设备关系
+     *
+     * @param   param           系统和设备的关系对象
+     * @return                  创建结果信息
+     */
+    @PostMapping("/link-sy")
+    public AdmResponse createDistinctEq(@RequestParam("projectId") String projectId,
+                              @RequestBody JSONObject param) throws Exception {
+        String equipId = param.getString("equipId");
+        String sysID = param.getString("sysId");
+        if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
+            return AdmResponse.failure("必填项:EquipId(设备id)、sysIdList(系统id列表)");
+        }
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        QueryCriteria queryRequest = new QueryCriteria();
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        node.put("graphCode", "MechSubset");
+        node.put("relCode", "Sy2Eq");
+        node.put("objTo", equipId);
+        queryRequest.setCriteria(node);
+        service.doDelete(context,queryRequest);
+        // 创建关系对象
+        List<RelationDTO> voList = new ArrayList<>();
+        voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysID , equipId));
+        // 组装上下文条件
+        service.doSave(context, voList);
+        return AdmResponse.success();
+    }
+
+
+    /**
+     * 根据对象删除系统和设备的关系
+     *
+     * @param   entytyList           根据对象删除系统和设备的关系
+     * @return                  创建结果信息
+     */
+    public AdmResponse deleteBatch(@RequestParam String projectId,
+                              @RequestBody JSONArray entytyList) throws Exception {
+        if(CollUtil.isEmpty(entytyList)) {
+            return AdmResponse.success();
+        }
+        // 组装上下文条件
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+        for (int i = 0; i < entytyList.size(); i++) {
+            JSONObject entity = entytyList.getJSONObject(i);
+            // 组装条件
+            QueryCriteria criteria = new QueryCriteria();
+            String equipId = entity.getString("equipId");
+            String sysID = entity.getString("sysId");
+            if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
+                continue;
+            }
+            ObjectNode node = JsonNodeFactory.instance.objectNode();
+            node.put("graphCode", "MechSubset");
+            node.put("relCode", "Sy2Eq");
+            node.put("objFrom", sysID);
+            node.put("objTo", equipId);
+            criteria.setCriteria(node);
+            service.doDelete(context, criteria);
+        }
+        return AdmResponse.success();
+    }
+
+}