RelationSyForBdController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.dmp.digital.entity.ObjectRelation;
  10. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  11. import com.persagy.proxy.adm.request.AdmResponse;
  12. import com.persagy.proxy.adm.service.IAdmRelationService;
  13. import com.persagy.proxy.common.client.DmpRwdClient;
  14. import com.persagy.proxy.common.entity.InstanceUrlParam;
  15. import com.persagy.proxy.common.entity.RelationDTO;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * @description:026、关系-系统服务于建筑
  23. * @author:lgy
  24. * @data:2021/9/24 20:29
  25. */
  26. @RestController
  27. @RequestMapping("/rel/sy-for-bd")
  28. public class RelationSyForBdController {
  29. @Autowired
  30. private IAdmRelationService service;
  31. @Autowired
  32. DmpRwdClient rwdClient;
  33. @Value("${middleware.group.code}")
  34. private String groupCode;
  35. /**
  36. * 默认图类型
  37. */
  38. public static String DEFAULT_GRAPH_CODE = "MechForArch";
  39. /**
  40. * 默认边类型
  41. */
  42. public static String DEFAULT_REL_CODE = "Sy2Bd";
  43. /**
  44. * 创建系统服务于建筑关系
  45. * @param param
  46. * @return
  47. * @throws Exception
  48. */
  49. @PostMapping(value = {"/link"})
  50. public AdmResponse create(@RequestParam("projectId") String projectId,
  51. @RequestBody JSONObject param) throws Exception {
  52. String sysId = param.getString("sysId");
  53. String buildingId = param.getString("buildingId");
  54. if(!StrUtil.isAllNotEmpty(buildingId,sysId)) {
  55. return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
  56. }
  57. // 创建关系对象
  58. List<RelationDTO> voList = new ArrayList<>();
  59. voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId , buildingId));
  60. // 组装上下文条件
  61. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  62. service.doSave(context, voList);
  63. return AdmResponse.success();
  64. }
  65. /**
  66. * 根据对象删除关系
  67. * 根据对象删除系统服务于建筑的关系,只针对一个对象
  68. * @param param 对象
  69. * @return 删除的结果信息
  70. */
  71. @PostMapping("/unlink")
  72. public AdmResponse delete(@RequestParam String projectId,
  73. @RequestBody JSONObject param) throws Exception {
  74. if(CollUtil.isEmpty(param)) {
  75. return AdmResponse.success();
  76. }
  77. // 组装上下文条件
  78. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  79. // 组装条件
  80. QueryCriteria criteria = new QueryCriteria();
  81. String sysId = param.getString("sysId");
  82. String buildingId = param.getString("buildingId");
  83. if(!StrUtil.isAllNotEmpty(buildingId,sysId)) {
  84. return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
  85. }
  86. ObjectNode node = JsonNodeFactory.instance.objectNode();
  87. node.put("graphCode", DEFAULT_GRAPH_CODE);
  88. node.put("relCode", DEFAULT_REL_CODE);
  89. node.put("objFrom", sysId);
  90. node.put("objTo",buildingId);
  91. criteria.setCriteria(node);
  92. service.doDelete(context, criteria);
  93. return AdmResponse.success();
  94. }
  95. /**
  96. * 创建系统服务于建筑关系
  97. * 系统服务于建筑,系统一对多
  98. * @param param
  99. * @return 创建的结果信息
  100. */
  101. @PostMapping("/link-shsps")
  102. public AdmResponse createBd(@RequestParam("projectId") String projectId,
  103. @RequestBody JSONObject param) throws Exception {
  104. String sysId = param.getString("sysId");
  105. JSONArray buildingIdList = param.getJSONArray("buildingIdList");
  106. if(StrUtil.isBlank(sysId) || CollUtil.isEmpty(buildingIdList)) {
  107. return AdmResponse.failure("必填项:BuildingIdList(建筑id列表)、SysId(系统id),测方法会覆盖以前的记录");
  108. }
  109. // 创建关系对象.先删除,后添加
  110. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  111. QueryCriteria queryRequestTmp = new QueryCriteria();
  112. ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
  113. nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
  114. nodeTmp.put("relCode", DEFAULT_REL_CODE);
  115. nodeTmp.put("objFrom", sysId);
  116. queryRequestTmp.setCriteria(nodeTmp);
  117. //关系之前的关系,并且删除
  118. List<ObjectRelation> objectRelations = service.queryByCondition(context, queryRequestTmp);
  119. for (ObjectRelation objectRelation : objectRelations) {
  120. QueryCriteria queryRequest = new QueryCriteria();
  121. ObjectNode node = JsonNodeFactory.instance.objectNode();
  122. node.put("graphCode", objectRelation.getGraphCode());
  123. node.put("relCode", objectRelation.getRelCode());
  124. node.put("relValue", objectRelation.getRelValue());
  125. node.put("objFrom", objectRelation.getObjFrom());
  126. node.put("objTo", objectRelation.getObjTo());
  127. queryRequest.setCriteria(node);
  128. service.doDelete(context, queryRequest);
  129. }
  130. List<RelationDTO> voList = new ArrayList<>();
  131. for(int i = 0;i < buildingIdList.size();i++) {
  132. String buildingId = buildingIdList.getString(i);
  133. if(StrUtil.isBlank(buildingId)) {
  134. continue;
  135. }
  136. voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId, buildingId));
  137. }
  138. // 组装上下文条件
  139. service.doSave(context, voList);
  140. return AdmResponse.success();
  141. }
  142. /**
  143. * 服务于建筑的系统,建筑一对多
  144. * @param param
  145. * @return 创建的结果信息
  146. */
  147. @PostMapping("/link-sy")
  148. public AdmResponse createSy(@RequestParam("projectId") String projectId,
  149. @RequestBody JSONObject param) throws Exception {
  150. String buildingId = param.getString("buildingId");
  151. JSONArray sysIdList = param.getJSONArray("sysIdList");
  152. if(StrUtil.isBlank(buildingId) || CollUtil.isEmpty(sysIdList)) {
  153. return AdmResponse.failure("必填项:sysIdList(系统id列表)、BuildingId(建筑id),测方法会覆盖以前的记录");
  154. }
  155. // 创建关系对象.先删除,后添加
  156. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  157. QueryCriteria queryRequestTmp = new QueryCriteria();
  158. ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
  159. nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
  160. nodeTmp.put("relCode", DEFAULT_REL_CODE);
  161. nodeTmp.put("objTo", buildingId);
  162. queryRequestTmp.setCriteria(nodeTmp);
  163. //关系之前的关系,并且删除
  164. List<ObjectRelation> objectRelations = service.queryByCondition(context, queryRequestTmp);
  165. for (ObjectRelation objectRelation : objectRelations) {
  166. QueryCriteria queryRequest = new QueryCriteria();
  167. ObjectNode node = JsonNodeFactory.instance.objectNode();
  168. node.put("graphCode", objectRelation.getGraphCode());
  169. node.put("relCode", objectRelation.getRelCode());
  170. node.put("relValue", objectRelation.getRelValue());
  171. node.put("objFrom", objectRelation.getObjFrom());
  172. node.put("objTo", objectRelation.getObjTo());
  173. queryRequest.setCriteria(node);
  174. service.doDelete(context, queryRequest);
  175. }
  176. List<RelationDTO> voList = new ArrayList<>();
  177. for(int i = 0;i < sysIdList.size();i++) {
  178. String sysId = sysIdList.getString(i);
  179. if(StrUtil.isBlank(sysId)) {
  180. continue;
  181. }
  182. voList.add(new RelationDTO(null, DEFAULT_GRAPH_CODE, DEFAULT_REL_CODE, null, sysId, buildingId));
  183. }
  184. // 组装上下文条件
  185. service.doSave(context, voList);
  186. return AdmResponse.success();
  187. }
  188. }