Преглед изворни кода

阶段提交:增加虫子,性诱的保留,后面自行分开,关闭checker

yf_zn пре 1 година
родитељ
комит
eae2b11a5d

+ 149 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotPestController.java

@@ -0,0 +1,149 @@
+package com.yunfeiyun.agmp.iotm.device.pest.controller;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.yunfeiyun.agmp.common.annotation.Log;
+import com.yunfeiyun.agmp.common.core.controller.BaseController;
+import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
+import com.yunfeiyun.agmp.common.enums.BusinessType;
+import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
+import com.yunfeiyun.agmp.iot.common.domain.*;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotAidispestService;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 害虫信息Controller
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ */
+@RestController
+@RequestMapping("/iot/pest")
+public class IotPestController extends BaseController
+{
+    @Autowired
+    private IIotPestService iotPestService;
+    @Autowired
+    private MongoTemplate mongoTemplate;
+    @Autowired
+    private IIotAidispestService iotAidispestService;
+
+    /**
+     * 查询害虫信息列表
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(IotPest iotPest)
+    {
+        startPage();
+        List<IotPest> list = iotPestService.selectIotPestList(iotPest);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出害虫信息列表
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:export')")
+    @Log(title = "害虫信息", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, IotPest iotPest)
+    {
+        List<IotPest> list = iotPestService.selectIotPestList(iotPest);
+        ExcelUtil<IotPest> util = new ExcelUtil<IotPest>(IotPest.class);
+        util.exportExcel(response, list, "害虫信息数据");
+    }
+
+    /**
+     * 获取害虫信息详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:query')")
+    @GetMapping(value = "/info")
+    public AjaxResult getInfo(@RequestParam("pestBid") String pestBid)
+    {
+        return success(iotPestService.selectIotPestByPestBid(pestBid));
+    }
+
+    /**
+     * 获取害虫信息详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:plug:query')")
+    @GetMapping(value = "/plug/info")
+    public AjaxResult getPlugInfo(@RequestParam("pestBid") String pestBid)
+    {
+        Criteria criteria = new Criteria();
+        criteria.and("pestBusid").is(pestBid);
+        Query query = new Query(criteria);
+        query.with(Sort.by(Sort.Direction.DESC, "pestrecogCreatedDate"));
+        IotPestrecog iotPestrecog = mongoTemplate.findOne(query, IotPestrecog.class, "IotPestrecog");
+        IotPest iotPest = iotPestService.selectIotPestByPestBid(pestBid);
+        if (iotPestrecog != null) {
+            Criteria criteria2 = new Criteria();
+            criteria2.and("pestrecogBid").is(iotPestrecog.getPestrecogBid());
+            IotCbdpest iotCbdpest = mongoTemplate.findOne(new Query(criteria2), IotCbdpest.class, "IotCbdpest");
+            if (iotCbdpest != null) {
+                Criteria criteria3 = new Criteria();
+                criteria3.and("cbdrecogBid").is(iotCbdpest.getCbdrecogBid());
+                IotCbdrecog iotCbdrecog = mongoTemplate.findOne(new Query(criteria3), IotCbdrecog.class, "IotCbdrecog");
+                if (iotCbdrecog != null) {
+                    Criteria criteria4 = new Criteria();
+                    criteria4.and("cbdimgBid").is(iotCbdrecog.getCbdimgBid());
+                    IotCbdimg iotCbdimg = mongoTemplate.findOne(new Query(criteria4), IotCbdimg.class, "IotCbdimg");
+                    iotPest.setPestImgUrl(iotCbdimg.getCbdimgAddr());
+                }
+            }
+        }
+
+        try {
+            JSONArray preventiveMeasuresInfo = iotAidispestService.getPreventiveMeasuresInfo(iotPest.getPestName());
+            if (preventiveMeasuresInfo.size() > 0) {
+                iotPest.setPestInfo(preventiveMeasuresInfo.getJSONObject(0).toJSONString());
+            }
+        } catch (Exception e) {
+            logger.error("获得防治措施异常", e);
+        }
+        return success(iotPest);
+    }
+
+    /**
+     * 新增害虫信息
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:add')")
+    @Log(title = "害虫信息", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    public AjaxResult add(@RequestBody IotPest iotPest)
+    {
+        return toAjax(iotPestService.insertIotPest(iotPest));
+    }
+
+    /**
+     * 修改害虫信息
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:edit')")
+    @Log(title = "害虫信息", businessType = BusinessType.UPDATE)
+    @PutMapping("/edit")
+    public AjaxResult edit(@RequestBody IotPest iotPest)
+    {
+        return toAjax(iotPestService.updateIotPest(iotPest));
+    }
+
+    /**
+     * 删除害虫信息
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pest:remove')")
+    @Log(title = "害虫信息", businessType = BusinessType.DELETE)
+	@DeleteMapping("/delete")
+    public AjaxResult remove(@RequestParam("ids") Long[] ids)
+    {
+        return toAjax(iotPestService.deleteIotPestByIds(ids));
+    }
+}

+ 537 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotPestrecogController.java

@@ -0,0 +1,537 @@
+package com.yunfeiyun.agmp.iotm.device.pest.controller;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.yunfeiyun.agmp.common.annotation.Log;
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
+import com.yunfeiyun.agmp.common.core.controller.BaseController;
+import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
+import com.yunfeiyun.agmp.common.core.page.TableSupport;
+import com.yunfeiyun.agmp.common.enums.BusinessType;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
+import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
+import com.yunfeiyun.agmp.iot.common.domain.IotPest;
+import com.yunfeiyun.agmp.iot.common.domain.IotPestrecog;
+import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iot.common.util.tmn.DatePlugUtil;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.*;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestrecogService;
+import lombok.extern.slf4j.Slf4j;
+import org.bson.Document;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.aggregation.*;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+
+/**
+ * 虫情识别信息表Controller
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ */
+@Slf4j
+@RestController
+@RequestMapping("/iot/pestrecog")
+public class IotPestrecogController extends BaseController {
+    @Autowired
+    private IIotPestService iotPestService;
+    @Autowired
+    private MongoService mongoService;
+    @Autowired
+    private IIotPestrecogService iIotPestrecogService;
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    /**
+     * 识别数据列表
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
+        if (reqVo.getPestBids() == null || reqVo.getPestBids().size() == 0) {
+            TableDataInfo rspData = new TableDataInfo();
+            rspData.setCode(ErrorCode.SUCCESS.getCode());
+            rspData.setMsg(ErrorCode.SUCCESS.getMessage());
+            rspData.setData(new ArrayList<>());
+            rspData.setTotal(0);
+            return (rspData);
+        }
+        Map<String, Object> map = getParamMap(reqVo);
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        IPage<IotPestrecogResVo> listPage = iIotPestrecogService.selectIotPestrecogList(reqVo, pageDomain);
+        return getDataTable(listPage);
+    }
+
+    /**
+     * 导出识别数据列表
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:data:export')")
+    @Log(title = "设备数据", businessType = BusinessType.EXPORT)
+    @PostMapping("/data/export")
+    public void dataExport(HttpServletResponse response, @RequestBody IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
+
+
+        List<IotPestrecogExportResVo> list = iIotPestrecogService.exportIotPestrecogList(reqVo);
+        //List<IotPestrecogResVo> list = getIotPestrecogResVoList2(records);
+        ExcelUtil<IotPestrecogExportResVo> util = new ExcelUtil<>(IotPestrecogExportResVo.class);
+        util.exportExcel(response, list, "识别数据");
+    }
+
+    /**
+     * 根据害虫分组统计数量
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:pest:list')")
+    @GetMapping("/group/pest/list")
+    public AjaxResult groupByPestList(IotPestRecogPeriodReqVo reqVo) {
+        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())
+                .and("ce.cbdrecogMarktype").is(reqVo.getPestrecogMarktype());;
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
+
+        GroupOperation group = Aggregation.group("c.pestBusid").first("c.pestBusid").as("pestBusid")
+                .sum("c.pestrecogNum").as("pestrecogNum");// fieldName为要分组的字段名称,totalField为需要求和的字段名称
+
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotCbdrecog,
+                unwindOperationCe,
+                matchOperation2,
+                group
+                );
+        List<IotPestResVo> results = mongoService.aggregate(IotPestrecog.class, aggregation, IotPestResVo.class);
+
+        //获取害虫数据
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
+        for (IotPestResVo result : results) {
+            if (!StringUtils.isEmpty(result.getPestBusid())) {
+                IotPest pest = pestMap.get(result.getPestBusid());
+                if (pest != null) {
+                    result.setPestName(pest.getPestName());
+                }
+            } else {
+                // 手动识别的名字,待完善
+                result.setPestName("-");
+            }
+
+
+        }
+
+        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(), "时间不能为空");
+        }
+        List<IotPestrecog> results = iIotPestrecogService.groupByDateName(reqVo);
+
+        //获取存在识别害虫集合
+        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);
+    }
+
+//    /**
+//     * 虫情趋势矩阵
+//     */
+//    @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);
+//    }
+
+
+//    /**
+//     * 根据害虫进行区分统计
+//     */
+//    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:name')")
+//    @GetMapping("/group/name")
+//    public AjaxResult groupByName(IotDeviceDataListReqVo reqVo) {
+//        if (StringUtils.isEmpty(reqVo.getStartTime()) || StringUtils.isEmpty(reqVo.getEndTime())) {
+//            return AjaxResult.error(ErrorCode.INVALID_PARAMETER.getCode(), "时间不能为空");
+//        }
+//
+//        //获取识别数据
+//        Map<String, Object> map = new HashMap<>();
+//        map.put("devBid", reqVo.getDevBid());
+//        if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
+//            map.put("time_pestrecogCreatedDate", reqVo.getStartTime() + "," + reqVo.getEndTime());
+//        }
+//        List<IotPestrecog> list = mongoService.findAll(IotPestrecog.class, map);
+//
+//        //获取存在识别害虫集合
+//        List<IotPest> iotPests2 = getIotPestList(list);
+//
+//        List<Map<String, Object>> list1 = new ArrayList<>();
+//        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 : list) {
+//                if (pestBid != null && pestBid.equals(iotPestrecog.getPestBusid())) {
+//                    sum += iotPestrecog.getPestrecogNum();
+//                }
+//            }
+//            pestMap.put("sum", sum);
+//            list1.add(pestMap);
+//        }
+//        return AjaxResult.success(list1);
+//    }
+
+    /**
+     * 根据害虫进行区分统计
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:name')")
+    @GetMapping("/group/name")
+    public AjaxResult groupByName(IotDeviceDataListReqVo reqVo) {
+        if (StringUtils.isEmpty(reqVo.getStartTime()) || StringUtils.isEmpty(reqVo.getEndTime())) {
+            return AjaxResult.error(ErrorCode.INVALID_PARAMETER.getCode(), "时间不能为空");
+        }
+
+        List<IotPestrecogGroupByNameResVo> iotPestrecogGroupByNameResVoList = iIotPestrecogService.groupByName(reqVo);
+        return AjaxResult.success(iotPestrecogGroupByNameResVoList);
+    }
+
+    /**
+     * 根据害虫业务标识查询始见期高峰期终见期
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:name')")
+    @GetMapping("/period")
+    public AjaxResult period(IotPestRecogPeriodReqVo reqVo) {
+        Map<String, Object> resultMap = iIotPestrecogService.period(reqVo);
+        return AjaxResult.success(resultMap);
+    }
+
+    public List<IotPest> getIotPestList(List<IotPestrecog> list) {
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
+        List<IotPest> iotPests2 = new ArrayList<>();
+        Set<String> set = new HashSet<>();
+        for (IotPestrecog iotPestrecog : list) {
+            set.add(iotPestrecog.getPestBusid());
+        }
+        for (String s : set) {
+            IotPest iotPest1 = new IotPest();
+            iotPest1.setPestBid(s);
+            IotPest pest = pestMap.get(s);
+            if (pest != null) {
+                iotPest1.setPestName(pest.getPestName());
+                iotPest1.setPestId(pest.getPestId());
+            }
+            iotPests2.add(iotPest1);
+        }
+        return iotPests2;
+    }
+
+    protected TableDataInfo getDataTable(IPage page) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(ErrorCode.SUCCESS.getCode());
+        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
+        rspData.setData(page.getRecords());
+        rspData.setTotal(page.getTotal());
+        return rspData;
+    }
+
+    /**
+     * 对列表与导出的参数进行封装
+     *
+     * @param reqVo
+     * @return
+     */
+    private Map<String, Object> getParamMap(IotPestRecogPeriodReqVo reqVo) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("devBid", reqVo.getDevBid());
+
+        if (StringUtils.isNotEmpty(reqVo.getPestrecogMarktype())) {
+            map.put("pestrecogMarktype", reqVo.getPestrecogMarktype());
+        }
+        if (StringUtils.isNotEmpty(reqVo.getPestBids())) {
+            map.put("newList_pestBusid", reqVo.getPestBids());
+        }
+        if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isEmpty(reqVo.getEndTime())) {
+            map.put("gte_pestrecogCreatedDate", reqVo.getStartTime());
+        }
+        if (StringUtils.isEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
+            map.put("lte_pestrecogCreatedDate", reqVo.getEndTime());
+        }
+        if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
+            map.put("time_pestrecogCreatedDate", reqVo.getStartTime() + "," + reqVo.getEndTime());
+        }
+        return map;
+    }
+
+    /**
+     * 对返回数据进行封装
+     *
+     * @param records
+     * @return
+     */
+    private List<IotPestrecogResVo> getIotPestrecogResVoList(List<IotPestrecog> records) {
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
+        List<IotPestrecogResVo> list = new ArrayList<>();
+        for (IotPestrecog record : records) {
+            IotPestrecogResVo resVo = new IotPestrecogResVo();
+            BeanUtils.copyProperties(record, resVo);
+            AggregationOperation lookupOperation = LookupOperation.newLookup()
+                    .from("IotCbdrecog")
+                    .localField("cbdrecogBid")
+                    .foreignField("cbdrecogBid")
+                    .as("IotCbdrecog");
+            Criteria criteria = new Criteria();
+            criteria.and("pestrecogBid").is(record.getPestrecogBid());
+            Aggregation aggregation = Aggregation.newAggregation(lookupOperation, Aggregation.match(criteria));
+//            Aggregation aggregation= Aggregation.newAggregation(
+//                    Aggregation.lookup("IotCbdrecog", "cbdrecogBid", "cbdrecogBid", "IotCbdrecog"),
+//                    Aggregation.match(criteria));
+            AggregationResults<Document> result = mongoTemplate.aggregate(aggregation, "IotCbdpest", Document.class);
+            List<Document> objs = result.getMappedResults();
+            if (objs.size() > 0) {
+                Document document = objs.get(0);
+                JSONObject from = JSONObject.from(document);
+                JSONArray array = from.getJSONArray("IotCbdrecog");
+                if (array.size() > 0) {
+                    JSONObject jsonObject = array.getJSONObject(0);
+                    resVo.setCbdrecogAddr(jsonObject.getString("cbdrecogAddr"));
+                    resVo.setCbdrecogManualaddr(jsonObject.getString("cbdrecogManualaddr"));
+                    resVo.setCbdrecogMarktype(jsonObject.getString("cbdrecogMarktype"));
+                    resVo.setCbdrecogManualmark(jsonObject.getString("cbdrecogManualmark"));
+                    resVo.setCbdrecogMachinemark(jsonObject.getString("cbdrecogMachinemark"));
+                }
+            }
+            if (!StringUtils.isEmpty(record.getPestBusid())) {
+                IotPest pest = pestMap.get(record.getPestBusid());
+                if (pest != null) {
+                    resVo.setPestName(pest.getPestName());
+                    resVo.setPestId(pest.getPestId());
+                    list.add(resVo);
+                } else {
+                    // 手动识别的名字,待完善
+                    resVo.setPestName("-");
+                    list.add(resVo);
+                }
+
+            }
+
+        }
+        return list;
+    }
+
+
+    /**
+     * 对返回数据进行封装
+     *
+     * @param records
+     * @return
+     */
+    private List<IotPestrecogResVo> getIotPestrecogResVoList2(List<IotPestrecog> records) {
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
+        List<IotPestrecogResVo> list = new ArrayList<>();
+        for (IotPestrecog record : records) {
+            IotPestrecogResVo resVo = new IotPestrecogResVo();
+            BeanUtils.copyProperties(record, resVo);
+            AggregationOperation lookupOperation = LookupOperation.newLookup()
+                    .from("IotCbdrecog")
+                    .localField("cbdrecogBid")
+                    .foreignField("cbdrecogBid")
+                    .as("IotCbdrecog");
+            Criteria criteria = new Criteria();
+            criteria.and("pestrecogBid").is(record.getPestrecogBid());
+            Aggregation aggregation = Aggregation.newAggregation(lookupOperation, Aggregation.match(criteria));
+//            Aggregation aggregation= Aggregation.newAggregation(
+//                    Aggregation.lookup("IotCbdrecog", "cbdrecogBid", "cbdrecogBid", "IotCbdrecog"),
+//                    Aggregation.match(criteria));
+            AggregationResults<Document> result = mongoTemplate.aggregate(aggregation, "IotCbdpest", Document.class);
+            List<Document> objs = result.getMappedResults();
+            if (objs.size() > 0) {
+                Document document = objs.get(0);
+                JSONObject from = JSONObject.from(document);
+                JSONArray array = from.getJSONArray("IotCbdrecog");
+                if (array.size() > 0) {
+                    JSONObject jsonObject = array.getJSONObject(0);
+                    resVo.setCbdrecogAddr(jsonObject.getString("cbdrecogAddr"));
+                    resVo.setCbdrecogManualaddr(jsonObject.getString("cbdrecogManualaddr"));
+                    resVo.setCbdrecogMarktype(jsonObject.getString("cbdrecogMarktype"));
+                    resVo.setCbdrecogManualmark(jsonObject.getString("cbdrecogManualmark"));
+                    resVo.setCbdrecogMachinemark(jsonObject.getString("cbdrecogMachinemark"));
+                }
+            }
+            if (!StringUtils.isEmpty(record.getPestBusid())) {
+                IotPest pest = pestMap.get(record.getPestBusid());
+                if (pest != null) {
+                    resVo.setPestName(pest.getPestName());
+                    resVo.setPestId(pest.getPestId());
+                    list.add(resVo);
+                } else {
+                    // 手动识别的名字,待完善
+                    resVo.setPestName("-");
+                    list.add(resVo);
+                }
+
+            }
+
+        }
+        return list;
+    }
+}

+ 30 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotPestResVo.java

@@ -0,0 +1,30 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import lombok.Data;
+
+/**
+ * 虫情识别信息对象 IotPestrecog
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ */
+@Data
+public class IotPestResVo
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 害虫业务标识 */
+    @Excel(name = "害虫业务标识")
+    private String pestBusid;
+
+    /** 害虫名称 */
+    @Excel(name = "害虫名称")
+    private String pestName;
+
+    /** 害虫数量 */
+    @Excel(name = "害虫数量")
+    private Long pestrecogNum;
+
+
+}

+ 138 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotPestrecogExportResVo.java

@@ -0,0 +1,138 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 害虫识别数据导出对象
+ *
+ * @author MZQ
+ * @date 2024-08-06
+ */
+@Data
+public class IotPestrecogExportResVo
+{
+    private static final long serialVersionUID = 1L;
+
+    /**  */
+    private String id;
+
+    /** 虫情识别信息业务标识 */
+    //@Excel(name = "虫情识别信息业务标识")
+    private String pestrecogBid;
+
+    /** 客户id */
+    //@Excel(name = "客户id")
+    private String cId;
+
+    /** 设备业务标识 */
+    //@Excel(name = "设备业务标识")
+    private String devBid;
+
+    /** 设备编号 */
+    @Excel(name = "设备编号")
+    private String devCode;
+
+    /** 设备类型标识 */
+    //@Excel(name = "设备类型标识")
+    private String devtypeBid;
+
+    /** 设备类型名称 */
+    @Excel(name = "设备类型")
+    private String devtypeName;
+
+
+
+    /** 害虫业务标识 */
+    //@Excel(name = "害虫业务标识")
+    private String pestBusid;
+
+    /** 害虫id */
+    //@Excel(name = "害虫id")
+    private String pestId;
+
+    /** 害虫名称 */
+    //@Excel(name = "害虫名称")
+    private String pestName;
+
+    /** 害虫数量 */
+    //@Excel(name = "害虫数量")
+    private Long pestrecogNum;
+
+    /** 识别结果(原始字段) */
+    private String cbdrecogResult;
+    /** 识别结果-人工修正后(原始字段) */
+    private String cbdrecogResultManual;
+
+    /** 识别结果 */
+    @Excel(name = "识别结果")
+    private String pestrecogResult;
+
+    /** 识别类型 */
+    @Excel(name = "识别类型", readConverterExp = "0=人工识别,1=AI识别")
+    private String cbdrecogMarktype;
+
+    /** 创建时间 */
+    @Excel(name = "识别时间")
+    private String pestrecogCreatedDate;
+
+    /** 识别图片地址 */
+    @Excel(name = "识别图片地址")
+    private String cbdrecogAddr;
+
+    /** 手动标记图片地址 */
+    //@Excel(name = "手动标记图片地址")
+    private String cbdrecogManualaddr;
+
+
+
+    /** 手动标记结果 */
+    //@Excel(name = "手动标记结果")
+    private String cbdrecogManualmark;
+
+    /** 机器标注结果 */
+    //@Excel(name = "机器标注结果")
+    private String cbdrecogMachinemark;
+
+    /** 原图地址 */
+    @Excel(name = "原图地址")
+    private String cbdimgAddr;
+
+    /** 温度 */
+    @Excel(name = "温度")
+    private BigDecimal pestrecogAt;
+
+    /** 湿度 */
+    @Excel(name = "湿度")
+    private BigDecimal pestrecogAh;
+
+    /** 经度 */
+    //@Excel(name = "经度")
+    private BigDecimal pestrecogLng;
+
+    /** 纬度 */
+    //@Excel(name = "纬度")
+    private BigDecimal pestrecogLat;
+
+    /** 省 */
+    //@Excel(name = "省")
+    private String pestrecogProvince;
+
+    /** 市 */
+    //@Excel(name = "市")
+    private String pestrecogCity;
+
+    /** 县 */
+    //@Excel(name = "县")
+    private String pestrecogDistrict;
+
+    /** 设备地址 */
+    @Excel(name = "设备地址")
+    private String address;
+    /** 地址 */
+    @Excel(name = "经纬度")
+    private String lnglat;
+
+}

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

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

+ 109 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotPestrecogResVo.java

@@ -0,0 +1,109 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 虫情识别信息对象 IotPestrecog
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ */
+@Data
+public class IotPestrecogResVo
+{
+    private static final long serialVersionUID = 1L;
+
+    /**  */
+    private String id;
+
+    /** 虫情识别信息业务标识 */
+    @Excel(name = "虫情识别信息业务标识")
+    private String pestrecogBid;
+
+    /** 客户id */
+    @Excel(name = "客户id")
+    private String cId;
+
+    /** 设备业务标识 */
+    @Excel(name = "设备业务标识")
+    private String devBid;
+
+    /** 设备类型标识 */
+    @Excel(name = "设备类型标识")
+    private String devtypeBid;
+
+    /** 温度 */
+    @Excel(name = "温度")
+    private BigDecimal pestrecogAt;
+
+    /** 湿度 */
+    @Excel(name = "湿度")
+    private BigDecimal pestrecogAh;
+
+    /** 经度 */
+    @Excel(name = "经度")
+    private BigDecimal pestrecogLng;
+
+    /** 纬度 */
+    @Excel(name = "纬度")
+    private BigDecimal pestrecogLat;
+
+    /** 省 */
+    @Excel(name = "省")
+    private String pestrecogProvince;
+
+    /** 市 */
+    @Excel(name = "市")
+    private String pestrecogCity;
+
+    /** 县 */
+    @Excel(name = "县")
+    private String pestrecogDistrict;
+
+    /** 害虫业务标识 */
+    @Excel(name = "害虫业务标识")
+    private String pestBusid;
+
+    /** 害虫id */
+    @Excel(name = "害虫id")
+    private String pestId;
+
+    /** 害虫名称 */
+    @Excel(name = "害虫名称")
+    private String pestName;
+
+    /** 害虫数量 */
+    @Excel(name = "害虫数量")
+    private Long pestrecogNum;
+
+    /** 创建时间 */
+    @Excel(name = "创建时间")
+    private String pestrecogCreatedDate;
+
+    /** 识别图片地址 */
+    @Excel(name = "识别图片地址")
+    private String cbdrecogAddr;
+
+    /** 手动标记图片地址 */
+    @Excel(name = "手动标记图片地址")
+    private String cbdrecogManualaddr;
+
+    /** 标记类型 */
+    @Excel(name = "标记类型")
+    private String cbdrecogMarktype;
+
+    /** 手动标记结果 */
+    @Excel(name = "手动标记结果")
+    private String cbdrecogManualmark;
+
+    /** 机器标注结果 */
+    @Excel(name = "机器标注结果")
+    private String cbdrecogMachinemark;
+
+    /** 图片原图地址 */
+    @Excel(name = "图片原图地址")
+    private String cbdimgAddr;
+}

+ 66 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/IIotAidispestService.java

@@ -0,0 +1,66 @@
+package com.yunfeiyun.agmp.iotm.device.pest.service;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.yunfeiyun.agmp.iot.common.domain.IotAidispest;
+
+import java.util.List;
+
+
+/**
+ * 病虫害信息Service接口
+ *
+ * @author 杨晓辉
+ * @date 2024-02-28
+ */
+public interface IIotAidispestService
+{
+    /**
+     * 查询病虫害信息
+     *
+     * @param id 病虫害信息主键
+     * @return 病虫害信息
+     */
+    public IotAidispest selectIotAidispestById(Long id);
+
+    /**
+     * 查询病虫害信息列表
+     *
+     * @param iotAidispest 病虫害信息
+     * @return 病虫害信息集合
+     */
+    public List<IotAidispest> selectIotAidispestList(IotAidispest iotAidispest);
+
+    /**
+     * 新增病虫害信息
+     *
+     * @param iotAidispest 病虫害信息
+     * @return 结果
+     */
+    public int insertIotAidispest(IotAidispest iotAidispest);
+
+    /**
+     * 修改病虫害信息
+     *
+     * @param iotAidispest 病虫害信息
+     * @return 结果
+     */
+    public int updateIotAidispest(IotAidispest iotAidispest);
+
+    /**
+     * 批量删除病虫害信息
+     *
+     * @param ids 需要删除的病虫害信息主键集合
+     * @return 结果
+     */
+    public int deleteIotAidispestByIds(Long[] ids);
+
+    /**
+     * 删除病虫害信息信息
+     *
+     * @param id 病虫害信息主键
+     * @return 结果
+     */
+    public int deleteIotAidispestById(Long id);
+
+    public JSONArray getPreventiveMeasuresInfo(String name) throws Exception;
+}

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

@@ -0,0 +1,30 @@
+package com.yunfeiyun.agmp.iotm.device.pest.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
+import com.yunfeiyun.agmp.iot.common.domain.IotPestrecog;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestRecogPeriodReqVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogExportResVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogGroupByNameResVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogResVo;
+import com.yunfeiyun.agmp.iotm.device.xy.domain.IotXyinfoPestTotalDto;
+
+import java.util.List;
+import java.util.Map;
+
+public interface IIotPestrecogService {
+    public IPage<IotPestrecogResVo> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo, PageDomain pageDomain) throws JsonProcessingException;
+
+    public List<IotPestrecog> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException;
+    public List<IotPestrecogExportResVo> exportIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException;
+
+    public List<IotPestrecogGroupByNameResVo> groupByName(IotDeviceDataListReqVo reqVo);
+
+    public List<IotPestrecog> groupByDateName(IotDeviceDataListReqVo reqVo);
+    public List<IotXyinfoPestTotalDto> getIotXyinfoPestTotal(List<String> devBidList);
+    public Map<String, IotXyinfoPestTotalDto> getIotXyinfoPestTotalMap(List<String> devBidList);
+
+    public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo);
+}

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/impl/IotCbdrecogServiceImpl.java

@@ -152,7 +152,7 @@ public class IotCbdrecogServiceImpl implements IIotCbdrecogService {
                         iotPest.setPestCreatedDate(DateUtils.dateTimeNow());
                         iotPest.setPestDelstatus("0");
                         iotPest.setPestInsertType("2");
-                        iotPest.setCId(CustomerIdUtil.getCustomerId());
+                        iotPest.setTid(CustomerIdUtil.getCustomerId());
                         iotPestService.insertIotPest(iotPest);//新害虫名称入库
 
                         //pestMap.put(iotPest.getPestId(), iotPest.getPestBid());

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

@@ -0,0 +1,846 @@
+package com.yunfeiyun.agmp.iotm.device.pest.service.impl;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
+import com.yunfeiyun.agmp.iot.common.domain.*;
+import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
+import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestRecogPeriodReqVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogExportResVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogGroupByNameResVo;
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogResVo;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestrecogService;
+import com.yunfeiyun.agmp.iotm.device.xy.domain.IotXyinfoPestTotalDto;
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.aggregation.*;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+public class IotPestrecogServiceImpl implements IIotPestrecogService {
+
+    @Autowired
+    private MongoService mongoService;
+
+    @Autowired
+    private IIotPestService iotPestService;
+
+    @Autowired
+    private IIotDeviceService iotDeviceService;
+
+    /**
+     * @param reqVo
+     * @param pageDomain
+     * @return
+     */
+    @Override
+    public IPage<IotPestrecogResVo> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo, PageDomain pageDomain) throws JsonProcessingException {
+        String devBid = reqVo.getDevBid();
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String pestrecogMarktype = reqVo.getPestrecogMarktype();
+        String cbdRecogType = reqVo.getCbdRecogType();
+        List<String> pestBids = reqVo.getPestBids();
+
+        Criteria criteria = new Criteria().and("devBid").is(devBid);
+        if(StringUtils.isNotEmpty(pestrecogMarktype)){
+            criteria.and("pestrecogMarktype").is(pestrecogMarktype);
+        }
+        List<IotPest> iotPestList = new ArrayList<>();
+        if(pestBids != null){
+            criteria.and("pestBusid").in(pestBids);
+            iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
+        }
+        Map<String, IotPest> iotPestMap = new HashMap<>();
+        if(iotPestList != null){
+            for(IotPest iotPest: iotPestList){
+                String pestId = iotPest.getPestId();
+                if(!iotPestMap.containsKey(pestId)){
+                    iotPestMap.put(pestId, iotPest);
+                }
+            }
+        }
+
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .andExclude("_id")
+                .and("$$ROOT").as("pr");
+
+        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
+                "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
+        );
+        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
+
+        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
+                "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
+        );
+        UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
+
+        LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
+                "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
+        );
+        UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
+
+        GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
+                .first("pr").as("pr")
+                .first("cr").as("cr")
+                .first("ci").as("ci")
+                .sum("pr.pestrecogNum").as("pestrecogNum");
+
+        Criteria criteria2 = new Criteria()
+                .and("ci.cbdimgDelstatus").is("0")
+                .and("cr.cbdrecogType").is(cbdRecogType)
+                .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
+
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.andOperator(
+                    Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
+                    Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
+        }
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
+
+        ProjectionOperation projectionOperationResult = Aggregation.project("_id")
+                .and("pr.pestrecogBid").as("pestrecogBid")
+                .and("pr.devBid").as("devBid")
+                .and("pr.devtypeBid").as("devtypeBid")
+                .and("pr.pestrecogAt").as("pestrecogAt")
+                .and("pr.pestrecogAh").as("pestrecogAh")
+                .and("pr.pestrecogLng").as("pestrecogLng")
+                .and("pr.pestrecogLat").as("pestrecogLat")
+                .and("pr.pestrecogProvince").as("pestrecogProvince")
+                .and("pr.pestrecogCity").as("pestrecogCity")
+                .and("pr.pestrecogDistrict").as("pestrecogDistrict")
+                .and("pr.pestBusid").as("pestBusid")
+
+                .and("pestrecogNum").as("pestrecogNum")
+                .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
+                .and("cr.cbdrecogAddr").as("cbdrecogAddr")
+                .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
+                .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
+                .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
+                .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
+                .and("cr.cbdrecogBid").as("cbdrecogBid")
+
+                .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
+                .and("ci.cbdimgBid").as("cbdimgBid")
+                .and("ci.cbdimgPestnum").as("cbdimgPestnum")
+                .and("ci.cbdimgRecognum").as("cbdimgRecognum")
+                .and("ci.cbdimgAddr").as("cbdimgAddr");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotCbdrecog,
+                unwindOperationCr,
+                lookupOperationIotCbdimg,
+                unwindOperationCi,
+                matchOperation2,
+                groupOperation,
+                projectionOperationResult,
+                sortOperation
+        );
+        IPage<IotPestrecogResVo> listPage = mongoService.aggregate(
+                IotPestrecog.class, aggregation, IotPestrecogResVo.class, pageDomain
+        );
+        List<IotPestrecogResVo> records = listPage.getRecords();
+
+        for(IotPestrecogResVo iotPestrecogResVo: records){
+            String cbdrecogMachinemark = iotPestrecogResVo.getCbdrecogMachinemark();
+
+            List pestList = (List) JSON.parse(cbdrecogMachinemark);
+            if(pestList == null){
+                continue;
+            }
+            StringBuilder newResult = new StringBuilder();
+            for(Object o: pestList){
+                JSONObject jsonObject = JSONObject.from(o);
+                for(String k: jsonObject.keySet()){
+                    if(iotPestMap.containsKey(k)){
+                        newResult.append("{'")
+                                .append(k).append("': ").append(jsonObject.getJSONArray(k))
+                                .append("}").append(",");
+                    }
+                }
+            }
+            if (newResult.length() > 0){
+                newResult.deleteCharAt(newResult.length()-1);
+                newResult.insert(0, "[");
+                newResult.append("]");
+                iotPestrecogResVo.setCbdrecogMachinemark(newResult.toString());
+                listPage.setRecords(records);
+            }
+        }
+        return listPage;
+    }
+
+    /**
+     * @param reqVo
+     * @return
+     * @throws JsonProcessingException
+     */
+    @Override
+    public List<IotPestrecog> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
+        String devBid = reqVo.getDevBid();
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String pestrecogMarktype = reqVo.getPestrecogMarktype();
+        String cbdRecogType = reqVo.getCbdRecogType();
+        List<String> pestBids = reqVo.getPestBids();
+
+        Criteria criteria = new Criteria().and("devBid").is(devBid);
+        if(StringUtils.isNotEmpty(pestrecogMarktype)){
+            criteria.and("pestrecogMarktype").is(pestrecogMarktype);
+        }
+        List<IotPest> iotPestList = new ArrayList<>();
+        if(pestBids != null){
+            criteria.and("pestBusid").in(pestBids);
+            iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
+        }
+        Map<String, IotPest> iotPestMap = new HashMap<>();
+        if(iotPestList != null){
+            for(IotPest iotPest: iotPestList){
+                String pestId = iotPest.getPestId();
+                if(!iotPestMap.containsKey(pestId)){
+                    iotPestMap.put(pestId, iotPest);
+                }
+            }
+        }
+
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .andExclude("_id")
+                .and("$$ROOT").as("pr");
+
+        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
+                "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
+        );
+        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
+
+        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
+                "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
+        );
+        UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
+
+        LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
+                "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
+        );
+        UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
+
+        GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
+                .first("pr").as("pr")
+                .first("cr").as("cr")
+                .first("ci").as("ci")
+                .sum("pr.pestrecogNum").as("pestrecogNum");
+
+        Criteria criteria2 = new Criteria()
+                .and("ci.cbdimgDelstatus").is("0")
+                .and("cr.cbdrecogType").is(cbdRecogType)
+                .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
+
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.andOperator(
+                    Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
+                    Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
+        }
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
+
+        ProjectionOperation projectionOperationResult = Aggregation.project("_id")
+                .and("pr.pestrecogBid").as("pestrecogBid")
+                .and("pr.devBid").as("devBid")
+                .and("pr.devtypeBid").as("devtypeBid")
+                .and("pr.pestrecogAt").as("pestrecogAt")
+                .and("pr.pestrecogAh").as("pestrecogAh")
+                .and("pr.pestrecogLng").as("pestrecogLng")
+                .and("pr.pestrecogLat").as("pestrecogLat")
+                .and("pr.pestrecogProvince").as("pestrecogProvince")
+                .and("pr.pestrecogCity").as("pestrecogCity")
+                .and("pr.pestrecogDistrict").as("pestrecogDistrict")
+                .and("pr.pestBusid").as("pestBusid")
+
+                .and("pestrecogNum").as("pestrecogNum")
+                .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
+                .and("cr.cbdrecogAddr").as("cbdrecogAddr")
+                .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
+                .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
+                .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
+                .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
+                .and("cr.cbdrecogBid").as("cbdrecogBid")
+
+                .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
+                .and("ci.cbdimgBid").as("cbdimgBid")
+                .and("ci.cbdimgPestnum").as("cbdimgPestnum")
+                .and("ci.cbdimgRecognum").as("cbdimgRecognum")
+                .and("ci.cbdimgAddr").as("cbdimgAddr");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotCbdrecog,
+                unwindOperationCr,
+                lookupOperationIotCbdimg,
+                unwindOperationCi,
+                matchOperation2,
+                groupOperation,
+                projectionOperationResult,
+                sortOperation
+        );
+        List<IotPestrecog> iotPestrecogList = mongoService.aggregate(
+                IotPestrecog.class, aggregation, IotPestrecog.class
+        );
+        return iotPestrecogList;
+    }
+
+    /**
+     * @param reqVo
+     * @return
+     * @throws JsonProcessingException
+     */
+    @Override
+    public List<IotPestrecogExportResVo> exportIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
+        String devBid = reqVo.getDevBid();
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String pestrecogMarktype = reqVo.getPestrecogMarktype();
+        String cbdRecogType = reqVo.getCbdRecogType();
+        List<String> pestBids = reqVo.getPestBids();
+
+        Criteria criteria = new Criteria().and("devBid").is(devBid);
+        if(StringUtils.isNotEmpty(pestrecogMarktype)){
+            criteria.and("pestrecogMarktype").is(pestrecogMarktype);
+        }
+        List<IotPest> iotPestList = new ArrayList<>();
+        if(pestBids != null){
+            criteria.and("pestBusid").in(pestBids);
+            iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
+        }
+        Map<String, IotPest> iotPestMap = new HashMap<>();
+        if(iotPestList != null){
+            for(IotPest iotPest: iotPestList){
+                String pestId = iotPest.getPestId();
+                if(!iotPestMap.containsKey(pestId)){
+                    iotPestMap.put(pestId, iotPest);
+                }
+            }
+        }
+
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .andExclude("_id")
+                .and("$$ROOT").as("pr");
+
+        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
+                "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
+        );
+        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
+
+        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
+                "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
+        );
+        UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
+
+        LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
+                "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
+        );
+        UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
+
+        GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
+                .first("pr").as("pr")
+                .first("cr").as("cr")
+                .first("ci").as("ci")
+                .sum("pr.pestrecogNum").as("pestrecogNum");
+
+        Criteria criteria2 = new Criteria()
+                .and("ci.cbdimgDelstatus").is("0")
+                .and("cr.cbdrecogType").is(cbdRecogType)
+                .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
+
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.andOperator(
+                    Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
+                    Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
+        }
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
+
+        ProjectionOperation projectionOperationResult = Aggregation.project("_id")
+                .and("pr.pestrecogBid").as("pestrecogBid")
+                .and("pr.devBid").as("devBid")
+                .and("pr.devtypeBid").as("devtypeBid")
+                .and("pr.pestrecogAt").as("pestrecogAt")
+                .and("pr.pestrecogAh").as("pestrecogAh")
+                .and("pr.pestrecogLng").as("pestrecogLng")
+                .and("pr.pestrecogLat").as("pestrecogLat")
+                .and("pr.pestrecogProvince").as("pestrecogProvince")
+                .and("pr.pestrecogCity").as("pestrecogCity")
+                .and("pr.pestrecogDistrict").as("pestrecogDistrict")
+                .and("pr.pestBusid").as("pestBusid")
+
+                .and("pestrecogNum").as("pestrecogNum")
+                .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
+                .and("cr.cbdrecogAddr").as("cbdrecogAddr")
+                .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
+                .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
+                .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
+                .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
+                .and("cr.cbdrecogBid").as("cbdrecogBid")
+                .and("cr.cbdrecogResult").as("cbdrecogResult")
+                .and("cr.cbdrecogResultManual").as("cbdrecogResultManual")
+
+                .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
+                .and("ci.cbdimgBid").as("cbdimgBid")
+                .and("ci.cbdimgPestnum").as("cbdimgPestnum")
+                .and("ci.cbdimgRecognum").as("cbdimgRecognum")
+                .and("ci.cbdimgAddr").as("cbdimgAddr");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotCbdrecog,
+                unwindOperationCr,
+                lookupOperationIotCbdimg,
+                unwindOperationCi,
+                matchOperation2,
+                groupOperation,
+                projectionOperationResult,
+                sortOperation
+        );
+        List<IotPestrecogExportResVo> iotPestrecogList = mongoService.aggregate(
+                IotPestrecog.class, aggregation, IotPestrecogExportResVo.class
+        );
+
+
+        //查询设备号
+        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo2();
+
+        for (IotPestrecogExportResVo item: iotPestrecogList) {
+
+            if(findDevice != null){
+                item.setDevCode(findDevice.getDevCode());
+            }
+
+            item.setPestrecogResult(parseRecogResult(item.getCbdrecogResult(),pestMap));
+
+            if("0".equals(item.getCbdrecogMarktype())){
+                item.setCbdrecogAddr(item.getCbdrecogManualaddr());
+                item.setPestrecogResult(parseRecogResult(item.getCbdrecogResultManual(),pestMap));
+            }
+            item.setAddress(item.getPestrecogProvince()+item.getPestrecogCity()+item.getPestrecogDistrict());
+            item.setLnglat(item.getPestrecogLng()+","+item.getPestrecogLat());
+
+            item.setDevtypeName(IotDeviceDictEnum.getNameByCode(item.getDevtypeBid()));
+        }
+
+        return iotPestrecogList;
+    }
+
+    /**
+     * 解析识别结果
+     *
+     * @param result "21,3#260,1#71,1#115,2"
+     * @return 害虫名称和数量
+     */
+    private String parseRecogResult(String result, Map<String, IotPest> pestMap){
+
+        String ret = "";
+        if(StringUtils.isNotEmpty(result)){
+            String[] arr = result.split("#");
+            for(int i=0;i<arr.length;i++){
+                if(StringUtils.isNotEmpty(arr[i])){
+                    String[] arr2 = arr[i].split(",");
+                    String pestName = "未命名";
+                    if(pestMap.get(arr2[0])!=null&&StringUtils.isNotEmpty(pestMap.get(arr2[0]).getPestName())){
+                        pestName = pestMap.get(arr2[0]).getPestName();
+                    }
+                    ret += pestName+""+arr2[1]+""+"头,";
+                }
+            }
+        }
+
+        //去除最后一个逗号
+        if(ret.endsWith(",")){
+            ret = ret.substring(0,ret.length()-1);
+        }
+
+        return ret;
+    }
+
+    /**
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotPestrecogGroupByNameResVo> groupByName(IotDeviceDataListReqVo reqVo) {
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String devBid = reqVo.getDevBid();
+        String cbdRecogType = reqVo.getCbdRecogType();
+        String pestrecogMarktype = reqVo.getPestrecogMarktype();
+
+        Criteria criteria = new Criteria()
+                .and("devBid").is(devBid)
+                .and("cbdimgDelstatus").is("0");
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.andOperator(
+                    Criteria.where("cbdimgCreatedDate").gte(startTime),
+                    Criteria.where("cbdimgCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria = criteria.and("cbdimgCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.and("cbdimgCreatedDate").lte(endTime);
+        }
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .andExclude("_id")
+                .and("$$ROOT").as("c");
+        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
+                "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce"
+        );
+        Criteria cbdRecogCriteria = new Criteria()
+                .and("ce.cbdrecogType").is(cbdRecogType)
+                .and("ce.cbdrecogMarktype").is(pestrecogMarktype);
+
+        MatchOperation cbdRecogMatchOperation = Aggregation.match(cbdRecogCriteria);
+        UnwindOperation unwindOperationCe = Aggregation.unwind("ce", true);
+
+        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
+                "IotCbdpest", "ce.cbdrecogBid", "cbdrecogBid", "cp"
+        );
+        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
+
+        LookupOperation lookupOperationIotPestrecog = Aggregation.lookup(
+                "IotPestrecog", "cp.pestrecogBid", "pestrecogBid", "pr"
+        );
+        UnwindOperation unwindOperationPr = Aggregation.unwind("pr", true);
+        Criteria criteria2 = new Criteria()
+                .and("pr.pestrecogMarktype").is(pestrecogMarktype);
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
+
+        GroupOperation groupOperation = Aggregation.group("pr.pestBusid")
+                .first("pr.pestBusid").as("pestBusid")
+                .sum("pr.pestrecogNum").as("sum");
+
+        ProjectionOperation projectionOperation2 = Aggregation.project()
+                .and("pestBusid").as("pestBid")
+                .and("sum").as("sum");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "sum");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdrecog,
+                unwindOperationCe,
+                cbdRecogMatchOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotPestrecog,
+                unwindOperationPr,
+                matchOperation2,
+                groupOperation,
+                projectionOperation2,
+                sortOperation
+        );
+        List<IotPestrecogGroupByNameResVo> iotPestrecogGroupByNameResVoList = mongoService.aggregate(
+                IotCbdimg.class, aggregation, IotPestrecogGroupByNameResVo.class
+        );
+
+        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
+        return  iotPestrecogGroupByNameResVoList.stream().filter(item->
+                {
+                    if(pestMap.containsKey(item.getPestBid())){
+                        item.setPestName(pestMap.get(item.getPestBid()).getPestName());
+                    }
+                    return StringUtils.isNotEmpty(item.getPestBid());
+                }
+        ).collect(Collectors.toList());
+    }
+
+    /**
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotPestrecog> groupByDateName(IotDeviceDataListReqVo reqVo) {
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String devBid = reqVo.getDevBid();
+        String cbdRecogType = reqVo.getCbdRecogType();
+        String pestrecogMarktype = reqVo.getPestrecogMarktype();
+
+        Criteria criteria = new Criteria()
+                .and("devBid").is(devBid)
+                .and("cbdimgDelstatus").is("0");
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.andOperator(
+                    Criteria.where("cbdimgCreatedDate").gte(startTime),
+                    Criteria.where("cbdimgCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria = criteria.and("cbdimgCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.and("cbdimgCreatedDate").lte(endTime);
+        }
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .andExclude("_id")
+                .and("$$ROOT").as("c");
+
+        LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
+                "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce"
+        );
+        Criteria cbdRecogCriteria = new Criteria()
+                .and("ce.cbdrecogType").is(cbdRecogType)
+                .and("ce.cbdrecogMarktype").is(pestrecogMarktype);
+        MatchOperation cbdRecogMatchOperation = Aggregation.match(cbdRecogCriteria);
+        UnwindOperation unwindOperationCe = Aggregation.unwind("ce", false);
+
+        LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
+                "IotCbdpest", "ce.cbdrecogBid", "cbdrecogBid", "cp"
+        );
+        UnwindOperation unwindOperationCp = Aggregation.unwind("cp", false);
+
+        LookupOperation lookupOperationIotPestrecog = Aggregation.lookup(
+                "IotPestrecog", "cp.pestrecogBid", "pestrecogBid", "pr"
+        );
+        UnwindOperation unwindOperationPr = Aggregation.unwind("pr", false);
+        Criteria pestRecogCriteria = new Criteria()
+                .and("pr.pestrecogMarktype").is(pestrecogMarktype);
+        MatchOperation pestRecogMatchOperation = Aggregation.match(pestRecogCriteria);
+
+        ProjectionOperation projectionOperation2 = Aggregation.project()
+                .and("pr.pestBusid").as("pestBusid")
+                .and("pr.pestrecogNum").as("pestrecogNum")
+                .andExpression(
+                        "{$dateTrunc: {date: {$dateFromString: {dateString: '$pr.pestrecogCreatedDate', format: '%Y-%m-%d %H:%M:%S'}}, unit:'day'}}").as("pestrecogCreatedDate");
+
+        GroupOperation groupOperation = Aggregation.group("pestrecogCreatedDate", "pestBusid")
+                .sum("pestrecogNum").as("pestrecogNum");
+        ProjectionOperation projectionOperation3 = Aggregation.project()
+                .and("_id.pestBusid").as("pestBusid")
+                .and("pestrecogNum").as("pestrecogNum")
+                .andExpression(
+                        "{$dateToString: { format: '%Y-%m-%d', date: '$_id.pestrecogCreatedDate'}}").as("pestrecogCreatedDate");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                lookupOperationIotCbdrecog,
+                unwindOperationCe,
+                cbdRecogMatchOperation,
+                lookupOperationIotCbdpest,
+                unwindOperationCp,
+                lookupOperationIotPestrecog,
+                unwindOperationPr,
+                pestRecogMatchOperation,
+                projectionOperation2,
+                groupOperation,
+                projectionOperation3
+        );
+        List<IotPestrecog> iotPestrecogList = mongoService.aggregate(
+                IotCbdimg.class, aggregation, IotPestrecog.class
+        );
+        return iotPestrecogList;
+    }
+
+    /**
+     * 获取性诱设备虫情识别总数
+     * @param devBidList
+     * @return
+     */
+    @Override
+    public List<IotXyinfoPestTotalDto> getIotXyinfoPestTotal(List<String> devBidList) {
+        Criteria criteria = new Criteria()
+                .and("devBid").in(devBidList);
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .and("devBid").as("devBid")
+                .andExpression("{$convert: {input: '$xycb2dataContent.ct', to: 'int', onError: 0, onNull: 0}}").as("ct");
+
+        GroupOperation groupOperation = Aggregation.group("devBid")
+                .sum("ct").as("pestTotal");
+
+        ProjectionOperation projectionOperation2 = Aggregation.project()
+                .and("_id").as("devBid")
+                .and("pestTotal").as("pestTotal");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                groupOperation,
+                projectionOperation2
+        );
+
+        List<IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoList = mongoService.aggregate(
+                IotYfXycb2data.class, aggregation, IotXyinfoPestTotalDto.class
+        );
+
+        return iotXyinfoPestTotalDtoList;
+    }
+
+    /**
+     * 获取性诱设备虫情识别总数
+     * @param devBidList
+     * @return
+     */
+    @Override
+    public Map<String, IotXyinfoPestTotalDto> getIotXyinfoPestTotalMap(List<String> devBidList) {
+        List<IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoList = getIotXyinfoPestTotal(devBidList);
+        Map<String, IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoMap = new HashMap<>();
+        for(IotXyinfoPestTotalDto iotXyinfoPestTotalDto: iotXyinfoPestTotalDtoList){
+            iotXyinfoPestTotalDtoMap.put(iotXyinfoPestTotalDto.getDevBid(), iotXyinfoPestTotalDto);
+        }
+        return iotXyinfoPestTotalDtoMap;
+    }
+
+    /**
+     * @param reqVo
+     */
+    @Override
+    public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo) {
+        String devBid = reqVo.getDevBid();
+        String startTime = reqVo.getStartTime();
+        String endTime = reqVo.getEndTime();
+        String pestBusid = reqVo.getPestBid();
+
+        Criteria criteria = new Criteria().and("devBid").is(devBid).and("pestBusid").is(pestBusid);
+        if(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){
+            criteria = criteria.andOperator(
+                    Criteria.where("pestrecogCreatedDate").gte(startTime),
+                    Criteria.where("pestrecogCreatedDate").lte(endTime)
+            );
+        } else if (StringUtils.isNotEmpty(startTime)) {
+            criteria = criteria.and("pestrecogCreatedDate").gte(startTime);
+        } else if (StringUtils.isNotEmpty(endTime)) {
+            criteria = criteria.and("pestrecogCreatedDate").lte(endTime);
+        }
+
+        MatchOperation matchOperation = Aggregation.match(criteria);
+
+        ProjectionOperation projectionOperation = Aggregation.project("_id")
+                .and("pestrecogNum").as("pestrecogNum")
+                .andExpression("{$dateTrunc: {date: {$dateFromString: {dateString: '$pestrecogCreatedDate', format: '%Y-%m-%d %H:%M:%S'}}, unit:'day'}}").as("date");
+
+        GroupOperation groupOperation = Aggregation.group("date")
+                .sum("pestrecogNum").as("pestrecogNum");
+
+        ProjectionOperation projectionOperation2 = Aggregation.project("_id")
+                .and("_id").as("date")
+                .and("pestrecogNum").as("pestrecogNum")
+                .andExpression("{$dateToString: {'date': '$_id', 'format': '%Y-%m-%d %H:%M:%S'}}").as("dataStr");
+
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "date");
+
+        GroupOperation groupOperation2 = Aggregation.group()
+                .push("$$ROOT").as("dataList");
+
+        ProjectionOperation projectionOperation3 = Aggregation.project()
+                .and("dataList").as("dataList")
+                .andExpression("{'$first': '$dataList'}").as("seeTimeInfo")
+                .andExpression("{'$last': '$dataList'}").as("endInPeriodInfo");
+
+        UnwindOperation unwindOperation = Aggregation.unwind("dataList");
+
+        SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.DESC, "dataList.pestrecogNum");
+
+        LimitOperation limitOperation = Aggregation.limit(1);
+
+        ProjectionOperation projectionOperation4 = Aggregation.project()
+                .and("seeTimeInfo").as("seeTimeInfo")
+                .and("endInPeriodInfo").as("endInPeriodInfo")
+                .and("dataList").as("fastigiumInfo");
+
+        Aggregation aggregation = Aggregation.newAggregation(
+                matchOperation,
+                projectionOperation,
+                groupOperation,
+                projectionOperation2,
+                sortOperation,
+                groupOperation2,
+                projectionOperation3,
+                unwindOperation,
+                sortOperation2,
+                limitOperation,
+                projectionOperation4
+        );
+        List<JSONObject> jsonObjectList = mongoService.aggregate(
+                IotPestrecog.class, aggregation, JSONObject.class
+        );
+
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("seeTimes", "");
+        resultMap.put("fastigium", "");
+        resultMap.put("fastigiumaNum", "");
+        resultMap.put("endInPeriod", "");
+
+        if(jsonObjectList.size() > 0){
+            JSONObject result = jsonObjectList.get(0);
+            resultMap.put("seeTimes", result.getJSONObject("seeTimeInfo").getString("dataStr"));
+            resultMap.put("fastigium", result.getJSONObject("fastigiumInfo").getString("dataStr"));
+            resultMap.put("fastigiumaNum", result.getJSONObject("fastigiumInfo").getInteger("pestrecogNum"));
+            resultMap.put("endInPeriod", result.getJSONObject("endInPeriodInfo").getString("dataStr"));
+        }
+
+        IoPestResVo ioPestResVo = iotPestService.selectIotPestDetailByPestBid(reqVo.getPestBid());
+        if (ioPestResVo == null) {
+            ioPestResVo = new IoPestResVo();
+        }
+        resultMap.put("pic", ioPestResVo.getPic());
+        resultMap.put("course", ioPestResVo.getCourse());
+        resultMap.put("calamRemark",ioPestResVo.getCalamRemark());
+        resultMap.put("alias", "");
+        String cropsList = iotPestService.selectIotPestCropsByCalarmId(ioPestResVo.getCalarmId());
+        resultMap.put("crops", cropsList);
+
+        return resultMap;
+    }
+}

+ 40 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/xy/domain/IotXyinfoDto.java

@@ -0,0 +1,40 @@
+package com.yunfeiyun.agmp.iotm.device.xy.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import lombok.Data;
+
+/**
+ * 性诱测报详细信息对象 IotXyinfo
+ *
+ * @author 杨晓辉
+ * @date 2024-06-03
+ */
+@Data
+public class IotXyinfoDto extends IotBaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    private Long id;
+
+    /** 业务唯一标识 */
+    @Excel(name = "业务唯一标识")
+    private String xyinfoBid;
+
+    /** 设备业务标识 */
+    @Excel(name = "设备业务标识")
+    private String devBid;
+
+    /** 诱芯名称 也是害虫表中的害虫名称 */
+    @Excel(name = "诱芯名称 也是害虫表中的害虫名称")
+    private String xyinfoLurename;
+
+    /** 诱芯到期时间 */
+    @Excel(name = "诱芯到期时间")
+    private String xyinfoLureexpireddate;
+
+    /** 害虫业务标识 */
+    @Excel(name = "害虫业务标识")
+    private String pestBusid;
+}

+ 25 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/xy/domain/IotXyinfoPestTotalDto.java

@@ -0,0 +1,25 @@
+package com.yunfeiyun.agmp.iotm.device.xy.domain;
+
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import lombok.Data;
+
+/**
+ * 性诱测报详细信息对象 IotXyinfo
+ *
+ * @author 杨晓辉
+ * @date 2024-06-03
+ */
+@Data
+public class IotXyinfoPestTotalDto extends IotBaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 设备业务标识 */
+    @Excel(name = "设备业务标识")
+    private String devBid;
+
+    /** 害虫业务标识 */
+    @Excel(name = "害虫识别总数")
+    private Integer pestTotal;
+}

+ 7 - 7
src/main/resources/mapper/IotPestMapper.xml

@@ -7,7 +7,7 @@
     <resultMap type="IotPest" id="IotPestResult">
         <result property="id" column="id"/>
         <result property="pestBid" column="pestBid"/>
-        <result property="cId" column="cId"/>
+        <result property="tid" column="tid"/>
         <result property="pestName" column="pestName"/>
         <result property="pestId" column="pestId"/>
         <result property="pestRemark" column="pestRemark"/>
@@ -20,7 +20,7 @@
     </resultMap>
 
     <sql id="selectIotPestVo">
-        select id, pestBid, cId, pestName, pestId, pestRemark, pestCreator, pestModifier, pestModifieddate, pestCreatedDate, pestDelstatus, pestInsertType from IotPest
+        select id, pestBid, tid, pestName, pestId, pestRemark, pestCreator, pestModifier, pestModifieddate, pestCreatedDate, pestDelstatus, pestInsertType from IotPest
     </sql>
 
     <select id="selectIotPestList" parameterType="IotPest" resultMap="IotPestResult">
@@ -28,7 +28,7 @@
         <where>
             pestDelstatus = 0
             <if test="pestBid != null  and pestBid != ''">and pestBid = #{pestBid}</if>
-            <if test="cId != null  and cId != ''">and cId = #{cId}</if>
+            <if test="tid != null  and tid != ''">and tid = #{tid}</if>
             <if test="pestName != null  and pestName != ''">and pestName like concat('%', #{pestName}, '%')</if>
             <if test="pestId != null  and pestId != ''">and pestId = #{pestId}</if>
             <if test="pestInsertType != null  and pestInsertType != ''">and pestInsertType = #{pestInsertType}</if>
@@ -69,7 +69,7 @@ SELECT * from  IotPest where pestBid=#{pestBid}
         <where>
             pestDelstatus = 0
             <if test="pestBid != null  and pestBid != ''">and pestBid = #{pestBid}</if>
-            <if test="cId != null  and cId != ''">and cId = #{cId}</if>
+            <if test="tid != null  and tid != ''">and tid = #{tid}</if>
             <if test="pestName != null  and pestName != ''">and pestName like concat('%', #{pestName}, '%')</if>
             <if test="pestId != null  and pestId != ''">and pestId = #{pestId}</if>
             <if test="pestRemark != null  and pestRemark != ''">and pestRemark like concat('%', #{pestRemark}, '%')</if>
@@ -81,7 +81,7 @@ SELECT * from  IotPest where pestBid=#{pestBid}
         insert into IotPest
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="pestBid != null and pestBid != ''">pestBid,</if>
-            <if test="cId != null">cId,</if>
+            <if test="tid != null">tid,</if>
             <if test="pestName != null">pestName,</if>
             <if test="pestId != null">pestId,</if>
             <if test="pestRemark != null">pestRemark,</if>
@@ -94,7 +94,7 @@ SELECT * from  IotPest where pestBid=#{pestBid}
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="pestBid != null and pestBid != ''">#{pestBid},</if>
-            <if test="cId != null">#{cId},</if>
+            <if test="tid != null">#{tid},</if>
             <if test="pestName != null">#{pestName},</if>
             <if test="pestId != null">#{pestId},</if>
             <if test="pestRemark != null">#{pestRemark},</if>
@@ -111,7 +111,7 @@ SELECT * from  IotPest where pestBid=#{pestBid}
         update IotPest
         <trim prefix="SET" suffixOverrides=",">
             <if test="pestBid != null and pestBid != ''">pestBid = #{pestBid},</if>
-            <if test="cId != null">cId = #{cId},</if>
+            <if test="tid != null">tid = #{tid},</if>
             <if test="pestName != null">pestName = #{pestName},</if>
             <if test="pestId != null">pestId = #{pestId},</if>
             <if test="pestRemark != null">pestRemark = #{pestRemark},</if>