AdmShaftController.java 20 KB

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