AdmFloorController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.persagy.dmp.common.model.entity.BaseEntity;
  5. import com.persagy.proxy.adm.model.AdmEquipment;
  6. import com.persagy.proxy.adm.model.AdmFloor;
  7. import com.persagy.proxy.adm.model.AdmISpace;
  8. import com.persagy.proxy.adm.model.AdmSpace;
  9. import com.persagy.proxy.adm.request.AdmCreateRequest;
  10. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  11. import com.persagy.proxy.adm.request.AdmResponse;
  12. import com.persagy.proxy.adm.service.IAdmEquipmentService;
  13. import com.persagy.proxy.adm.service.IAdmFloorService;
  14. import com.persagy.proxy.adm.service.IAdmISpaceService;
  15. import com.persagy.proxy.adm.service.IAdmSpaceService;
  16. import com.persagy.proxy.adm.utils.AdmContextUtil;
  17. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  18. import com.persagy.proxy.common.entity.DmpResult;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * Adm 楼层 API
  28. * @author lvxy
  29. * @date 2021/8/16
  30. */
  31. @RestController
  32. @RequestMapping("/object/floor")
  33. public class AdmFloorController {
  34. @Autowired
  35. private IAdmFloorService service;
  36. @Autowired
  37. private IAdmEquipmentService equipmentService;
  38. @Autowired
  39. private IAdmISpaceService iAdmISpaceService;
  40. @Autowired
  41. private IAdmSpaceService spaceService;
  42. /**
  43. * 创建
  44. * @param createRequest
  45. * @return
  46. * @throws Exception
  47. */
  48. @PostMapping("/create")
  49. public AdmResponse create(@RequestBody AdmCreateRequest<AdmFloor> createRequest) throws Exception {
  50. List<AdmFloor> vos = createRequest.getContent();
  51. for(AdmFloor floor : vos){
  52. if(StrUtil.isEmpty(floor.getName())){
  53. floor.setName(ObjectNameUtil.objectName("楼层-"));
  54. }
  55. if(floor.getFloorSequenceID() == null){
  56. return AdmResponse.failure("楼层顺序号不可以为空或类型错误");
  57. }
  58. }
  59. Map<String, AdmFloor> admFloorMap = CollUtil.fieldValueMap(vos, "buildingId");
  60. if (CollUtil.isNotEmpty(admFloorMap)){
  61. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  62. StringBuilder stringBuilder = new StringBuilder();
  63. stringBuilder.append("buildingId in [");
  64. admFloorMap.keySet().stream().forEach(buildingId -> {
  65. stringBuilder.append("'").append(buildingId).append("'").append(",");
  66. });
  67. String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
  68. filters+= "]";
  69. admQueryCriteria.setFilters(filters);
  70. admQueryCriteria.setName("floor");
  71. AdmResponse admResponseF = service.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmFloor.class);
  72. if(DmpResult.SUCCESS.equals(admResponseF.getResult()) && admResponseF.getTotal() > 0){
  73. List<AdmFloor> vosOld = (List<AdmFloor>) admResponseF.getContent();
  74. for(AdmFloor admFloorOld : vosOld){
  75. if(admFloorMap.containsKey(admFloorOld.getBuildingId())){
  76. AdmFloor admFloorNew = admFloorMap.get(admFloorOld.getBuildingId());
  77. //楼层序列号相同
  78. if(admFloorOld.getFloorSequenceID() !=null && admFloorNew.getFloorSequenceID().equals(admFloorOld.getFloorSequenceID())){
  79. return AdmResponse.failure("楼层顺序号不可以重复");
  80. }
  81. }
  82. }
  83. }
  84. }
  85. List<AdmFloor> admFloors = service.doInsert(AdmContextUtil.toDmpContext(), AdmFloor.class, createRequest.getContent());
  86. return AdmResponse.success(admFloors);
  87. }
  88. /**
  89. * 根据ID删除
  90. * @param vos
  91. * @return
  92. * @throws Exception
  93. */
  94. @PostMapping("/delete")
  95. public AdmResponse delete( @RequestBody List<AdmFloor> vos) throws Exception {
  96. String msg = "楼层下包含其他对象实例,请解除关系后删除";
  97. Map<String, AdmFloor> admFloorMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
  98. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  99. StringBuilder stringBuilder = new StringBuilder();
  100. stringBuilder.append("floorId in [");
  101. admFloorMap.keySet().stream().forEach(buildingId -> {
  102. stringBuilder.append("'").append(buildingId).append("'").append(",");
  103. });
  104. String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
  105. filters+= "]";
  106. admQueryCriteria.setFilters(filters);
  107. admQueryCriteria.setOnlyCount(true);
  108. admQueryCriteria.setName(AdmSpace.OBJ_TYPE);
  109. AdmResponse admResponseSpace = spaceService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmSpace.class);
  110. if(admResponseSpace.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseSpace.getContent())){
  111. return AdmResponse.failure(msg);
  112. }
  113. admQueryCriteria.setName(AdmISpace.OBJ_TYPE);
  114. AdmResponse admResponseISpace = iAdmISpaceService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmISpace.class);
  115. if(admResponseISpace.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseISpace.getContent())){
  116. return AdmResponse.failure(msg);
  117. }
  118. admQueryCriteria.setName(AdmEquipment.OBJ_TYPE);
  119. AdmResponse admResponseEuip = equipmentService.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmEquipment.class);
  120. if(admResponseEuip.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(admResponseEuip.getContent())){
  121. return AdmResponse.failure(msg);
  122. }
  123. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  124. return AdmResponse.success();
  125. }
  126. /**
  127. * 根据ID删除 - 单条删除
  128. * @param vos
  129. * @return
  130. * @throws Exception
  131. */
  132. @PostMapping("/single/delete")
  133. public AdmResponse deleteSingle( @RequestBody List<AdmFloor> vos) throws Exception {
  134. delete(vos);
  135. return AdmResponse.success();
  136. }
  137. /**
  138. * 更新
  139. * @param admFloor
  140. * @return
  141. * @throws Exception
  142. */
  143. @PostMapping("/update")
  144. public AdmResponse update(@RequestBody AdmCreateRequest<AdmFloor> admFloor) throws Exception {
  145. List<AdmFloor> vos = CollUtil.newArrayList(admFloor.getContent());
  146. /** 遍历楼层列表 */
  147. Map<String, AdmFloor> admFloorBdMap = CollUtil.fieldValueMap(vos, "buildingId");
  148. if (CollUtil.isNotEmpty(admFloorBdMap)){
  149. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  150. StringBuilder stringBuilder = new StringBuilder();
  151. stringBuilder.append("buildingId in [");
  152. admFloorBdMap.keySet().stream().forEach(buildingId -> {
  153. stringBuilder.append("'").append(buildingId).append("'").append(",");
  154. });
  155. String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
  156. filters+= "]";
  157. admQueryCriteria.setFilters(filters);
  158. admQueryCriteria.setName("floor");
  159. AdmResponse admResponseF = service.doQuery(AdmContextUtil.toDmpContext(), admQueryCriteria, AdmFloor.class);
  160. if(DmpResult.SUCCESS.equals(admResponseF.getResult()) && admResponseF.getTotal() > 0 && CollUtil.isNotEmpty(admResponseF.getContent())){
  161. List<AdmFloor> vosOld = (List<AdmFloor>) admResponseF.getContent();
  162. for(AdmFloor admFloorOld : vosOld){
  163. if(admFloorBdMap.containsKey(admFloorOld.getBuildingId())){
  164. AdmFloor admFloorNew = admFloorBdMap.get(admFloorOld.getBuildingId());
  165. //楼层序列号相同
  166. if(!admFloorOld.getId().equals(admFloorNew.getId()) && admFloorOld.getFloorSequenceID()!=null && admFloorNew.getFloorSequenceID().equals(admFloorOld.getFloorSequenceID())){
  167. return AdmResponse.failure("楼层顺序号不可以重复");
  168. }
  169. }
  170. }
  171. }
  172. }
  173. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmFloor.class, vos);
  174. return AdmResponse.success(vos);
  175. }
  176. /**
  177. * 更新 outline
  178. * TODO 暂时不知道具体的参数,先做所有字段的更新,之后有具体场景再做细化
  179. * @param admFloor
  180. * @return
  181. * @throws Exception
  182. */
  183. @PostMapping("/update-outline")
  184. public AdmResponse updateOutline(@RequestBody AdmCreateRequest<AdmFloor> admFloor) throws Exception {
  185. // 组装上下文条件
  186. AdmResponse admResponse = update(admFloor);
  187. //TODO 处理关系
  188. /** 处理关系标记 */
  189. /* val listtype = ArrayList<String>()
  190. listtype.add("sh2bd")
  191. listtype.add("bd2sp")
  192. listtype.add("fl2sp")
  193. listtype.add("syeq2bd")
  194. listtype.add("sy2fl")
  195. listtype.add("eq2fl")
  196. listtype.add("pe2bd")
  197. listtype.add("pe2fl")
  198. for (type in listtype){
  199. val entity = EquipmentService.relationTypeProjectservice.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.eq("relationType", type)).entity()
  200. if (entity!=null){
  201. entity.computationalState = 2
  202. EquipmentService.relationTypeProjectservice.update(entity)
  203. }
  204. }*/
  205. return admResponse;
  206. }
  207. /**
  208. * 查询
  209. *
  210. * @param request
  211. * @return
  212. * @throws Exception
  213. */
  214. @PostMapping("/query")
  215. public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
  216. request.setName(AdmFloor.OBJ_TYPE);
  217. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmFloor.class);
  218. }
  219. /**
  220. * 查询
  221. *
  222. * @param request
  223. * @return
  224. * @throws Exception
  225. */
  226. @PostMapping("/query-outline")
  227. public AdmResponse queryOutline(@RequestBody AdmQueryCriteria request) throws Exception {
  228. request.setName(AdmFloor.OBJ_TYPE);
  229. return service.doQueryOutLine(AdmContextUtil.toDmpContext(), request, AdmFloor.class);
  230. }
  231. }