RelationSyForSpController.java 7.4 KB

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