RelationSyInShController.java 10.0 KB

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