AdmSpaceController.java 15 KB

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