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

新增 获取虫情数据信息接口

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

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

@@ -105,97 +105,17 @@ public class IotPestrecogController extends BaseController {
         List<IotPestrecogGroupPestListResVo> results = iIotPestrecogService.groupByPestList(reqVo);
         return AjaxResult.success(results);
     }
-//
-//    /**
-//     * 根据害虫分组统计数量
-//     */
-//    @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").gte(reqVo.getStartTime());
-//        }
-//        if (StringUtils.isEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
-//            criteria.and("pestrecogCreatedDate").lte(reqVo.getEndTime());
-//        }
-//        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:name')")
-//    @GetMapping("/period")
-//    public AjaxResult period(IotPestRecogPeriodReqVo reqVo) {
-//        Map<String, Object> resultMap = iIotPestrecogService.period(reqVo);
-//        return AjaxResult.success(resultMap);
-//    }
+
+    /**
+     * 根据害虫业务标识查询始见期高峰期终见期
+     */
+    @PreAuthorize("@ss.hasPermi('iot:pestrecog:group:name')")
+    @GetMapping("/period")
+    public AjaxResult period(IotPestRecogPeriodReqVo reqVo) {
+        IotPestRecogPeriodInfoResVo infoResVo = iIotPestrecogService.period(reqVo);
+        return AjaxResult.success(infoResVo);
+    }
 //
 //    public List<IotPest> getIotPestList(List<IotPestrecog> list) {
 //        Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();

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

@@ -0,0 +1,24 @@
+package com.yunfeiyun.agmp.iotm.device.pest.domain;
+
+import lombok.Data;
+
+/**
+ * 获取害虫周期
+ *
+ * @author 杨晓辉
+ * @date 2024-01-04
+ */
+@Data
+public class IotPestRecogPeriodInfoResVo {
+    private static final long serialVersionUID = 1L;
+
+    private String alias;
+    private String calamRemark;
+    private String course;
+    private String crops;
+    private String endInPeriod;
+    private String fastigium;
+    private String pic;
+    private String seeTimes;
+    private String pestName;
+}

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/domain/IotPestRecogPeriodReqVo.java

@@ -67,4 +67,6 @@ public class IotPestRecogPeriodReqVo {
     private String cbdrecogMarktype;
 
     private List<String> cbdrecogBids;
+
+    private String pestName;
 }

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/IIotPestService.java

@@ -83,6 +83,8 @@ public interface IIotPestService
 
     IoPestResVo selectIotPestDetailByPestBid(String pestBid);
 
+    IoPestResVo selectIotPestDetailByPestName(String pestName);
+
     String selectIotPestCropsByCalarmId(String calarmId);
 
     IotPest selectIotPestByPestName(IotPest iotPest);

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

@@ -24,5 +24,5 @@ public interface IIotPestrecogService {
     public List<IotXyinfoPestTotalDto> getIotXyinfoPestTotal(List<String> devBidList);
     public Map<String, IotXyinfoPestTotalDto> getIotXyinfoPestTotalMap(List<String> devBidList);
 
-    public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo);
+    public IotPestRecogPeriodInfoResVo period(IotPestRecogPeriodReqVo reqVo);
 }

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

@@ -161,6 +161,11 @@ public class IotPestServiceImpl implements IIotPestService
     }
 
     @Override
+    public IoPestResVo selectIotPestDetailByPestName(String pestName) {
+        return iotPestMapper.selectIotPestDetailByPestName(pestName);
+    }
+
+    @Override
     public String selectIotPestCropsByCalarmId(String calarmId) {
         return iotPestMapper.selectIotPestCropsByCalarmId(calarmId);
     }

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

@@ -1,11 +1,13 @@
 package com.yunfeiyun.agmp.iotm.device.pest.service.impl;
 
-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.domain.*;
+import com.yunfeiyun.agmp.iot.common.domain.IotCbdimg;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iot.common.domain.IotPest;
+import com.yunfeiyun.agmp.iot.common.domain.IotYfXycb2data;
 import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
 import com.yunfeiyun.agmp.iot.common.enums.EnumCbdMarkType;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
@@ -16,6 +18,7 @@ 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 lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.mongodb.core.aggregation.*;
@@ -492,101 +495,86 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
      * @param reqVo
      */
     @Override
-    public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo) {
-        String devBid = reqVo.getDevBid();
+    public IotPestRecogPeriodInfoResVo period(IotPestRecogPeriodReqVo reqVo) {
         String startTime = reqVo.getStartTime();
         String endTime = reqVo.getEndTime();
+        String devBid = reqVo.getDevBid();
+        String cbdrecogType = reqVo.getCbdrecogType();
+        String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
         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 = new Criteria()
+                .and("devBid").is(devBid)
+                .and("cbdimgDelstatus").is("0")
+                .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid").is(pestBusid);
+
+        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
             criteria = criteria.andOperator(
-                    Criteria.where("pestrecogCreatedDate").gte(startTime),
-                    Criteria.where("pestrecogCreatedDate").lte(endTime)
+                    Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime),
+                    Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime)
             );
         } else if (StringUtils.isNotEmpty(startTime)) {
-            criteria = criteria.and("pestrecogCreatedDate").gte(startTime);
+            criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime);
         } else if (StringUtils.isNotEmpty(endTime)) {
-            criteria = criteria.and("pestrecogCreatedDate").lte(endTime);
+            criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").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");
+        ProjectionOperation projectionOperation = Aggregation.project()
+                .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype).as("pestrecog");
 
-        SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "date");
+        UnwindOperation unwindOperation = Aggregation.unwind("pestrecog", false);
 
-        GroupOperation groupOperation2 = Aggregation.group()
-                .push("$$ROOT").as("dataList");
+        Criteria criteria2 = new Criteria().and("pestrecog.pestBusid").is(pestBusid);
+        MatchOperation matchOperation2 = Aggregation.match(criteria2);
 
-        ProjectionOperation projectionOperation3 = Aggregation.project()
-                .and("dataList").as("dataList")
-                .andExpression("{'$first': '$dataList'}").as("seeTimeInfo")
-                .andExpression("{'$last': '$dataList'}").as("endInPeriodInfo");
+        ProjectionOperation projectionOperation2 = Aggregation.project()
+                .and("pestrecog.pestBusid").as("pestBusid")
+                .and("pestrecog.pestName").as("pestName")
+                .and("pestrecog.pestrecogNum").as("pestrecogNum")
+                .and("pestrecog.pestrecogCreatedDate").as("pestrecogCreatedDate");
 
-        UnwindOperation unwindOperation = Aggregation.unwind("dataList");
+        SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "pestrecogCreatedDate");
 
-        SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.DESC, "dataList.pestrecogNum");
+        Map<String, String> dataMap = new HashMap<>();
+        dataMap.put("pestrecogNum", "$pestrecogNum");
+        dataMap.put("pestrecogCreatedDate", "$pestrecogCreatedDate");
 
-        LimitOperation limitOperation = Aggregation.limit(1);
+        GroupOperation groupOperation = Aggregation.group()
+                .first("pestName").as("pestName")
+                .push(dataMap).as("dataList");
 
-        ProjectionOperation projectionOperation4 = Aggregation.project()
-                .and("seeTimeInfo").as("seeTimeInfo")
-                .and("endInPeriodInfo").as("endInPeriodInfo")
-                .and("dataList").as("fastigiumInfo");
+        ProjectionOperation projectionOperationResult = Aggregation.project()
+                .and("pestName").as("pestName")
+                .andExpression("{'$substrBytes': {{'$first': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("seeTimes")
+                .andExpression("{'$substrBytes': {{'$last': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("endInPeriod")
+                .andExpression("{'$substrBytes': {{'$max': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("fastigium");
 
         Aggregation aggregation = Aggregation.newAggregation(
                 matchOperation,
                 projectionOperation,
-                groupOperation,
+                unwindOperation,
+                matchOperation2,
                 projectionOperation2,
                 sortOperation,
-                groupOperation2,
-                projectionOperation3,
-                unwindOperation,
-                sortOperation2,
-                limitOperation,
-                projectionOperation4
+                groupOperation,
+                projectionOperationResult
         );
-        List<JSONObject> jsonObjectList = mongoService.aggregate(
-                IotPestrecog.class, aggregation, JSONObject.class
+        List<IotPestRecogPeriodInfoResVo> infoResVoList = mongoService.aggregate(
+                IotCbdimg.class, aggregation, IotPestRecogPeriodInfoResVo.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();
+        IotPestRecogPeriodInfoResVo result = new IotPestRecogPeriodInfoResVo();
+        if(infoResVoList != null && infoResVoList.size() > 0){
+            result = infoResVoList.get(0);
+            IoPestResVo ioPestResVo = null;
+            if(Objects.equals(cbdrecogMarktype, EnumCbdMarkType.AUTO.getCode())){
+                ioPestResVo = iotPestService.selectIotPestDetailByPestBid(pestBusid);
+            }else{
+                ioPestResVo = iotPestService.selectIotPestDetailByPestName(pestBusid);
+            }
+            BeanUtils.copyProperties(ioPestResVo, result);
         }
-        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;
+        return result;
     }
 }

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotPestMapper.java

@@ -72,4 +72,6 @@ public interface IotPestMapper
     String selectIotPestCropsByCalarmId(@Param("calarmId")  String calarmId);
 
     IotPest selectIotPestByPestName(IotPest iotPest);
+
+    IoPestResVo selectIotPestDetailByPestName(String pestName);
 }

+ 9 - 0
src/main/resources/mapper/IotPestMapper.xml

@@ -76,6 +76,15 @@ SELECT * from  IotPest where pestBid=#{pestBid}
         </where>
         limit 1
     </select>
+    <select id="selectIotPestDetailByPestName" parameterType="String"
+            resultType="com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo">
+        SELECT b.calarmCloudresurl pic , b.calamRemark ,CONCAT(b.calamFamilies,b.calamOrders) course ,b.calarmId
+        from (
+            SELECT * from IotPest where pestName=#{pestName} order by id desc limit 1
+        ) a
+        LEFT JOIN FmsCalarm b on calarmName = a.pestName
+        limit 0,1
+    </select>
 
     <insert id="insertIotPest" parameterType="IotPest" useGeneratedKeys="true" keyProperty="id">
         insert into IotPest