AdmSpaceController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package com.persagy.proxy.object.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  6. import com.fasterxml.jackson.databind.node.ObjectNode;
  7. import com.persagy.dmp.basic.model.QueryCriteria;
  8. import com.persagy.dmp.basic.utils.JsonNodeUtils;
  9. import com.persagy.proxy.adm.request.*;
  10. import com.persagy.proxy.adm.service.IAdmRelationService;
  11. import com.persagy.proxy.adm.utils.AdmContextUtil;
  12. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  13. import com.persagy.proxy.common.entity.RelationDTO;
  14. import com.persagy.proxy.object.model.AdmBuilding;
  15. import com.persagy.proxy.object.model.AdmFloor;
  16. import com.persagy.proxy.object.model.AdmSpace;
  17. import com.persagy.proxy.object.service.IAdmBuildingService;
  18. import com.persagy.proxy.object.service.IAdmFloorService;
  19. import com.persagy.proxy.object.service.IAdmSpaceService;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.PostMapping;
  22. import org.springframework.web.bind.annotation.RequestBody;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import javax.ws.rs.QueryParam;
  26. import java.util.*;
  27. /**
  28. * Adm 空间 API
  29. * @author lvxy
  30. * @date 2021/8/16
  31. */
  32. @RestController
  33. @RequestMapping("/object/zone")
  34. public class AdmSpaceController {
  35. @Autowired
  36. private IAdmSpaceService service;
  37. @Autowired
  38. private IAdmBuildingService buildingService;
  39. @Autowired
  40. private IAdmRelationService relationService;
  41. @Autowired
  42. private IAdmFloorService floorService;
  43. /**
  44. * 统计
  45. *
  46. * @param request
  47. * @return
  48. * @throws Exception
  49. */
  50. @PostMapping("/count")
  51. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  52. request.setName(AdmSpace.OBJ_TYPE);
  53. request.setOnlyCount(true);
  54. //return service.doQuery( AdmContextUtil.toDmpContext(), request, AdmSpace.class);
  55. return service.query(request);
  56. }
  57. /**
  58. * 创建
  59. * @param createRequest
  60. * @return
  61. * @throws Exception
  62. */
  63. @PostMapping("/create")
  64. public AdmCreateResponse create(@RequestBody AdmCreateRequest<AdmSpace> createRequest) throws Exception {
  65. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  66. String msg = null;
  67. for (AdmSpace admSpace : vos) {
  68. if(StrUtil.isEmpty(admSpace.getClassCode())){
  69. msg = "classCode不可以为空!";
  70. break;
  71. }
  72. if (StrUtil.isEmpty(admSpace.getName())) {
  73. admSpace.setName(ObjectNameUtil.objectName("空间-"));
  74. }
  75. }
  76. if(StrUtil.isEmpty(msg)){
  77. vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
  78. AdmCreateResponse admResponseObj = AdmCreateResponse.success(vos);
  79. return admResponseObj;
  80. }else{
  81. return AdmCreateResponse.failure(msg);
  82. }
  83. }
  84. /**
  85. * 根据ID删除
  86. * @param vos
  87. * @return
  88. * @throws Exception
  89. */
  90. @PostMapping("/delete")
  91. public AdmResponse delete( @RequestBody List<AdmSpace> vos) throws Exception {
  92. service.doDelete( AdmContextUtil.toDmpContext(), vos);
  93. QueryCriteria queryCriteria = new QueryCriteria();
  94. vos.forEach(vo -> {
  95. /** 清除空间和建筑楼层的的数据 */
  96. dealRelation(vo.getId(), queryCriteria,"Bd2Sp", false);
  97. dealRelation(vo.getId(), queryCriteria,"Fl2Sp", false);
  98. dealRelation(vo.getId(), queryCriteria,"Sp2Si", true);
  99. });
  100. return AdmResponse.success();
  101. }
  102. /**
  103. * 更新分区对象信息
  104. * @param createRequest
  105. * @return
  106. * @throws Exception
  107. */
  108. @PostMapping("/update")
  109. public AdmResponse update(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  110. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  111. return service.doUpdate(vos);
  112. }
  113. /**
  114. * 查询
  115. *
  116. * @param request
  117. * @return
  118. * @throws Exception
  119. */
  120. @PostMapping("/query")
  121. public ObjectNode query(@RequestBody AdmDCSQueryRequest request) throws Exception {
  122. AdmResponse response = service.doQuerySpaces( AdmContextUtil.toDmpContext(), request);
  123. ObjectNode objectNode = JsonNodeUtils.toObjectNode(response, null, null);
  124. if(StrUtil.isNotEmpty(request.getZoneType())){
  125. objectNode.put("zoneType", request.getZoneType());
  126. }
  127. return objectNode;
  128. /*ObjectNode criteria = AdmQueryCriteriaHelper.toCriteria(null, request.getFilters());
  129. List<OrderItem> orderItem = AdmQueryCriteriaHelper.toOrderItem(request.getOrders());
  130. return this.spaceRelationInfoHandler.querySpaceInfo(request, criteria, orderItem);*/
  131. }
  132. /**
  133. * 查询业务空间的建筑楼层,包含受影响的空间数量
  134. *
  135. * @param request
  136. * @return
  137. * @throws Exception
  138. */
  139. @PostMapping("/building-floor")
  140. public AdmResponse queryBuildingFloor(@RequestBody AdmQueryCriteria request) throws Exception {
  141. request.setName(AdmBuilding.OBJ_TYPE);
  142. AdmQueryCriteria criteriaFloor = new AdmQueryCriteria();
  143. criteriaFloor.setName(AdmFloor.OBJ_TYPE);
  144. AdmQueryCriteria criteriaSpace = new AdmQueryCriteria();
  145. criteriaSpace.setName("spaceList");
  146. criteriaSpace.setFilters("state = 1");
  147. criteriaFloor.setCascade(CollUtil.newArrayList(criteriaSpace));
  148. criteriaFloor.setOrders("floorSequenceID desc");
  149. request.setCascade(CollUtil.newArrayList(criteriaFloor));
  150. AdmResponse response = buildingService.doQueryBuildingFloor(AdmContextUtil.toDmpContext(), request);
  151. List<AdmBuilding> buildings = (List<AdmBuilding>) response.getContent();
  152. buildings.forEach(building -> {
  153. if(CollUtil.isNotEmpty(building.getFloor())){
  154. List<AdmFloor> floors = building.getFloor();
  155. floors.forEach(floor -> {
  156. if(CollUtil.isNotEmpty(floor.getSpaceList())){
  157. floor.setCount(floor.getSpaceList().size());
  158. floor.setSpaceList(null);
  159. }else{
  160. floor.setCount(0);
  161. }
  162. });
  163. }
  164. });
  165. return response;
  166. }
  167. /**
  168. * 修改业务空间对象和建筑楼层的关系
  169. * spaceId 业务空间id,id 楼层或建筑id,type 业务空间的类型
  170. * @param voList
  171. * @return
  172. * @throws Exception
  173. */
  174. @PostMapping("/update-fl-bd")
  175. public AdmResponse updateFlBd(@RequestBody List<AdmUpDataFloorAndBuildingRequests> voList, @QueryParam("projectId") String projectId) throws Exception {
  176. if(CollUtil.isEmpty(voList)){
  177. return AdmResponse.failure("不可以传入空数据");
  178. }
  179. //TODO 循环删除 需要改为 批量删除
  180. List<RelationDTO> RSpInBd_up = new ArrayList<>();
  181. List<RelationDTO> RSpInFl_up = new ArrayList<>();
  182. List<AdmSpace> space_up = new ArrayList<>();
  183. QueryCriteria queryCriteria = new QueryCriteria();
  184. voList.stream().forEach(requestData -> {
  185. String spaceId = requestData.getSpaceId();
  186. String id = requestData.getId();
  187. String type = requestData.getType();//classCode
  188. //更新实体
  189. AdmSpace space = new AdmSpace();
  190. space.setId(spaceId);
  191. space.setObjectType(AdmSpace.OBJ_TYPE);
  192. space.setClassCode(type);
  193. /** 清除空间和建筑楼层的的数据 */
  194. dealRelation(spaceId, queryCriteria,"Bd2Sp", false);
  195. dealRelation(spaceId, queryCriteria,"Fl2Sp", false);
  196. if(StrUtil.isNotEmpty(id)){
  197. if(id.startsWith("Fl") && StrUtil.isNotEmpty(spaceId)){
  198. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  199. admQueryCriteria.setName(AdmFloor.OBJ_TYPE);
  200. admQueryCriteria.setFilters("id = '"+id+"'");
  201. AdmResponse admResponseFl = floorService.query(admQueryCriteria);
  202. if(CollUtil.isNotEmpty(admResponseFl.getContent())){
  203. AdmFloor floor = (AdmFloor) admResponseFl.getContent().get(0);
  204. if (floor!=null){
  205. //更新关系
  206. RelationDTO rBd_up = new RelationDTO();
  207. rBd_up.setObjTo(spaceId);
  208. rBd_up.setRelCode("Bd2Sp");
  209. rBd_up.setGraphCode("ArchSubset");
  210. rBd_up.setObjFrom(floor.getBuildingId());
  211. RSpInBd_up.add(rBd_up);
  212. RelationDTO rFl_up = new RelationDTO();
  213. rFl_up.setObjTo(spaceId);
  214. rFl_up.setRelCode("Fl2Sp");
  215. rFl_up.setGraphCode("ArchSubset");
  216. rFl_up.setObjFrom(floor.getId());
  217. RSpInFl_up.add(rFl_up);
  218. //楼层 建筑信息点维护
  219. space.setBuildingId(floor.getBuildingId());
  220. space.setFloorId(floor.getId());
  221. space_up.add(space);
  222. }
  223. }
  224. }else if(id.startsWith("Bd")){
  225. //更新关系
  226. QueryCriteria criteria = new QueryCriteria();
  227. ObjectNode node = JsonNodeFactory.instance.objectNode();
  228. //删除关系 然后重建
  229. node.put("relCode", "Bd2Sp");
  230. node.put("objTo", "spaceId");
  231. node.put("graphCode", "ArchSubset");
  232. criteria.setCriteria(node);
  233. relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
  234. RelationDTO rBd_up = new RelationDTO();
  235. rBd_up.setObjTo(spaceId);
  236. rBd_up.setRelCode("Bd2Sp");
  237. rBd_up.setGraphCode("ArchSubset");
  238. rBd_up.setObjFrom(id);
  239. RSpInBd_up.add(rBd_up);
  240. //楼层 建筑信息点维护
  241. space.setBuildingId(id);
  242. Map<String, Object> info = new HashMap<>(1);
  243. info.put("$remove",Arrays.asList("floorId"));
  244. space.setInfos(info);
  245. space_up.add(space);
  246. }
  247. }else{
  248. //楼层 建筑信息点维护 清除
  249. Map<String, Object> info = new HashMap<>(1);
  250. info.put("$remove",Arrays.asList("floorId","buildingId"));
  251. space.setInfos(info);
  252. space_up.add(space);
  253. }
  254. });
  255. service.doUpdate( AdmContextUtil.toDmpContext(), AdmSpace.class, space_up);
  256. relationService.doSave( AdmContextUtil.toDmpContext(), RSpInBd_up);
  257. relationService.doSave( AdmContextUtil.toDmpContext(), RSpInFl_up);
  258. return AdmResponse.success(space_up);
  259. }
  260. /**
  261. * 更新分区对象信息-Outline
  262. * @param createRequest
  263. * @return
  264. * @throws Exception
  265. */
  266. @PostMapping("/update-outline")
  267. public AdmResponse updateOutLine(@RequestBody AdmCreateRequest<AdmSpace> createRequest) throws Exception {
  268. List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
  269. /*vos = service.doUpdate( AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
  270. //更新计算关系ZoneSpaceBaseService.upDateOutline
  271. service.processRelationType(vos);
  272. return AdmResponse.success(vos);*/
  273. return service.updateOutLine(vos);
  274. }
  275. /**
  276. * 查询空间信息-outline 级联查询:建筑(building),楼层(floor),空间类型(objectType)
  277. *
  278. * @param request
  279. * @return
  280. * @throws Exception
  281. */
  282. @PostMapping("/query-outline")
  283. public ObjectNode queryOutline(@RequestBody AdmDCSQueryRequest request) throws Exception {
  284. request.setName(AdmSpace.OBJ_TYPE);
  285. request.setProjection(null);
  286. List<String> list = new ArrayList<>();
  287. list.add("id");
  288. list.add("name");
  289. list.add("localId");
  290. list.add("localName");
  291. list.add("outline");
  292. list.add("classCode");
  293. list.add("buildingId");
  294. list.add("floorId");
  295. list.add("state");
  296. list.add("floorSequenceId");
  297. list.add("modelId");
  298. list.add("infos");
  299. list.add("properties");
  300. request.setProjection(list);
  301. AdmResponse response = service.doQuerySpaces(AdmContextUtil.toDmpContext(), request);
  302. ObjectNode objectNode = JsonNodeUtils.toObjectNode(response, null, null);
  303. if(StrUtil.isNotEmpty(request.getZoneType())){
  304. objectNode.put("zoneType", request.getZoneType());
  305. }
  306. if(StrUtil.isNotEmpty(request.getFloorId())){
  307. objectNode.put("floorId", request.getFloorId());
  308. }
  309. if(StrUtil.isNotEmpty(request.getBuildingId())){
  310. objectNode.put("buildingId", request.getBuildingId());
  311. }
  312. return objectNode;
  313. }
  314. /**
  315. * 获取项目下已有的空间类型
  316. *
  317. * @return
  318. * @throws Exception
  319. */
  320. @PostMapping("/space-type")
  321. public List<JSONObject> querySpaceType() throws Exception {
  322. return service.doQuerySpaceTypes( AdmContextUtil.toDmpContext());
  323. }
  324. /**
  325. * 查询业务空间所有类型
  326. *
  327. * @param request
  328. * @return
  329. * @throws Exception
  330. */
  331. @PostMapping("/type")
  332. public ObjectNode queryType(@RequestBody AdmDCSQueryRequest request) throws Exception {
  333. AdmResponse response = service.doQueryType( AdmContextUtil.toDmpContext(), request);
  334. ObjectNode objectNode = JsonNodeUtils.toObjectNode(response, null, null);
  335. if(StrUtil.isNotEmpty(request.getZoneType())){
  336. objectNode.put("zoneType", request.getZoneType());
  337. }
  338. return objectNode;
  339. }
  340. /**
  341. * 上传EXCEL 识别镜头信息点
  342. *
  343. * @param
  344. * @return
  345. * @throws Exception
  346. */
  347. @PostMapping("/import")
  348. public AdmResponse importExcel() throws Exception {
  349. return null;
  350. }
  351. private void dealRelation(String spaceId, QueryCriteria queryCriteria, String relCode, Boolean isObjFrom){
  352. ObjectNode rBd = JsonNodeFactory.instance.objectNode();
  353. if(isObjFrom){
  354. rBd.put("objFrom",spaceId);
  355. }else{
  356. rBd.put("objTo",spaceId);
  357. }
  358. rBd.put("relCode",relCode);
  359. queryCriteria.setCriteria(rBd);
  360. relationService.doDelete( AdmContextUtil.toDmpContext(), queryCriteria);
  361. }
  362. }