RelationSyInShController.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package com.persagy.proxy.relation.controller;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.excel.util.CollectionUtils;
  4. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  5. import com.fasterxml.jackson.databind.node.ObjectNode;
  6. import com.persagy.dmp.basic.model.QueryCriteria;
  7. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  8. import com.persagy.proxy.relation.model.ShInSyList;
  9. import com.persagy.proxy.relation.model.SyInSh;
  10. import com.persagy.proxy.relation.model.SyInShList;
  11. import com.persagy.proxy.adm.request.AdmResponse;
  12. import com.persagy.proxy.adm.service.IAdmRelationService;
  13. import com.persagy.proxy.adm.utils.AdmContextUtil;
  14. import com.persagy.proxy.common.entity.InstanceUrlParam;
  15. import com.persagy.proxy.common.entity.RelationDTO;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. /**
  27. * @author zhangwencheng
  28. * 系统所在楼层相关接口-032
  29. */
  30. @Slf4j
  31. @RestController
  32. @RequestMapping("/rel/sy-in-sh")
  33. public class RelationSyInShController {
  34. @Autowired
  35. private IAdmRelationService service;
  36. /**
  37. * 创建系统所在竖井关系
  38. *
  39. * @param syInSh 系统和竖井的关系对象
  40. * @return project 创建的结果信息
  41. */
  42. @PostMapping(value = "/link")
  43. public AdmResponse create(@RequestBody SyInSh syInSh) {
  44. //系统Id
  45. String sysID = syInSh.getSysId();
  46. //楼层Id
  47. String shaftId = syInSh.getShaftId();
  48. //
  49. String type = syInSh.getType();
  50. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(shaftId)) {
  51. return AdmResponse.failure("必填项:SysId(系统id)、shaftId(竖井id)");
  52. }
  53. List<RelationDTO> voList = new ArrayList<>();
  54. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  55. String graphCode = typeEnum.getGraphCode();
  56. String relCode = typeEnum.getRelCode();
  57. RelationDTO relation = new RelationDTO(null, graphCode, relCode, type, sysID, shaftId);
  58. voList.add(relation);
  59. service.doSave(AdmContextUtil.toDmpContext(), voList);
  60. return AdmResponse.success();
  61. }
  62. /**
  63. * 根据对象删除
  64. *
  65. * @param syInSh
  66. * @param projectId
  67. * @return
  68. */
  69. @PostMapping("/unlink")
  70. public AdmResponse delete(@RequestBody SyInSh syInSh) {
  71. String sysID = syInSh.getSysId();
  72. //楼层Id
  73. String shaftId = syInSh.getShaftId();
  74. //
  75. // String type = syInSh.getType();
  76. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(shaftId)) {
  77. return AdmResponse.failure("必填项:SysId(系统id)、shaftId(竖井id)");
  78. }
  79. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  80. String graphCode = typeEnum.getGraphCode();
  81. String relCode = typeEnum.getRelCode();
  82. ObjectNode node = JsonNodeFactory.instance.objectNode();
  83. node.put("graphCode", graphCode);
  84. node.put("relCode", relCode);
  85. // node.put("relValue", type);
  86. node.put("objFrom", sysID);
  87. node.put("objTo", shaftId);
  88. QueryCriteria criteria = new QueryCriteria();
  89. criteria.setCriteria(node);
  90. service.doDelete(AdmContextUtil.toDmpContext(), criteria);
  91. return AdmResponse.success();
  92. }
  93. /**
  94. * 创建系统所在竖井关系
  95. *
  96. * @param syInShList 系统和竖井的关系对象
  97. * @return 创建的结果信息
  98. */
  99. @PostMapping(value = "/link-sh")
  100. public AdmResponse createSh(@RequestBody SyInShList syInShList) {
  101. String sysId = syInShList.getSysId();
  102. List<String> shaftIdList = syInShList.getShaftIdList();
  103. if (StringUtils.isBlank(sysId) || CollectionUtils.isEmpty(shaftIdList)) {
  104. return AdmResponse.failure("必填项:sysId(系统sysId不能为空)、shaftIdList(竖井Id不能为空)");
  105. }
  106. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  107. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  108. deleteBySysId(typeEnum,sysId,context);
  109. String graphCode = typeEnum.getGraphCode();
  110. String relCode = typeEnum.getRelCode();
  111. List<RelationDTO> voList = new ArrayList<>();
  112. for (String shaftId : shaftIdList) {
  113. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, shaftId);
  114. voList.add(relation);
  115. }
  116. service.doSave(context, voList);
  117. return AdmResponse.success();
  118. }
  119. /**
  120. * 根据系统Id删除关系
  121. * @param typeEnum
  122. * @param sysId
  123. * @param context
  124. */
  125. private void deleteBySysId(AdmRelationTypeEnum typeEnum, String sysId, InstanceUrlParam context) {
  126. ObjectNode node = JsonNodeFactory.instance.objectNode();
  127. node.put("graphCode", typeEnum.getGraphCode());
  128. node.put("relCode", typeEnum.getRelCode());
  129. node.put("objFrom", sysId);
  130. QueryCriteria criteria = new QueryCriteria();
  131. criteria.setCriteria(node);
  132. service.doDelete(context, criteria);
  133. }
  134. /**
  135. * 创建所在竖井的系统关系 先删除以前的竖井在增加新的关系
  136. *
  137. * @param shInSyList 系统和竖井的关系对象
  138. * @return 创建的结果信息
  139. */
  140. @PostMapping(value = "/link-sy")
  141. public AdmResponse createSy(@RequestBody ShInSyList shInSyList){
  142. List<String> sysIdList = shInSyList.getSysIdList();
  143. String shaftId = shInSyList.getShaftId();
  144. if (StringUtils.isBlank(shaftId) || CollectionUtils.isEmpty(sysIdList)) {
  145. return AdmResponse.failure("必填项:shaftId(竖井shaftId不能为空)、sysIdList(系统Id不能为空)");
  146. }
  147. //先删除以前竖井
  148. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  149. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  150. deleteByShaftId(shaftId,typeEnum,context);
  151. String graphCode = typeEnum.getGraphCode();
  152. String relCode = typeEnum.getRelCode();
  153. List<RelationDTO> voList = new ArrayList<>();
  154. for (String sysId : sysIdList) {
  155. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, shaftId);
  156. voList.add(relation);
  157. }
  158. service.doSave(context, voList);
  159. return AdmResponse.success();
  160. }
  161. /**
  162. * 根据竖井Id删除竖井关系
  163. * @param shaftId
  164. */
  165. private void deleteByShaftId(String shaftId,AdmRelationTypeEnum typeEnum,InstanceUrlParam context) {
  166. ObjectNode node = JsonNodeFactory.instance.objectNode();
  167. node.put("graphCode", typeEnum.getGraphCode());
  168. node.put("relCode", typeEnum.getRelCode());
  169. node.put("objTo", shaftId);
  170. QueryCriteria criteria = new QueryCriteria();
  171. criteria.setCriteria(node);
  172. service.doDelete(context, criteria);
  173. }
  174. /**
  175. * 创建所在竖井的系统关系
  176. *
  177. * @param shInSyList 系统和竖井的关系对象
  178. * @return 创建的结果信息
  179. */
  180. @PostMapping("/link-sy-sh")
  181. public AdmResponse createSySh(@RequestBody ShInSyList shInSyList){
  182. String shaftId = shInSyList.getShaftId();
  183. List<String> sysIdList = shInSyList.getSysIdList();
  184. if (StringUtils.isBlank(shaftId) || CollectionUtils.isEmpty(sysIdList)) {
  185. return AdmResponse.failure("必填项:shaftId(竖井shaftId不能为空)、sysIdList(系统Id不能为空)");
  186. }
  187. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  188. String graphCode = typeEnum.getGraphCode();
  189. String relCode = typeEnum.getRelCode();
  190. List<RelationDTO> voList = new ArrayList<>();
  191. for (String sysId : sysIdList) {
  192. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, shaftId);
  193. voList.add(relation);
  194. }
  195. service.doSave(AdmContextUtil.toDmpContext(), voList);
  196. return AdmResponse.success();
  197. }
  198. /**
  199. * 系统所在竖井,系统一对多,不覆盖
  200. *
  201. * @param syInShList 系统和竖井的关系对象
  202. * @return 创建的结果信息
  203. */
  204. @PostMapping("/link-sy-shs")
  205. public AdmResponse createSyShs(@RequestBody SyInShList syInShList){
  206. String sysId = syInShList.getSysId();
  207. List<String> shaftIdList = syInShList.getShaftIdList();
  208. if (StringUtils.isBlank(sysId) || CollectionUtils.isEmpty(shaftIdList)) {
  209. return AdmResponse.failure("必填项:shaftId(竖井shaftId不能为空)、sysId(系统Id不能为空)");
  210. }
  211. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SH;
  212. String graphCode = typeEnum.getGraphCode();
  213. String relCode = typeEnum.getRelCode();
  214. List<RelationDTO> voList = new ArrayList<>();
  215. for (String shaftId : shaftIdList) {
  216. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, shaftId);
  217. voList.add(relation);
  218. }
  219. service.doSave(AdmContextUtil.toDmpContext(), voList);
  220. return AdmResponse.success();
  221. }
  222. }