RelationEqInShController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * @description:020、关系-设备所在竖井
  24. * @author:lgy
  25. * @data:2021/9/13 10:00
  26. */
  27. @RequestMapping("/rel/eq-in-sh")
  28. @RestController
  29. public class RelationEqInShController {
  30. @Autowired
  31. private IAdmRelationService service;
  32. @Value("${middleware.group.code}")
  33. private String groupCode;
  34. /**
  35. * 创建设备所在竖井关系,累计添加不会覆盖以前记录
  36. * @param param
  37. * @return
  38. * @throws Exception
  39. */
  40. @PostMapping(value = {"/link"})
  41. public AdmResponse create(@RequestBody JSONObject param) throws Exception {
  42. String equipId = param.getString("equipId");
  43. String shaftId = param.getString("shaftId");
  44. if(!StrUtil.isAllNotEmpty(equipId,shaftId)) {
  45. return AdmResponse.failure("必填项:EquipId(设备id)、ShaftId(竖井id)");
  46. }
  47. // 创建关系对象 EquipinShaft
  48. List<RelationDTO> voList = new ArrayList<>();
  49. voList.add(new RelationDTO(null, "MechInArch", "Eq2Sh", null, equipId , shaftId));
  50. service.doSave(AdmContextUtil.toDmpContext(), voList);
  51. return AdmResponse.success();
  52. }
  53. /**
  54. * 根据对象删除设备所在竖井关系,只针对一个对象
  55. * @param param 对象
  56. * @return 删除的结果信息
  57. */
  58. @PostMapping("/unlink")
  59. public AdmResponse delete(@RequestBody JSONObject param) throws Exception {
  60. if(CollUtil.isEmpty(param)) {
  61. return AdmResponse.success();
  62. }
  63. // 组装上下文条件
  64. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  65. // 组装条件
  66. QueryCriteria criteria = new QueryCriteria();
  67. String equipId = param.getString("equipId");
  68. String shaftId = param.getString("shaftId");
  69. if(!StrUtil.isAllNotEmpty(equipId,shaftId)) {
  70. return AdmResponse.failure("必填项:EquipId(设备id)、shaftId(竖井id)");
  71. }
  72. ObjectNode node = JsonNodeFactory.instance.objectNode();
  73. node.put("graphCode", "MechInArch");
  74. node.put("relCode", "Eq2Sh");
  75. node.put("objFrom", equipId);
  76. node.put("objTo",shaftId);
  77. criteria.setCriteria(node);
  78. service.doDelete(context, criteria);
  79. return AdmResponse.success();
  80. }
  81. /**
  82. * 设备所在竖井,设备一对多,此方法会覆盖以前的记录
  83. * @param param
  84. * @return
  85. * @throws Exception
  86. */
  87. @PostMapping("/link-sh")
  88. public AdmResponse createSh(@RequestBody JSONObject param) throws Exception {
  89. String equipId = param.getString("equipId");
  90. JSONArray shaftIdList = param.getJSONArray("shaftIdList");
  91. if(StrUtil.isBlank(equipId) || CollUtil.isEmpty(shaftIdList)) {
  92. return AdmResponse.failure("必填项:EquipId(设备id)、ShaftIdList(竖井id列表),此方法会覆盖以前的记录");
  93. }
  94. // 创建关系对象.先删除,后添加
  95. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  96. List<RelationDTO> voList = new ArrayList<>();
  97. for(int i = 0;i < shaftIdList.size();i++) {
  98. String shaftId = shaftIdList.getString(i);
  99. if(StrUtil.isBlank(shaftId)) {
  100. continue;
  101. }
  102. QueryCriteria queryRequest = new QueryCriteria();
  103. ObjectNode node = JsonNodeFactory.instance.objectNode();
  104. node.put("graphCode", "MechInArch");
  105. node.put("relCode", "Eq2Sh");
  106. node.put("objFrom", equipId);
  107. node.put("objTo", shaftId);
  108. queryRequest.setCriteria(node);
  109. service.doDelete(context,queryRequest);
  110. // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
  111. voList.add(new RelationDTO(null, "MechInArch", "Eq2Sh", null, equipId, shaftId));
  112. }
  113. // 组装上下文条件
  114. service.doSave(context, voList);
  115. return AdmResponse.success();
  116. }
  117. /**
  118. * 所在竖井的设备,竖井一对多,此方法会覆盖以前的记录
  119. * @param param
  120. * @return
  121. * @throws Exception
  122. */
  123. @PostMapping(value = {"/link-eq","/link-eq-sh"})
  124. public AdmResponse createEq(@RequestBody JSONObject param) throws Exception {
  125. String shaftId = param.getString("shaftId");
  126. JSONArray equipIdList = param.getJSONArray("shaftIdList");
  127. if(StrUtil.isBlank(shaftId) || CollUtil.isEmpty(equipIdList)) {
  128. return AdmResponse.failure("必填项:EquipIdList(设备id列表)、ShaftId(竖井id),此方法会覆盖以前的记录");
  129. }
  130. // 创建关系对象.先删除,后添加
  131. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  132. List<RelationDTO> voList = new ArrayList<>();
  133. for(int i = 0;i < equipIdList.size();i++) {
  134. String equipId = equipIdList.getString(i);
  135. if(StrUtil.isBlank(shaftId)) {
  136. continue;
  137. }
  138. QueryCriteria queryRequest = new QueryCriteria();
  139. ObjectNode node = JsonNodeFactory.instance.objectNode();
  140. node.put("graphCode", "MechInArch");
  141. node.put("relCode", "Eq2Sh");
  142. node.put("objFrom", equipId);
  143. node.put("objTo", shaftId);
  144. queryRequest.setCriteria(node);
  145. service.doDelete(context,queryRequest);
  146. // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
  147. voList.add(new RelationDTO(null, "MechInArch", "Eq2Sh", null, equipId, shaftId));
  148. }
  149. // 组装上下文条件
  150. service.doSave(context, voList);
  151. return AdmResponse.success();
  152. }
  153. }