|
@@ -0,0 +1,258 @@
|
|
|
+package com.persagy.proxy.adm.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.dmp.basic.dto.RequestData;
|
|
|
+import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
|
|
|
+import com.persagy.dmp.digital.entity.ObjectDigital;
|
|
|
+import com.persagy.dmp.digital.entity.ObjectRelation;
|
|
|
+import com.persagy.proxy.adm.constant.AdmCommonConstant;
|
|
|
+import com.persagy.proxy.adm.constant.enums.AdmDictCategoryEnum;
|
|
|
+import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
+import com.persagy.proxy.adm.service.IAdmRelationService;
|
|
|
+import com.persagy.proxy.common.client.DmpRwdClient;
|
|
|
+import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
+import com.persagy.proxy.common.entity.RelationDTO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+ * @description:024、关系-空间关系
|
|
|
+ * @author:lgy
|
|
|
+ * @data:2021/9/24 11:53
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/rel/sp-rel")
|
|
|
+public class RelationSpaceConnectionController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAdmRelationService service;
|
|
|
+ @Autowired
|
|
|
+ DmpRwdClient rwdClient;
|
|
|
+ @Value("${middleware.group.code}")
|
|
|
+ private String groupCode;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 创创建邻接关系
|
|
|
+ * 图类型 GraphType:空间邻接关系 SpaceNeighborhood 建筑交通关系 TrafficNetwork 空气流通关系 ConvectionNetwork 光照辐射关系 RadiationNetwork
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping(value = {"/space-neighborhood-Create"})
|
|
|
+ public AdmResponse spaceNeighborhood(@RequestParam("projectId") String projectId,
|
|
|
+ @RequestBody JSONObject param) throws Exception {
|
|
|
+ JSONArray contentList = param.getJSONArray("content");
|
|
|
+ for (int i = 0; i < contentList.size(); i++) {
|
|
|
+ JSONObject content = contentList.getJSONObject(i);
|
|
|
+ String spaceIdOne = content.getString("spaceIdOne");
|
|
|
+ String spaceIdTwo = content.getString("spaceIdTwo");
|
|
|
+ String graphType = content.getString("graphType");
|
|
|
+ String relType = content.getString("relType");
|
|
|
+ String zoneType = content.getString("zoneType");
|
|
|
+ if (!StrUtil.isAllNotEmpty(graphType, spaceIdTwo, spaceIdOne, relType)) {
|
|
|
+ return AdmResponse.failure("请检查数据的完整性");
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(zoneType)) {
|
|
|
+ QueryCriteria queryCriteria = new QueryCriteria();
|
|
|
+ ObjectNode criteria = JsonNodeFactory.instance.objectNode();
|
|
|
+ criteria.put("id", spaceIdOne);
|
|
|
+ queryCriteria.setCriteria(criteria);
|
|
|
+ List<ObjectNode> objectNodeList = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, null, queryCriteria);
|
|
|
+ if (CollUtil.isNotEmpty(objectNodeList)) {
|
|
|
+ String classCode = objectNodeList.get(0).get("classCode").asText();
|
|
|
+ content.put("zoneType", classCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
|
|
|
+ for (int i = 0; i < contentList.size(); i++) {
|
|
|
+ JSONObject content = contentList.getJSONObject(i);
|
|
|
+ String spaceIdOne = content.getString("spaceIdOne");
|
|
|
+ String spaceIdTwo = content.getString("spaceIdTwo");
|
|
|
+ String graphType = content.getString("graphType");
|
|
|
+ String relType = content.getString("relType");
|
|
|
+ String zoneType = content.getString("zoneType");
|
|
|
+ QueryCriteria queryRequest = new QueryCriteria();
|
|
|
+ ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
+ node.put("graphCode", graphType);
|
|
|
+ node.put("relCode", relType);
|
|
|
+ node.put("relValue", zoneType);
|
|
|
+ node.put("objFrom", spaceIdOne);
|
|
|
+ node.put("objTo", spaceIdTwo);
|
|
|
+ queryRequest.setCriteria(node);
|
|
|
+ service.doDelete(context, queryRequest);
|
|
|
+
|
|
|
+ List<RelationDTO> voList = new ArrayList<>();
|
|
|
+ voList.add(new RelationDTO(null, graphType, relType, zoneType, spaceIdOne, spaceIdTwo));
|
|
|
+ service.doSave(context, voList);
|
|
|
+ }
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询空间关系
|
|
|
+ * " 楼层id FloorId 图类型 GraphType:空间邻接关系 SpaceNeighborhood 建筑交通关系 TrafficNetwork 空气流通关系 ConvectionNetwork 光照辐射关系 RadiationNetwork ,边类型RelType
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return 创建的结果信息
|
|
|
+ */
|
|
|
+ @PostMapping("/space-neighborhood-query")
|
|
|
+ public AdmResponse spaceNeighborhoodQuery(@RequestParam("projectId") String projectId,
|
|
|
+ @RequestBody JSONObject param) throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ return AdmResponse.failure("不支持该接口");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 删除某一个关系
|
|
|
+ * 为了防止误删,边类型也改成了必填项
|
|
|
+ *
|
|
|
+ * @param paramList 对象
|
|
|
+ * @return 删除的结果信息
|
|
|
+ */
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public AdmResponse delete(@RequestParam String projectId,
|
|
|
+ @RequestBody JSONArray paramList) throws Exception {
|
|
|
+ if (CollUtil.isEmpty(paramList)) {
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < paramList.size(); i++) {
|
|
|
+ JSONObject param = paramList.getJSONObject(i);
|
|
|
+ String spaceIdOne = param.getString("spaceIdOne");
|
|
|
+ String spaceIdTwo = param.getString("spaceIdTwo");
|
|
|
+ String graphType = param.getString("graphType");
|
|
|
+ String relType = param.getString("relType");
|
|
|
+ String zoneType = param.getString("zoneType");
|
|
|
+ if (!StrUtil.isAllNotEmpty(spaceIdOne, spaceIdTwo, graphType, relType, zoneType)) {
|
|
|
+ return AdmResponse.failure("必填: SpaceIdOne、SpaceIdTwo、GraphType、ZoneType、relType");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
|
|
|
+ for (int i = 0; i < paramList.size(); i++) {
|
|
|
+ JSONObject param = paramList.getJSONObject(i);
|
|
|
+ String spaceIdOne = param.getString("spaceIdOne");
|
|
|
+ String spaceIdTwo = param.getString("spaceIdTwo");
|
|
|
+ String graphType = param.getString("graphType");
|
|
|
+ String relType = param.getString("relType");
|
|
|
+ String zoneType = param.getString("zoneType");
|
|
|
+ if (!StrUtil.isAllNotEmpty(spaceIdOne, spaceIdTwo, graphType, relType, zoneType)) {
|
|
|
+ return AdmResponse.failure("必填: SpaceIdOne、SpaceIdTwo、GraphType、ZoneType、relType");
|
|
|
+ }
|
|
|
+ QueryCriteria criteria = new QueryCriteria();
|
|
|
+ ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
+ node.put("graphCode", graphType);
|
|
|
+ node.put("relCode", relType);
|
|
|
+ node.put("relValue", zoneType);
|
|
|
+ node.put("objFrom", spaceIdOne);
|
|
|
+ node.put("objTo", spaceIdTwo);
|
|
|
+ criteria.setCriteria(node);
|
|
|
+ service.doDelete(context, criteria);
|
|
|
+
|
|
|
+ ObjectNode node2 = JsonNodeFactory.instance.objectNode();
|
|
|
+ node2.put("graphCode", graphType);
|
|
|
+ node2.put("relCode", relType);
|
|
|
+ node2.put("relValue", zoneType);
|
|
|
+ node2.put("objFrom", spaceIdTwo);
|
|
|
+ node2.put("objTo", spaceIdOne);
|
|
|
+ criteria.setCriteria(node2);
|
|
|
+ service.doDelete(context, criteria);
|
|
|
+ }
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 清除某个楼层下的数据
|
|
|
+ *
|
|
|
+ * @param param 竖井和业务空间的关系对象
|
|
|
+ * @return 创建的结果信息
|
|
|
+ */
|
|
|
+ @PostMapping("/delete-floor")
|
|
|
+ public AdmResponse createSpshs(@RequestParam("projectId") String projectId,
|
|
|
+ @RequestBody JSONObject param) throws Exception {
|
|
|
+ String graphType = param.getString("graphType");
|
|
|
+ String relType = param.getString("relType");
|
|
|
+ String zoneType = param.getString("zoneType");
|
|
|
+ String floorId = param.getString("floorId");
|
|
|
+ if (!StrUtil.isAllNotEmpty(graphType, relType, zoneType, floorId)) {
|
|
|
+ return AdmResponse.failure("必填 graphType、floorId、ZoneType、relType");
|
|
|
+ }
|
|
|
+ InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
|
|
|
+ RequestData requestData = RequestData.builder().classCode(zoneType).floorId(floorId).projectId(projectId).objType(AdmDictCategoryEnum.SPACE.getValue()).build();
|
|
|
+
|
|
|
+ List<ObjectDigital> objectDigitals = DigitalObjectFacade.queryObjectListSuperiorId(groupCode, projectId, AdmCommonConstant.APP_ID, null, requestData);
|
|
|
+
|
|
|
+ Set<String> spaceIdSet = objectDigitals.stream().map(ObjectDigital::getId).collect(Collectors.toSet());
|
|
|
+ HashMap<String, ObjectRelation> distinctMap = new HashMap<>(spaceIdSet.size());
|
|
|
+ for (String spaceId : spaceIdSet) {
|
|
|
+ QueryCriteria queryRequestTmp = new QueryCriteria();
|
|
|
+ ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
|
|
|
+ nodeTmp.put("graphCode", graphType);
|
|
|
+ nodeTmp.put("relCode", relType);
|
|
|
+ nodeTmp.put("relValue", zoneType);
|
|
|
+ nodeTmp.put("objFrom", spaceId);
|
|
|
+ queryRequestTmp.setCriteria(nodeTmp);
|
|
|
+
|
|
|
+ List<ObjectRelation> objectRelations = service.queryByCondition(context, queryRequestTmp);
|
|
|
+ for (ObjectRelation objectRelation : objectRelations) {
|
|
|
+ String key = StrUtil.format("{}_{}_{}_{}_{}", objectRelation.getGraphCode(), objectRelation.getRelCode(), objectRelation.getRelValue(), objectRelation.getObjFrom(), objectRelation.getObjTo());
|
|
|
+ distinctMap.put(key, objectRelation);
|
|
|
+ }
|
|
|
+ nodeTmp = JsonNodeFactory.instance.objectNode();
|
|
|
+ nodeTmp.put("graphCode", graphType);
|
|
|
+ nodeTmp.put("relCode", relType);
|
|
|
+ nodeTmp.put("relValue", zoneType);
|
|
|
+ nodeTmp.put("objTo",spaceId);
|
|
|
+ queryRequestTmp.setCriteria(nodeTmp);
|
|
|
+
|
|
|
+ objectRelations = service.queryByCondition(context, queryRequestTmp);
|
|
|
+ for (ObjectRelation objectRelation : objectRelations) {
|
|
|
+ String key = StrUtil.format("{}_{}_{}_{}_{}", objectRelation.getGraphCode(), objectRelation.getRelCode(), objectRelation.getRelValue(), objectRelation.getObjFrom(), objectRelation.getObjTo());
|
|
|
+ distinctMap.put(key, objectRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ObjectRelation objectRelation : distinctMap.values()) {
|
|
|
+ QueryCriteria queryRequest = new QueryCriteria();
|
|
|
+ ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
+ node.put("graphCode", objectRelation.getGraphCode());
|
|
|
+ node.put("relCode", objectRelation.getRelCode());
|
|
|
+ node.put("relValue", objectRelation.getRelValue());
|
|
|
+ node.put("objFrom", objectRelation.getObjFrom());
|
|
|
+ node.put("objTo", objectRelation.getObjTo());
|
|
|
+ queryRequest.setCriteria(node);
|
|
|
+ service.doDelete(context, queryRequest);
|
|
|
+ }
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|