RelationSyInSpController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.fastjson.JSON;
  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.proxy.adm.constant.AdmCommonConstant;
  10. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  11. import com.persagy.proxy.adm.model.relation.*;
  12. import com.persagy.proxy.adm.request.AdmCreateRequest;
  13. import com.persagy.proxy.adm.request.AdmResponse;
  14. import com.persagy.proxy.adm.service.IAdmRelationService;
  15. import com.persagy.proxy.common.entity.InstanceUrlParam;
  16. import com.persagy.proxy.common.entity.RelationDTO;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.util.CollectionUtils;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. /**
  25. * @author zhangwencheng
  26. * 关系-系统所在业务空间-033
  27. */
  28. @Slf4j
  29. @RestController
  30. @RequestMapping("/rel/sy-in-sp-base")
  31. public class RelationSyInSpController {
  32. @Autowired
  33. private IAdmRelationService service;
  34. @Value("${middleware.group.code}")
  35. private String groupCode;
  36. @PostMapping("/link-list")
  37. public AdmResponse create(@RequestBody AdmCreateRequest<SyInSpBase> syInSpBase, @RequestParam("projectId") String projectId) {
  38. List<SyInSpBase> syInSpBases = syInSpBase.getContent();
  39. List<RelationDTO> voList = new ArrayList<>();
  40. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SP;
  41. String graphCode = typeEnum.getGraphCode();
  42. String relCode = typeEnum.getRelCode();
  43. for (SyInSpBase inSpBase : syInSpBases) {
  44. String spaceId = inSpBase.getSpaceId();
  45. String sysId = inSpBase.getSysId();
  46. String objectType = inSpBase.getObjectType();
  47. if (StrUtil.isBlank(spaceId) || StrUtil.isBlank(sysId) ) {
  48. return AdmResponse.failure("必填项:SysId(系统id)、spaceId(空间id)");
  49. }
  50. RelationDTO relation = new RelationDTO(null, graphCode, relCode, objectType, sysId, spaceId);
  51. voList.add(relation);
  52. }
  53. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  54. service.doSave(context, voList);
  55. return AdmResponse.success();
  56. }
  57. /**
  58. * 处理所有空间分区和系统关系 系统所在的业务空间关系,空间分区一对多,累计叠加,不覆盖
  59. */
  60. @PostMapping(value = "/link-sp-sys")
  61. public AdmResponse createsSpSys( @RequestBody JSONObject param , @RequestParam("projectId") String projectId) {
  62. JSONObject rSyIn = param.getJSONObject("rSyInSpBase");
  63. String type = param.getString("type");
  64. SpInSyBaseList rSyInSpBase = JSON.toJavaObject(rSyIn, SpInSyBaseList.class);
  65. String spaceId = rSyInSpBase.getSpaceId();
  66. List<String> sysIdList = rSyInSpBase.getSysIdList();
  67. if (StrUtil.isBlank(spaceId) || CollectionUtils.isEmpty(sysIdList)) {
  68. return AdmResponse.failure("必填项:SysId(系统id)、spaceId(空间id)");
  69. }
  70. List<RelationDTO> voList = new ArrayList<>();
  71. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SP;
  72. String graphCode = typeEnum.getGraphCode();
  73. String relCode = typeEnum.getRelCode();
  74. for (String sysId : sysIdList) {
  75. RelationDTO relation = new RelationDTO(null, graphCode, relCode, type, sysId, spaceId);
  76. voList.add(relation);
  77. }
  78. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  79. service.doSave(context, voList);
  80. return AdmResponse.success();
  81. }
  82. /**
  83. * 创建系统所在业务空间关系
  84. * 系统所在业务空间关系,系统一对多,不覆盖
  85. *
  86. * @param param 系统和业务空间的关系对象
  87. * @return 创建的结果信息
  88. */
  89. @PostMapping(value = "/link-sy-sps")
  90. public AdmResponse createSySps( @RequestBody JSONObject param, @RequestParam("projectId") String projectId) {
  91. JSONObject rSyIn = param.getJSONObject("rSyInSpBase");
  92. String type = param.getString("type");
  93. SyInSpBaseList syInSpBaseList= JSON.toJavaObject(rSyIn, SyInSpBaseList.class);
  94. List<String> spaceIdList = syInSpBaseList.getSpaceIdList();
  95. String sysId = syInSpBaseList.getSysId();
  96. List<RelationDTO> voList = new ArrayList<>();
  97. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SP;
  98. String graphCode = typeEnum.getGraphCode();
  99. String relCode = typeEnum.getRelCode();
  100. for (String spaceId : spaceIdList) {
  101. if (StrUtil.isBlank(spaceId) || StrUtil.isEmpty(sysId)) {
  102. return AdmResponse.failure("必填项:SysId(系统id)、spaceId(空间id)");
  103. }
  104. RelationDTO relation = new RelationDTO(null, graphCode, relCode, type, sysId, spaceId);
  105. voList.add(relation);
  106. }
  107. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  108. service.doSave(context, voList);
  109. return AdmResponse.success();
  110. }
  111. /**
  112. * 根据对象删除系统所在业务空间关系
  113. *
  114. * @param
  115. * @return 删除的结果信息
  116. */
  117. @PostMapping("/unlink-list")
  118. public AdmResponse delete(@RequestBody JSONObject param, @RequestParam("projectId") String projectId) {
  119. JSONArray jsonArray = param.getJSONArray("rSyInSpBase");
  120. List<SyInSpBase> syInSpBases = JSONArray.parseArray(jsonArray.toJSONString(),SyInSpBase.class);
  121. String type = param.getString("type");
  122. // String type = deleteSyInSpBase.getType();
  123. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.SY2SP;
  124. String graphCode = typeEnum.getGraphCode();
  125. String relCode = typeEnum.getRelCode();
  126. List<QueryCriteria> queryCriteriaList = new ArrayList<>();
  127. if(CollectionUtils.isEmpty(syInSpBases)){
  128. return AdmResponse.failure("必填项:syInSpBases");
  129. }
  130. for (SyInSpBase syInSpBase : syInSpBases) {
  131. String sysId = syInSpBase.getSysId();
  132. String spaceId = syInSpBase.getSpaceId();
  133. if (StrUtil.isBlank(spaceId) || StrUtil.isEmpty(sysId)) {
  134. return AdmResponse.failure("必填项:SysId(系统id)、spaceId(空间id)");
  135. }
  136. QueryCriteria criteria = new QueryCriteria();
  137. ObjectNode node = JsonNodeFactory.instance.objectNode();
  138. node.put("graphCode", graphCode);
  139. node.put("relCode", relCode);
  140. node.put("relValue", type);
  141. node.put("objFrom", sysId);
  142. node.put("objTo", spaceId);
  143. criteria.setCriteria(node);
  144. queryCriteriaList.add(criteria);
  145. }
  146. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  147. for (QueryCriteria queryCriteria : queryCriteriaList) {
  148. //问题:如何调用一次接口,如何保证一起成功
  149. service.doDelete(context, queryCriteria);
  150. }
  151. return AdmResponse.success();
  152. }
  153. }