AdmEquipmentController.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.fasterxml.jackson.databind.node.ObjectNode;
  5. import com.persagy.dmp.basic.utils.JsonNodeUtils;
  6. import com.persagy.proxy.adm.model.AdmEquipment;
  7. import com.persagy.proxy.adm.request.AdmCreateRequest;
  8. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  9. import com.persagy.proxy.adm.request.AdmResponse;
  10. import com.persagy.proxy.adm.service.IAdmEquipmentService;
  11. import com.persagy.proxy.adm.service.IAdmRelationService;
  12. import com.persagy.proxy.adm.utils.AdmContextUtil;
  13. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  14. import com.persagy.proxy.common.entity.RelationDTO;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * Adm 楼层 API
  21. * @author lvxy
  22. * @date 2021/8/16
  23. */
  24. @RestController
  25. @RequestMapping("/object/equip")
  26. public class AdmEquipmentController {
  27. @Autowired
  28. private IAdmEquipmentService service;
  29. @Autowired
  30. private IAdmRelationService relationService;
  31. /**
  32. * 统计
  33. *
  34. * @param request
  35. * @return
  36. * @throws Exception
  37. */
  38. @PostMapping("/count")
  39. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  40. request.setName(AdmEquipment.OBJ_TYPE);
  41. request.setOnlyCount(true);
  42. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  43. }
  44. /**
  45. * 创建
  46. * @param createRequest
  47. * @return
  48. * @throws Exception
  49. */
  50. @PostMapping("/create")
  51. public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
  52. List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
  53. if(CollUtil.isEmpty(vos)){
  54. return AdmResponse.success();
  55. }
  56. //创建设备
  57. vos.stream().forEach(equipment -> {
  58. if (StrUtil.isEmpty(equipment.getName())){
  59. equipment.setName(ObjectNameUtil.objectName("设备-"));
  60. }
  61. });
  62. vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  63. return AdmResponse.success(vos);
  64. }
  65. /**
  66. * 根据ID删除
  67. * @param vos
  68. * @return
  69. * @throws Exception
  70. */
  71. @PostMapping("/delete")
  72. public AdmResponse delete( @RequestBody List<AdmEquipment> vos) throws Exception {
  73. // 组装上下文条件
  74. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  75. return AdmResponse.success();
  76. }
  77. /**
  78. * 更新
  79. * @param createRequest
  80. * @return
  81. * @throws Exception
  82. */
  83. @PostMapping("/update")
  84. public AdmResponse update(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
  85. List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
  86. //vos = service.doUpdateEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  87. //针对设备更新时,所有更新的字段都放到信息点中的情况特殊处理
  88. if(CollUtil.isNotEmpty(vos)){
  89. List<AdmEquipment> equipmentList = new ArrayList<>(vos.size());
  90. vos.stream().forEach(equipment -> {
  91. if(CollUtil.isNotEmpty(equipment.getInfos())){
  92. AdmEquipment admEquipment = new AdmEquipment();
  93. admEquipment.setId(equipment.getId());
  94. admEquipment.setInfos(equipment.getInfos());
  95. ObjectNode objectNode = JsonNodeUtils.toObjectNode(admEquipment, "infos", null);
  96. AdmEquipment admEquipmentNew = JsonNodeUtils.toEntity(objectNode, AdmEquipment.class, "infos");
  97. equipmentList.add(admEquipmentNew);
  98. }
  99. });
  100. vos = equipmentList;
  101. }
  102. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  103. return AdmResponse.success(vos);
  104. }
  105. /**
  106. * 查询
  107. *
  108. * @param request
  109. * @return
  110. * @throws Exception
  111. */
  112. @PostMapping("/query")
  113. public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
  114. // 组装上下文条件
  115. request.setName(AdmEquipment.OBJ_TYPE);
  116. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  117. }
  118. /**
  119. * 设备绑定的动态信息点或静态信息点
  120. * @param admEquipment
  121. * @return
  122. * @throws Exception
  123. */
  124. @GetMapping("/export")
  125. public AdmResponse exportInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
  126. List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
  127. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  128. return AdmResponse.success(vos);
  129. }
  130. /**
  131. * 设备上传excel识别静态信息点
  132. * @param admEquipment
  133. * @return
  134. * @throws Exception
  135. */
  136. @PostMapping("/import")
  137. public AdmResponse importInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
  138. List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
  139. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  140. return AdmResponse.success(vos);
  141. }
  142. /**
  143. * 根据项目id查询所有的设备和部件
  144. *
  145. * @param request
  146. * @return
  147. * @throws Exception
  148. */
  149. @GetMapping("/query-equip")
  150. public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
  151. //request.setName("equipment");
  152. if(StrUtil.isNotEmpty(request.getFilters())){
  153. request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
  154. }else{
  155. request.setFilters("objType in ['equipment','component']");
  156. }
  157. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  158. }
  159. /**
  160. * 批量创建设备同时创建资产、创建设备和系统的关系
  161. * @param admEquipment
  162. * @return
  163. * @throws Exception
  164. */
  165. @PostMapping("/creat-equip-pro")
  166. public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
  167. List<AdmEquipment> vos = admEquipment.getContent();
  168. if(CollUtil.isEmpty(vos)){
  169. return AdmResponse.success();
  170. }
  171. //创建设备
  172. vos.stream().forEach(equipment -> {
  173. if (StrUtil.isEmpty(equipment.getName())){
  174. equipment.setName(ObjectNameUtil.objectName("设备-"));
  175. }
  176. });
  177. List<AdmEquipment> reVos = new ArrayList<>(vos.size());
  178. List<RelationDTO> relationDTOS = new ArrayList<>(16);
  179. vos.stream().forEach(admEq -> {
  180. //创建设备
  181. List<AdmEquipment> vosR = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, CollUtil.newArrayList(admEq));
  182. //TODO 创建资产
  183. //添加设备和系统、建筑、楼层的关系
  184. if(CollUtil.isNotEmpty(vosR)){
  185. String equipId = vosR.get(0).getId();
  186. if(StrUtil.isNotEmpty(equipId)){
  187. if(CollUtil.isNotEmpty(admEq.getLinkSystem())){
  188. admEq.getLinkSystem().stream().forEach(admSystem -> {
  189. relationDTOS.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null , admSystem.getId(), equipId));
  190. });
  191. }
  192. if(StrUtil.isNotEmpty(admEq.getBuildingId())){
  193. relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Bd", null , equipId, admEq.getBuildingId()));
  194. }
  195. if(StrUtil.isNotEmpty(admEq.getFloorId())){
  196. relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Fl", null , equipId, admEq.getBuildingId()));
  197. }
  198. }
  199. }
  200. reVos.addAll(vosR);
  201. });
  202. relationService.doSave(AdmContextUtil.toDmpContext(),relationDTOS);
  203. return AdmResponse.success(reVos);
  204. }
  205. }