Browse Source

平面图查询设备bug修复

linhuili 3 years ago
parent
commit
9948a710f0

+ 61 - 5
src/main/java/com/persagy/proxy/dictionary/controller/AdmLabslController.java

@@ -1,13 +1,18 @@
 package com.persagy.proxy.dictionary.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.persagy.proxy.adm.request.AdmQueryCriteria;
+import com.persagy.proxy.object.model.AdmEquipment;
 import com.persagy.proxy.object.model.AdmObjectInfo;
 import com.persagy.proxy.dictionary.model.AdmObjectType;
 import com.persagy.proxy.adm.request.AdmResponse;
+import com.persagy.proxy.object.service.IAdmEquipmentService;
 import com.persagy.proxy.report.service.IAdmLabslService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -16,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.ws.rs.QueryParam;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -38,6 +44,9 @@ public class AdmLabslController {
     @Value("${middleware.group.code}")
     private String groupCode;
 
+    @Autowired
+    private IAdmEquipmentService iAdmEquipmentService;
+
     /**
      * 查询项目下的设备类型
      * @return
@@ -46,6 +55,9 @@ public class AdmLabslController {
     @PostMapping("/category")
     public AdmResponse queryCategory() throws Exception {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        if(StringUtils.isEmpty(context.getGroupCode())){
+            context.setGroupCode(groupCode);
+        }
         return service.queryCategory(context, AdmObjectInfo.class);
     }
 
@@ -58,6 +70,9 @@ public class AdmLabslController {
     @PostMapping("/zone/type")
     public AdmResponse queryZoneType() throws Exception {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        if(StringUtils.isEmpty(context.getGroupCode())){
+            context.setGroupCode(groupCode);
+        }
         return service.queryZoneType(context, AdmObjectInfo.class);
     }
 
@@ -69,21 +84,59 @@ public class AdmLabslController {
     @PostMapping("/building/floor")
     public AdmResponse queryBuildFloor(@QueryParam("projectId") String projectId) throws Exception {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        if(StringUtils.isEmpty(context.getGroupCode())){
+            context.setGroupCode(groupCode);
+        }
         return service.queryBuildFloor(context, AdmObjectInfo.class);
     }
 
 
+  /*  *//**
+     * 查询设备包含设备类型
+     * @return
+     * @throws Exception
+     *//*
+    @PostMapping("/query/equip")
+    public AdmResponse queryEquipType(@QueryParam("projectId") AdmQueryCriteria request) throws Exception {
+        InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        return iAdmEquipmentService.doQuery(context, AdmObjectInfo.class);
+    }*/
+
+
     /**
      * 查询设备包含设备类型
      * @return
      * @throws Exception
      */
     @PostMapping("/query/equip")
-    public AdmResponse queryEquipType(@QueryParam("projectId") String projectId) throws Exception {
+    public AdmResponse queryEquipType(@RequestBody AdmQueryCriteria request) throws Exception {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
-        return service.queryBuildFloor(context, AdmObjectInfo.class);
-    }
+        if(StringUtils.isEmpty(context.getGroupCode())){
+            context.setGroupCode(groupCode);
+        }
+        // 组装上下文条件
+        request.setName(AdmEquipment.OBJ_TYPE);
+        //过滤条件处理
+        String filters = request.getFilters();
 
+        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]);
+                }
+                newFilters.append(filter[i]);
+                if(i != filter.length -1){
+                    newFilters.append(" ; ");
+                }
+            }
+            request.setFilters(newFilters.toString());
+        }
+
+        return iAdmEquipmentService.doQuery(context, request, AdmEquipment.class);
+    }
 
     /**
      * 根据设备id统计设备所属的专业
@@ -94,12 +147,15 @@ public class AdmLabslController {
     public AdmResponse queryMajorCategory(@QueryParam("projectId") String projectId,
                                           @RequestBody List<String> ids) throws Exception {
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        if(StringUtils.isEmpty(context.getGroupCode())){
+            context.setGroupCode(groupCode);
+        }
         if(CollUtil.isEmpty(ids)){
-            return AdmResponse.failure("项目下没有设备类型");
+            return AdmResponse.success(new ArrayList<>());
         }
         List<String> newIds = ids.stream().filter(id->"fisnull".equals(id)).collect(Collectors.toList());
         if(CollUtil.isEmpty(newIds)){
-            return AdmResponse.failure("项目下没有设备类型");
+            return AdmResponse.success(new ArrayList<>());
         }
         return service.queryMajorCategory(context, newIds , AdmObjectType.class);
     }

+ 5 - 2
src/main/java/com/persagy/proxy/report/service/impl/AdmLabslServiceImpl.java

@@ -181,7 +181,9 @@ public class AdmLabslServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> im
         request.setFilters("id in ["+filters+"]");
         AdmResponse equipResponse = equipmentService.doQuery(context, request, AdmEquipment.class);
         if(CollUtil.isEmpty(equipResponse.getContent())){
-            throw new Exception("设备不存在");
+            log.info("设备不存在");
+            return AdmResponse.success(new ArrayList<>());
+
         }
         List<AdmEquipment> equipments = (List<AdmEquipment>)equipResponse.getContent();
         Set<String> classCodes = equipments.stream().map(k -> k.getClassCode()).collect(Collectors.toSet());
@@ -195,7 +197,8 @@ public class AdmLabslServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> im
         dictCriteria.setCriteria(node);
         AdmResponse dictResponse = doQueryObjectType(context, dictCriteria, clazz);
         if(CollUtil.isEmpty(dictResponse.getContent())){
-            throw new Exception("项目下没有设备类型");
+            log.info("项目下没有设备类型");
+            return AdmResponse.success(new ArrayList<>());
         }
 
         //获取设备类对应的专业编码