RelationSyForSpController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package com.persagy.proxy.relation.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.AdmRelationTypeEnum;
  7. import com.persagy.proxy.adm.request.AdmResponse;
  8. import com.persagy.proxy.adm.service.IAdmRelationService;
  9. import com.persagy.proxy.adm.utils.AdmContextUtil;
  10. import com.persagy.proxy.common.entity.InstanceUrlParam;
  11. import com.persagy.proxy.common.entity.RelationDTO;
  12. import com.persagy.proxy.relation.model.SpForSyBaseList;
  13. import com.persagy.proxy.relation.model.SyForSpBase;
  14. import com.persagy.proxy.relation.model.SyForSpBaseList;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.util.CollectionUtils;
  18. import org.springframework.util.StringUtils;
  19. import org.springframework.web.bind.annotation.PostMapping;
  20. import org.springframework.web.bind.annotation.RequestBody;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RestController;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * @author zhangwencheng
  27. * 系统服务于业务空间
  28. */
  29. @Slf4j
  30. @RestController
  31. @RequestMapping("/rel/sy-for-sp-base")
  32. public class RelationSyForSpController {
  33. @Autowired
  34. private IAdmRelationService service;
  35. /**
  36. * 创建系统服务于业务空间关系
  37. *
  38. * @param rSyForSpBase
  39. * @return
  40. * @throws Exception
  41. */
  42. @PostMapping("/link")
  43. public AdmResponse create(@RequestBody SyForSpBase rSyForSpBase) throws Exception {
  44. log.info("创建系统服务于业务空间关系create方法开始参数projectId为{}");
  45. //系统Id
  46. String sysID = rSyForSpBase.getSysId();
  47. //业务空间Id
  48. String spaceId = rSyForSpBase.getSpaceId();
  49. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(spaceId)) {
  50. return AdmResponse.failure("必填项:sysID(系统id)、SpaceId(业务空间id)");
  51. }
  52. AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
  53. String graphCode = sy2spFor.getGraphCode();
  54. String relCode = sy2spFor.getRelCode();
  55. List<RelationDTO> voList = new ArrayList<>();
  56. RelationDTO relation = new RelationDTO(null, graphCode, relCode, rSyForSpBase.getObjectType(), sysID, spaceId);
  57. voList.add(relation);
  58. service.doSave(AdmContextUtil.toDmpContext(), voList);
  59. log.info("创建系统服务于业务空间关系create方法结束");
  60. return AdmResponse.success();
  61. }
  62. /**
  63. * 系统服务于业务空间关系,系统一对多
  64. *
  65. * @return
  66. * @throws Exception
  67. */
  68. @PostMapping("/link-sp")
  69. public AdmResponse createSp(@RequestBody SyForSpBaseList syForSpBaseList) throws Exception {
  70. log.info("创建系统空间关系createSp开始");
  71. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  72. List<String> spaceIdList = syForSpBaseList.getSpaceIdList();
  73. String sysId = syForSpBaseList.getSysId();
  74. List<RelationDTO> voList = new ArrayList<>();
  75. AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
  76. String graphCode = sy2spFor.getGraphCode();
  77. String relCode = sy2spFor.getRelCode();
  78. //校验输入参数
  79. if (CollectionUtils.isEmpty(spaceIdList) || StringUtils.isEmpty(sysId)) {
  80. return AdmResponse.failure("必填项:SpaceIdList(业务空间id列表)、SysID(系统id)");
  81. }
  82. for (String spaceId : spaceIdList) {
  83. RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", sysId, spaceId);
  84. voList.add(relation);
  85. }
  86. service.doSave(context, voList);
  87. log.info("创建系统空间关系createSp结束");
  88. return AdmResponse.success();
  89. }
  90. /**
  91. * 服务于业务空间的系统,业务空间一对多
  92. *
  93. * @param spForSyBaseList
  94. * @return
  95. * @throws Exception
  96. */
  97. @PostMapping("/link-sy")
  98. public AdmResponse createSy(@RequestBody SpForSyBaseList spForSyBaseList) {
  99. log.info("创建系统空间关系业务空间一对多link-sy开始");
  100. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  101. List<String> sysIdList = spForSyBaseList.getSysIdList();
  102. String spaceId = spForSyBaseList.getSpaceId();
  103. List<RelationDTO> voList = new ArrayList<>();
  104. if (CollectionUtils.isEmpty(sysIdList) || StringUtils.isEmpty(spaceId)) {
  105. return AdmResponse.failure("必填项:spaceId业务空间id,SysIDList(系统id列表))");
  106. }
  107. AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
  108. String graphCode = sy2spFor.getGraphCode();
  109. String relCode = sy2spFor.getRelCode();
  110. for (String sysId: sysIdList) {
  111. RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", sysId, spaceId);
  112. voList.add(relation);
  113. }
  114. service.doSave(context, voList);
  115. log.info("创建系统空间关系业务空间一对多link-sy结束");
  116. return AdmResponse.success();
  117. }
  118. /**
  119. * 根据对象删除系统服务于业务空间关系,只针对一个对象
  120. * @param syForSpBase
  121. * @return
  122. * @throws Exception
  123. */
  124. @PostMapping("/unlink")
  125. public AdmResponse delete(@RequestBody SyForSpBase syForSpBase) throws Exception {
  126. log.info("创建系统服务于业务空间关系create方法开始参数projectId为{}");
  127. //系统Id
  128. String sysID = syForSpBase.getSysId();
  129. //业务空间Id
  130. String spaceId = syForSpBase.getSpaceId();
  131. if (StrUtil.isBlank(sysID) || StrUtil.isBlank(spaceId)) {
  132. return AdmResponse.failure("必填项:sysID(系统id)、SpaceId(业务空间id)");
  133. }
  134. // 组装上下文条件
  135. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  136. QueryCriteria criteria = new QueryCriteria();
  137. ObjectNode node = JsonNodeFactory.instance.objectNode();
  138. AdmRelationTypeEnum sy2spFor = AdmRelationTypeEnum.SY2SP_FOR;
  139. String graphCode = sy2spFor.getGraphCode();
  140. String relCode = sy2spFor.getRelCode();
  141. node.put("graphCode", graphCode);
  142. node.put("relCode", relCode);
  143. // node.put("relValue", syForSpBase.getObjectType());
  144. node.put("objFrom", sysID);
  145. node.put("objTo", spaceId);
  146. criteria.setCriteria(node);
  147. service.doDelete(context, criteria);
  148. log.info("创建系统服务于业务空间关系create方法结束");
  149. return AdmResponse.success();
  150. }
  151. }