RelationSyInSpController.java 7.2 KB

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