AdmSpaceController.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  4. import com.persagy.proxy.adm.model.AdmBuilding;
  5. import com.persagy.proxy.adm.model.AdmFloor;
  6. import com.persagy.proxy.adm.model.AdmSpace;
  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.IAdmBuildingService;
  11. import com.persagy.proxy.adm.service.IAdmSpaceService;
  12. import com.persagy.proxy.common.entity.InstanceUrlParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import javax.ws.rs.QueryParam;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * Adm 空间 API
  24. * @author lvxy
  25. * @date 2021/8/16
  26. */
  27. @RestController
  28. @RequestMapping("/object/zone")
  29. public class AdmSpaceController {
  30. @Autowired
  31. private IAdmSpaceService service;
  32. @Autowired
  33. private IAdmBuildingService buildingService;
  34. @Value("${middleware.group.code}")
  35. private String groupCode;
  36. /**
  37. * 统计
  38. * @param projectId
  39. * @param request
  40. * @return
  41. * @throws Exception
  42. */
  43. @PostMapping("/count")
  44. public AdmResponse count(@QueryParam("projectId") String projectId,
  45. @RequestBody AdmQueryCriteria request) throws Exception {
  46. // 组装上下文条件
  47. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  48. request.setName("space");
  49. request.setOnlyCount(true);
  50. return service.doQuery(context, request, AdmSpace.class);
  51. }
  52. /**
  53. * 创建
  54. * @param createRequest
  55. * @return
  56. * @throws Exception
  57. */
  58. @PostMapping("/create")
  59. public AdmResponse create(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  60. // 组装上下文条件
  61. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  62. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  63. vos = service.doInsert(context, AdmSpace.class, vos);
  64. return AdmResponse.success(vos);
  65. }
  66. /**
  67. * 根据ID删除
  68. * @param vos
  69. * @return
  70. * @throws Exception
  71. */
  72. @PostMapping("/delete")
  73. public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmSpace> vos) throws Exception {
  74. // 组装上下文条件
  75. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  76. service.doDelete(context, vos);
  77. return AdmResponse.success();
  78. }
  79. /**
  80. * 更新分区对象信息
  81. * @param createRequest
  82. * @return
  83. * @throws Exception
  84. */
  85. @PostMapping("/update")
  86. public AdmResponse update(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  87. // 组装上下文条件
  88. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  89. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  90. vos = service.doUpdate(context, AdmSpace.class, vos);
  91. return AdmResponse.success(vos);
  92. }
  93. /**
  94. * 查询
  95. * @param projectId
  96. * @param request
  97. * @return
  98. * @throws Exception
  99. */
  100. @PostMapping("/query")
  101. public AdmResponse query(@QueryParam("projectId") String projectId,
  102. @RequestBody AdmQueryCriteria request) throws Exception {
  103. // 组装上下文条件
  104. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  105. request.setName("space");
  106. return service.doQuery(context, request, AdmSpace.class);
  107. }
  108. /**
  109. * 查询业务空间的建筑楼层,包含受影响的空间数量
  110. * @param projectId
  111. * @param request
  112. * @return
  113. * @throws Exception
  114. */
  115. @PostMapping("/building-floor")
  116. public AdmResponse queryBuildingFloor(@QueryParam("projectId") String projectId,
  117. @RequestBody AdmQueryCriteria request) throws Exception {
  118. // 组装上下文条件
  119. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  120. request.setName("building");
  121. AdmQueryCriteria criteriaFloor = new AdmQueryCriteria();
  122. criteriaFloor.setName("floor");
  123. AdmQueryCriteria criteriaSpace = new AdmQueryCriteria();
  124. criteriaSpace.setName("spaceList");
  125. criteriaSpace.setFilters("state = 1");
  126. criteriaFloor.setCascade(CollUtil.newArrayList(criteriaSpace));
  127. request.setCascade(CollUtil.newArrayList(criteriaFloor));
  128. AdmResponse response = buildingService.doQueryBuildingFloor(context, request);
  129. List<AdmBuilding> buildings = (List<AdmBuilding>) response.getContent();
  130. buildings.stream().forEach(building -> {
  131. if(CollUtil.isNotEmpty(building.getFloor())){
  132. List<AdmFloor> floors = building.getFloor();
  133. floors.stream().forEach(floor -> {
  134. if(CollUtil.isNotEmpty(floor.getSpaceList())){
  135. floor.setCount(String.valueOf(floor.getSpaceList().size()));
  136. floor.setSpaceList(null);
  137. }else{
  138. floor.setCount("0");
  139. }
  140. });
  141. }
  142. });
  143. return response;
  144. }
  145. /**
  146. * 修改业务空间对象和建筑楼层的关系
  147. * spaceId 业务空间id,id 楼层或建筑id,type 业务空间的类型
  148. * @param createRequest
  149. * @return
  150. * @throws Exception
  151. */
  152. @PostMapping("/update-fl-bd")
  153. public AdmResponse updateFlBd(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  154. // 组装上下文条件
  155. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  156. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  157. vos = service.doUpdate(context, AdmSpace.class, vos);
  158. return AdmResponse.success(vos);
  159. }
  160. /**
  161. * 更新分区对象信息-Outline
  162. * @param createRequest
  163. * @return
  164. * @throws Exception
  165. */
  166. @PostMapping("/update-outline")
  167. public AdmResponse updateOutLine(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  168. // 组装上下文条件
  169. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  170. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  171. vos = service.doUpdate(context, AdmSpace.class, vos);
  172. return AdmResponse.success(vos);
  173. }
  174. /**
  175. * 查询空间信息-outline 级联查询:建筑(building),楼层(floor),空间类型(objectType)
  176. * @param projectId
  177. * @param request
  178. * @return
  179. * @throws Exception
  180. */
  181. @PostMapping("/query-outline")
  182. public AdmResponse queryOutline(@QueryParam("projectId") String projectId,
  183. @RequestBody AdmQueryCriteria request) throws Exception {
  184. // 组装上下文条件
  185. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  186. request.setName("space");
  187. return service.doQuery(context, request, AdmSpace.class);
  188. }
  189. /**
  190. * 获取项目下已有的空间类型
  191. * @param projectId
  192. * @param request
  193. * @return
  194. * @throws Exception
  195. */
  196. @PostMapping("/space-type")
  197. public AdmResponse querySpaceType(@QueryParam("projectId") String projectId,
  198. @RequestBody AdmQueryCriteria request) throws Exception {
  199. // 组装上下文条件
  200. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  201. request.setName("space");
  202. return service.doQuery(context, request, AdmSpace.class);
  203. }
  204. /**
  205. * 查询业务空间所有类型
  206. * @param projectId
  207. * @param request
  208. * @return
  209. * @throws Exception
  210. */
  211. @PostMapping("/type")
  212. public AdmResponse queryType(@QueryParam("projectId") String projectId,
  213. @RequestBody AdmQueryCriteria request) throws Exception {
  214. // 组装上下文条件
  215. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  216. request.setName("space");
  217. return service.doQuery(context, request, AdmSpace.class);
  218. }
  219. /**
  220. * 上传EXCEL 识别镜头信息点
  221. * @param projectId
  222. * @param request
  223. * @return
  224. * @throws Exception
  225. */
  226. @PostMapping("/import")
  227. public AdmResponse importExcel(@QueryParam("projectId") String projectId,
  228. @RequestBody AdmQueryCriteria request) throws Exception {
  229. // 组装上下文条件
  230. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  231. request.setName("space");
  232. return service.doQuery(context, request, AdmSpace.class);
  233. }
  234. }