RelationSyEqController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  7. import com.fasterxml.jackson.databind.node.ObjectNode;
  8. import com.persagy.dmp.basic.model.QueryCriteria;
  9. import com.persagy.proxy.adm.request.AdmResponse;
  10. import com.persagy.proxy.adm.service.IAdmRelationService;
  11. import com.persagy.proxy.adm.utils.AdmContextUtil;
  12. import com.persagy.proxy.common.entity.InstanceUrlParam;
  13. import com.persagy.proxy.common.entity.RelationDTO;
  14. import org.apache.commons.lang.StringUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Value;
  17. import org.springframework.web.bind.annotation.*;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. /**
  21. * @description:系统下的设备设施
  22. * @author:lgy
  23. * @data:2021/9/3 15:25
  24. */
  25. @RestController
  26. @RequestMapping("/rel/sy-in-eq")
  27. public class RelationSyEqController {
  28. @Autowired
  29. private IAdmRelationService service;
  30. @Value("${middleware.group.code}")
  31. private String groupCode;
  32. /**
  33. * 创建系统下的设备关系,数据叠加,不会覆盖以前的数据
  34. * 必填项:EquipID(设备id)、SysID(系统id)
  35. * @param param
  36. * @return
  37. * @throws Exception
  38. */
  39. @PostMapping(value = {"/link-sy-eq","/link"})
  40. public AdmResponse create(@RequestBody JSONObject param) throws Exception {
  41. //String equipId = param.getString("equipId");
  42. JSONArray equipIdList = param.getJSONArray("equipIdList");
  43. String sysID = param.getString("sysId");
  44. if(StringUtils.isEmpty(sysID) || CollUtil.isEmpty(equipIdList)) {
  45. return AdmResponse.failure("必填项:EquipIdList(设备id列表)、SysID(系统id)");
  46. }
  47. // 创建关系对象
  48. List<RelationDTO> voList = new ArrayList<>();
  49. equipIdList.forEach(item->{
  50. voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysID , item.toString()));
  51. });
  52. // 组装上下文条件
  53. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  54. service.doSave(context, voList);
  55. return AdmResponse.success();
  56. }
  57. /**
  58. * 根据对象删除系统和设备的关系,只针对一个对象
  59. *必填项:EquipID(设备id)、SysID(系统id)
  60. * @param param 对象
  61. * @return 删除的结果信息
  62. */
  63. @PostMapping("/unlink")
  64. public AdmResponse delete(@RequestBody JSONObject param) throws Exception {
  65. if(CollUtil.isEmpty(param)) {
  66. return AdmResponse.success();
  67. }
  68. // 组装上下文条件
  69. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  70. // 组装条件
  71. QueryCriteria criteria = new QueryCriteria();
  72. String equipId = param.getString("equipId");
  73. String sysID = param.getString("sysId");
  74. if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
  75. return AdmResponse.failure("必填项:EquipID(设备id)、SysID(系统id)");
  76. }
  77. ObjectNode node = JsonNodeFactory.instance.objectNode();
  78. node.put("graphCode", "MechSubset");
  79. node.put("relCode", "Sy2Eq");
  80. node.put("objFrom", sysID);
  81. node.put("objTo", equipId);
  82. criteria.setCriteria(node);
  83. service.doDelete(context, criteria);
  84. return AdmResponse.success();
  85. }
  86. /**
  87. * 创建系统下的设备关系
  88. *
  89. * @param syEqList 系统和设备的关系对象
  90. * @return 创建结果信息
  91. */
  92. @PostMapping("/link-eq")
  93. public AdmResponse createBatchWithDeleteOldsysIdRelation(@RequestBody JSONObject syEqList) throws Exception {
  94. JSONArray equipIdList = syEqList.getJSONArray("equipIdList");
  95. String sysId = syEqList.getString("sysId");
  96. if(StrUtil.isBlank(sysId) || CollUtil.isEmpty(equipIdList)) {
  97. return AdmResponse.failure("必填项:EquipIdList(设备id列表)、SysID(系统id)");
  98. }
  99. InstanceUrlParam context =AdmContextUtil.toDmpContext();
  100. QueryCriteria queryRequest = new QueryCriteria();
  101. ObjectNode node = JsonNodeFactory.instance.objectNode();
  102. node.put("graphCode", "MechSubset");
  103. node.put("relCode", "Sy2Eq");
  104. node.put("objFrom", sysId);
  105. queryRequest.setCriteria(node);
  106. service.doDelete(context,queryRequest);
  107. // 创建关系对象
  108. List<RelationDTO> voList = new ArrayList<>();
  109. for (int i = 0; i < equipIdList.size(); i++) {
  110. voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, sysId , equipIdList.getString(i)));
  111. }
  112. // 组装上下文条件
  113. service.doSave(context, voList);
  114. return AdmResponse.success();
  115. }
  116. /**
  117. * 创建系统下的设备关系
  118. *
  119. * @param param 系统和设备的关系对象
  120. * @return 创建结果信息
  121. */
  122. @PostMapping("/link-sy")
  123. public AdmResponse createDistinctEq(@RequestBody JSONObject param) throws Exception {
  124. String equipId = param.getString("equipId");
  125. JSONArray sysIdList = param.getJSONArray("sysIdList");
  126. if(StringUtils.isEmpty(equipId) || CollUtil.isEmpty(sysIdList)) {
  127. return AdmResponse.failure("必填项:EquipId(设备id)、sysIdList(系统id列表)");
  128. }
  129. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  130. QueryCriteria queryRequest = new QueryCriteria();
  131. ObjectNode node = JsonNodeFactory.instance.objectNode();
  132. node.put("graphCode", "MechSubset");
  133. node.put("relCode", "Sy2Eq");
  134. node.put("objTo", equipId);
  135. queryRequest.setCriteria(node);
  136. service.doDelete(context,queryRequest);
  137. // 创建关系对象
  138. List<RelationDTO> voList = new ArrayList<>();
  139. sysIdList.forEach(item->{
  140. voList.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null, item.toString() , equipId));
  141. });
  142. // 组装上下文条件
  143. service.doSave(context, voList);
  144. return AdmResponse.success();
  145. }
  146. /**
  147. * 根据对象删除系统和设备的关系
  148. *
  149. * @param entytyList 根据对象删除系统和设备的关系
  150. * @return 创建结果信息
  151. */
  152. public AdmResponse deleteBatch(@RequestBody JSONArray entytyList) {
  153. if(CollUtil.isEmpty(entytyList)) {
  154. return AdmResponse.success();
  155. }
  156. // 组装上下文条件
  157. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  158. for (int i = 0; i < entytyList.size(); i++) {
  159. JSONObject entity = entytyList.getJSONObject(i);
  160. // 组装条件
  161. QueryCriteria criteria = new QueryCriteria();
  162. String equipId = entity.getString("equipId");
  163. String sysID = entity.getString("sysId");
  164. if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
  165. continue;
  166. }
  167. ObjectNode node = JsonNodeFactory.instance.objectNode();
  168. node.put("graphCode", "MechSubset");
  169. node.put("relCode", "Sy2Eq");
  170. node.put("objFrom", sysID);
  171. node.put("objTo", equipId);
  172. criteria.setCriteria(node);
  173. service.doDelete(context, criteria);
  174. }
  175. return AdmResponse.success();
  176. }
  177. }