RelationSyInFlController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package com.persagy.proxy.relation.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.extra.spring.SpringUtil;
  5. import com.alibaba.excel.util.CollectionUtils;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. import com.fasterxml.jackson.databind.node.ArrayNode;
  8. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  9. import com.fasterxml.jackson.databind.node.ObjectNode;
  10. import com.persagy.dmp.basic.model.QueryCriteria;
  11. import com.persagy.dmp.common.constant.ResponseCode;
  12. import com.persagy.dmp.common.model.response.CommonResult;
  13. import com.persagy.dmp.digital.client.DigitalRelationFacade;
  14. import com.persagy.dmp.digital.entity.ObjectRelation;
  15. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  16. import com.persagy.proxy.adm.request.AdmResponse;
  17. import com.persagy.proxy.adm.service.IAdmRelationService;
  18. import com.persagy.proxy.adm.utils.AdmContextUtil;
  19. import com.persagy.proxy.common.entity.InstanceUrlParam;
  20. import com.persagy.proxy.common.entity.RelationDTO;
  21. import com.persagy.proxy.relation.model.FlInSyList;
  22. import com.persagy.proxy.relation.model.SyInFl;
  23. import com.persagy.proxy.relation.model.SyInFlList;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.PostMapping;
  28. import org.springframework.web.bind.annotation.RequestBody;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. import java.util.Map;
  34. /**
  35. * @author zhangwencheng
  36. * 系统所在楼层相关接口
  37. */
  38. @Slf4j
  39. @RestController
  40. @RequestMapping("/rel/sy-in-fl")
  41. public class RelationSyInFlController {
  42. @Autowired
  43. private IAdmRelationService service;
  44. /**
  45. * 创建系统所在楼层关系
  46. *
  47. * @param syInFl
  48. * @param
  49. * @return
  50. * @throws Exception
  51. */
  52. @PostMapping("/link")
  53. public AdmResponse create(@RequestBody SyInFl syInFl) throws Exception {
  54. //系统Id
  55. String sysID = syInFl.getSysId();
  56. //楼层Id
  57. String floorId = syInFl.getFloorId();
  58. //
  59. String type = syInFl.getType();
  60. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(floorId)) {
  61. return AdmResponse.failure("必填项:SysId(系统id)、floorId(楼层id)");
  62. }
  63. List<RelationDTO> voList = new ArrayList<>();
  64. AdmRelationTypeEnum sy2fl = AdmRelationTypeEnum.SY2FL;
  65. String graphCode = sy2fl.getGraphCode();
  66. String relCode = sy2fl.getRelCode();
  67. RelationDTO relation = new RelationDTO(null, graphCode, relCode, type, sysID, floorId);
  68. voList.add(relation);
  69. // 组装上下文条件
  70. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  71. service.doSave(context, voList);
  72. return AdmResponse.success();
  73. }
  74. /**
  75. * 创建所在系统和楼层的关系 系统楼层一对多
  76. *
  77. * @param
  78. * @return
  79. * @throws Exception
  80. */
  81. @PostMapping("/link-fl")
  82. public AdmResponse createSy(@RequestBody SyInFlList syInFlList) throws Exception {
  83. log.info("创建系统所在楼层关系link-fl方法开始,参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  84. //系统Id
  85. String sysId = syInFlList.getSysId();
  86. //楼层Id
  87. List<String> floorIdList = syInFlList.getFloorIdList();
  88. if (StringUtils.isBlank(sysId)) {
  89. //return AdmResponse.failure("必填项:sysId(系统id)、floorIdList(楼层Id)");
  90. //兼容adm历史逻辑,若楼层id为空时,返回success
  91. return AdmResponse.success();
  92. }
  93. // 按原有逻辑接口处理:2021年11月2日16:52:13 by lijie
  94. // 1.根据系统id,图类型编码为MechInArch,边类型为Sy2Fl删除关系
  95. // 1.1 组装删除参数
  96. QueryCriteria deleteQueryCriteria = new QueryCriteria();
  97. ObjectMapper mapper = SpringUtil.getBean(ObjectMapper.class);
  98. ObjectNode criteria = mapper.createObjectNode();
  99. criteria.put("graphCode",AdmRelationTypeEnum.SY2FL.getGraphCode());
  100. criteria.put("relCode",AdmRelationTypeEnum.SY2FL.getRelCode());
  101. criteria.put("objFrom",sysId);
  102. criteria.put("valid",Boolean.TRUE);
  103. deleteQueryCriteria.setCriteria(criteria);
  104. // 1.2 根据参数删除关系
  105. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  106. CommonResult<List<ObjectRelation>> commonResult = DigitalRelationFacade.deleteByCriteria(context.getGroupCode(),
  107. context.getProjectId(), context.getAppId(), context.getUserId(), deleteQueryCriteria);
  108. if (!ResponseCode.A00000.getDesc().equals(commonResult.getResult())){
  109. return AdmResponse.failure(commonResult.getMessage());
  110. }
  111. if (CollUtil.isEmpty(floorIdList)){
  112. return AdmResponse.success(new ArrayList<>());
  113. }
  114. // 2.创建系统所属楼层关系
  115. List<RelationDTO> voList = new ArrayList<>();
  116. AdmRelationTypeEnum sy2fl = AdmRelationTypeEnum.SY2FL;
  117. String graphCode = sy2fl.getGraphCode();
  118. String relCode = sy2fl.getRelCode();
  119. for (String floorId : floorIdList) {
  120. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, floorId);
  121. voList.add(relation);
  122. }
  123. //查询 floor所属的建筑 增加关系:页面交互的/rel/sy-in-bd/link-bd接口会创建系统所属建筑的关系,该处省略.防止重复创建
  124. // QueryCriteria criteriaQuery = new QueryCriteria();
  125. // ObjectNode buildCriteria = JsonNodeFactory.instance.objectNode();
  126. // buildCriteria.put(ObjectRelation.REL_CODE_HUM, "Bd2Fl");
  127. // buildCriteria.put(ObjectRelation.GRAPH_CODE_HUM, "ArchSubset");
  128. // ArrayNode arrayNode = buildCriteria.putObject("objTo").putArray("$in");
  129. // floorIdList.stream().forEach(floorId -> arrayNode.add(floorId));
  130. // criteriaQuery.setCriteria(buildCriteria);
  131. // List<ObjectRelation> relationList = service.queryByCondition(AdmContextUtil.toDmpContext(), criteriaQuery);
  132. // if(CollUtil.isNotEmpty(relationList)){
  133. // Map<String,ObjectRelation> objectRelationMap = CollUtil.fieldValueMap(relationList, "objFrom");
  134. // for (String buildingId : objectRelationMap.keySet()) {
  135. // RelationDTO relation = new RelationDTO(null, graphCode, "Sy2Bd", null, sysId, buildingId);
  136. // voList.add(relation);
  137. // }
  138. // }
  139. // 组装上下文条件
  140. service.doSave(AdmContextUtil.toDmpContext(), voList);
  141. log.info("创建系统所在楼层关系link-fl方法结束");
  142. return AdmResponse.success();
  143. }
  144. /**
  145. * 所在楼层的系统,楼层一对多系统
  146. */
  147. @PostMapping("/link-sy")
  148. public AdmResponse createSy(@RequestBody FlInSyList flInSyList) {
  149. log.info("创建系统所在楼层关系link-sy方法开始,参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  150. String floorId = flInSyList.getFloorId();
  151. List<String> sysIdList = flInSyList.getSysIdList();
  152. if (StringUtils.isBlank(floorId) || CollectionUtils.isEmpty(sysIdList)) {
  153. return AdmResponse.failure("必填项:sysIdList(系统id不能为空)、floorId(楼层Id)");
  154. }
  155. AdmRelationTypeEnum sy2fl = AdmRelationTypeEnum.SY2FL;
  156. String graphCode = sy2fl.getGraphCode();
  157. String relCode = sy2fl.getRelCode();
  158. List<RelationDTO> voList = new ArrayList<>();
  159. for (String sysId : sysIdList) {
  160. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, floorId);
  161. voList.add(relation);
  162. }
  163. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  164. service.doSave(context, voList);
  165. log.info("创建系统所在楼层关系link-sy方法结束");
  166. return AdmResponse.success();
  167. }
  168. /**
  169. * 系统所在楼层,系统一对多楼层,此方法不会覆盖
  170. */
  171. @PostMapping("/link-fl-sy")
  172. public AdmResponse createSyFl(@RequestBody SyInFlList syInFlList) {
  173. log.info("创建系统所在楼层关系link-fl-sy方法开始,参数projectId为{}", AdmContextUtil.toDmpContext().getProjectId());
  174. List<String> floorIdList = syInFlList.getFloorIdList();
  175. String sysId = syInFlList.getSysId();
  176. if (StringUtils.isBlank(sysId) || CollectionUtils.isEmpty(floorIdList)) {
  177. return AdmResponse.failure("必填项:sysId(系统sysId不能为空)、floorIdList(楼层Id不能为空)");
  178. }
  179. AdmRelationTypeEnum sy2fl = AdmRelationTypeEnum.SY2FL;
  180. String graphCode = sy2fl.getGraphCode();
  181. String relCode = sy2fl.getRelCode();
  182. List<RelationDTO> voList = new ArrayList<>();
  183. for (String floorId : floorIdList) {
  184. RelationDTO relation = new RelationDTO(null, graphCode, relCode, null, sysId, floorId);
  185. voList.add(relation);
  186. }
  187. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  188. service.doSave(context, voList);
  189. log.info("创建系统所在楼层关系link-fl-sy方法结束");
  190. return AdmResponse.success();
  191. }
  192. /**
  193. * 根据对象删除
  194. *
  195. * @return
  196. */
  197. @PostMapping("/unlink")
  198. public AdmResponse delete(@RequestBody SyInFl syInFl) {
  199. String floorId = syInFl.getFloorId();
  200. String sysId = syInFl.getSysId();
  201. AdmRelationTypeEnum sy2fl = AdmRelationTypeEnum.SY2FL;
  202. String graphCode = sy2fl.getGraphCode();
  203. String relCode = sy2fl.getRelCode();
  204. String type = syInFl.getType();
  205. ObjectNode node = JsonNodeFactory.instance.objectNode();
  206. node.put("graphCode", graphCode);
  207. node.put("relCode", relCode);
  208. node.put("relValue",type);
  209. node.put("objFrom", sysId);
  210. node.put("objTo", floorId);
  211. QueryCriteria criteria = new QueryCriteria();
  212. criteria.setCriteria(node);
  213. // 组装上下文条件
  214. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  215. service.doDelete(context,criteria);
  216. return AdmResponse.success();
  217. }
  218. }