RelationShaftThroughShaftController.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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:022、关系-竖井的贯通关系
  24. * @author:lgy
  25. * @data:2021/9/13 13:06
  26. */
  27. @RestController
  28. @RequestMapping("/rel/sh-through-sh")
  29. public class RelationShaftThroughShaftController {
  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 shaftId = param.getString("shaftId");
  43. String shaftOtherId = param.getString("shaftOtherId");
  44. if(!StrUtil.isAllNotEmpty(shaftId,shaftOtherId)) {
  45. return AdmResponse.failure("必填项:ShaftId(竖井id)、ShaftOtherId(其他竖井id)");
  46. }
  47. // 创建关系对象
  48. List<RelationDTO> voList = new ArrayList<>();
  49. voList.add(new RelationDTO(null, "ThroughRelationship", "Sh2Sh", null, shaftId , shaftOtherId));
  50. service.doSave(AdmContextUtil.toDmpContext(), voList);
  51. return AdmResponse.success();
  52. }
  53. /**
  54. * 根据对象删除关系
  55. * 根据对象删除竖井的贯通关系,只针对一个对象
  56. * @param param 对象
  57. * @return 删除的结果信息
  58. */
  59. @PostMapping("/unlink")
  60. public AdmResponse delete(@RequestBody JSONObject param) throws Exception {
  61. if(CollUtil.isEmpty(param)) {
  62. return AdmResponse.success();
  63. }
  64. // 组装上下文条件
  65. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  66. // 组装条件
  67. QueryCriteria criteria = new QueryCriteria();
  68. String shaftId = param.getString("shaftId");
  69. String shaftOtherId = param.getString("shaftOtherId");
  70. if(!StrUtil.isAllNotEmpty(shaftId,shaftOtherId)) {
  71. return AdmResponse.failure("必填项:ShaftId(竖井id)、ShaftOtherId(其他数据竖井id)");
  72. }
  73. ObjectNode node = JsonNodeFactory.instance.objectNode();
  74. node.put("graphCode", "ThroughRelationship");
  75. node.put("relCode", "Sh2Sh");
  76. node.put("objFrom", shaftId);
  77. node.put("objTo",shaftOtherId);
  78. criteria.setCriteria(node);
  79. service.doDelete(context, criteria);
  80. return AdmResponse.success();
  81. }
  82. /**
  83. * 创建竖井的贯通关系
  84. * 竖井的贯通,竖井一对多,此方法会覆盖以前的记录
  85. * @return
  86. * @throws Exception
  87. */
  88. @PostMapping("/link-or")
  89. public AdmResponse createFloorOtherIdList(@RequestBody JSONObject param) throws Exception {
  90. String shaftId = param.getString("shaftId");
  91. JSONArray shaftOtherIdList = param.getJSONArray("shaftOtherIdList");
  92. if(StrUtil.isBlank(shaftId) || CollUtil.isEmpty(shaftOtherIdList)) {
  93. return AdmResponse.failure("必填项:ShaftId(竖井id)、ShaftOtherIdList(其他竖井id列表),此方法会覆盖以前的记录");
  94. }
  95. // 创建关系对象.先删除,后添加
  96. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  97. List<RelationDTO> voList = new ArrayList<>();
  98. for(int i = 0;i < shaftOtherIdList.size();i++) {
  99. String shaftOtherId = shaftOtherIdList.getString(i);
  100. if(StrUtil.isBlank(shaftOtherId)) {
  101. continue;
  102. }
  103. QueryCriteria queryRequest = new QueryCriteria();
  104. ObjectNode node = JsonNodeFactory.instance.objectNode();
  105. node.put("graphCode", "ThroughRelationship");
  106. node.put("relCode", "Sh2Sh");
  107. node.put("objFrom", shaftId);
  108. node.put("objTo", shaftOtherId);
  109. queryRequest.setCriteria(node);
  110. service.doDelete(context,queryRequest);
  111. // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
  112. voList.add(new RelationDTO(null, "ThroughRelationship", "Sh2Sh", null, shaftId, shaftOtherId));
  113. }
  114. // 组装上下文条件
  115. service.doSave(context, voList);
  116. return AdmResponse.success();
  117. }
  118. /**
  119. * 创建竖井的贯通关系
  120. * 竖井的贯通,竖井一对多,此方法会覆盖以前的记录
  121. * @param param 竖井和其他竖井列表关系对象r
  122. * @return
  123. * @throws Exception
  124. */
  125. @PostMapping("/link-shaft")
  126. public AdmResponse createFloorIdList(@RequestBody JSONObject param) throws Exception {
  127. String shaftId = param.getString("shaftId");
  128. JSONArray shaftOtherIdList = param.getJSONArray("shaftOtherIdList");
  129. if(StrUtil.isBlank(shaftId) || CollUtil.isEmpty(shaftOtherIdList)) {
  130. return AdmResponse.failure("必填项:ShaftId(竖井id)、ShaftOtherIdList(其他竖井id列表)");
  131. }
  132. // 创建关系对象.先删除,后添加
  133. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  134. List<RelationDTO> voList = new ArrayList<>();
  135. for(int i = 0;i < shaftOtherIdList.size();i++) {
  136. String shaftOtherId = shaftOtherIdList.getString(i);
  137. if(StrUtil.isBlank(shaftOtherId)) {
  138. continue;
  139. }
  140. QueryCriteria queryRequest = new QueryCriteria();
  141. ObjectNode node = JsonNodeFactory.instance.objectNode();
  142. node.put("graphCode", "ThroughRelationship");
  143. node.put("relCode", "Sh2Sh");
  144. node.put("objFrom", shaftId);
  145. node.put("objTo", shaftOtherId);
  146. queryRequest.setCriteria(node);
  147. service.doDelete(context,queryRequest);
  148. // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
  149. voList.add(new RelationDTO(null, "ThroughRelationship", "Sh2Sh", null, shaftId, shaftOtherId));
  150. }
  151. // 组装上下文条件
  152. service.doSave(context, voList);
  153. return AdmResponse.success();
  154. }
  155. }