lvxianyun 3 лет назад
Родитель
Сommit
851c2503c1
1 измененных файлов с 277 добавлено и 35 удалено
  1. 277 35
      src/main/java/com/persagy/proxy/adm/controller/AdmShaftController.java

+ 277 - 35
src/main/java/com/persagy/proxy/adm/controller/AdmShaftController.java

@@ -1,22 +1,41 @@
 package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+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.basic.utils.JsonNodeUtils;
+import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
+import com.persagy.dmp.define.entity.ObjectInfoDefine;
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
+import com.persagy.dmp.digital.client.DigitalObjectSimpleFacade;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
-import com.persagy.proxy.adm.model.AdmShaft;
+import com.persagy.proxy.adm.model.*;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
+import com.persagy.proxy.adm.service.IAdmBuildingService;
+import com.persagy.proxy.adm.service.IAdmDictBaseService;
+import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.service.IAdmShaftService;
+import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
 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.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.ws.rs.QueryParam;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * Adm 竖井 API
@@ -29,6 +48,12 @@ import java.util.List;
 public class AdmShaftController {
     @Autowired
     private IAdmShaftService service;
+    @Autowired
+    private IAdmRelationService relationService;
+    @Autowired
+    private IAdmBuildingService buildingService;
+    @Autowired
+    private IAdmDictBaseService dictBaseService;
     @Value("${middleware.group.code}")
     private String groupCode;
 
@@ -61,7 +86,38 @@ public class AdmShaftController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmShaft> vos = CollUtil.newArrayList(createRequest.getContent());
+        vos.stream().forEach(admShaft -> {
+            if (StrUtil.isEmpty(admShaft.getName())) {
+                admShaft.setName(ObjectNameUtil.objectName("竖井-"));
+            }
+        });
         vos = service.doInsert(context, AdmShaft.class, vos);
+
+        //TODO 创建竖井和建筑的关系
+        /*if (!entity.buildingList.isNullOrEmpty()){
+            for (building in entity.buildingList!!) {
+                try {
+                    val rShInBd = RShInBd()
+                    rShInBd.buildingId = building.id
+                    rShInBd.shaftId = entity.id
+                    rShInBd.projectId = entity.projectId
+                    rShInBd.type = "bd2sh"
+                    val insert = rShInBdService.insert(rShInBd)
+                    if (insert) {
+                        try {
+                            *//** 发送消息 *//*
+                            RService.rabbitMqService.sendRel(Opt.projectId!!, "sh2bd","11",rShInBd.buildingId!!,rShInBd.shaftId!!)
+                        } catch (e: Exception) {
+                            e.printStackTrace()
+                        }
+                    }
+                } catch (e: Exception) {
+                    e.printStackTrace()
+                }
+            }
+        }*/
+
+
         return AdmResponse.success(vos);
     }
 
@@ -111,15 +167,17 @@ public class AdmShaftController {
     }
 
     /**
-     * 查询项目下已有的竖井类型
+     * 查询竖井信息-包含统计信息
      * 此方法可能会弃用
+     *
+     * 暂不实现
      * @param projectId
      * @param request
      * @return
      * @throws Exception
      */
-    @PostMapping("/query-shaft-functype")
-    public AdmResponse queryShFuncType(@QueryParam("projectId") String projectId,
+    @PostMapping("/query-with-count")
+    public AdmResponse queryWithCount(@QueryParam("projectId") String projectId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
@@ -128,37 +186,118 @@ public class AdmShaftController {
     }
 
     /**
-     * 查询竖井信息-包含统计信息
-     * 此方法可能会弃用
+     * 查询关联元空间
+     * 可能移至关系
      * @param projectId
      * @param request
      * @return
      * @throws Exception
      */
-    @PostMapping("/query-with-count")
-    public AdmResponse queryWithCount(@QueryParam("projectId") String projectId,
-                             @RequestBody AdmQueryCriteria request) throws Exception {
+    @PostMapping("/relate-space")
+    public AdmResponse queryRelateSp(@QueryParam("projectId") String projectId,
+                             @RequestBody JSONObject request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("shaft");
-        return service.doQuery(context, request, AdmShaft.class);
+        //Sh2Sp
+        // 先取消后重新建立
+        if(JSONUtil.isNull(request)){
+            return AdmResponse.failure("参数为空");
+        }
+        String shaftId = request.getString("shaftId");
+        String spaceId = request.getString("spaceId");
+        // 组装条件
+        QueryCriteria criteria = new QueryCriteria();
+        if(!StrUtil.isAllNotEmpty(shaftId,spaceId)) {
+            return AdmResponse.failure("必填项:shaftId(竖井id)、spaceId(空间id)");
+        }
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        node.put("graphCode", "ArchSubset");
+        node.put("relCode", "Sh2Sp");
+        node.put("objFrom", shaftId);
+        criteria.setCriteria(node);
+        relationService.doDelete(context, criteria);
+
+        List<String> spaceIds = Arrays.asList(spaceId.split(","));
+        Set<String> existsIds = spaceExists(context, spaceIds);
+        List<String> failureList = null;
+        if(CollUtil.isNotEmpty(existsIds)){
+            failureList = spaceIds.stream().filter(isId -> !existsIds.contains(isId)).collect(Collectors.toList());
+            List<RelationDTO> relationDTOS = new ArrayList<>();
+            existsIds.stream().forEach(spId -> {
+                RelationDTO relationDTO = new RelationDTO();
+                relationDTO.setGraphCode("ArchSubset");
+                relationDTO.setObjFrom(shaftId);
+                relationDTO.setRelCode("Sh2Sp");
+                relationDTO.setObjTo(spId);
+                relationDTOS.add(relationDTO);
+            });
+            List<ObjectNode> nodeList = JsonNodeUtils.toListNode(relationDTOS, null, null);
+            DigitalRelationFacade.create(context.getGroupCode(), context.getProjectId(),context.getAppId(), null, nodeList);
+        }else{
+            failureList = spaceIds;
+        }
+
+        if(CollUtil.isNotEmpty(failureList))
+            return AdmResponse.failure("元空间 " +failureList.stream().collect(Collectors.joining(","))+ " 不存在");
+        else
+            return AdmResponse.success();
     }
 
     /**
-     * 查询关联元空间
-     * 可能移至关系
+     * 查询项目下已有的竖井类型
+     * 此方法可能会弃用
+     * {
+     *     "id":"shaftFuncType",
+     *     "name":"竖井功能"
+     * }
      * @param projectId
-     * @param request
      * @return
      * @throws Exception
      */
-    @PostMapping("/relate-space")
-    public AdmResponse queryRelateSp(@QueryParam("projectId") String projectId,
-                             @RequestBody AdmQueryCriteria request) throws Exception {
+    @PostMapping("/query-shaft-functype")
+    public AdmResponse queryShFuncType(@QueryParam("projectId") String projectId) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("shaft");
-        return service.doQuery(context, request, AdmShaft.class);
+        if(StrUtil.isNotEmpty(projectId)){
+            AdmResponse admResponse = AdmResponse.success();
+            //查询参数请求查询的类型是否存在
+            AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
+            StringBuilder filters = new StringBuilder(" code = '");
+            filters.append("shaftFuncType").append("';");
+            filters.append(" classCode ='").append("shaft").append(" '");
+            admQueryCriteria.setFilters(filters.toString());
+            QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
+            List<ObjectInfoDefine> defineList = DigitalObjectInfoFacade.query(context.getGroupCode(),context.getProjectId(),context.getAppId(),null,dmpRequest);
+            //是否有该类型的竖井信息
+            if(CollUtil.isNotEmpty(defineList)){
+                //查询中台项目实际使用该信息点的竖井
+                RequestData requestData = new RequestData();
+                requestData.setObjType(AdmShaft.OBJ_TYPE);
+                requestData.setGroups(Arrays.asList("shaftFuncType"));
+                List<Map<String, Object>> listInfos = DigitalObjectSimpleFacade.queryObjectCountByObjInfos(context.getGroupCode(),context.getAppId(),null, requestData);
+
+                if(CollUtil.isNotEmpty(listInfos)){
+                    ArrayNode datasource = defineList.get(0).getDataSource();
+                    List<HashMap> datasourceList = JSONUtil.toList(datasource.toString(), HashMap.class);
+                    Map<String, String> datasourceMap = new HashMap<>(datasourceList.size());
+                    for (HashMap map : datasourceList){
+                        datasourceMap.put(map.get("code").toString(),map.get("name").toString());
+                    }
+                    Map<String, String> datasourceMapUsed = new HashMap<>(datasourceMap.size());
+                    listInfos.stream().forEach(map -> {
+                        if(!datasourceMapUsed.containsKey(map.get("shaftFuncType")) || datasourceMap.containsKey(map.get("shaftFuncType"))){
+                            datasourceMapUsed.put(map.get("shaftFuncType").toString(),datasourceMap.get(map.get("shaftFuncType").toString()));
+                        }
+                    });
+                    if(CollUtil.isNotEmpty(datasourceMapUsed)){
+                        admResponse = AdmResponse.success(Arrays.asList(datasourceMapUsed.entrySet().toArray()));
+                    }
+                }
+            }
+            return admResponse;
+        }else{
+            return AdmResponse.failure("项目Id为空");
+        }
     }
 
     /**
@@ -170,29 +309,89 @@ public class AdmShaftController {
      * @throws Exception
      */
     @PostMapping("/shaft-zoneSpaceBaseTable")
-    public AdmResponse queryZoneSp(@QueryParam("projectId") String projectId,
+    public AdmResponse queryZoneSp(@QueryParam("projectId") String projectId, @RequestParam String shaftId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("shaft");
-        return service.doQuery(context, request, AdmShaft.class);
+        // 组装条件
+        QueryCriteria queryCriteria = new QueryCriteria();
+        if(!StrUtil.isAllNotEmpty(shaftId,projectId)) {
+            return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
+        }
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
+        relationTO.put("relCode", "Sh2Sp");
+        relationTO.put("objFrom", shaftId);
+        criteria.putPOJO("relationTo", relationTO);
+        criteria.put("objType", AdmSpace.OBJ_TYPE);
+        queryCriteria.setCriteria(relationTO);
+
+        List<ObjectNode> spaceList = DigitalObjectFacade.query(context.getGroupCode(), context.getProjectId(), context.getAppId(), null, queryCriteria);
+        if(CollUtil.isNotEmpty(spaceList)){
+            List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
+            return AdmResponse.success(spaceList);
+        }else{
+            return AdmResponse.success();
+        }
     }
 
     /**
      * 查询和当前竖井有关联的业务空间所在建筑及楼层信息
      * shaftId 为竖井id
      * @param projectId
-     * @param request
      * @return
      * @throws Exception
      */
     @PostMapping("/shaft-zoneSpaceBaseTable-building")
-    public AdmResponse queryZoneSpBd(@QueryParam("projectId") String projectId,
-                             @RequestBody AdmQueryCriteria request) throws Exception {
+    public AdmResponse queryZoneSpBd(@QueryParam("projectId") String projectId, @RequestParam String shaftId,
+             @RequestParam String objectType) throws Exception {
+        if(!StrUtil.isAllNotEmpty(shaftId,projectId)) {
+            return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
+        }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("shaft");
-        return service.doQuery(context, request, AdmShaft.class);
+        // 组装条件 查询竖井下的空间
+        AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
+        admQueryCriteria.setName(AdmSpace.OBJ_TYPE);
+        if(StrUtil.isNotEmpty(objectType)){
+            admQueryCriteria.setFilters(" classCode = '"+objectType+"'");
+        }
+        //转化为中台的查询条件
+        QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteria);
+
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
+        relationTO.put("relCode", "Sh2Sp");
+        relationTO.put("objFrom", shaftId);
+        criteria.putPOJO("relationTo", relationTO);
+        criteria.put("objType", AdmSpace.OBJ_TYPE);
+        queryCriteria.setCriteria(criteria);
+
+        List<ObjectNode> spaceList = DigitalObjectFacade.query(context.getGroupCode(), context.getProjectId(), context.getAppId(), null, queryCriteria);
+        if(CollUtil.isNotEmpty(spaceList)){
+            AdmQueryCriteria queryCriteriaBd = new AdmQueryCriteria();
+            queryCriteriaBd.setName(AdmBuilding.OBJ_TYPE);
+            queryCriteriaBd.setProjection(Arrays.asList("id","name","localName","floor"));
+            //建筑级联楼层
+            List<AdmQueryCriteria> cascade = new ArrayList<>(1);
+            AdmQueryCriteria cascadeFloor = new AdmQueryCriteria();
+            cascadeFloor.setName(AdmFloor.OBJ_TYPE);
+            cascadeFloor.setProjection(Arrays.asList("id","name","localName"));
+            cascade.add(cascadeFloor);
+            cascadeFloor.setOrders("floorSequenceId desc");
+            queryCriteriaBd.setCascade(cascade);
+
+            List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
+            Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(vos, "buildingId");
+            StringBuilder filter = new StringBuilder(" id in ['");
+            admSpaceMap.keySet().stream().forEach(spaceId -> filter.append(spaceId).append("','"));
+            String filters = StrUtil.sub(filter.toString(), 0,-2)+"]";
+            queryCriteriaBd.setFilters(filters);
+            AdmResponse response =  buildingService.doQuery(context, queryCriteriaBd, AdmBuilding.class);
+            return response;
+        }else{
+            return AdmResponse.success();
+        }
     }
 
     /**
@@ -204,11 +403,54 @@ public class AdmShaftController {
      * @throws Exception
      */
     @PostMapping("/un-shaft-zoneSpaceBaseTable")
-    public AdmResponse queryUnZoneSp(@QueryParam("projectId") String projectId,
+    public AdmResponse queryUnZoneSp(@QueryParam("projectId") String projectId, @RequestParam String shaftId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("shaft");
-        return service.doQuery(context, request, AdmShaft.class);
+        // 组装条件
+        QueryCriteria queryCriteria = new QueryCriteria();
+        if(!StrUtil.isAllNotEmpty(shaftId,projectId)) {
+            return AdmResponse.failure("必填项:shaftId(竖井id)、projectId(项目id)");
+        }
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
+        ArrayNode arrayNode = relationTO.putObject("objFrom").putArray("$notcontains");
+        arrayNode.add(shaftId);
+        relationTO.put("relCode", "Sh2Sp");
+        criteria.putPOJO("relationTo", relationTO);
+
+        criteria.put("objType", "space");
+        queryCriteria.setCriteria(relationTO);
+        List<ObjectNode> spaceList = DigitalObjectFacade.query(context.getGroupCode(), context.getProjectId(), context.getAppId(), null, queryCriteria);
+        if(CollUtil.isNotEmpty(spaceList)){
+            List<AdmSpace> vos = JSONUtil.toList(spaceList.toString(), AdmSpace.class);
+            return AdmResponse.success(spaceList);
+        }else{
+            return AdmResponse.success();
+        }
+    }
+
+    /**
+     * 元空间是否存在
+     *
+     * @param       spaceIds       failureList
+     * @return      是否存在
+     */
+    private Set<String> spaceExists(InstanceUrlParam context, List<String> spaceIds) {
+        QueryCriteria queryCriteria = new QueryCriteria();
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+        ArrayNode arrayNode = node.putObject("id").putArray("$in");
+        spaceIds.stream().forEach(spaceId -> arrayNode.add(spaceId));
+        node.put("objType","ispace");
+        queryCriteria.setCriteria(node);
+        List<ObjectNode> ispaces = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(),context.getAppId(),context.getAppId(),queryCriteria);
+        if(CollUtil.isNotEmpty(ispaces)){
+            List<AdmISpace> iSpaceList = JSONUtil.toList(JSONUtil.parseArray(ispaces.toString()), AdmISpace.class);
+            Map<String, AdmISpace> admISpaceMap = CollUtil.fieldValueMap(iSpaceList, BaseEntity.PROP_ID);
+            return admISpaceMap.keySet();
+        }else{
+            return null;
+        }
     }
+
 }