Browse Source

Merge remote-tracking branch 'origin/develop' into develop

lijie 3 years ago
parent
commit
40073e1d53

+ 149 - 11
src/main/java/com/persagy/proxy/dictionary/controller/AdmLabslController.java

@@ -1,8 +1,13 @@
 package com.persagy.proxy.dictionary.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 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 +27,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 +54,9 @@ public class AdmLabslController {
     @Autowired
     private IAdmEquipmentService iAdmEquipmentService;
 
+    @Autowired
+    private IAdmDictService admDictService;
+
     /**
      * 查询项目下的设备类型
      * @return
@@ -58,7 +68,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 +129,89 @@ 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<>();
+
+        AdmQueryCriteria specifal = new AdmQueryCriteria();
+        specifal = request;
+        specifal.setFilters(specailFilters.toString());
+
+        int totalCount = 0 ;
+        request.setFilters(newFilters.toString());
+        AdmResponse queryResponse = iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+        List<AdmEquipment> content = (List<AdmEquipment>)queryResponse.getContent();
+        if(queryResponse.getTotal() != null){
+            totalCount += queryResponse.getTotal().intValue();
+        }
+        if(specialQueryFlag){
+            //查询未明确建筑,未明确楼层
+            Long count = CollectionUtil.isEmpty(queryResponse.getContent()) ? 0 : Long.valueOf(queryResponse.getContent().size());
+            Integer pageSize = request.getPageSize();
+            if(count < pageSize){
+                long specailPageSize = pageSize - count;
+                specifal.setPageSize((int) specailPageSize);
+                AdmResponse specailQueryResponse = iAdmEquipmentService.doQuery(context, specifal, AdmEquipment.class);
+                specailContent = (List<AdmEquipment>)specailQueryResponse.getContent();
+                if(specailQueryResponse.getTotal() != null){
+                    totalCount += specailQueryResponse.getTotal().intValue();
                 }
+            }
+        }
+        if(CollUtil.isNotEmpty(content)){
+            result.addAll(content);
+        }
+        if(CollUtil.isNotEmpty(specailContent)){
+            result.addAll(specailContent);
+        }
+        AdmResponse response = AdmResponse.success(result);
+        response.setTotal(Long.valueOf(totalCount));
+        response.setCount(CollectionUtil.isEmpty(result) ? 0 : Long.valueOf(result.size()));
+        response.setPageNumber(request.getPageNumber());
+        response.setPageSize(request.getPageSize());
+        return response;
+    }
+
+    /**
+     * 处理查询条件
+     * @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 +236,66 @@ 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();
+                        }
+                    }
+                }
+            }
+            if(CollUtil.isEmpty(systemList)){
+                it.remove();
+            }
+
+        }
+        return AdmResponse.success(objectTypes);
+    }
 }

+ 10 - 2
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
@@ -115,7 +116,7 @@ public class AdmLabslServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> im
         List<AdmBuilding> admBuildings = new ArrayList<>();
         //添加未明确建筑
         AdmBuilding admBuilding = new AdmBuilding();
-        admBuilding.setId("fisnull");
+        admBuilding.setId("bisnull");
         admBuilding.setName("未明确建筑");
         admBuilding.setLocalName("未明确建筑");
         admBuildings.add(admBuilding);
@@ -150,10 +151,17 @@ public class AdmLabslServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> im
             admBuildings.addAll(buildContent);
         }
         for (AdmBuilding building : admBuildings) {
+            if("未明确建筑".equals(building.getName())){
+                continue;
+            }
+            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);
     }