AdmEquipmentController.java 6.6 KB

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