AdmShaftController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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.ArrayNode;
  7. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  8. import com.fasterxml.jackson.databind.node.ObjectNode;
  9. import com.persagy.dmp.basic.dto.RequestData;
  10. import com.persagy.dmp.basic.model.QueryCriteria;
  11. import com.persagy.dmp.basic.utils.JsonNodeUtils;
  12. import com.persagy.dmp.common.model.entity.BaseEntity;
  13. import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
  14. import com.persagy.dmp.define.entity.ObjectInfoDefine;
  15. import com.persagy.dmp.digital.client.DigitalObjectFacade;
  16. import com.persagy.dmp.digital.client.DigitalRelationFacade;
  17. import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
  18. import com.persagy.proxy.adm.model.*;
  19. import com.persagy.proxy.adm.request.AdmCreateRequest;
  20. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  21. import com.persagy.proxy.adm.request.AdmResponse;
  22. import com.persagy.proxy.adm.service.IAdmBuildingService;
  23. import com.persagy.proxy.adm.service.IAdmRelationService;
  24. import com.persagy.proxy.adm.service.IAdmShaftService;
  25. import com.persagy.proxy.adm.utils.AdmContextUtil;
  26. import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
  27. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  28. import com.persagy.proxy.common.entity.RelationDTO;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.web.bind.annotation.*;
  31. import javax.ws.rs.QueryParam;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. /**
  35. * Adm 竖井 API
  36. * @author lvxy
  37. * @date 2021/8/16
  38. */
  39. @RestController
  40. @RequestMapping("/object/shaft")
  41. public class AdmShaftController {
  42. @Autowired
  43. private IAdmShaftService service;
  44. @Autowired
  45. private IAdmRelationService relationService;
  46. @Autowired
  47. private IAdmBuildingService buildingService;
  48. /**
  49. * 统计
  50. *
  51. * @param request
  52. * @return
  53. * @throws Exception
  54. */
  55. @PostMapping("/count")
  56. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  57. request.setName("shaft");
  58. request.setOnlyCount(true);
  59. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
  60. }
  61. /**
  62. * 创建
  63. * @param createRequest
  64. * @return
  65. * @throws Exception
  66. */
  67. @PostMapping("/create")
  68. public AdmResponse create(@RequestBody AdmCreateRequest<AdmShaft> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  69. List<AdmShaft> vos = CollUtil.newArrayList(createRequest.getContent());
  70. vos.stream().forEach(admShaft -> {
  71. if (StrUtil.isEmpty(admShaft.getName())) {
  72. admShaft.setName(ObjectNameUtil.objectName("竖井-"));
  73. }
  74. });
  75. vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmShaft.class, vos);
  76. //TODO 创建竖井和建筑的关系
  77. /*if (!entity.buildingList.isNullOrEmpty()){
  78. for (building in entity.buildingList!!) {
  79. try {
  80. val rShInBd = RShInBd()
  81. rShInBd.buildingId = building.id
  82. rShInBd.shaftId = entity.id
  83. rShInBd.projectId = entity.projectId
  84. rShInBd.type = "bd2sh"
  85. val insert = rShInBdService.insert(rShInBd)
  86. if (insert) {
  87. try {
  88. *//** 发送消息 *//*
  89. RService.rabbitMqService.sendRel(Opt.projectId!!, "sh2bd","11",rShInBd.buildingId!!,rShInBd.shaftId!!)
  90. } catch (e: Exception) {
  91. e.printStackTrace()
  92. }
  93. }
  94. } catch (e: Exception) {
  95. e.printStackTrace()
  96. }
  97. }
  98. }*/
  99. return AdmResponse.success(vos);
  100. }
  101. /**
  102. * 根据ID删除
  103. * @param vos
  104. * @return
  105. * @throws Exception
  106. */
  107. @PostMapping("/delete")
  108. public AdmResponse delete( @RequestBody List<AdmShaft> vos) throws Exception {
  109. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  110. return AdmResponse.success();
  111. }
  112. /**
  113. * 更新
  114. * @param createRequest
  115. * @return
  116. * @throws Exception
  117. */
  118. @PostMapping("/update")
  119. public AdmResponse update(@RequestBody AdmCreateRequest<AdmShaft> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  120. List<AdmShaft> vos = CollUtil.newArrayList(createRequest.getContent());
  121. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmShaft.class, vos);
  122. return AdmResponse.success(vos);
  123. }
  124. /**
  125. * 查询
  126. *
  127. * @param request
  128. * @return
  129. * @throws Exception
  130. */
  131. @PostMapping("/query")
  132. public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
  133. request.setName(AdmShaft.OBJ_TYPE);
  134. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
  135. }
  136. /**
  137. * 查询竖井信息-包含统计信息
  138. * 此方法可能会弃用
  139. *
  140. * 暂不实现
  141. *
  142. * @param request
  143. * @return
  144. * @throws Exception
  145. */
  146. @PostMapping("/query-with-count")
  147. public AdmResponse queryWithCount(@RequestBody AdmQueryCriteria request) throws Exception {
  148. request.setName("shaft");
  149. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmShaft.class);
  150. }
  151. /**
  152. * 查询关联元空间
  153. * 可能移至关系
  154. *
  155. * @param request
  156. * @return
  157. * @throws Exception
  158. */
  159. @PostMapping("/relate-space")
  160. public AdmResponse queryRelateSp(@RequestBody JSONObject request) throws Exception {
  161. //Sh2Sp
  162. // 先取消后重新建立
  163. if(JSONUtil.isNull(request)){
  164. return AdmResponse.failure("参数为空");
  165. }
  166. String shaftId = request.getString("shaftId");
  167. String spaceId = request.getString("spaceId");
  168. // 组装条件
  169. QueryCriteria criteria = new QueryCriteria();
  170. if(!StrUtil.isAllNotEmpty(shaftId,spaceId)) {
  171. return AdmResponse.failure("必填项:shaftId(竖井id)、spaceId(空间id)");
  172. }
  173. ObjectNode node = JsonNodeFactory.instance.objectNode();
  174. node.put("graphCode", "ArchSubset");
  175. node.put("relCode", "Sh2Sp");
  176. node.put("objFrom", shaftId);
  177. criteria.setCriteria(node);
  178. relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
  179. List<String> spaceIds = Arrays.asList(spaceId.split(","));
  180. Set<String> existsIds = spaceExists(spaceIds);
  181. List<String> failureList = null;
  182. if(CollUtil.isNotEmpty(existsIds)){
  183. failureList = spaceIds.stream().filter(isId -> !existsIds.contains(isId)).collect(Collectors.toList());
  184. List<RelationDTO> relationDTOS = new ArrayList<>();
  185. existsIds.stream().forEach(spId -> {
  186. RelationDTO relationDTO = new RelationDTO();
  187. relationDTO.setGraphCode("ArchSubset");
  188. relationDTO.setObjFrom(shaftId);
  189. relationDTO.setRelCode("Sh2Sp");
  190. relationDTO.setObjTo(spId);
  191. relationDTOS.add(relationDTO);
  192. });
  193. List<ObjectNode> nodeList = JsonNodeUtils.toListNode(relationDTOS, null, null);
  194. DigitalRelationFacade.create(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(), null, nodeList);
  195. }else{
  196. failureList = spaceIds;
  197. }
  198. if(CollUtil.isNotEmpty(failureList))
  199. return AdmResponse.failure("元空间 " +failureList.stream().collect(Collectors.joining(","))+ " 不存在");
  200. else
  201. return AdmResponse.success();
  202. }
  203. /**
  204. * 查询项目下已有的竖井类型
  205. * 此方法可能会弃用
  206. * {
  207. * "id":"shaftFuncType",
  208. * "name":"竖井功能"
  209. * }
  210. *
  211. * @return
  212. * @throws Exception
  213. */
  214. @PostMapping("/query-shaft-functype")
  215. public AdmResponse queryShFuncType() throws Exception {
  216. String projectId = AdmContextUtil.toDmpContext().getProjectId();
  217. if(StrUtil.isNotEmpty(projectId)){
  218. AdmResponse admResponse = AdmResponse.success();
  219. //查询参数请求查询的类型是否存在
  220. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  221. StringBuilder filters = new StringBuilder(" code = '");
  222. filters.append("shaftFuncType").append("';");
  223. filters.append(" classCode ='").append("shaft").append(" '");
  224. admQueryCriteria.setFilters(filters.toString());
  225. QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
  226. List<ObjectInfoDefine> defineList = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),null,dmpRequest);
  227. //是否有该类型的竖井信息
  228. if(CollUtil.isNotEmpty(defineList)){
  229. //查询中台项目实际使用该信息点的竖井
  230. RequestData requestData = new RequestData();
  231. requestData.setObjType(AdmShaft.OBJ_TYPE);
  232. requestData.setGroups(Arrays.asList("shaftFuncType"));
  233. List<Map<String, Object>> listInfos = DigitalObjectSimpleFacade.queryObjectCountByObjInfos(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getAppId(),null, requestData);
  234. if(CollUtil.isNotEmpty(listInfos)){
  235. ArrayNode datasource = defineList.get(0).getDataSource();
  236. List<HashMap> datasourceList = JSONUtil.toList(datasource.toString(), HashMap.class);
  237. Map<String, String> datasourceMap = new HashMap<>(datasourceList.size());
  238. for (HashMap map : datasourceList){
  239. datasourceMap.put(map.get("code").toString(),map.get("name").toString());
  240. }
  241. Map<String, Object> datasourceMapUsed = new HashMap<>(datasourceMap.size());
  242. listInfos.stream().forEach(map -> {
  243. if(!datasourceMapUsed.containsKey(map.get("shaftFuncType")) || datasourceMap.containsKey(map.get("shaftFuncType"))){
  244. JSONObject jsonObject = new JSONObject();
  245. jsonObject.put("id", map.get("shaftFuncType").toString());
  246. jsonObject.put("name", datasourceMap.get(map.get("shaftFuncType").toString()));
  247. datasourceMapUsed.put(map.get("shaftFuncType").toString(),jsonObject);
  248. }
  249. });
  250. if(CollUtil.isNotEmpty(datasourceMapUsed)){
  251. admResponse = AdmResponse.success(Arrays.asList(datasourceMapUsed.values()));
  252. }
  253. }
  254. }
  255. return admResponse;
  256. }else{
  257. return AdmResponse.failure("项目Id为空");
  258. }
  259. }
  260. /**
  261. * 查询和当前竖井有关联的业务空间
  262. * shaftId 为竖井id
  263. *
  264. * @param request
  265. * @return
  266. * @throws Exception
  267. */
  268. @PostMapping("/shaft-zoneSpaceBaseTable")
  269. public AdmResponse queryZoneSp(@RequestParam String shaftId,
  270. @RequestBody AdmQueryCriteria request) throws Exception {
  271. // 组装条件
  272. QueryCriteria queryCriteria = new QueryCriteria();
  273. if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
  274. return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
  275. }
  276. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  277. ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
  278. relationTO.put("relCode", "Sh2Sp");
  279. relationTO.put("objFrom", shaftId);
  280. criteria.putPOJO("relationTo", relationTO);
  281. criteria.put("objType", AdmSpace.OBJ_TYPE);
  282. queryCriteria.setCriteria(relationTO);
  283. List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
  284. if(CollUtil.isNotEmpty(spaceList)){
  285. List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
  286. return AdmResponse.success(spaceList);
  287. }else{
  288. return AdmResponse.success();
  289. }
  290. }
  291. /**
  292. * 查询和当前竖井有关联的业务空间所在建筑及楼层信息
  293. * shaftId 为竖井id
  294. *
  295. * @return
  296. * @throws Exception
  297. */
  298. @PostMapping("/shaft-zoneSpaceBaseTable-building")
  299. public AdmResponse queryZoneSpBd( @RequestParam String shaftId,
  300. @RequestParam String objectType) throws Exception {
  301. if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
  302. return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
  303. }
  304. // 组装条件 查询竖井下的空间
  305. AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
  306. admQueryCriteria.setName(AdmSpace.OBJ_TYPE);
  307. if(StrUtil.isNotEmpty(objectType)){
  308. admQueryCriteria.setFilters(" classCode = '"+objectType+"'");
  309. }
  310. //转化为中台的查询条件
  311. QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
  312. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  313. ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
  314. relationTO.put("relCode", "Sh2Sp");
  315. relationTO.put("objFrom", shaftId);
  316. criteria.putPOJO("relationTo", relationTO);
  317. criteria.put("objType", AdmSpace.OBJ_TYPE);
  318. queryCriteria.setCriteria(criteria);
  319. List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
  320. if(CollUtil.isNotEmpty(spaceList)){
  321. AdmQueryCriteria queryCriteriaBd = new AdmQueryCriteria();
  322. queryCriteriaBd.setName(AdmBuilding.OBJ_TYPE);
  323. queryCriteriaBd.setProjection(Arrays.asList("id","name","localName","floor"));
  324. //建筑级联楼层
  325. List<AdmQueryCriteria> cascade = new ArrayList<>(1);
  326. AdmQueryCriteria cascadeFloor = new AdmQueryCriteria();
  327. cascadeFloor.setName(AdmFloor.OBJ_TYPE);
  328. cascadeFloor.setProjection(Arrays.asList("id","name","localName"));
  329. cascade.add(cascadeFloor);
  330. cascadeFloor.setOrders("floorSequenceId desc");
  331. queryCriteriaBd.setCascade(cascade);
  332. List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
  333. Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(vos, "buildingId");
  334. StringBuilder filter = new StringBuilder(" id in ['");
  335. admSpaceMap.keySet().stream().forEach(spaceId -> filter.append(spaceId).append("','"));
  336. String filters = StrUtil.sub(filter.toString(), 0,-2)+"]";
  337. queryCriteriaBd.setFilters(filters);
  338. AdmResponse response = buildingService.doQuery(AdmContextUtil.toDmpContext(), queryCriteriaBd, AdmBuilding.class);
  339. return response;
  340. }else{
  341. return AdmResponse.success();
  342. }
  343. }
  344. /**
  345. * 查询和当前竖井没有关联的业务空间
  346. * shaftId 为竖井id
  347. *
  348. * @param request
  349. * @return
  350. * @throws Exception
  351. */
  352. @PostMapping("/un-shaft-zoneSpaceBaseTable")
  353. public AdmResponse queryUnZoneSp( @RequestParam String shaftId,
  354. @RequestBody AdmQueryCriteria request) throws Exception {
  355. // 组装条件
  356. QueryCriteria queryCriteria = new QueryCriteria();
  357. if(!StrUtil.isAllNotEmpty(shaftId,AdmContextUtil.toDmpContext().getProjectId())) {
  358. return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
  359. }
  360. ObjectNode criteria = JsonNodeFactory.instance.objectNode();
  361. ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
  362. ArrayNode arrayNode = relationTO.putObject("objFrom").putArray("$notcontains");
  363. arrayNode.add(shaftId);
  364. relationTO.put("relCode", "Sh2Sp");
  365. criteria.putPOJO("relationTo", relationTO);
  366. criteria.put("objType", "space");
  367. queryCriteria.setCriteria(relationTO);
  368. List<ObjectNode> spaceList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmContextUtil.toDmpContext().getAppId(), null, queryCriteria);
  369. if(CollUtil.isNotEmpty(spaceList)){
  370. List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
  371. return AdmResponse.success(spaceList);
  372. }else{
  373. return AdmResponse.success();
  374. }
  375. }
  376. /**
  377. * 元空间是否存在
  378. *
  379. * @param spaceIds failureList
  380. * @return 是否存在
  381. */
  382. private Set<String> spaceExists(List<String> spaceIds) {
  383. QueryCriteria queryCriteria = new QueryCriteria();
  384. ObjectNode node = JsonNodeFactory.instance.objectNode();
  385. ArrayNode arrayNode = node.putObject("id").putArray("$in");
  386. spaceIds.stream().forEach(spaceId -> arrayNode.add(spaceId));
  387. node.put("objType","ispace");
  388. queryCriteria.setCriteria(node);
  389. List<ObjectNode> ispaces = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmContextUtil.toDmpContext().getAppId(),AdmContextUtil.toDmpContext().getAppId(),queryCriteria);
  390. if(CollUtil.isNotEmpty(ispaces)){
  391. List<AdmISpace> iSpaceList = JSONUtil.toList(JSONUtil.parseArray(ispaces.toString()), AdmISpace.class);
  392. Map<String, AdmISpace> admISpaceMap = CollUtil.fieldValueMap(iSpaceList, BaseEntity.PROP_ID);
  393. return admISpaceMap.keySet();
  394. }else{
  395. return null;
  396. }
  397. }
  398. }