Browse Source

系统接口 query-new 查询系统 包含不确定建筑/不确定楼层

lvxianyun 3 years ago
parent
commit
e1bd816d33
1 changed files with 185 additions and 141 deletions
  1. 185 141
      src/main/java/com/persagy/proxy/adm/controller/AdmSystemController.java

+ 185 - 141
src/main/java/com/persagy/proxy/adm/controller/AdmSystemController.java

@@ -2,9 +2,12 @@ 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.common.model.entity.BaseEntity;
 import com.persagy.dmp.define.client.DigitalDefineFacade;
@@ -12,6 +15,7 @@ import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.*;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
@@ -22,6 +26,7 @@ import com.persagy.proxy.adm.service.IAdmFloorService;
 import com.persagy.proxy.adm.service.IAdmSystemService;
 import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
 import com.persagy.proxy.adm.utils.ObjectNameUtil;
+import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -209,6 +214,9 @@ public class AdmSystemController {
      * 查询系统信息-系统建筑楼层一对多
      * MajorName 专业名称 ,级联查询 系统分类名(categoryNames),系统下的设备(equipmentList),系统下的竖井(shaftList),业务空间(zoneSpaceBaseTableList)
      *
+     * 明确建筑楼层的 adm级联 查询获取建筑楼层信息  使用正常接口 先查询楼层 再根据楼层信息拼接建筑
+     * 未明确建筑/未明确楼层 中台定制接口
+     *
      * 这个参见中心代码,
      * @param projectId
      * @param buildingId buildingId=1,未明确建筑
@@ -220,163 +228,199 @@ public class AdmSystemController {
     @PostMapping("/query-new")
     public AdmResponse queryNew(@QueryParam("projectId") String projectId, @QueryParam("buildingId") String buildingId,
                                 @QueryParam("floorId") String floorId, @RequestBody AdmQueryCriteria request) throws Exception {
-        if(StrUtil.isEmpty(projectId)){
+        if (StrUtil.isEmpty(projectId)) {
             return AdmResponse.failure("项目id为空");
         }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        if(StrUtil.isAllNotEmpty(buildingId, floorId) && !"1".equals(buildingId) && !"1".equals(floorId)){
-            //系统级联建筑 楼层
-            AdmResponse syses = service.doQuery(context, request, AdmSystem.class);
-            if(CollUtil.isEmpty(syses.getContent())){
-                return syses;
-            }
-            AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
-            admQueryCriteria.setName(AdmBuilding.OBJ_TYPE);
-            admQueryCriteria.setFilters("id = "+buildingId);
-            AdmResponse buildings = buildingService.doQuery(context, request, AdmBuilding.class);
-
-            admQueryCriteria = new AdmQueryCriteria();
-            admQueryCriteria.setName(AdmFloor.OBJ_TYPE);
-            admQueryCriteria.setFilters("id = "+floorId);
-            AdmResponse floors = floorService.doQuery(context, request, AdmFloor.class);
+        AdmResponse syses = new AdmResponse();
+
+        if(StrUtil.isAllEmpty(buildingId,floorId)){
+            //case one 查询全部系统,级联建筑,建筑级联楼层
+            AdmQueryCriteria admQueryCriteriaBd = new AdmQueryCriteria();
+            admQueryCriteriaBd.setName("buildingList");
+            List<AdmQueryCriteria> cascadeBd = new ArrayList<>(1);
+            AdmQueryCriteria admQueryCriteriaFl = new AdmQueryCriteria();
+            admQueryCriteriaFl.setName("floor");
+            cascadeBd.add(admQueryCriteriaFl);
+            admQueryCriteriaBd.setCascade(cascadeBd);
+
+            List<AdmQueryCriteria> cascade = new ArrayList<>(1);
+            cascade.add(admQueryCriteriaBd);
+            request.setCascade(cascade);
+            syses = service.doQuery(context,request,AdmSystem.class);
             //处理数据 BuildingFloorInfo
-            AdmBuildingFloorInfo buildingFloorInfo = new AdmBuildingFloorInfo();
-            if(CollUtil.isNotEmpty(floors.getContent())){
-                AdmFloor floor = (AdmFloor) floors.getContent().get(0);
-                buildingFloorInfo.setFloorName(floor.getLocalName());
-                buildingFloorInfo.setFloorID(floorId);
-            }
-            if(CollUtil.isNotEmpty(buildings.getContent())){
-                AdmBuilding building = (AdmBuilding) floors.getContent().get(0);
-                buildingFloorInfo.setBuildName(building.getLocalName());
-                buildingFloorInfo.setBuildID(buildingId);
-            }
-            List<AdmSystem> admSystemList = (List<AdmSystem>) syses.getContent();
-            admSystemList.stream().forEach( admSystem -> {
-                admSystem.setBuildingFloorInfoList(CollUtil.newArrayList(buildingFloorInfo));
-            });
-            syses.setContent(admSystemList);
-            return syses;
-        }
-
-
-
-        return null;
-       /*
-        QueryCriteria queryCriteria_sysInFl = new QueryCriteria();
-        ObjectNode criteria_sysInFl = JsonNodeFactory.instance.objectNode();
-        criteria_sysInFl.put("relCode","Sy2Fl");
-        criteria_sysInFl.put("graphCode", "MechInArch");
-
-        QueryCriteria queryCriteria_sysInBd = new QueryCriteria();
-        ObjectNode criteria_sysInBd= JsonNodeFactory.instance.objectNode();
-        criteria_sysInBd.put("graphCode", "MechInArch");
-        criteria_sysInBd.put("relCode","Sy2Bd");
-
-        QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
-        ObjectNode criteria_obj = JsonNodeFactory.instance.objectNode();
-        criteria_obj.put("objType", AdmSystem.OBJ_TYPE);
-
-        Set<String> sysIds = new HashSet<>();
-        List<ObjectRelation> relations_SysInFl = null;
-        if(StrUtil.isAllNotEmpty(buildingId,floorId)&&!floorId.equals("1")){
-            *//** 楼层id不为空且不为1,建筑id为空 ---> 系统和楼层关系表 取系统id  408 --> 明确建筑明确楼层->空间*//*
-            criteria_sysInFl.put("objTo", floorId);
-            queryCriteria_sysInFl.setCriteria(criteria_sysInFl);
-            relations_SysInFl = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInFl);
-            if(CollUtil.isNotEmpty(relations_SysInFl)){
-                sysIds = relations_SysInFl.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toSet());
+            if(CollUtil.isNotEmpty(syses.getContent())){
+                List<AdmSystem> admSystemList = (List<AdmSystem>) syses.getContent();
+                admSystemList.stream().forEach(admSystem -> {
+                    List<AdmBuildingFloorInfo> buildingFloorInfoList = new ArrayList<>();
+                    List<AdmBuilding> buildingList = admSystem.getBuildingList();
+                    if(CollUtil.isNotEmpty(buildingList)){
+                        buildingList.stream().forEach(admBuilding -> {
+                            List<AdmFloor> admFloorList = admBuilding.getFloor();
+                            if(CollUtil.isNotEmpty(admFloorList)){
+                                admFloorList.stream().forEach(floor -> {
+                                    AdmBuildingFloorInfo info = new AdmBuildingFloorInfo();
+                                    info.setBuildID(admBuilding.getId());
+                                    info.setBuildName(admBuilding.getLocalName());
+                                    info.setFloorID(floor.getId());
+                                    info.setFloorName(floor.getLocalName());
+                                    buildingFloorInfoList.add(info);
+                                });
+                            }else{
+                                AdmBuildingFloorInfo info = new AdmBuildingFloorInfo();
+                                info.setBuildID(admBuilding.getId());
+                                info.setBuildName(admBuilding.getLocalName());
+                                buildingFloorInfoList.add(info);
+                            }
+                        });
+                        admSystem.setBuildingFloorInfoList(buildingFloorInfoList);
+                        admSystem.setBuildingList(null);
+                    } else{
+                        admSystem.setBuildingFloorInfoList(buildingFloorInfoList);
+                    }
+                });
+                syses.setContent(admSystemList);
             }
-            ensureCondion(context, null, sysIds, criteria_obj,true);
-        }else if(StrUtil.isAllNotEmpty(buildingId,floorId)&&floorId.equals("1")&&!buildingId.equals("1")){
-            *//** 楼层id为空,建筑id不为空且不为1 ---> 系统和建筑关系表 取系统id  421*//*
-            // 明确建筑 未明确楼层
-            relations_SysInFl = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInFl);
-            if(CollUtil.isNotEmpty(relations_SysInFl)){
-                List<String> sysIds_floor = relations_SysInFl.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toList());
-                criteria_sysInBd.put("objTo", buildingId);
-                ArrayNode arrayNode = criteria_sysInBd.putObject("$notcontains").putArray("objFrom");
-                sysIds_floor.stream().forEach(id -> arrayNode.add(id));
-                queryCriteria_sysInBd.setCriteria(criteria_sysInBd);
-                ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,true);
+        }else{
+            QueryCriteria rwdQueryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(request);
+            ObjectNode criteria = rwdQueryCriteria.getCriteria();
+            if(JSONUtil.isNull(criteria)){
+                return AdmResponse.failure("请求参数错误");
             }
-        }else if(StrUtil.isEmpty(floorId) && StrUtil.isNotEmpty(buildingId) && buildingId.equals("1")){
-            *//** 楼层id为1,建筑id为1 ---> 系统id不在(系统和楼层关系表 取系统id  系统和建筑关系表 取系统id)之内 450*//*
-            //未明确建筑 没有Sy2Bd关系的系统
-            ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,false);
-        }else if(StrUtil.isEmpty(floorId) && StrUtil.isNotEmpty(buildingId) && !buildingId.equals("1")){
-            *//** 楼层id不为空,建筑id不为空 ---> 系统和楼层关系表 取系统id  将建筑id作为条件 461*//*
-            criteria_sysInBd.put("objTo", buildingId);
-            queryCriteria_sysInBd.setCriteria(criteria_sysInBd);
-            ensureCondion(context, queryCriteria_sysInBd, sysIds, criteria_obj,true);
-        } else if(StrUtil.isAllEmpty(floorId, buildingId)){
-            *//** 楼层id为空,建筑id为空 ---> 查询所有 *//*
-        }
-        queryCriteriaObj.setCriteria(criteria_obj);
-        List<ObjectNode> systems = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
-        if(CollUtil.isNotEmpty(systems)){
-            List<AdmSystem> admSystemList = JSONUtil.toList(systems.toString(), AdmSystem.class);
-            if(StrUtil.isNotEmpty(buildingId)){
-                if(!buildingId.equals("1")){
-                    //处理数据 添加每个系统关联的建筑楼层信息, 查看全部信息展示所在建筑
-                    //查询关联的建筑信息
-                    QueryCriteria queryCriteriaInfo = new QueryCriteria();
-                    ObjectNode criteria = JsonNodeFactory.instance.objectNode();
-                    ArrayNode arrayNode = criteria.putObject("id").putArray("$in");
-                    arrayNode.add(buildingId);
-                    if(StrUtil.isNotEmpty(floorId)){
-                        //明确的建筑,明确的楼层  查询建筑关联的楼层信息 如果Sy2Fl -> Sy2Bd & Bd2Fl
-                        if(!floorId.equals("1")){
-                            arrayNode.add(floorId);
-                        }
-                        queryCriteriaInfo.setCriteria(criteria);
-                        List<ObjectNode> objs = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaInfo);
-                        if(CollUtil.isNotEmpty(objs)){
-                            List<ObjectDigital> objectDigitals = JSONUtil.toList(objs.toString(), ObjectDigital.class);
-                            AdmBuildingFloorInfo admBuildingFloorInfo =  new AdmBuildingFloorInfo();
-                            objectDigitals.forEach(objectDigital -> {
-                                if(objectDigital.getObjType().equals(AdmFloor.OBJ_TYPE)){
-                                    admBuildingFloorInfo.setFloorID(objectDigital.getId());
-                                    admBuildingFloorInfo.setFloorName(objectDigital.getLocalName());
-                                }
-                                if(objectDigital.getObjType().equals(AdmBuilding.OBJ_TYPE)){
-                                    admBuildingFloorInfo.setBuildID(objectDigital.getId());
-                                    admBuildingFloorInfo.setBuildName(objectDigital.getLocalName());
-                                }
-                            });
-                            admSystemList.stream().forEach(admSystem -> admSystem.setBuildingFloorInfoList(CollUtil.newArrayList(admBuildingFloorInfo)));
-                        }
+            criteria.put("objType", AdmSystem.OBJ_TYPE);
+            List<AdmSystem> admSystemList = null;
+            if (StrUtil.isAllNotEmpty(buildingId, floorId)) {
+                if(!"1".equals(floorId)){
+                    //case two 明确建筑、明确楼层的 系统
+                    JSONObject relationFrom = new JSONObject();
+                    relationFrom.put("relCode", "Sy2Fl");
+                    relationFrom.put("graphCode", "MechInArch");
+                    relationFrom.put("objTo", floorId);
+                    criteria.putPOJO("relationFrom",relationFrom);
+                    rwdQueryCriteria.setCriteria(criteria);
+                    syses = service.doQuery(context, rwdQueryCriteria, AdmSystem.class);
+                    if (CollUtil.isNotEmpty(syses.getContent())) {
+                        admSystemList = (List<AdmSystem>) syses.getContent();
                     }
+
+                }else if("1".equals(floorId)){
+                    //case three 明确建筑 不明确楼层
+                    admSystemList = queryNotSureObj(buildingId, rwdQueryCriteria, context);
+                    //处理通用返回结果
+                    dealRespose(syses, request);
+                }
+                if(CollUtil.isNotEmpty(admSystemList)){
+                    //处理数据 BuildingFloorInfo
+                    admSystemList = dealBdFlInfo(floorId,buildingId,admSystemList,context);
+                    syses.setContent(admSystemList);
                 }
             }else{
-                //查询每个系统的建筑楼层信息
-                Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(admSystemList, BaseEntity.PROP_ID);
-                //查询
-                //查询楼层
+                //处理通用返回结果
+                dealRespose(syses, request);
+                if(StrUtil.isNotEmpty(buildingId) && buildingId.equals("1")){
+                    //case four 未明确建筑
+                    admSystemList = queryNotSureObj(null, rwdQueryCriteria, context);
+                    if(CollUtil.isNotEmpty(admSystemList)){
+                        //处理数据 BuildingFloorInfo
+                        admSystemList = dealBdFlInfo(null,null, admSystemList, context);
+                        syses.setContent(admSystemList);
+                    }
+                }
             }
-            return AdmResponse.success(systems);
+            if(CollUtil.isNotEmpty(admSystemList))
+                syses.setTotal(admSystemList.size()*1l);
+
+        }
+        return syses;
+    }
+
+    private void dealRespose(AdmResponse syses, AdmQueryCriteria request){
+        syses.setPageSize(request.getPageSize());
+        syses.setPageNumber(request.getPageNumber());
+        syses.setResult(DmpResult.SUCCESS);
+        syses.setTotal(0L);
+    }
+    /**
+     * 查询不确定建筑/楼层的系统
+     * @param buildingId
+     * @param rwdQueryCriteria
+     * @param context
+     * @return
+     */
+    private List<AdmSystem> queryNotSureObj(String buildingId, QueryCriteria rwdQueryCriteria, InstanceUrlParam context){
+        RequestData requestData = new RequestData();
+        String classCode = rwdQueryCriteria.getCriteria().get("classCode").textValue();
+        if(StrUtil.isNotEmpty(classCode)){
+            requestData.setClassCode(classCode);
+        }
+        if(StrUtil.isNotEmpty(buildingId)){
+            requestData.setBuildingId(buildingId);
+        }
+        requestData.setObjType(AdmSystem.OBJ_TYPE);
+        requestData.setPage(rwdQueryCriteria.getPage());
+        requestData.setSize(rwdQueryCriteria.getSize());
+        List result = DigitalObjectSimpleFacade.queryNotSureSystem(context.getGroupCode(), context.getProjectId(), context.getAppId(),null, requestData);
+        if(CollUtil.isNotEmpty(result)){
+           List<AdmSystem> admSystemList = JSONUtil.toList(result.toString(), AdmSystem.class);
+           return admSystemList;
         }else{
-            return AdmResponse.success();
-        }*/
+            return null;
+        }
     }
 
-    /*private void ensureCondion(InstanceUrlParam context, QueryCriteria queryCriteria_sysInBd, Set<String>sysIds, ObjectNode criteria_obj, boolean ifInCondition){
-        if(queryCriteria_sysInBd != null){
-            List<ObjectRelation> relations_SysInBd = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria_sysInBd);
-            if(CollUtil.isNotEmpty(relations_SysInBd)){
-                sysIds = relations_SysInBd.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toSet());
-            }
+    /**
+     * 处理建筑楼层信息 建筑确定,楼层可为空
+     * @param floorId
+     * @param buildingId
+     * @param admSystemList
+     * @param context
+     * @return
+     */
+    private List<AdmSystem> dealBdFlInfo(String floorId, String buildingId, List<AdmSystem> admSystemList, InstanceUrlParam context){
+        if(CollUtil.isEmpty(admSystemList)){
+            return null;
         }
-        if(CollUtil.isNotEmpty(sysIds)){
-            if(ifInCondition){
-                criteria_obj.put("id", sysIds.toArray().toString());
-            }else {
-                ArrayNode arrayNode = criteria_obj.putObject("$notcontains").putArray("id");
-                sysIds.stream().forEach(id -> arrayNode.add(id));
-            }
+        if(StrUtil.isEmpty(buildingId)){//处理成adm目标格式
+            List<AdmBuildingFloorInfo> nullList = new ArrayList<>(0);
+            admSystemList.stream().forEach(admSystem -> {
+                admSystem.setBuildingFloorInfoList(nullList);
+            });
+            return admSystemList;
+        }
+        AdmResponse buildings = null;
+        if(StrUtil.isNotEmpty(buildingId)){
+            AdmQueryCriteria admQueryCriteria = getAdmQueryCriteria(AdmBuilding.OBJ_TYPE, buildingId);
+            buildings = buildingService.doQuery(context, admQueryCriteria, AdmBuilding.class);
+        }
+        AdmResponse floors = null;
+        if(StrUtil.isNotEmpty(floorId)){
+            AdmQueryCriteria admQueryCriteria = getAdmQueryCriteria(AdmFloor.OBJ_TYPE, floorId);
+            floors = floorService.doQuery(context, admQueryCriteria, AdmFloor.class);
+        }
+        AdmBuildingFloorInfo buildingFloorInfo = new AdmBuildingFloorInfo();
+        if (CollUtil.isNotEmpty(buildings.getContent())) {
+            AdmBuilding building = (AdmBuilding) buildings.getContent().get(0);
+            buildingFloorInfo.setBuildName(building.getLocalName());
+            buildingFloorInfo.setBuildID(buildingId);
         }
-    }*/
+        if (null!=floors && CollUtil.isNotEmpty(floors.getContent())) {
+            AdmFloor floor = (AdmFloor) floors.getContent().get(0);
+            buildingFloorInfo.setFloorName(floor.getLocalName());
+            buildingFloorInfo.setFloorID(floorId);
+        }
+        admSystemList.stream().forEach(admSystem -> {
+            admSystem.setBuildingFloorInfoList(CollUtil.newArrayList(buildingFloorInfo));
+        });
+        return admSystemList;
+    }
+
+    private AdmQueryCriteria getAdmQueryCriteria(String objType, String Id){
+        AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
+        admQueryCriteria.setName(objType);
+        admQueryCriteria.setFilters("id = " + Id);
+        return  admQueryCriteria;
+    }
 
     /**
      * 查询系统信息-试图级联建筑楼层 暂未使用