lvxianyun il y a 3 ans
Parent
commit
75687f6d55

+ 233 - 21
src/main/java/com/persagy/proxy/adm/controller/AdmSystemController.java

@@ -1,20 +1,37 @@
 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.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.dmp.define.client.DigitalDefineFacade;
+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.ObjectDigital;
+import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
-import com.persagy.proxy.adm.model.AdmSystem;
+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.IAdmSystemService;
+import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
+import javax.json.JsonObject;
 import javax.validation.constraints.NotNull;
 import javax.ws.rs.QueryParam;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * Adm 系统 API
@@ -73,6 +90,25 @@ public class AdmSystemController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmSystem> vos = CollUtil.newArrayList(createRequest.getContent());
+
+        Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(vos, "classCode");
+
+        QueryCriteria defineCriteria = new QueryCriteria();
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        ArrayNode array = criteria.putObject("code").putArray("$in");
+        admSystemMap.keySet().stream().forEach(classCode -> array.add(classCode));
+        defineCriteria.setCriteria(criteria);
+        List<ObjectTypeDefine> defineList = DigitalDefineFacade.queryObjectType(context.getGroupCode(),context.getProjectId(),context.getAppId(),null,defineCriteria);
+        Map<String, ObjectTypeDefine> defineMap = CollUtil.fieldValueMap(defineList, "code");
+        vos.stream().forEach(admSystem -> {
+            if(StrUtil.isEmpty(admSystem.getName())){
+                if(CollUtil.isNotEmpty(defineList) && defineMap.containsKey(admSystem.getClassCode())){
+                    admSystem.setName(ObjectNameUtil.objectName(defineMap.get(admSystem.getClassCode()).getName()+"系统-"));
+                }else {
+                    admSystem.setName(ObjectNameUtil.objectName("系统-"));
+                }
+            }
+        });
         vos = service.doInsert(context, AdmSystem.class, vos);
         return AdmResponse.success(vos);
     }
@@ -130,12 +166,21 @@ public class AdmSystemController {
      * @throws Exception
      */
     @PostMapping("/link-equip")
-    public AdmResponse createRelateEquip(@RequestBody AdmCreateRequest<AdmSystem> createRequest, @QueryParam("projectId") String projectId) throws Exception {
+    public AdmResponse createRelateEquip(@RequestBody JsonObject createRequest, @QueryParam("projectId") String projectId) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        List<AdmSystem> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doInsert(context, AdmSystem.class, vos);
-        return AdmResponse.success(vos);
+        String sysId = createRequest.get("sysId").toString();
+        List<String> equipIdList = (List<String>)createRequest.get("equipIdList");
+        List<ObjectNode> relations = new ArrayList<>(equipIdList.size());
+        equipIdList.stream().forEach(euipId -> {
+            ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
+            objectNode.put("relCode", "Sy2Eq");
+            objectNode.put("graphCode","MechSubset");
+            objectNode.put("objFrom", sysId);
+            objectNode.put("objTo", euipId);
+        });
+        List<ObjectRelation> list = DigitalRelationFacade.create(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, relations);
+        return AdmResponse.success(list);
     }
 
     /**
@@ -158,7 +203,11 @@ public class AdmSystemController {
     /**
      * 查询系统信息-系统建筑楼层一对多
      * MajorName 专业名称 ,级联查询 系统分类名(categoryNames),系统下的设备(equipmentList),系统下的竖井(shaftList),业务空间(zoneSpaceBaseTableList)
+     *
+     * 这个参见中心代码,
      * @param projectId
+     * @param buildingId buildingId=1,未明确建筑
+     * @param floorId   floorId=1,未明确楼层
      * @param request
      * @return
      * @throws Exception
@@ -166,15 +215,127 @@ 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)){
+            return AdmResponse.failure("项目id为空");
+        }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName(AdmSystem.OBJ_TYPE);
-        return service.doQuery(context, request, AdmSystem.class);
+        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());
+            }
+            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 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)));
+                        }
+                    }
+                }
+            }else{
+                //查询每个系统的建筑楼层信息
+                Map<String, AdmSystem> admSystemMap = CollUtil.fieldValueMap(admSystemList, BaseEntity.PROP_ID);
+                //查询
+                //查询楼层
+            }
+            return AdmResponse.success(systems);
+        }else{
+            return AdmResponse.success();
+        }
     }
 
+    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());
+            }
+        }
+        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));
+            }
+        }
+    }
 
     /**
-     * 查询系统信息-试图级联建筑楼层
+     * 查询系统信息-试图级联建筑楼层 暂未使用
      * @param projectId
      * @param request
      * @return
@@ -198,12 +359,12 @@ public class AdmSystemController {
      * @throws Exception
      */
     @PostMapping("/un-sys-equip")
-    public AdmResponse queryUnEquip(@QueryParam("projectId") String projectId, @NotNull  @QueryParam("sysId") String sysId,
+    public AdmResponse queryUnEquip(@QueryParam("projectId") String projectId, @NotNull @QueryParam("sysId") String sysId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName(AdmSystem.OBJ_TYPE);
-        return service.doQuery(context, request, AdmSystem.class);
+        AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Eq","MechSubset", AdmEquipment.OBJ_TYPE);
+        return admResponse;
     }
 
 
@@ -216,12 +377,12 @@ public class AdmSystemController {
      * @throws Exception
      */
     @PostMapping("/un-sys-shaft")
-    public AdmResponse queryUnSh(@QueryParam("projectId") String projectId,
+    public AdmResponse queryUnSh(@QueryParam("projectId") String projectId, @NotNull @QueryParam("sysId") String sysId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName(AdmSystem.OBJ_TYPE);
-        return service.doQuery(context, request, AdmSystem.class);
+        AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Sh",null, AdmShaft.OBJ_TYPE);
+        return admResponse;
     }
 
 
@@ -234,12 +395,12 @@ public class AdmSystemController {
      * @throws Exception
      */
     @PostMapping("/un-sys-zoneSpaceBaseTable")
-    public AdmResponse queryUnZoneSp(@QueryParam("projectId") String projectId,
+    public AdmResponse queryUnZoneSp(@QueryParam("projectId") String projectId,@NotNull @QueryParam("sysId") String sysId,
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName(AdmSystem.OBJ_TYPE);
-        return service.doQuery(context, request, AdmSystem.class);
+        AdmResponse admResponse = queryObjectByType(context,sysId,request,"Sy2Sp",null, AdmSpace.OBJ_TYPE);
+        return admResponse;
     }
 
 
@@ -252,11 +413,62 @@ public class AdmSystemController {
      * @throws Exception
      */
     @PostMapping("/unspace-sys")
-    public AdmResponse queryUnSpSy(@QueryParam("projectId") String projectId,
+    public AdmResponse queryUnSpSy(@QueryParam("projectId") String projectId,  @QueryParam("type") String type, @QueryParam("spaceId") String spaceId,
                                      @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName(AdmSystem.OBJ_TYPE);
-        return service.doQuery(context, request, AdmSystem.class);
+        if(StrUtil.isNotEmpty(spaceId)){
+            AdmResponse admResponse = queryObjectByType(context, spaceId, request,"Sy2Sp",null, AdmSystem.OBJ_TYPE);
+            return admResponse;
+        }else{
+            if(StrUtil.isNotEmpty(type)){
+                QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
+                ObjectNode criteriaObj = JsonNodeFactory.instance.objectNode();
+                criteriaObj.put("objType", AdmSpace.OBJ_TYPE);
+                queryCriteriaObj.setCriteria(criteriaObj);
+                List<ObjectNode> objs = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
+
+                QueryCriteria queryCriteriaObjSys = AdmQueryCriteriaHelper.toDmpCriteria(request);
+                ObjectNode criteriaSys = JsonNodeFactory.instance.objectNode();
+                criteriaObj.put("objType", AdmSystem.OBJ_TYPE);
+                if(CollUtil.isNotEmpty(objs)){
+                    ArrayNode arrayNode = criteriaObj.putObject("id").putArray("$notcontains");
+                    for(ObjectNode objectNode: objs){
+                        arrayNode.add(objectNode.get("id").toString());
+                    }
+                }
+                queryCriteriaObj.setCriteria(criteriaObj);
+                List<ObjectNode> syses = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObjSys);
+                return AdmResponse.success(syses);
+            }
+            return AdmResponse.success();
+        }
+    }
+
+
+    private AdmResponse queryObjectByType(InstanceUrlParam context, String sysId, AdmQueryCriteria request, String relCode, String graphCode, String objType){
+        QueryCriteria queryCriteria = new QueryCriteria();
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        criteria.put("objFrom", sysId);
+        criteria.put("relCode", relCode);
+        if(StrUtil.isNotEmpty(graphCode)){
+            criteria.put("graphCode", graphCode);
+        }
+        queryCriteria.setCriteria(criteria);
+        queryCriteria.setSize(request.getPageSize()*1L);
+        queryCriteria.setPage(request.getPageNumber()*1L);
+        List<ObjectRelation> relations = DigitalRelationFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteria);
+
+        QueryCriteria queryCriteriaObj = AdmQueryCriteriaHelper.toDmpCriteria(request);
+        ObjectNode criteriaObj = JsonNodeFactory.instance.objectNode();
+        criteriaObj.put("objType", objType);
+        if(CollUtil.isNotEmpty(relations)){
+            Map<String, ObjectRelation> objectRelationMap = CollUtil.fieldValueMap(relations,BaseEntity.PROP_ID);
+            ArrayNode arrayNode = criteriaObj.putObject("id").putArray("$notcontains");
+            objectRelationMap.keySet().stream().forEach(id -> arrayNode.add(id));
+        }
+        queryCriteriaObj.setCriteria(criteriaObj);
+        List<ObjectNode> obj = DigitalObjectFacade.query(context.getGroupCode(),context.getProjectId(), context.getAppId(), null, queryCriteriaObj);
+        return AdmResponse.success(obj);
     }
 }