Просмотр исходного кода

新增 获取害虫占比列表接口

zhaiyifei 1 год назад
Родитель
Сommit
28ea099368

+ 10 - 93
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotPestrecogController.java

@@ -96,6 +96,15 @@ public class IotPestrecogController extends BaseController {
     }
 
 
+    /**
+     * 根据害虫分组统计数量
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:pest:list')")
+    @GetMapping("/group/pest/list")
+    public AjaxResult groupByPestList(IotDeviceDataListReqVo reqVo) {
+        List<IotPestrecogGroupPestListResVo> results = iIotPestrecogService.groupByPestList(reqVo);
+        return AjaxResult.success(results);
+    }
 //
 //    /**
 //     * 根据害虫分组统计数量
@@ -173,99 +182,7 @@ public class IotPestrecogController extends BaseController {
 //        return AjaxResult.success(results);
 //    }
 //
-////    /**
-////     * 虫情趋势矩阵
-////     */
-////    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:date:name')")
-////    @GetMapping("/group/date/name")
-////    public AjaxResult groupByDateName(IotDeviceDataListReqVo reqVo) {
-////        if (StringUtils.isEmpty(reqVo.getStartTime()) || StringUtils.isEmpty(reqVo.getEndTime())) {
-////            return AjaxResult.error(ErrorCode.INVALID_PARAMETER.getCode(), "时间不能为空");
-////        }
-////
-////
-////        Criteria criteria = new Criteria();
-////        criteria.and("devBid").is(reqVo.getDevBid());
-////        if (StringUtils.isNotEmpty(reqVo.getPestrecogMarktype())) {
-////            criteria.and("pestrecogMarktype").is(reqVo.getPestrecogMarktype());
-////        }
-////        if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isEmpty(reqVo.getEndTime())) {
-////            criteria.and("pestrecogCreatedDate").is(reqVo.getPestrecogMarktype());
-////        }
-////        if (StringUtils.isEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
-////            criteria.and("pestrecogCreatedDate").is(reqVo.getPestrecogMarktype());
-////        }
-////        if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
-////            criteria.and("pestrecogCreatedDate").gte(reqVo.getStartTime()).lte(reqVo.getEndTime());
-////        }
-////        MatchOperation matchOperation = Aggregation.match(criteria);
-////
-////        ProjectionOperation projectionOperation = Aggregation.project()
-////                .andExclude("_id")
-////                .and("$$ROOT").as("c");
-////
-////        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
-////                "IotCbdpest", "c.pestrecogBid", "pestrecogBid", "cp"
-////        );
-////        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
-////
-////
-////        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
-////                "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "ce"
-////        );
-////        UnwindOperation unwindOperationCe = Aggregation.unwind("ce", true);
-////        Criteria criteria2 = new Criteria()
-////                .and("ce.cbdrecogType").is(reqVo.getCbdRecogType());
-////        MatchOperation matchOperation2 = Aggregation.match(criteria2);
-////
-////        GroupOperation group = Aggregation.group("c.pestBusid")
-////                .first("c.pestBusid").as("pestBusid")
-////                .first("c.pestrecogCreatedDate").as("pestrecogCreatedDate")
-////                .sum("c.pestrecogNum").as("pestrecogNum");// fieldName为要分组的字段名称,totalField为需要求和的字段名称
-////
-////
-////        Aggregation aggregation = Aggregation.newAggregation(
-////                matchOperation,
-////                projectionOperation,
-////                lookupOperationIotCbdpest,
-////                unwindOperationCp,
-////                lookupOperationIotCbdrecog,
-////                unwindOperationCe,
-////                matchOperation2,
-////                group
-////        );
-////        List<IotPestrecog> results = mongoService.aggregate(IotPestrecog.class, aggregation, IotPestrecog.class);
-////
-////        //获取存在识别害虫集合
-////        List<IotPest> iotPests2 = getIotPestList(results);
-////
-////        List<Map<String, Object>> list1 = new ArrayList<>();
-////        //获取日期集合
-////        List<String> dateList = DatePlugUtil.getTwoDaysDayDes(reqVo.getStartTime(), reqVo.getEndTime());
-////        for (String s : dateList) {
-////            Map<String, Object> dateMap = new HashMap<>();
-////            dateMap.put("date", s);
-////            List<Map<String, Object>> list2 = new ArrayList<>();
-////            dateMap.put("data", list2);
-////            for (IotPest iotPest : iotPests2) {
-////                String pestBid = iotPest.getPestBid();
-////                Map<String, Object> pestMap = new HashMap<>();
-////                pestMap.put("pestName", iotPest.getPestName());
-////                pestMap.put("pestBid", iotPest.getPestBid());
-////                int sum = 0;
-////                for (IotPestrecog iotPestrecog : results) {
-////                    if (s.equals(iotPestrecog.getPestrecogCreatedDate().substring(0, 10))
-////                            && pestBid != null && pestBid.equals(iotPestrecog.getPestBusid())) {
-////                        sum += iotPestrecog.getPestrecogNum();
-////                    }
-////                }
-////                pestMap.put("sum", sum);
-////                list2.add(pestMap);
-////            }
-////            list1.add(dateMap);
-////        }
-////        return AjaxResult.success(list1);
-////    }
+
 //
 //
 //

+ 10 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotPestrecogGroupPestListResVo.java

@@ -0,0 +1,10 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import lombok.Data;
+
+@Data
+public class IotPestrecogGroupPestListResVo {
+    private String pestBusid;
+    private String pestName;
+    private int pestrecogNum;
+}

+ 3 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/IIotPestrecogService.java

@@ -18,6 +18,9 @@ public interface IIotPestrecogService {
     public List<IotPestrecogGroupByNameResVo> groupByName(IotDeviceDataListReqVo reqVo);
 
     public List<IotPestrecogGroupByNameListResVo> groupByDateName(IotDeviceDataListReqVo reqVo);
+
+    public List<IotPestrecogGroupPestListResVo> groupByPestList(IotDeviceDataListReqVo reqVo);
+
     public List<IotXyinfoPestTotalDto> getIotXyinfoPestTotal(List<String> devBidList);
     public Map<String, IotXyinfoPestTotalDto> getIotXyinfoPestTotalMap(List<String> devBidList);
 

+ 64 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/impl/IotPestrecogServiceImpl.java

@@ -373,6 +373,70 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
         return iotPestrecogGroupByNameResVoList;
     }
 
+    @Override
+    public List<IotPestrecogGroupPestListResVo> groupByPestList(IotDeviceDataListReqVo reqVo) {
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String devBid = reqVo.getDevBid();
+        String cbdrecogType = reqVo.getCbdrecogType();
+        String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
+
+        Criteria criteria = new Criteria()
+                .and("devBid").is(devBid)
+                .and("cbdimgDelstatus").is("0");
+
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.andOperator(
+                    Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime),
+                    Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime);
+        }
+        criteria = criteria.and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid").exists(true);
+
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype).as("pestrecog");
+
+        UnwindOperation unwindOperation = Aggregation.unwind("pestrecog", false);
+
+        ProjectionOperation projectionOperation2 = Aggregation.project()
+                .and("pestrecog.pestBusid").as("pestBusid")
+                .and("pestrecog.pestName").as("pestName")
+                .and("pestrecog.pestrecogNum").as("pestrecogNum");
+
+        GroupOperation groupOperation = Aggregation.group("pestBusid")
+                .sum("pestrecogNum").as("pestrecogNum")
+                .first("pestName").as("pestName");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "pestrecogNum");
+
+        ProjectionOperation projectionOperationResult = Aggregation.project()
+                .and("_id").as("pestBusid")
+                .and("pestrecogNum").as("pestrecogNum")
+                .and("pestName").as("pestName");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                unwindOperation,
+                projectionOperation2,
+                groupOperation,
+                sortOperation,
+                projectionOperationResult
+        );
+
+        List<IotPestrecogGroupPestListResVo> iotPestrecogGroupPestListResVoList = mongoService.aggregate(
+                IotCbdimg.class, aggregation, IotPestrecogGroupPestListResVo.class
+        );
+        return iotPestrecogGroupPestListResVoList;
+    }
+
+
     /**
      * 获取性诱设备虫情识别总数
      * @param devBidList