Browse Source

查询系统-设备类型树排序优化+未明确建筑、楼层查询有误问题修复

linhuili 3 years ago
parent
commit
30d5324a83

+ 9 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmBaseService.java

@@ -73,4 +73,13 @@ public interface IAdmBaseService<T> {
      * @return
      */
     List<T> doUpdateRelationProjectCal(InstanceUrlParam context, Class<T> clazz, List<T> voList);
+
+    /**
+     * 查询对象类型
+     * @param context
+     * @param request
+     * @param clazz
+     * @return
+     */
+    AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz);
 }

+ 31 - 0
src/main/java/com/persagy/proxy/adm/service/impl/AbstractAdmBaseServiceImpl.java

@@ -508,4 +508,35 @@ public class AbstractAdmBaseServiceImpl<T> implements IAdmBaseService<T> {
         return AdmEntityTransferUtil.toAdmMultiEntity(response.getData(), null, clazz);
     }
 
+
+    /**
+     * 查询对象类型
+     * @param request
+     * @return
+     */
+    @Override
+    public AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz) {
+        // 转换为数据中台查询条件
+        QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
+        //重置分页,查询所有
+        dmpRequest.setSize(null);
+        // 提供一个钩子方法用于处理已封装好的中台查询参数(因传参有buildingId而处理)
+        processDmpCriteria(dmpRequest);
+        // 转换参数
+        JSONObject para = null;
+        try {
+            para = JsonHelper.toJsonObject(dmpRequest);
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+            return AdmResponse.failure("参数格式有误");
+        }
+        log.info("request:{},dmpRequest:{}, dmp-param: {}", request.toString(), dmpRequest.toString(), para.toString());
+        // 调用中台查询
+        DmpResult<List<String>> dmpResult = rwdClient.queryObjectClassCode(context, para);
+        // 设置返回值
+        AdmResponse response = AdmResponse.success(dmpResult.getData());
+        Long total = dmpResult.getCount() == null ? null : dmpResult.getCount().longValue();
+        response.setTotal(total);
+        return response;
+    }
 }

+ 1 - 8
src/main/java/com/persagy/proxy/dictionary/service/IAdmDictBaseService.java

@@ -80,12 +80,5 @@ public interface IAdmDictBaseService<T>{
      */
     List<T> doSetObjectInfoCollect(InstanceUrlParam context, Class<T> clazz, List<T> voList);
 
-    /**
-     * 查询对象类型
-     * @param context
-     * @param request
-     * @param clazz
-     * @return
-     */
-    AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz);
+
 }

+ 0 - 27
src/main/java/com/persagy/proxy/dictionary/service/impl/AbstractAdmDictBaseServiceImpl.java

@@ -388,31 +388,4 @@ public class AbstractAdmDictBaseServiceImpl<T> implements IAdmDictBaseService<T>
         return AdmEntityTransferUtil.toAdmMultiEntity(response.getData(), null, clazz);
     }
 
-    /**
-     * 查询对象类型
-     * @param request
-     * @return
-     */
-    @Override
-    public AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz) {
-        // 转换为数据中台查询条件
-        QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
-        // 转换参数
-        JSONObject para = null;
-        try {
-            para = JsonHelper.toJsonObject(dmpRequest);
-        } catch (IOException e) {
-            log.error(e.getMessage(), e);
-            return AdmResponse.failure("参数格式有误");
-        }
-        log.info("request:{},dmpRequest:{}, dmp-param: {}", request.toString(), dmpRequest.toString(), para.toString());
-        // 调用中台查询
-        DmpResult<List<String>> dmpResult = rwdClient.queryObjectClassCode(context, para);
-        // 设置返回值
-        AdmResponse response = AdmResponse.success(dmpResult.getData());
-        Long total = dmpResult.getCount() == null ? null : dmpResult.getCount().longValue();
-        response.setTotal(total);
-        return response;
-    }
-
 }

+ 27 - 29
src/main/java/com/persagy/proxy/dictionary/service/impl/AdmDictServiceImpl.java

@@ -758,47 +758,45 @@ public class AdmDictServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> imp
     public AdmResponse querySystemEquipTree(InstanceUrlParam context, AdmDictQueryCriteria request, Class<T> clazz) throws Exception {
         //查询项目下已有的设备类型
         request.setName("equipment");
-        AdmResponse dictResponse = queryObjectClassCode(context, request, clazz);
+        AdmResponse dictResponse = equipmentService.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()));
-        //查询所有的对象类型
-        AdmResponse allDictResponse = doQueryObjectType(context, new QueryCriteria(), clazz);
-        List<AdmObjectType> objectTypes = (List<AdmObjectType>) allDictResponse.getContent();
-        Map<String, AdmObjectType> allObjTypeMap = objectTypes.stream().collect(Collectors.toMap(AdmObjectType::getCode, admObjectType -> admObjectType, (k1, k2) -> k1));
-        if(CollUtil.isEmpty(allObjTypeMap)){
+        //查询系统设备类树
+        AdmDict admDict = new AdmDict();
+        admDict.setType(AdmDictCategoryEnum.SYSTEM_EQUIP.getValue());
+        AdmResponse categoryResponse = queryCategory(context, admDict, clazz);
+        List<AdmObjectType> objectTypes = (List<AdmObjectType>) categoryResponse.getContent();
+        if(CollUtil.isEmpty(objectTypes)){
             return AdmResponse.success(new ArrayList<>());
         }
-        //结果集封装
-        List<AdmObjectType> admObjectTypeList = new ArrayList<>();
-        for (Map.Entry<String, List<String>> map : classCodeMap.entrySet()) {
-            String systemCode = map.getKey();
-            List<String> classCodeList = map.getValue();
-            if(CollUtil.isEmpty(classCodeList)){
-                continue;
-            }
-            //设置系统类型
-            AdmObjectType systemType = allObjTypeMap.get(systemCode);
-            if(systemType == null){
+        //过滤设备实体中不存在的类型
+        Iterator<AdmObjectType> it = objectTypes.iterator();
+        while(it.hasNext()){
+            //过滤系统
+            AdmObjectType objectType = it.next();
+            List<String> objTypes = classCodeMap.get(objectType.getCode());
+            if(CollUtil.isEmpty(objTypes)){
+               it.remove();
+               continue;
+            }
+            //过滤子级:设备类型
+            List<AdmObjectType> children = objectType.getChildren();
+            if(CollUtil.isEmpty(children)){
+                it.remove();
                 continue;
             }
-            //设置系统子级:设备类型
-            List<AdmObjectType> children = new ArrayList<>();
-            for (String classCode: classCodeList) {
-                AdmObjectType admObjectType = allObjTypeMap.get(classCode);
-                if(admObjectType!=null){
-                    children.add(admObjectType);
+            Iterator<AdmObjectType> chidIterator = children.iterator();
+            while (chidIterator.hasNext()){
+                AdmObjectType next = chidIterator.next();
+                if(!objTypes.contains(next.getCode())){
+                    chidIterator.remove();
                 }
             }
-            if(CollUtil.isEmpty(children)){
-                continue;
-            }
-            systemType.setChildren(children);
-            admObjectTypeList.add(systemType);
         }
-        return AdmResponse.success(admObjectTypeList);
+        return AdmResponse.success(objectTypes);
     }
 
 

+ 9 - 0
src/main/java/com/persagy/proxy/object/service/IAdmEquipmentService.java

@@ -59,4 +59,13 @@ public interface IAdmEquipmentService extends IAdmBaseService<AdmEquipment> {
      * Update By lijie 2021/10/29 11:42
      */
     AdmResponse query(AdmQueryCriteria admQueryCriteria);
+
+    /**
+     * 查询对象设备类型
+     * @param context
+     * @param request
+     * @param clazz
+     * @return
+     */
+    AdmResponse queryEquipClassCode(InstanceUrlParam context,AdmQueryCriteria request,Class<AdmEquipment> clazz);
 }

+ 12 - 0
src/main/java/com/persagy/proxy/object/service/impl/AdmEquipmentServiceImpl.java

@@ -342,4 +342,16 @@ public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquip
         }
         return isDealDataSucc;
     }
+
+    /**
+     * 查询对象设备类型
+     * @param context
+     * @param request
+     * @param clazz
+     * @return
+     */
+    @Override
+    public AdmResponse queryEquipClassCode(InstanceUrlParam context,AdmQueryCriteria request,Class<AdmEquipment> clazz){
+        return queryObjectClassCode(context,request,clazz);
+    }
 }