RelationSyInBdController.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  4. import com.fasterxml.jackson.databind.node.ObjectNode;
  5. import com.persagy.dmp.basic.model.QueryCriteria;
  6. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  7. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  8. import com.persagy.proxy.adm.model.relation.*;
  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 lombok.extern.slf4j.Slf4j;
  15. import org.apache.commons.lang.StringUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.util.CollectionUtils;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * @author zhangwencheng
  24. * 系统所在建筑
  25. */
  26. @Slf4j
  27. @RestController
  28. @RequestMapping("/rel/sy-in-bd")
  29. public class RelationSyInBdController {
  30. @Autowired
  31. private IAdmRelationService service;
  32. @Value("${middleware.group.code}")
  33. private String groupCode;
  34. /**
  35. * 系统所在建筑
  36. *
  37. * @param syInBd
  38. * @param projectId
  39. * @return
  40. * @throws Exception
  41. */
  42. @PostMapping("/link")
  43. public AdmResponse create(@RequestBody SyInBd syInBd) throws Exception {
  44. log.info("创建系统所在建筑关系create方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  45. //系统Id
  46. String sysID = syInBd.getSysId();
  47. //建筑Id
  48. String buildingId = syInBd.getBuildingId();
  49. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(buildingId)) {
  50. return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
  51. }
  52. List<RelationDTO> voList = new ArrayList<>();
  53. AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
  54. String graphCode = sy2bdMechinarch.getGraphCode();
  55. String relCode = sy2bdMechinarch.getRelCode();
  56. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildingId);
  57. voList.add(relation);
  58. // 组装上下文条件
  59. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  60. service.doSave(context, voList);
  61. log.info("创建系统所在建筑create方法结束");
  62. return AdmResponse.success();
  63. }
  64. // /**
  65. // * 系统和楼层的关系对象
  66. // *
  67. // * @param syInFlList
  68. // * @param projectId
  69. // * @return
  70. // * @throws Exception
  71. // */
  72. // @PostMapping("/link-fl")
  73. // public AdmResponse createSy(@RequestBody SyInFlList syInFlList, @RequestParam("projectId") String projectId) throws Exception {
  74. // log.info("创建系统所在建筑关系create方法开始参数projectId为{}", projectId);
  75. // //系统Id
  76. // String sysID = syInFlList.getSysId();
  77. // //楼层
  78. // List<String> floors = syInFlList.getFloorIdList();
  79. // if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(floors)) {
  80. // return AdmResponse.failure("必填项:SysId(系统id)、floorIdList(楼层)");
  81. // }
  82. // List<RelationDTO> voList = new ArrayList<>();
  83. // for (String floorId : floors) {
  84. // //todo graphCode
  85. // RelationDTO relation = new RelationDTO(null, "MechInArch", "Eq2Sp", null, sysID, floorId);
  86. // voList.add(relation);
  87. // }
  88. // // 组装上下文条件
  89. // InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  90. // service.doSave(context, voList);
  91. // log.info("创建系统服务于业务空间关系create方法结束");
  92. // return AdmResponse.success();
  93. // }
  94. /**
  95. * 创建系统所在建筑关系
  96. * @param syInFlList
  97. * @param projectId
  98. * @return
  99. * @throws Exception
  100. */
  101. @PostMapping("/link-bd")
  102. public AdmResponse createBd(@RequestBody SyInBdList syInFlList) throws Exception {
  103. log.info("创建系统所在建筑关系createBD方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  104. //系统Id
  105. String sysID = syInFlList.getSysId();
  106. //楼层
  107. List<String> builds = syInFlList.getBuildingIdList();
  108. if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(builds)) {
  109. return AdmResponse.failure("必填项:SysId(系统id)、buildingIdList(建筑Id)");
  110. }
  111. List<RelationDTO> voList = new ArrayList<>();
  112. AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
  113. String graphCode = sy2bdMechinarch.getGraphCode();
  114. String relCode = sy2bdMechinarch.getRelCode();
  115. for (String buildId : builds) {
  116. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildId);
  117. voList.add(relation);
  118. }
  119. // 组装上下文条件
  120. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  121. service.doSave(context, voList);
  122. log.info("创建系统所在建筑关系createBD方法结束");
  123. return AdmResponse.success();
  124. }
  125. /**
  126. * 创建系统所在建筑关系 同上
  127. * @param syInFlList
  128. * @param projectId
  129. * @return
  130. * @throws Exception
  131. */
  132. @PostMapping("/link-bd-sy")
  133. public AdmResponse createSyBd(@RequestBody SyInBdList syInFlList) throws Exception {
  134. log.info("创建系统所在建筑关系createSyBd方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  135. //系统Id
  136. String sysID = syInFlList.getSysId();
  137. //楼层
  138. List<String> builds = syInFlList.getBuildingIdList();
  139. if (StringUtils.isBlank(sysID) || CollectionUtils.isEmpty(builds)) {
  140. return AdmResponse.failure("必填项:SysId(系统id)、buildingIdList(建筑Id)");
  141. }
  142. List<RelationDTO> voList = new ArrayList<>();
  143. AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
  144. String graphCode = sy2bdMechinarch.getGraphCode();
  145. String relCode = sy2bdMechinarch.getRelCode();
  146. for (String buildId : builds) {
  147. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysID, buildId);
  148. voList.add(relation);
  149. }
  150. // 组装上下文条件
  151. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  152. service.doSave(context, voList);
  153. log.info("创建系统所在建筑关系createSyBd方法结束");
  154. return AdmResponse.success();
  155. }
  156. /**
  157. * 创建所在建筑的系统关系
  158. * @param bdInSyList
  159. * @param projectId
  160. * @return
  161. * @throws Exception
  162. */
  163. @PostMapping("/link-sy")
  164. public AdmResponse createSyBd(@RequestBody BdInSyList bdInSyList) throws Exception {
  165. log.info("创建系统所在建筑关系createSyBd方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  166. //建筑Id
  167. String buildingId = bdInSyList.getBuildingId();
  168. //系统
  169. List<String> sysIdList = bdInSyList.getSysIdList();
  170. if (StringUtils.isBlank(buildingId) || CollectionUtils.isEmpty(sysIdList)) {
  171. return AdmResponse.failure("必填项:buildingId(建筑id)、sysIdList(系统Id)");
  172. }
  173. List<RelationDTO> voList = new ArrayList<>();
  174. AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
  175. String graphCode = sy2bdMechinarch.getGraphCode();
  176. String relCode = sy2bdMechinarch.getRelCode();
  177. for (String sysId : sysIdList) {
  178. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, buildingId);
  179. voList.add(relation);
  180. }
  181. // 组装上下文条件
  182. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  183. service.doSave(context, voList);
  184. log.info("创建系统所在建筑关系createSyBd方法结束");
  185. return AdmResponse.success();
  186. }
  187. /**
  188. * 系统所在建筑
  189. *
  190. * @param syInBd
  191. * @param projectId
  192. * @return
  193. * @throws Exception
  194. */
  195. @PostMapping("/unlink")
  196. public AdmResponse delete(@RequestBody SyInBd syInBd) throws Exception {
  197. log.info("创建系统所在建筑关系delete方法开始参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  198. //系统Id
  199. String sysID = syInBd.getSysId();
  200. //建筑Id
  201. String buildingId = syInBd.getBuildingId();
  202. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(buildingId)) {
  203. return AdmResponse.failure("必填项:SysId(系统id)、BuildingId(建筑id)");
  204. }
  205. QueryCriteria criteria = new QueryCriteria();
  206. // RelationDTO relation = new RelationDTO(null, "MechInArch", "Eq2Sp", null, sysID, buildingId);
  207. AdmRelationTypeEnum sy2bdMechinarch = AdmRelationTypeEnum.SY2BD_MECHINARCH;
  208. String graphCode = sy2bdMechinarch.getGraphCode();
  209. String relCode = sy2bdMechinarch.getRelCode();
  210. // 组装上下文条件
  211. ObjectNode node = JsonNodeFactory.instance.objectNode();
  212. node.put("graphCode", graphCode);
  213. node.put("relCode", relCode);
  214. // node.put("relValue", );
  215. node.put("objFrom", sysID);
  216. node.put("objTo", buildingId);
  217. criteria.setCriteria(node);
  218. // 组装上下文条件
  219. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  220. service.doDelete(context,criteria);
  221. log.info("创建系统服务于业务空间关系delete方法结束");
  222. return AdmResponse.success();
  223. }
  224. }