Browse Source

拓扑图相关bug修复

linhuili 3 years ago
parent
commit
995491ff5a

+ 126 - 12
src/main/java/com/persagy/proxy/dictionary/controller/AdmLabslController.java

@@ -2,7 +2,11 @@ package com.persagy.proxy.dictionary.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
+import com.persagy.proxy.adm.request.AdmDictQueryCriteria;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
+import com.persagy.proxy.dictionary.model.AdmDict;
+import com.persagy.proxy.dictionary.service.IAdmDictService;
 import com.persagy.proxy.object.model.AdmEquipment;
 import com.persagy.proxy.object.model.AdmObjectInfo;
 import com.persagy.proxy.dictionary.model.AdmObjectType;
@@ -22,7 +26,9 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.ws.rs.QueryParam;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -47,6 +53,9 @@ public class AdmLabslController {
     @Autowired
     private IAdmEquipmentService iAdmEquipmentService;
 
+    @Autowired
+    private IAdmDictService admDictService;
+
     /**
      * 查询项目下的设备类型
      * @return
@@ -58,7 +67,8 @@ public class AdmLabslController {
         if(StringUtils.isEmpty(context.getGroupCode())){
             context.setGroupCode(groupCode);
         }
-        return service.queryCategory(context, AdmObjectInfo.class);
+        return querySystemEquipTree(AdmContextUtil.toDmpContext(),AdmObjectType.class);
+        //return service.queryCategory(context, AdmObjectInfo.class);
     }
 
 
@@ -118,24 +128,69 @@ public class AdmLabslController {
         request.setName(AdmEquipment.OBJ_TYPE);
         //过滤条件处理
         String filters = request.getFilters();
-
+        Boolean specialQueryFlag = false;
         StringBuilder newFilters = new StringBuilder();
-        if(StringUtils.isNotEmpty(filters)){
-            String[] filter = filters.split(";");
-            for(int i =0 ;i< filter.length;i++){
-                if(filter[i].contains("not")){
-                    String[] param = filter[i].split(" ");
-                    filter[i] = StrUtil.format("{} $notcontains {}",param[1],param[3]);
-                }
+        StringBuilder specailFilters = new StringBuilder();
+        if(StringUtils.isEmpty(filters)){
+            return iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+        }
+        //处理查询条件
+        specialQueryFlag = handleRequestCriteria(filters, newFilters, specailFilters, specialQueryFlag);
+        List<AdmEquipment> result = new ArrayList<>();
+        List<AdmEquipment> specailContent = new ArrayList<>();
+        if(specialQueryFlag){
+            //查询未明确建筑,未明确楼层
+            AdmQueryCriteria specifal = new AdmQueryCriteria();
+            specifal = request;
+            specifal.setFilters(specailFilters.toString());
+            AdmResponse specailQueryResponse = iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+            specailContent = (List<AdmEquipment>)specailQueryResponse.getContent();
+        }
+        request.setFilters(newFilters.toString());
+        AdmResponse queryResponse = iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+        List<AdmEquipment> content = (List<AdmEquipment>)queryResponse.getContent();
+        if(CollUtil.isNotEmpty(content)){
+            result.addAll(content);
+        }
+        if(CollUtil.isNotEmpty(specailContent)){
+            result.addAll(specailContent);
+        }
+        return AdmResponse.success(result);
+    }
+
+    /**
+     * 处理查询条件
+     * @param filters
+     * @param newFilters
+     * @param specailFilters
+     * @param specialQueryFlag
+     */
+    private boolean handleRequestCriteria(String filters,StringBuilder newFilters,StringBuilder specailFilters,Boolean specialQueryFlag){
+        String[] filter = filters.split(";");
+        for(int i =0 ;i< filter.length;i++){
+            if(filter[i].contains("not")){
+                String[] param = filter[i].split(" ");
+                filter[i] = StrUtil.format("{} $notcontains {}",param[1],param[3]);
+            }
+            if(filter[i].contains(" in [") && filter[i].contains("]or")){
+                //针对未明确建筑,未明确楼层查询单独处理
+                String[] split = filter[i].split("]or");
+                newFilters.append(split[0]+"]");
+                specailFilters.append(split[1]);
+                //标记特殊查询标识
+                specialQueryFlag = true;
+                newFilters.append(" ; ");
+                specailFilters.append(" ; ");
+            }else{
                 newFilters.append(filter[i]);
+                specailFilters.append(filter[i]);
                 if(i != filter.length -1){
                     newFilters.append(" ; ");
+                    specailFilters.append(" ; ");
                 }
             }
-            request.setFilters(newFilters.toString());
         }
-
-        return iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+        return specialQueryFlag;
     }
 
     /**
@@ -160,4 +215,63 @@ public class AdmLabslController {
         return service.queryMajorCategory(context, newIds , AdmObjectType.class);
     }
 
+    /**
+     * 查询项目下已有的系统设备类型树
+     * @param context
+     * @param clazz
+     * @return
+     * @throws Exception
+     */
+    private <T> AdmResponse querySystemEquipTree(InstanceUrlParam context, Class<T> clazz) throws Exception {
+        AdmDictQueryCriteria request = new AdmDictQueryCriteria();
+        //查询项目下已有的设备类型
+        request.setName("equipment");
+        AdmResponse dictResponse = iAdmEquipmentService.queryEquipClassCode(context, request, AdmEquipment.class);
+        List<String> classCodes = (List<String>)dictResponse.getContent();
+        if(CollUtil.isEmpty(classCodes)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        Map<String, List<String>> classCodeMap = classCodes.stream().collect(Collectors.groupingBy(item->item.substring(0,4),Collectors.toList()));
+        //查询系统设备类树
+        AdmDict admDict = new AdmDict();
+        admDict.setType(AdmDictCategoryEnum.MAJOR_SYSTEM_EQUIP.getValue());
+        AdmResponse categoryResponse = admDictService.queryCategory(context, admDict, clazz);
+        List<AdmObjectType> objectTypes = (List<AdmObjectType>) categoryResponse.getContent();
+        if(CollUtil.isEmpty(objectTypes)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        //过滤设备实体中不存在的类型
+        Iterator<AdmObjectType> it = objectTypes.iterator();
+        while(it.hasNext()){
+            AdmObjectType major = it.next();
+            //过滤系统
+            List<AdmObjectType> systemList = major.getChildren();
+            if(CollUtil.isNotEmpty(systemList)){
+                Iterator<AdmObjectType> systemListIter = systemList.iterator();
+                while (systemListIter.hasNext()){
+                    AdmObjectType objectType = systemListIter.next();
+                    List<String> objTypes = classCodeMap.get(objectType.getCode());
+                    if(CollUtil.isEmpty(objTypes)){
+                        systemListIter.remove();
+                        continue;
+                    }
+                    //过滤子级:设备类型
+                    List<AdmObjectType> children = objectType.getChildren();
+                    if(CollUtil.isEmpty(children)){
+                        systemListIter.remove();
+                        continue;
+                    }
+                    Iterator<AdmObjectType> chidIterator = children.iterator();
+                    while (chidIterator.hasNext()){
+                        AdmObjectType next = chidIterator.next();
+                        if(!objTypes.contains(next.getCode())){
+                            chidIterator.remove();
+                        }
+                    }
+                }
+            }
+
+        }
+        return AdmResponse.success(objectTypes);
+    }
 }

+ 6 - 1
src/main/java/com/persagy/proxy/report/service/impl/AdmLabslServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @ClassName AdmLabslServiceImpl
@@ -150,10 +151,14 @@ public class AdmLabslServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> im
             admBuildings.addAll(buildContent);
         }
         for (AdmBuilding building : admBuildings) {
+            List<AdmFloor> floorList = new ArrayList<>();
+            floorList.add(admFloor);
             List<AdmFloor> floor = building.getFloor();
             if(CollUtil.isNotEmpty(floor)){
-                floor.add(admFloor);
+                List<AdmFloor> sortFloor = floor.stream().sorted(Comparator.comparing(AdmFloor::getFloorSequenceID).reversed()).collect(Collectors.toList());
+                floorList.addAll(sortFloor);
             }
+            building.setFloor(floorList);
         }
         return AdmResponse.success(admBuildings);
     }