RelationEqForShController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.persagy.proxy.adm.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.model.relation.EqForSh;
  8. import com.persagy.proxy.adm.model.relation.EqForShList;
  9. import com.persagy.proxy.adm.model.relation.ShForEqList;
  10. import com.persagy.proxy.adm.request.AdmResponse;
  11. import com.persagy.proxy.adm.service.IAdmRelationService;
  12. import com.persagy.proxy.adm.utils.AdmContextUtil;
  13. import com.persagy.proxy.common.entity.InstanceUrlParam;
  14. import com.persagy.proxy.common.entity.RelationDTO;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Value;
  17. import org.springframework.util.CollectionUtils;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * @author zhangwencheng
  23. * 设备服务于竖井
  24. */
  25. @RestController
  26. @RequestMapping("/rel/eq-for-sh")
  27. public class RelationEqForShController {
  28. @Autowired
  29. private IAdmRelationService service;
  30. @Value("${middleware.group.code}")
  31. private String groupCode;
  32. /**
  33. * 创建设备服务于竖井关系
  34. * 必填项:EquipId(设备id)、ShaftId(竖井id)
  35. *
  36. * @return 创建的结果信息
  37. */
  38. @PostMapping("/link")
  39. public AdmResponse create(@RequestBody EqForSh eqForSh) {
  40. String equipId = eqForSh.getEquipId();
  41. String shaftId = eqForSh.getShaftId();
  42. String type = eqForSh.getType();
  43. //检验输入参数
  44. if (StrUtil.isEmpty(equipId) || StrUtil.isEmpty(shaftId)) {
  45. return AdmResponse.failure("必填项:equipId(设备id)、shaftId(竖井Id)");
  46. }
  47. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.EQ2SH_FOR;
  48. String graphCode = typeEnum.getGraphCode();
  49. String relCode = typeEnum.getRelCode();
  50. List<RelationDTO> voList = new ArrayList<>();
  51. RelationDTO relation = new RelationDTO(null, graphCode, relCode, type, equipId, shaftId);
  52. voList.add(relation);
  53. service.doSave(AdmContextUtil.toDmpContext(), voList);
  54. return AdmResponse.success();
  55. }
  56. /**
  57. * 创建设备服务于竖井关系
  58. * 必填项:ShaftIdList(竖井id列表)、EquipId(设备id),测方法会覆盖以前的记录
  59. *
  60. * @param
  61. * @return 创建的结果信息
  62. */
  63. @PostMapping("/link-sh")
  64. public AdmResponse createSh(@RequestBody EqForShList eqForShList) {
  65. String equipId = eqForShList.getEquipId();
  66. List<String> shaftIdList = eqForShList.getShaftIdList();
  67. //检验输入参数
  68. if (StrUtil.isEmpty(equipId) || CollectionUtils.isEmpty(shaftIdList)) {
  69. return AdmResponse.failure("必填项:equipId(设备id)、shaftIdList(竖井Id列表)");
  70. }
  71. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.EQ2SH_FOR;
  72. String graphCode = typeEnum.getGraphCode();
  73. String relCode = typeEnum.getRelCode();
  74. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  75. deleteByObjId(equipId, null, null, typeEnum, context);
  76. List<RelationDTO> voList = new ArrayList<>();
  77. for (String shaftId : shaftIdList) {
  78. RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", equipId, shaftId);
  79. voList.add(relation);
  80. }
  81. service.doSave(context, voList);
  82. return AdmResponse.success();
  83. }
  84. /**
  85. * 服务于竖井的设备,竖井一对多
  86. * 必填项:ShaftId(竖井id)、EquipIdList(设备id列表),测方法会覆盖以前的记录
  87. *
  88. * @param shForEqList 设备和竖井的关系对象
  89. * @return 创建的结果信息
  90. */
  91. @PostMapping("/link-eq")
  92. public AdmResponse createEq(@RequestBody ShForEqList shForEqList) {
  93. List<String> equipIdList = shForEqList.getEquipIdList();
  94. String shaftId = shForEqList.getShaftId();
  95. //检验输入参数
  96. if (StrUtil.isEmpty(shaftId) || CollectionUtils.isEmpty(equipIdList)) {
  97. return AdmResponse.failure("必填项:equipId(设备id)、shaftIdList(竖井Id列表)");
  98. }
  99. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  100. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.EQ2SH_FOR;
  101. String graphCode = typeEnum.getGraphCode();
  102. String relCode = typeEnum.getRelCode();
  103. deleteByObjId(null, shaftId, null, typeEnum, context);
  104. List<RelationDTO> voList = new ArrayList<>();
  105. for (String equipId : equipIdList) {
  106. RelationDTO relation = new RelationDTO(null, graphCode, relCode, "", equipId, shaftId);
  107. voList.add(relation);
  108. }
  109. service.doSave(context, voList);
  110. return AdmResponse.success();
  111. }
  112. /**
  113. * 根据对象删除设备服务于竖井关系,只针对一个对象
  114. * 必填项:EquipId(设备id)、shaftId(竖井id)
  115. *
  116. * @param eqForSh 对象
  117. * @return 删除的结果信息
  118. */
  119. @PostMapping("/unlink")
  120. public AdmResponse delete(@RequestBody EqForSh eqForSh) {
  121. String shaftId = eqForSh.getShaftId();
  122. String equipId = eqForSh.getEquipId();
  123. //检验输入参数
  124. if (StrUtil.isEmpty(equipId) || StrUtil.isEmpty(shaftId)) {
  125. return AdmResponse.failure("必填项:equipId(设备id)、shaftId(竖井Id)");
  126. }
  127. String type = eqForSh.getType();
  128. AdmRelationTypeEnum typeEnum = AdmRelationTypeEnum.EQ2SH_FOR;
  129. deleteByObjId(equipId, shaftId, type, typeEnum, AdmContextUtil.toDmpContext());
  130. return AdmResponse.success();
  131. }
  132. private void deleteByObjId(String objFrom, String objTo, String type, AdmRelationTypeEnum typeEnum, InstanceUrlParam context) {
  133. QueryCriteria criteria = new QueryCriteria();
  134. ObjectNode node = JsonNodeFactory.instance.objectNode();
  135. node.put("graphCode", typeEnum.getGraphCode());
  136. node.put("relCode", typeEnum.getRelCode());
  137. node.put("relValue", type);
  138. node.put("objFrom", objFrom);
  139. node.put("objTo", objTo);
  140. criteria.setCriteria(node);
  141. service.doDelete(context, criteria);
  142. }
  143. }