Przeglądaj źródła

修复 获取测报灯列表接口获取图片数量不正确的问题

zhaiyifei 1 rok temu
rodzic
commit
e924d5c285

+ 69 - 25
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotDeviceCbdController.java

@@ -18,7 +18,6 @@ import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotCbddata;
 import com.yunfeiyun.agmp.iot.common.domain.IotCbdimg;
-import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
 import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotCbdConfigEditReqVo;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
@@ -27,6 +26,7 @@ import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListResVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceRefreshService;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdimgCountResVo;
 import com.yunfeiyun.agmp.iotm.device.pest.service.IotCbdService;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
@@ -34,6 +34,11 @@ import com.yunfeiyun.agmp.iotm.web.service.IIotCmdtaskService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.aggregation.Aggregation;
+import org.springframework.data.mongodb.core.aggregation.GroupOperation;
+import org.springframework.data.mongodb.core.aggregation.MatchOperation;
+import org.springframework.data.mongodb.core.aggregation.ProjectionOperation;
+import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -79,11 +84,13 @@ public class IotDeviceCbdController extends BaseController {
      * @param reqVo
      * @return
      */
-    @GetMapping({"/gk/list", "/sd/list", "/pt/list"})
+    @GetMapping({"/list", "/gk/list", "/sd/list", "/pt/list"})
     public TableDataInfo list(HttpServletRequest request, IotDeviceListReqVo reqVo) {
-        startPage();
         String reqUri = request.getRequestURI();
-        String[] devTypeList = null;
+        log.info("【{}】【测报灯】【列表】客户id {}", LogCore.getSeq(), getCustomerId());
+        String[] devTypeList = new String[]{
+                IotDeviceDictConst.TYPE_YF_GKCBD, IotDeviceDictConst.TYPE_YF_SDCBD, IotDeviceDictConst.TYPE_YF_CBD
+        };
         if(reqUri.endsWith("/gk/list")){
             devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_GKCBD};
         }else if(reqUri.endsWith("/sd/list")){
@@ -91,11 +98,48 @@ public class IotDeviceCbdController extends BaseController {
         }else if(reqUri.endsWith("/pt/list")){
             devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_CBD};
         }
-        List<IotDeviceListResVo> list = new ArrayList<>();
-        if(devTypeList != null){
-            reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
-            list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
+
+        startPage();
+        List<IotDeviceListResVo> list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        List<String> devBidList = new ArrayList<>();
+        if(!list.isEmpty()){
+            for(IotDeviceListResVo resVo : list){
+                devBidList.add(resVo.getDevBid());
+            }
         }
+
+        if(!devBidList.isEmpty()) {
+            Criteria criteria = new Criteria()
+                    .and("devBid").in(devBidList)
+                    .and("cbdimgDelstatus").is("0");
+            MatchOperation matchOperation = Aggregation.match(criteria);
+            GroupOperation groupOperation = Aggregation.group("devBid").count().as("imgCount");
+
+            ProjectionOperation projectionOperationResult = Aggregation.project()
+                    .and("_id").as("devBid")
+                    .and("imgCount").as("imgCount");
+            Aggregation aggregation = Aggregation.newAggregation(
+                    matchOperation,
+                    groupOperation,
+                    projectionOperationResult
+            );
+            List<IotCbdimgCountResVo> iotCbdimgCountResVoList = mongoService.aggregate(
+                    IotCbdimg.class, aggregation, IotCbdimgCountResVo.class
+            );
+
+            Map<String, Long> imgCountMap = new HashMap<>();
+            for (IotCbdimgCountResVo iotCbdimgCountResVo : iotCbdimgCountResVoList) {
+                String devBid = iotCbdimgCountResVo.getDevBid();
+                imgCountMap.put(devBid, (long) iotCbdimgCountResVo.getImgCount());
+            }
+            for (IotDeviceListResVo resVo : list) {
+                //查询图片数量
+                String devBid = resVo.getDevBid();
+                resVo.setImgCount(imgCountMap.getOrDefault(devBid, 0L));
+            }
+        }
+
         return getDataTable(list);
     }
 
@@ -217,23 +261,23 @@ public class IotDeviceCbdController extends BaseController {
      * @param reqVo
      * @return
      */
-    @GetMapping("/list")
-    public TableDataInfo list(IotDeviceListReqVo reqVo) {
-        startPage();
-        TosDevicetype tosDevicetype= typeCacheService.getCacheObjectByDevTypeCode(IotDeviceDictConst.TYPE_YF_CBD);
-        reqVo.setDevtypeBid(tosDevicetype.getDevtypeBid());
-        List<IotDeviceListResVo> list = iIotDeviceService.selectIotDeviceListByType(reqVo);
-        for (IotDeviceListResVo resVo : list) {
-            //查询图片数量
-            Map<String, Object> map = new HashMap<>();
-            map.put("devBid", resVo.getDevBid());
-            map.put("cbdimgDelstatus", "0");
-            long count = mongoService.count(IotCbdimg.class, map);
-            resVo.setImgCount(count);
-
-        }
-        return getDataTable(list);
-    }
+//    @GetMapping("/list")
+//    public TableDataInfo list(IotDeviceListReqVo reqVo) {
+//        startPage();
+//        TosDevicetype tosDevicetype= typeCacheService.getCacheObjectByDevTypeCode(IotDeviceDictConst.TYPE_YF_CBD);
+//        reqVo.setDevtypeBid(tosDevicetype.getDevtypeBid());
+//        List<IotDeviceListResVo> list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+//        for (IotDeviceListResVo resVo : list) {
+//            //查询图片数量
+//            Map<String, Object> map = new HashMap<>();
+//            map.put("devBid", resVo.getDevBid());
+//            map.put("cbdimgDelstatus", "0");
+//            long count = mongoService.count(IotCbdimg.class, map);
+//            resVo.setImgCount(count);
+//
+//        }
+//        return getDataTable(list);
+//    }
 
 //
 //    /**

+ 24 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotCbdimgCountResVo.java

@@ -0,0 +1,24 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import lombok.Data;
+
+/**
+ * 测报灯图片基础对象 IotCbdimg
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ *
+ */
+@Data
+public class IotCbdimgCountResVo extends IotBaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 设备业务标识 */
+    @Excel(name = "设备业务标识")
+    private String devBid;
+
+    private int imgCount;
+}

+ 18 - 6
src/main/java/com/yunfeiyun/agmp/iotm/device/qxsqz/controller/IotDeviceQxzController.java

@@ -54,23 +54,35 @@ public class IotDeviceQxzController extends BaseController {
 
     /**
      * 气象站列表
+     * /qxz/list  所有气象设备
+     * /qxz/pt/list 普通气象设备
+     *
+     * 墒情站列表
+     * /sqz/list 所有墒情设备
+     * /sqz/pt/list 普通墒情设备
      * @param reqVo
      * @return
      */
-    @GetMapping("/list")
+    @GetMapping({"/list", "/pt/list"})
     public TableDataInfo list(HttpServletRequest request, IotDeviceListReqVo reqVo) {
         startPage();
         String reqUri = request.getRequestURI();
         String[] devTypeList = null;
+
         if(reqUri.endsWith("/qxz/list")){
             devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_QXZ, IotDeviceDictConst.TYPE_XPH_YF_QXZ};
-        }else{
+        }else if(reqUri.endsWith("/qxz/pt/list")){
+            devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_QXZ, IotDeviceDictConst.TYPE_XPH_YF_QXZ};
+        } else if (reqUri.endsWith("/sqz/list")) {
+            devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_SQZ, IotDeviceDictConst.TYPE_XPH_YF_SQZ};
+        } else if (reqUri.endsWith("/sqz/pt/list")) {
             devTypeList = new String[]{IotDeviceDictConst.TYPE_YF_SQZ, IotDeviceDictConst.TYPE_XPH_YF_SQZ};
         }
-
-        reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
-
-        List<IotDeviceListResVo> list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        List<IotDeviceListResVo> list = null;
+        if (devTypeList != null) {
+            reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
+            list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        }
         return getDataTable(list);
     }
 

+ 10 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/domain/reqvo/IotDeviceListReqVo.java

@@ -39,4 +39,14 @@ public class IotDeviceListReqVo extends IotDevice {
     private List<String> devtypeBidList;
     /**通用查询字段,用于同时查询设备名称和设备标识 */
     private String devQuery;
+
+    /**
+     * 测报灯识别类型
+     * 1  A模型
+     * 2  B模型
+     */
+    private String cbdrecogType;
+
+    /** 标记类型 0 手动标记 1  机器自动标记 */
+    private String cbdrecogMarktype;
 }