|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|