Browse Source

Merge branch 'develop' of com_yunfei_saas/agmp_iotm into master

yf_zn 1 year atrás
parent
commit
44d93f1fa7
31 changed files with 707 additions and 270 deletions
  1. 4 6
      src/main/java/com/yunfeiyun/agmp/iotm/device/bzy/controller/IotDeviceBzyController.java
  2. 5 17
      src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotDeviceCbdController.java
  3. 8 0
      src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/IIotPestService.java
  4. 12 0
      src/main/java/com/yunfeiyun/agmp/iotm/device/pest/service/impl/IotPestServiceImpl.java
  5. 12 22
      src/main/java/com/yunfeiyun/agmp/iotm/device/qxsqz/controller/IotDeviceQxzController.java
  6. 3 3
      src/main/java/com/yunfeiyun/agmp/iotm/device/qxsqz/service/IIotQxzCommService.java
  7. 3 13
      src/main/java/com/yunfeiyun/agmp/iotm/device/scd/controller/IotDeviceScdController.java
  8. 3 14
      src/main/java/com/yunfeiyun/agmp/iotm/device/xycb/controller/IotXycbController.java
  9. 13 9
      src/main/java/com/yunfeiyun/agmp/iotm/device/ybq/controller/IotYbqController.java
  10. 6 5
      src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotWarnconfigController.java
  11. 9 1
      src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotWarnindicatorController.java
  12. 8 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/domain/IotWarnPestVo.java
  13. 9 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotPestMapper.java
  14. 2 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarncountMapper.java
  15. 10 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarnindicatorMapper.java
  16. 8 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarnobjectMapper.java
  17. 3 3
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnconfigService.java
  18. 4 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarncountService.java
  19. 35 1
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnindicatorService.java
  20. 8 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnobjectService.java
  21. 3 1
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceServiceImpl.java
  22. 306 132
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnconfigServiceImpl.java
  23. 12 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarncountServiceImpl.java
  24. 138 37
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnindicatorServiceImpl.java
  25. 12 0
      src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnobjectServiceImpl.java
  26. 7 0
      src/main/resources/mapper/IotDeviceMapper.xml
  27. 12 0
      src/main/resources/mapper/IotPestMapper.xml
  28. 7 5
      src/main/resources/mapper/IotWarnconfigMapper.xml
  29. 7 0
      src/main/resources/mapper/IotWarncountMapper.xml
  30. 31 1
      src/main/resources/mapper/IotWarnindicatorMapper.xml
  31. 7 0
      src/main/resources/mapper/IotWarnobjectMapper.xml

+ 4 - 6
src/main/java/com/yunfeiyun/agmp/iotm/device/bzy/controller/IotDeviceBzyController.java

@@ -24,6 +24,7 @@ import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotBzydataReqVo;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.bzy.domain.IotBzyDeviceDataListResVo;
 import com.yunfeiyun.agmp.iotm.device.bzy.domain.IotYfBzyPolylineResVo;
@@ -171,9 +172,7 @@ public class IotDeviceBzyController extends BaseController {
     public AjaxResult takePhoto(@PathVariable("devBid") String devBid) {
         log.info("【{}】【孢子仪】【拍照】客户id {}", LogCore.getSeq(), getCustomerId());
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if (iotDevice == null) {
-            throw new IotBizException(ErrorCode.FAILURE.getCode(),"设备不存在");
-        }
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
 
         IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
         iotDeviceconfig.setTid(iotDevice.getTid());
@@ -224,9 +223,8 @@ public class IotDeviceBzyController extends BaseController {
             throw new IotBizException(ErrorCode.FAILURE.getCode(),"设备id不可为空");
         }
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if (iotDevice == null) {
-            throw new IotBizException(ErrorCode.FAILURE.getCode(),"设备不存在");
-        }
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
+
         IotDeviceconfig iotDeviceconfig = iIotDeviceconfigService.selectIotDeviceConfigByDevBid(devBid);
         if (null == iotDeviceconfig) {
             // 如果测报灯配置为空,则新增测报灯配置

+ 5 - 17
src/main/java/com/yunfeiyun/agmp/iotm/device/pest/controller/IotDeviceCbdController.java

@@ -8,15 +8,15 @@ 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.log.LogCore;
-import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotCbdimg;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotCbdConfigEditReqVo;
-import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
+import com.yunfeiyun.agmp.iot.common.enums.EnumDevRecogType;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
@@ -177,8 +177,8 @@ public class IotDeviceCbdController extends BaseController {
         devBidList.add(devInfo.getDevBid());
         Map<String, Long> imgCountMap = getImgCountMap(devBidList);
         devInfo.setImgCount(imgCountMap.getOrDefault(devBid, 0L));
-        if(!"1".equals(devInfo.getDevRecogtype())){
-            devInfo.setDevRecogtype("0");
+        if(!EnumDevRecogType.PEST_RECOG.getCode().equals(devInfo.getDevRecogtype())){
+            devInfo.setDevRecogtype(EnumDevRecogType.DISABLE.getCode());
         }
         return success(devInfo);
     }
@@ -195,20 +195,8 @@ public class IotDeviceCbdController extends BaseController {
         log.info("【{}】【测报灯】【下发指令配置】客户id {}", LogCore.getSeq(), getCustomerId());
         String devBid = reqVo.getDevBid();
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if(iotDevice == null){
-            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
-        }
 
-        String devStatus = iotDevice.getDevStatus();
-        String devCreateddate = iotDevice.getDevCreateddate();
-        Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
-        Date nowDate = DateUtils.getNowDate();
-        long diffTime = nowDate.getTime() - createdDate.getTime();
-        if(diffTime > 10 * 1000){
-            if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
-                throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
-            }
-        }
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
 
         reqVo.setIotDevice(iotDevice);
 

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

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iotm.device.pest.service;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotPest;
 import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.IotWarnPestVo;
 
 import java.util.List;
 import java.util.Map;
@@ -88,4 +89,11 @@ public interface IIotPestService
     String selectIotPestCropsByCalarmId(String calarmId);
 
     IotPest selectIotPestByPestName(IotPest iotPest);
+
+    /**
+     * 查询告警关联的害虫信息列表
+     * @param warnPestVo
+     * @return
+     */
+    public List<IotPest> selectIotWarnPestList(IotWarnPestVo warnPestVo);
 }

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

@@ -5,6 +5,7 @@ import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
 import com.yunfeiyun.agmp.iot.common.domain.IotPest;
 import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
 import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
+import com.yunfeiyun.agmp.iotm.web.domain.IotWarnPestVo;
 import com.yunfeiyun.agmp.iotm.web.mapper.IotPestMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -174,4 +175,15 @@ public class IotPestServiceImpl implements IIotPestService
     public IotPest selectIotPestByPestName(IotPest iotPest) {
         return iotPestMapper.selectIotPestByPestName(iotPest);
     }
+
+    /**
+     * 查询告警关联的害虫信息列表
+     *
+     * @param warnPestVo
+     * @return
+     */
+    @Override
+    public List<IotPest> selectIotWarnPestList(IotWarnPestVo warnPestVo) {
+        return iotPestMapper.selectIotWarnPestList(warnPestVo);
+    }
 }

+ 12 - 22
src/main/java/com/yunfeiyun/agmp/iotm/device/qxsqz/controller/IotDeviceQxzController.java

@@ -5,15 +5,14 @@ import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.log.LogCore;
-import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.common.utils.poi.SensdataExcelUtil;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotQxzDataListRseVo;
-import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
-import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
@@ -33,7 +32,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * 气象站,墒情站 设备控制器
@@ -74,15 +75,15 @@ public class IotDeviceQxzController extends BaseController {
         String[] devTypeList = null;
 
         if(reqUri.endsWith("/qxz/list")){
-            devTypeList = QxzTypeUtil.getAllQxzTypes();
+            devTypeList = DevTypeUtil.getAllQxzTypes();
         }else if(reqUri.endsWith("/qxz/pt/list")){
-            devTypeList = QxzTypeUtil.getPtQxzTypes();
+            devTypeList = DevTypeUtil.getPtQxzTypes();
         } else if (reqUri.endsWith("/sqz/list")) {
-            devTypeList = QxzTypeUtil.getAllSqzTypes();
+            devTypeList = DevTypeUtil.getAllSqzTypes();
         } else if (reqUri.endsWith("/sqz/pt/list")) {
-            devTypeList = QxzTypeUtil.getPtSqzTypes();
+            devTypeList = DevTypeUtil.getPtSqzTypes();
         } else if (reqUri.endsWith("/sqz/gssq/list")) {
-            devTypeList = QxzTypeUtil.getGssqTypes();
+            devTypeList = DevTypeUtil.getGssqTypes();
         }
         List<IotDeviceListResVo> list = null;
         if (devTypeList != null) {
@@ -269,19 +270,8 @@ public class IotDeviceQxzController extends BaseController {
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
         }
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if(iotDevice == null){
-            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
-        }
-        String devStatus = iotDevice.getDevStatus();
-        String devCreateddate = iotDevice.getDevCreateddate();
-        Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
-        Date nowDate = DateUtils.getNowDate();
-        long diffTime = nowDate.getTime() - createdDate.getTime();
-        if(diffTime > 10 * 1000){
-            if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
-                throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
-            }
-        }
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
 
         reqVo.setIotDevice(iotDevice);
 

+ 3 - 3
src/main/java/com/yunfeiyun/agmp/iotm/device/qxsqz/service/IIotQxzCommService.java

@@ -20,7 +20,7 @@ import com.yunfeiyun.agmp.iot.common.domain.*;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
-import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
 import com.yunfeiyun.agmp.iotm.device.common.domin.DeviceRefreshDto;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
@@ -66,9 +66,9 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
 
     public Class getTableClass(String devtypeBid) {
         Class tableClass = null;
-        if(QxzTypeUtil.isXphYfQxSq(devtypeBid)){
+        if(DevTypeUtil.isXphYfQxSq(devtypeBid)){
             tableClass = IotXphYfqxzdata.class;
-        }else if(QxzTypeUtil.isYfQxSq(devtypeBid)){
+        }else if(DevTypeUtil.isYfQxSq(devtypeBid)){
             tableClass = IotYfqxzdata.class;
         }else if (devtypeBid.equals(IotDeviceDictConst.TYPE_ADZN_GSSQ)) {
             tableClass = IotAdznGssqdata.class;

+ 3 - 13
src/main/java/com/yunfeiyun/agmp/iotm/device/scd/controller/IotDeviceScdController.java

@@ -13,6 +13,7 @@ import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconfig;
 import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
@@ -241,19 +242,8 @@ public class IotDeviceScdController extends BaseController {
         }
 
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if(iotDevice == null){
-            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
-        }
-        String devStatus = iotDevice.getDevStatus();
-        String devCreateddate = iotDevice.getDevCreateddate();
-        Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
-        Date nowDate = DateUtils.getNowDate();
-        long diffTime = nowDate.getTime() - createdDate.getTime();
-        if(diffTime > 10 * 1000){
-            if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
-                throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
-            }
-        }
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
 
         reqVo.setIotDevice(iotDevice);
 

+ 3 - 14
src/main/java/com/yunfeiyun/agmp/iotm/device/xycb/controller/IotXycbController.java

@@ -12,9 +12,9 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotPest;
 import com.yunfeiyun.agmp.iot.common.domain.IotXycbimg;
-import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
@@ -353,19 +353,8 @@ public class IotXycbController extends BaseController
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
         }
         IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-        if(iotDevice == null){
-            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
-        }
-        String devStatus = iotDevice.getDevStatus();
-        String devCreateddate = iotDevice.getDevCreateddate();
-        Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
-        Date nowDate = DateUtils.getNowDate();
-        long diffTime = nowDate.getTime() - createdDate.getTime();
-        if(diffTime > 10 * 1000){
-            if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
-                throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
-            }
-        }
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
 
         reqVo.setIotDevice(iotDevice);
 

+ 13 - 9
src/main/java/com/yunfeiyun/agmp/iotm/device/ybq/controller/IotYbqController.java

@@ -3,8 +3,10 @@ package com.yunfeiyun.agmp.iotm.device.ybq.controller;
 import cn.hutool.core.bean.BeanUtil;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 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.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
@@ -120,20 +122,22 @@ public class IotYbqController extends BaseController {
         if (StringUtils.isEmpty(ybqType)) {
             throw new IotBizException(IotErrorCode.FAILURE.getCode(), "数据类型不可为空");
         }
+        String startDate = reqVo.getStartDate();
+        String endDate = reqVo.getEndDate();
         Map<String, Object> map = BeanUtil.beanToMap(reqVo);
         // 预测时间可能会被更新,所以用修改时间,创建时候这个值会默认有
-        if (StringUtils.isNotEmpty(reqVo.getStartDate()) && StringUtils.isEmpty(reqVo.getEndDate())) {
-            map.put("gte_ybqdataModifiedDate", reqVo.getStartDate());
-        }
-        if (StringUtils.isEmpty(reqVo.getStartDate()) && StringUtils.isNotEmpty(reqVo.getEndDate())) {
-            map.put("lte_ybqdataModifiedDate", reqVo.getEndDate());
-        }
-        if (StringUtils.isNotEmpty(reqVo.getStartDate()) && StringUtils.isNotEmpty(reqVo.getEndDate())) {
-            map.put("time_ybqdataModifiedDate", reqVo.getStartDate() + "," + reqVo.getEndDate());
+        if (StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate)) {
+            startDate = DateUtils.parseDateToStr("yyyyMMdd", DateUtils.parseDate(startDate));
+            endDate = DateUtils.parseDateToStr("yyyyMMdd", DateUtils.parseDate(endDate));
+            map.put("timeStr_computeDate", startDate + "," + endDate);
         }
         map.remove("startDate");
         map.remove("endDate");
-        return getDataTable(mongoService.findListPage(IotYbqPredictData.class, map, TableSupport.buildPageRequest()));
+
+        PageDomain queryRequest = TableSupport.buildPageRequest();
+        queryRequest.setOrderByColumn("computeDate asc,ybqdataCreatedDate asc");
+        queryRequest.setIsAsc("desc");
+        return getDataTable(mongoService.findListPage(IotYbqPredictData.class, map, queryRequest));
     }
 
 

+ 6 - 5
src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotWarnconfigController.java

@@ -1,5 +1,6 @@
 package com.yunfeiyun.agmp.iotm.web.controller;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.annotation.Log;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.controller.BaseController;
@@ -46,10 +47,10 @@ public class IotWarnconfigController extends BaseController{
         List<IotWarnconfigResVo> list = iotWarnconfigService.selectIotWarnconfigResVoList(iotWarnconfig);
         return getDataTable(list);
     }
-    @PreAuthorize("@ss.hasPermi('iot:warn:config:list')")
-    @GetMapping("/dev/info/{devBids}")
-    public AjaxResult devConfigInfo(@PathVariable String[] devBids){
-        return AjaxResult.success(iotWarnconfigService.devConfigInfo(devBids));
+    @GetMapping("/dev/interval/{devBid}")
+    public AjaxResult devInterval(@PathVariable String devBid){
+        JSONObject jsonObject = iotWarnconfigService.devInterval(devBid);
+        return success(jsonObject);
     }
 
     @PreAuthorize("@ss.hasPermi('iot:warn:config:add')")
@@ -80,7 +81,7 @@ public class IotWarnconfigController extends BaseController{
     @PreAuthorize("@ss.hasPermi('iot:warn:config:query')")
     @GetMapping(value = "/info/{wcBid}")
     public AjaxResult getInfo(@PathVariable("wcBid") String wcBid){
-        return success(iotWarnconfigService.info(wcBid,SecurityUtils.getTid()));
+        return success(iotWarnconfigService.info(wcBid));
     }
 
     /**

+ 9 - 1
src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotWarnindicatorController.java

@@ -43,7 +43,7 @@ public class IotWarnindicatorController extends BaseController{
     }
 
     /**
-     * 查询告警要素列表
+     * 查询气象墒情告警要素列表
      */
     @PreAuthorize("@ss.hasPermi('iot:warn:indicator:list')")
     @GetMapping("/query")
@@ -51,6 +51,14 @@ public class IotWarnindicatorController extends BaseController{
         return AjaxResult.success(iotWarnindicatorService.query(iotDevice));
     }
 
+    /**
+     * 查询虫情列表
+     */
+    @GetMapping("/pest/list")
+    public AjaxResult pestList(String devBid){
+        return AjaxResult.success(iotWarnindicatorService.pestList(devBid));
+    }
+
 
     /**
      * 导出告警指标,存储所有与告警相关的指标信息列表

+ 8 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/domain/IotWarnPestVo.java

@@ -0,0 +1,8 @@
+package com.yunfeiyun.agmp.iotm.web.domain;
+
+import lombok.Data;
+
+@Data
+public class IotWarnPestVo {
+    private String devType;
+}

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

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iotm.web.mapper;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotPest;
 import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.IotWarnPestVo;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -74,4 +75,12 @@ public interface IotPestMapper
     IotPest selectIotPestByPestName(IotPest iotPest);
 
     IoPestResVo selectIotPestDetailByPestName(String pestName);
+
+    /**
+     * 查询预警害虫信息列表
+     *
+     * @param iotPest 害虫信息
+     * @return 害虫信息集合
+     */
+    public List<IotPest> selectIotWarnPestList(IotWarnPestVo warnPestVo);
 }

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

@@ -61,4 +61,6 @@ public interface IotWarncountMapper {
     public int deleteIotWarncountByWctBids(@Param("array") String[] ids, @Param("tid") String tid);
 
     public int deleteIotWarncountByDevBidAndWcBid(@Param("devBid") String devBid, @Param("wcBid") String wcBid, @Param("tid") String tid);
+
+    public int deleteIotWarncountByWcBids(@Param("array") String[] wcBids, @Param("tid") String tid);
 }

+ 10 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarnindicatorMapper.java

@@ -62,4 +62,14 @@ public interface IotWarnindicatorMapper {
     public int deleteIotWarnindicatorByWiBids(@Param("array") String[] ids, @Param("tid") String tid);
 
     int deleteIotWarnindicatorByWcBid(@Param("wcBid") String wcBid,@Param("tid")String tid);
+
+    /**
+     * 新增告警指标,存储所有与告警相关的指标信息
+     *
+     * @param iotWarnindicator 告警指标,存储所有与告警相关的指标信息
+     * @return 结果
+     */
+    public int insertIotWarnindicatorBatch(List<IotWarnindicator> iotWarnindicator);
+
+    int deleteIotWarnindicatorByWcBids(@Param("array") String[] wcBids, @Param("tid") String tid);
 }

+ 8 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarnobjectMapper.java

@@ -65,4 +65,12 @@ public interface IotWarnobjectMapper {
     List<IotWarnobjectResVo> selectIotWarnobjectResVoList(IotWarnobject iotWarnobject);
 
     List<IotWarnobject> selectIotWarnobjectListByWcBids(@Param("list") List<String> wcBids,@Param("tid") String tid);
+
+    /**
+     * 批量删除告警对象
+     *
+     * @param woBids 需要删除的告警对象主键集合
+     * @return 结果
+     */
+    public int deleteIotWarnobjectByWcBids(@Param("array") String[] wcBids, @Param("tid") String tid);
 }

+ 3 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnconfigService.java

@@ -1,6 +1,6 @@
 package com.yunfeiyun.agmp.iotm.web.service;
 
-import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconfig;
+import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigAddReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigEditReqVo;
@@ -72,9 +72,9 @@ public interface IIotWarnconfigService {
 
     int edit(@Valid IotWarnconfigEditReqVo iotWarnconfigEditReqVo);
 
-    IotWarnconfigInfoResVo info(String wcBid, String tid);
+    IotWarnconfigInfoResVo info(String wcBid);
 
-    IotDeviceconfig devConfigInfo(String[] devBids);
+    public JSONObject devInterval(String devBid);
 
     IotWarnconfig copy(String wcBid);
 

+ 4 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarncountService.java

@@ -59,4 +59,8 @@ public interface IIotWarncountService {
      * @return 结果
      */
     public int deleteIotWarncountByWctBid(String wctBid, String tid);
+
+    public int deleteIotWarncountByDevBidAndWcBid(String devBid, String wcBid, String tid);
+
+    public int deleteIotWarncountByWcBids(String[] wcBids, String tid);
 }

+ 35 - 1
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnindicatorService.java

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iotm.web.service;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iot.common.domain.IotPest;
 import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
 
 import java.util.List;
@@ -62,5 +63,38 @@ public interface IIotWarnindicatorService {
     public int deleteIotWarnindicatorByWiBid(String wiBid, String tid);
 
     List<IotWarnindicator> query(IotDevice iotDevice);
-    public List<IotWarnindicator> warnindicatorDevQuery(IotDevice iotDevice);
+    /**
+     * 查询气象墒情告警要素列表
+     * @param iotDevice
+     * @return
+     */
+    public List<IotWarnindicator> warnindicatorDevQueryByQxSq(IotDevice iotDevice);
+
+    /**
+     * 查询测报灯告警要素列表
+     * @param iotDevice
+     * @return
+     */
+    public List<IotWarnindicator> warnindicatorDevQueryByCbd(IotDevice iotDevice);
+
+    /**
+     * 查询虫情列表
+     * @param iotDevice
+     * @return
+     */
+    List<IotPest> pestList(String devBid);
+
+    /**
+     * 批量新增告警指标
+     *
+     * @param iotWarnindicator
+     * @return 结果
+     * @param iotWarnindicator
+     * @return
+     */
+    public int insertIotWarnindicatorBatch(List<IotWarnindicator> iotWarnindicator);
+
+    int deleteIotWarnindicatorByWcBid(String wcBid, String tid);
+
+    int deleteIotWarnindicatorByWcBids(String[] wcBids, String tid);
 }

+ 8 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotWarnobjectService.java

@@ -68,4 +68,12 @@ public interface IIotWarnobjectService {
      * @return 结果
      */
     public int deleteIotWarnobjectByWoBid(String woBid, String tid);
+
+    /**
+     * 批量删除告警对象
+     *
+     * @param woBids 需要删除的告警对象主键集合
+     * @return 结果
+     */
+    public int deleteIotWarnobjectByWcBids(String[] wcBids, String tid);
 }

+ 3 - 1
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceServiceImpl.java

@@ -265,11 +265,12 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
      * 查询设备基础列表
      *
      * @param iotDevice 设备基础
+     * @param isTid 是否查询租户ID,true查询当前租户下的设备,false 查询全局所有设备
      * @return 设备基础
      */
     public List<IotDevice> selectIotDeviceList(IotDevice iotDevice, boolean isTid) {
         // 生产环境
-        if ("0".equals(runMode) && !isTid) {
+        if (!isTid) {
             iotDevice.setTid(null);
         } else {
             iotDevice.setTid(SecurityUtils.getTid());
@@ -383,6 +384,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
         List<String> devtypeBidList = IotMqttConstant.getDevtypeBidList(devtypeBid);
         IotDevice selectIotDevice = new IotDevice();
         selectIotDevice.setDevtypeBidList(devtypeBidList);
+        selectIotDevice.setDevCodeList(Arrays.asList(devCode));
         List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice, false);
 
         Set<String> newDevCodeSet = new HashSet<>(Arrays.asList(devCode));

+ 306 - 132
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnconfigServiceImpl.java

@@ -1,8 +1,10 @@
 package com.yunfeiyun.agmp.iotm.web.service.impl;
 
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
 import com.yunfeiyun.agmp.common.exception.BizException;
 import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
@@ -14,13 +16,23 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
 import com.yunfeiyun.agmp.iot.common.domain.*;
 import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnTouchTypeEnum;
 import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnlevelEnum;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.QxElementTypeUtil;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigAddReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigEditReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigInfoResVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigResVo;
-import com.yunfeiyun.agmp.iotm.web.mapper.*;
+import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceMapper;
+import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceconfigMapper;
+import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnconfigMapper;
+import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnobjectMapper;
 import com.yunfeiyun.agmp.iotm.web.service.IIotWarnconfigService;
+import com.yunfeiyun.agmp.iotm.web.service.IIotWarncountService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotWarnindicatorService;
+import com.yunfeiyun.agmp.iotm.web.service.IIotWarnobjectService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,13 +40,13 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
  * 告警配置Service业务层处理
- * 
+ *
  * @author 杨晓辉
  * @date 2025-03-07
  */
@@ -45,70 +57,79 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
     @Resource
     private IotWarnobjectMapper iotWarnobjectMapper;
     @Resource
-    private IotWarnindicatorMapper iotWarnindicatorMapper;
-    @Resource
     private IotDeviceMapper iotDeviceMapper;
     @Resource
     private IotDeviceconfigMapper iotDeviceconfigMapper;
     @Resource
     private RedisCacheManager redisCacheManager;
-    @Resource
-    private IotWarncountMapper iotWarncountMapper;
+
     @Resource
     private IIotWarnindicatorService iotWarnindicatorService;
 
+    @Resource
+    private IotDeviceCommonService iotDeviceCommonService;
+
+    @Autowired
+    private IIotWarnobjectService iotWarnobjectService;
+
+    @Autowired
+    private IIotWarncountService iIotWarncountService;
+
+
     /**
      * 查询告警配置
-     * 
+     *
      * @param wcBid 告警配置主键
      * @return 告警配置
      */
     @Override
-    public IotWarnconfig selectIotWarnconfigByWcBid(String wcBid, String tid){
+    public IotWarnconfig selectIotWarnconfigByWcBid(String wcBid, String tid) {
 
         return iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid, tid);
     }
+
     /**
      * 查询告警配置列表
-     * 
+     *
      * @param iotWarnconfig 告警配置
      * @return 告警配置
      */
     @Override
-    public List<IotWarnconfig> selectIotWarnconfigList(IotWarnconfig iotWarnconfig){
+    public List<IotWarnconfig> selectIotWarnconfigList(IotWarnconfig iotWarnconfig) {
         return iotWarnconfigMapper.selectIotWarnconfigList(iotWarnconfig);
     }
+
     /**
      * 查询告警配置列表
-     * */
+     */
     @Override
     public List<IotWarnconfigResVo> selectIotWarnconfigResVoList(IotWarnconfig iotWarnconfig) {
         List<IotWarnconfigResVo> iotWarnconfigResVoList = iotWarnconfigMapper.selectIotWarnconfigResVoList(iotWarnconfig);
         List<String> wcBids = new ArrayList<>();
-        Map<String,IotWarnconfigResVo> map = new HashMap<>();
-        for(IotWarnconfigResVo iotWarnconfigResVo : iotWarnconfigResVoList){
+        Map<String, IotWarnconfigResVo> map = new HashMap<>();
+        for (IotWarnconfigResVo iotWarnconfigResVo : iotWarnconfigResVoList) {
             iotWarnconfigResVo.setDevtypeName(IotDeviceDictEnum.getNameByCode(iotWarnconfigResVo.getDevtypeBid()));
             iotWarnconfigResVo.setWcTouchtypeName(IotWarnTouchTypeEnum.findByCode(iotWarnconfigResVo.getWcTouchtype()).getContent());
             iotWarnconfigResVo.setWcLevelName(IotWarnlevelEnum.findByCode(iotWarnconfigResVo.getWcLevel()).getContent());
             iotWarnconfigResVo.setIotDeviceList(new ArrayList<>());
             iotWarnconfigResVo.setSysUserList(new ArrayList<>());
             wcBids.add(iotWarnconfigResVo.getWcBid());
-            map.put(iotWarnconfigResVo.getWcBid(),iotWarnconfigResVo);
+            map.put(iotWarnconfigResVo.getWcBid(), iotWarnconfigResVo);
         }
-        if(!wcBids.isEmpty()){
+        if (!wcBids.isEmpty()) {
             // 填充设备信息
-            List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectListByWcBids(wcBids,SecurityUtils.getTid());
-            Map<String,List<IotWarnobject>> iotWarnobjectMap = iotWarnobjectList.stream().collect(Collectors.groupingBy(IotWarnobject::getDevBid));
-            if(!iotWarnobjectMap.isEmpty()){
-                List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(new ArrayList<>(iotWarnobjectMap.keySet()),SecurityUtils.getTid());
-                for(IotDevice iotDevice : iotDeviceList){
+            List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectListByWcBids(wcBids, SecurityUtils.getTid());
+            Map<String, List<IotWarnobject>> iotWarnobjectMap = iotWarnobjectList.stream().collect(Collectors.groupingBy(IotWarnobject::getDevBid));
+            if (!iotWarnobjectMap.isEmpty()) {
+                List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(new ArrayList<>(iotWarnobjectMap.keySet()), SecurityUtils.getTid());
+                for (IotDevice iotDevice : iotDeviceList) {
                     List<IotWarnobject> devWarnObjectList = iotWarnobjectMap.get(iotDevice.getDevBid());
-                    if(null == devWarnObjectList){
+                    if (null == devWarnObjectList) {
                         continue;
                     }
-                    for(IotWarnobject iotWarnobject : devWarnObjectList){
+                    for (IotWarnobject iotWarnobject : devWarnObjectList) {
                         IotWarnconfigResVo iotWarnconfigResVo = map.get(iotWarnobject.getWcBid());
-                        if(null != iotWarnconfigResVo){
+                        if (null != iotWarnconfigResVo) {
                             iotWarnconfigResVo.getIotDeviceList().add(iotDevice);
                         }
                     }
@@ -124,47 +145,100 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
 
     /**
      * 新增告警配置
-     * 
+     *
      * @param iotWarnconfig 告警配置
      * @return 结果
      */
     @Override
-    public int insertIotWarnconfig(IotWarnconfig iotWarnconfig){
+    public int insertIotWarnconfig(IotWarnconfig iotWarnconfig) {
         return iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfig);
     }
 
     /**
      * 修改告警配置
-     * 
+     *
      * @param iotWarnconfig 告警配置
      * @return 结果
      */
     @Override
-    public int updateIotWarnconfig(IotWarnconfig iotWarnconfig){
+    public int updateIotWarnconfig(IotWarnconfig iotWarnconfig) {
         return iotWarnconfigMapper.updateIotWarnconfig(iotWarnconfig);
     }
 
     /**
      * 批量删除告警配置
-     * 
+     *
      * @param wcBids 需要删除的告警配置主键
      * @return 结果
      */
+    @Transactional(rollbackFor = Exception.class)
     @Override
-    public int deleteIotWarnconfigWcBids(String[] wcBids, String tid){
-        return iotWarnconfigMapper.deleteIotWarnconfigWcBids(wcBids, tid);
+    public int deleteIotWarnconfigWcBids(String[] wcBids, String tid) {
+        int status = iotWarnconfigMapper.deleteIotWarnconfigWcBids(wcBids, tid);
+        iIotWarncountService.deleteIotWarncountByWcBids(wcBids, tid);
+        iotWarnindicatorService.deleteIotWarnindicatorByWcBids(wcBids, tid);
+        iotWarnobjectService.deleteIotWarnobjectByWcBids(wcBids, tid);
+        return status;
     }
 
     /**
      * 删除告警配置信息
-     * 
+     *
      * @param wcBid 告警配置主键
      * @return 结果
      */
     @Override
-    public int deleteIotWarnconfigByWcBid(String wcBid, String tid){
+    public int deleteIotWarnconfigByWcBid(String wcBid, String tid) {
         return iotWarnconfigMapper.deleteIotWarnconfigByWcBid(wcBid, tid);
     }
+
+    private void addWarnindicator(String wcBid, List<IotWarnindicator> iotWarnindicatorList) {
+        String createDate = DateUtils.dateTimeNow();
+        String wiCreator = SecurityUtils.getUserId();
+        String tid = SecurityUtils.getTid();
+        List<IotWarnindicator> insertList = new ArrayList<>();
+
+        for (IotWarnindicator item : iotWarnindicatorList) {
+            String wiBid = item.getUUId();
+
+            item.setWiBid(wiBid);
+            item.setWcBid(wcBid);
+            item.setTid(tid);
+            item.setWiCreator(wiCreator);
+            item.setWiCreateddate(createDate);
+            insertList.add(item);
+
+            List<IotWarnindicator> childrenList = item.getChildrenList();
+            if (childrenList != null && !childrenList.isEmpty()) {
+                Set<String> wiCodeSet = new HashSet<>();
+                for (IotWarnindicator iotWarnindicator : childrenList) {
+                    String wiCode = iotWarnindicator.getWiCode();
+                    if (StringUtils.isEmpty(wiCode)) {
+                        throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警要素不能为空");
+                    }
+                    if (wiCodeSet.contains(wiCode)) {
+                        throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警要素不能重复");
+                    }
+
+                    iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
+                    iotWarnindicator.setWcBid(wcBid);
+                    iotWarnindicator.setTid(tid);
+                    iotWarnindicator.setWiCreator(wiCreator);
+                    iotWarnindicator.setWiCreateddate(createDate);
+                    iotWarnindicator.setWiOptiontype("0");
+                    iotWarnindicator.setWiStatus("0");
+                    iotWarnindicator.setWiParentbid(wiBid);
+
+                    insertList.add(iotWarnindicator);
+                    wiCodeSet.add(wiCode);
+                }
+            }
+        }
+        if (!insertList.isEmpty()) {
+            iotWarnindicatorService.insertIotWarnindicatorBatch(insertList);
+        }
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public int add(IotWarnconfigAddReqVo iotWarnconfigAddReqVo) {
@@ -176,7 +250,7 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
 
         // 获取告警对象
         List<IotWarnobject> warnobjects = iotWarnconfigAddReqVo.getIotWarnobjectList();
-        for(IotWarnobject iotWarnobject : warnobjects){
+        for (IotWarnobject iotWarnobject : warnobjects) {
             iotWarnobject.setWoBid(iotWarnobject.getUUId());
             iotWarnobject.setWcBid(iotWarnconfigAddReqVo.getWcBid());
             iotWarnobject.setTid(SecurityUtils.getTid());
@@ -185,22 +259,17 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
 
         // 获取告警规则
         List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigAddReqVo.getIotWarnindicatorList();
-        for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
-            iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
-            iotWarnindicator.setWcBid(iotWarnconfigAddReqVo.getWcBid());
-            iotWarnindicator.setTid(SecurityUtils.getTid());
-            iotWarnindicator.setWiCreator(SecurityUtils.getTid());
-            iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
-            iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
-        }
+
+        addWarnindicator(iotWarnconfigAddReqVo.getWcBid(), iotWarnindicatorList);
         return iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfigAddReqVo);
     }
 
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public int edit(IotWarnconfigEditReqVo iotWarnconfigEditReqVo) {
-        if(StringUtils.isEmpty(iotWarnconfigEditReqVo.getWcBid())){
-            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(),"告警规则标识不能为空");
+        if (StringUtils.isEmpty(iotWarnconfigEditReqVo.getWcBid())) {
+            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警规则标识不能为空");
         }
         // 告警对象全量编辑
         // 获取告警对象
@@ -208,126 +277,188 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
         iotWarnobjectQuery.setTid(SecurityUtils.getTid());
         iotWarnobjectQuery.setWcBid(iotWarnconfigEditReqVo.getWcBid());
         // 获取配置的旧的告警对象
-        List<IotWarnobject> oldWarnObjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
+        List<IotWarnobject> oldWarnObjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
         // 对比两个集合,获取不同的内容
-        Collection<IotWarnobject> differ = CollectionUtils.disjunction(oldWarnObjectList,iotWarnconfigEditReqVo.getIotWarnobjectList());
+        Collection<IotWarnobject> differ = CollectionUtils.disjunction(oldWarnObjectList, iotWarnconfigEditReqVo.getIotWarnobjectList());
         // 老数据中存在,新数据中不存在,代表被删除的数据,即旧数据与differ的交集
-        Collection<IotWarnobject> deleteData = CollectionUtils.intersection(oldWarnObjectList,differ);
-        for(IotWarnobject iotWarnobject :deleteData){
-            iotWarnobjectMapper.deleteIotWarnobjectByWoBid(iotWarnobject.getWoBid(), SecurityUtils.getTid());
-            iotWarncountMapper.deleteIotWarncountByDevBidAndWcBid(iotWarnobject.getDevBid(),iotWarnobject.getWcBid(),SecurityUtils.getTid());
+        Collection<IotWarnobject> deleteData = CollectionUtils.intersection(oldWarnObjectList, differ);
+        for (IotWarnobject iotWarnobject : deleteData) {
+            iotWarnobjectService.deleteIotWarnobjectByWoBid(iotWarnobject.getWoBid(), SecurityUtils.getTid());
+            iIotWarncountService.deleteIotWarncountByDevBidAndWcBid(iotWarnobject.getDevBid(), iotWarnobject.getWcBid(), SecurityUtils.getTid());
             // 清除告警对象的缓存
             redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, iotWarnconfigEditReqVo.getWcBid() + ":" + iotWarnobject.getDevBid());
         }
         // 老数据中不存在,新数据中存在,代表新增的数据,即入参与differ的交集
-        Collection<IotWarnobject> addData = CollectionUtils.intersection(iotWarnconfigEditReqVo.getIotWarnobjectList(),differ);
-        for(IotWarnobject addWarnObject : addData){
+        Collection<IotWarnobject> addData = CollectionUtils.intersection(iotWarnconfigEditReqVo.getIotWarnobjectList(), differ);
+        for (IotWarnobject addWarnObject : addData) {
             addWarnObject.setTid(SecurityUtils.getTid());
             addWarnObject.setWcBid(iotWarnconfigEditReqVo.getWcBid());
             addWarnObject.setWoBid(addWarnObject.getUUId());
             iotWarnobjectMapper.insertIotWarnobject(addWarnObject);
         }
+
         // 考虑编辑设备的情况下,对应的规则可能出现调整的情况,
-        iotWarnindicatorMapper.deleteIotWarnindicatorByWcBid(iotWarnconfigEditReqVo.getWcBid(),SecurityUtils.getTid());
-        for(IotWarnindicator iotWarnindicator : iotWarnconfigEditReqVo.getIotWarnindicatorList()){
-            iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
-            iotWarnindicator.setWcBid(iotWarnconfigEditReqVo.getWcBid());
-            iotWarnindicator.setTid(SecurityUtils.getTid());
-            iotWarnindicator.setWiCreator(SecurityUtils.getTid());
-            iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
-            iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
-        }
+        iotWarnindicatorService.deleteIotWarnindicatorByWcBid(iotWarnconfigEditReqVo.getWcBid(), SecurityUtils.getTid());
+
+        List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigEditReqVo.getIotWarnindicatorList();
+        addWarnindicator(iotWarnconfigEditReqVo.getWcBid(), iotWarnindicatorList);
         return iotWarnconfigMapper.updateIotWarnconfig(iotWarnconfigEditReqVo);
     }
 
-    @Override
-    public IotWarnconfigInfoResVo info(String wcBid, String tid) {
-        IotWarnconfig iotWarnconfig = iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid,SecurityUtils.getTid());
-        if(null == iotWarnconfig){
-            return null;
-        }
-        IotWarnobject iotWarnobjectQuery = new IotWarnobject();
-        iotWarnobjectQuery.setWcBid(wcBid);
-        iotWarnobjectQuery.setTid(SecurityUtils.getTid());
-        List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
+    private void setInfoByQxz(IotWarnconfig iotWarnconfig, List<IotWarnobject> iotWarnobjectList, List<IotWarnindicator> resultIotWarnIndicatorList) {
+        String wcBid = iotWarnconfig.getWcBid();
+        String tid = SecurityUtils.getTid();
+
         IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
         iotWarnindicatorQuery.setWcBid(wcBid);
-        iotWarnindicatorQuery.setTid(SecurityUtils.getTid());
+        iotWarnindicatorQuery.setTid(tid);
         // 获取已经配置的设备要素
-        List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicatorQuery);
+        List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorService.selectIotWarnindicatorList(iotWarnindicatorQuery);
         Set<String> wiCodeSet = new HashSet<>();
-        if(iotWarnobjectList.size() ==1){
+        if (iotWarnobjectList.size() == 1) {
             IotDevice deviceQuery = new IotDevice();
             deviceQuery.setDevBid(iotWarnobjectList.get(0).getDevBid());
             deviceQuery.setDevtypeBid(iotWarnconfig.getDevtypeBid());
-            List<IotWarnindicator> devNowWarnIndicator = iotWarnindicatorService.warnindicatorDevQuery(deviceQuery);
+            List<IotWarnindicator> devNowWarnIndicator = iotWarnindicatorService.warnindicatorDevQueryByQxSq(deviceQuery);
             wiCodeSet.addAll(devNowWarnIndicator.stream().map(IotWarnindicator::getWiCode).collect(Collectors.toList()));
         }
-        List<IotWarnindicator> resultIotWarnIndicatorList = new ArrayList<>();
-        for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
-            if(wiCodeSet.contains(iotWarnindicator.getWiCode())){
+
+        for (IotWarnindicator iotWarnindicator : iotWarnindicatorList) {
+            String wiCode = iotWarnindicator.getWiCode();
+            if (wiCodeSet.contains(wiCode)) {
+                String typeName = QxElementTypeUtil.getTypeName(wiCode);
+                iotWarnindicator.setTypeName(typeName);
                 resultIotWarnIndicatorList.add(iotWarnindicator);
             }
         }
+    }
+
+    private void setInfoByCbd(IotWarnconfig iotWarnconfig, List<IotWarnobject> iotWarnobjectList, List<IotWarnindicator> resultIotWarnIndicatorList) {
+        String wcBid = iotWarnconfig.getWcBid();
+        String tid = SecurityUtils.getTid();
+
+        IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
+        iotWarnindicatorQuery.setWcBid(wcBid);
+        iotWarnindicatorQuery.setTid(tid);
+        // 获取已经配置的设备要素
+        List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorService.selectIotWarnindicatorList(iotWarnindicatorQuery);
+        Map<String, IotWarnindicator> iotWarnindicatorMap = new LinkedHashMap<>();
+        for (IotWarnindicator iotWarnindicator : iotWarnindicatorList) {
+            String wiBid = iotWarnindicator.getWiBid();
+            String wiParentbid = iotWarnindicator.getWiParentbid();
+            if (iotWarnindicatorMap.containsKey(wiParentbid)) {
+                List<IotWarnindicator> childrenList = iotWarnindicatorMap.get(wiParentbid).getChildrenList();
+                if (childrenList == null) {
+                    childrenList = new ArrayList<>();
+                }
+                childrenList.add(iotWarnindicator);
+                iotWarnindicatorMap.get(wiParentbid).setChildrenList(childrenList);
+            } else {
+                iotWarnindicatorMap.put(wiBid, iotWarnindicator);
+            }
+        }
+        resultIotWarnIndicatorList.addAll(iotWarnindicatorMap.values());
+    }
+
+    @Override
+    public IotWarnconfigInfoResVo info(String wcBid) {
+        String tid = SecurityUtils.getTid();
+        IotWarnconfig iotWarnconfig = selectIotWarnconfigByWcBid(wcBid, tid);
+        if (null == iotWarnconfig) {
+            return null;
+        }
+
+        IotWarnobject iotWarnobjectQuery = new IotWarnobject();
+        iotWarnobjectQuery.setWcBid(wcBid);
+        iotWarnobjectQuery.setTid(tid);
+        List<IotWarnobject> iotWarnobjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
+
+        List<IotWarnindicator> resultIotWarnIndicatorList = new ArrayList<>();
+
         IotWarnconfigInfoResVo iotWarnconfigInfoResVo = new IotWarnconfigInfoResVo();
-        BeanUtils.copyProperties(iotWarnconfig,iotWarnconfigInfoResVo);
+        BeanUtils.copyProperties(iotWarnconfig, iotWarnconfigInfoResVo);
+        iotWarnconfigInfoResVo.setIotWarnindicatorList(resultIotWarnIndicatorList);
+        iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
+
+        String devtypeBid = iotWarnconfig.getDevtypeBid();
+        if (!StringUtils.isEmpty(devtypeBid)) {
+            if (DevTypeUtil.isQxSq(devtypeBid)) {
+                setInfoByQxz(iotWarnconfig, iotWarnobjectList, resultIotWarnIndicatorList);
+            } else if (DevTypeUtil.isYfCbd(devtypeBid)) {
+                setInfoByCbd(iotWarnconfig, iotWarnobjectList, resultIotWarnIndicatorList);
+            }
+        }
+
+
+        BeanUtils.copyProperties(iotWarnconfig, iotWarnconfigInfoResVo);
         iotWarnconfigInfoResVo.setIotWarnindicatorList(resultIotWarnIndicatorList);
         iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
         return iotWarnconfigInfoResVo;
     }
 
     @Override
-    public IotDeviceconfig devConfigInfo(String[] devBids) {
-        List<String> devBidList = Arrays.asList(devBids);
-        List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(devBidList,SecurityUtils.getTid());
-        if(iotDeviceList.isEmpty()){
-           return null;
+    public JSONObject devInterval(String devBid) {
+        Integer interval = null;
+        Set<String> devtypeSet = new HashSet<>();
+        devtypeSet.add(IotDeviceDictConst.TYPE_DAHUA_YUNRUI_DEVICE);
+        devtypeSet.add(IotDeviceDictConst.TYPE_EZVIZ_JKSB);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("interval", interval);
+
+        IotDevice iotDevice = iotDeviceMapper.selectIotDeviceByDevBid(devBid);
+        if (iotDevice == null || devtypeSet.contains(iotDevice.getDevtypeBid())) {
+            return jsonObject;
         }
-        IotDevice first = iotDeviceList.get(0);
-        if(IotDeviceDictConst.TYPE_YF_QXZ.equals(first.getDevtypeBid())) {
-           return getDevConfigByMaxAttr(devBidList,"interval",Integer.class);
+
+        interval = getReportIntervalByConfig(devBid);
+        if (interval == null) {
+            interval = getReportIntervalByData(iotDevice);
         }
-        return null;
+        jsonObject.put("interval", interval);
+        return jsonObject;
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public IotWarnconfig copy(String wcBid) {
         // 查询告警规则
-        IotWarnconfig iotWarnconfig = iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid,SecurityUtils.getTid());
-        if(null == iotWarnconfig){
-            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(),"告警规则不存在");
+        IotWarnconfig iotWarnconfig = selectIotWarnconfigByWcBid(wcBid, SecurityUtils.getTid());
+        if (null == iotWarnconfig) {
+            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警规则不存在");
         }
+
         // 查询告警对象
         IotWarnobject iotWarnobjectQuery = new IotWarnobject();
         iotWarnobjectQuery.setTid(SecurityUtils.getTid());
         iotWarnobjectQuery.setWcBid(wcBid);
-        List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
+        List<IotWarnobject> iotWarnobjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
+
         // 查询告警策略
-        IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
-        iotWarnindicatorQuery.setTid(SecurityUtils.getTid());
-        iotWarnindicatorQuery.setWcBid(wcBid);
-        List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicatorQuery);
-        // 重新赋值
-        iotWarnconfig.setWcBid(iotWarnconfig.getUUId());
+        String devtypeBid = iotWarnconfig.getDevtypeBid();
+        List<IotWarnindicator> iotWarnindicatorList = new ArrayList<>();
+        if (DevTypeUtil.isQxSq(devtypeBid)) {
+            setInfoByQxz(iotWarnconfig, iotWarnobjectList, iotWarnindicatorList);
+        } else if (DevTypeUtil.isYfCbd(devtypeBid)) {
+            setInfoByCbd(iotWarnconfig, iotWarnobjectList, iotWarnindicatorList);
+        }
+
+        String newWcBid = iotWarnconfig.getUUId();
+
+        iotWarnconfig.setWcBid(newWcBid);
         iotWarnconfig.setWcCreateddate(DateUtils.dateTimeNow());
         iotWarnconfig.setWcCreator(SecurityUtils.getUserId());
         iotWarnconfig.setWcModifieddate(null);
         iotWarnconfig.setWcModifier(null);
-        for(IotWarnobject iotWarnobject : iotWarnobjectList){
-            iotWarnobject.setWcBid(iotWarnconfig.getWcBid());
+        for (IotWarnobject iotWarnobject : iotWarnobjectList) {
+            iotWarnobject.setWcBid(newWcBid);
             iotWarnobject.setWoBid(iotWarnobject.getUUId());
             iotWarnobjectMapper.insertIotWarnobject(iotWarnobject);
         }
-        for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
-            iotWarnindicator.setWcBid(iotWarnconfig.getWcBid());
-            iotWarnindicator.setWdBid(iotWarnindicator.getUUId());
-            iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
-            iotWarnindicator.setWiCreator(SecurityUtils.getUserId());
-            iotWarnindicator.setWiModifieddate(null);
-            iotWarnindicator.setWiModifier(null);
-            iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
-        }
+
+        // 重新赋值
+        addWarnindicator(newWcBid, iotWarnindicatorList);
+
         iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfig);
         return iotWarnconfig;
     }
@@ -337,35 +468,78 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
         return iotWarnconfigMapper.updateIotWarnconfig(updateObject);
     }
 
-    // 根据最大值获取配置
-    private IotDeviceconfig getDevConfigByMaxAttr(List<String> devBidList,String attr,Class attrType){
-        List<IotDeviceconfig> iotDeviceconfigs = iotDeviceconfigMapper.selectIotDeviceConfigByDevBidList(devBidList);
-        if(iotDeviceconfigs.isEmpty()){
-            return null;
+    private Integer getQxZReportInterval(JSONArray dataList) {
+        Integer interval = null;
+        try {
+            JSONArray oneArray = dataList.getJSONArray(0);
+            JSONArray twoArray = dataList.getJSONArray(1);
+
+            String oneTime = oneArray.getJSONObject(0).getString("time");
+            String twoTime = twoArray.getJSONObject(0).getString("time");
+
+            Date oneDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, oneTime);
+            Date twoDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, twoTime);
+            interval = (int) (oneDate.getTime() - twoDate.getTime()) / 1000 / 60;
+        } catch (Exception e) {
         }
-        IotDeviceconfig result = null;
-        JSONObject resultConfig = new JSONObject();
-        for(IotDeviceconfig iotDeviceconfig : iotDeviceconfigs){
+        return interval;
+    }
+
+    private Integer getReportIntervalByConfig(String devBid) {
+        Integer interval = null;
+        String[] keys = {
+                "interval", "datt", "dat_f"
+        };
+        IotDeviceconfig iotDeviceconfig = iotDeviceconfigMapper.selectIotDeviceConfigByDevBid(devBid);
+        if (iotDeviceconfig != null) {
             String configContext = iotDeviceconfig.getDevcfgContext();
-            if(JSON.isValidObject(configContext)){
-                JSONObject config = JSONObject.parseObject(configContext);
-                Object value = config.get(attr);
-                Object resultConfigValue = resultConfig.get(attr);
-                if(null != resultConfigValue&&null != value){
-                    // 数字类型的比较
-                    if(attrType.equals(Integer.class)){
-                        if(new BigDecimal(String.valueOf(value)).compareTo(new BigDecimal(String.valueOf(resultConfigValue))) >= 1){
-                            resultConfig = config;
-                            result = iotDeviceconfig;
-                        }
+            if (JSON.isValidObject(configContext)) {
+                JSONObject jsonObject = JSONObject.parseObject(configContext);
+                for (String key : keys) {
+                    if (jsonObject.containsKey(key)) {
+                        interval = jsonObject.getInteger(key);
+                        break;
                     }
-                } else if (value != null ){
-                    resultConfig = config;
-                    result = iotDeviceconfig;
                 }
             }
         }
-        return result;
+        return interval;
+    }
+
+    private Integer getReportIntervalByData(IotDevice iotDevice) {
+        Integer interval = null;
+        // 获取今天23:59:59
+        LocalDateTime todayEnd = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
+        Date todayEndDate = DateUtils.toDate(todayEnd);
+
+        // 获取30天前的0:00:00
+        LocalDateTime thirtyDaysAgo = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
+        Date thirtyDaysAgoDate = DateUtils.toDate(thirtyDaysAgo);
+
+        String startTime = DateUtils.formatDate(thirtyDaysAgoDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
+        String endTime = DateUtils.formatDate(todayEndDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
+
+        IotDeviceDataListReqVo reqVo = new IotDeviceDataListReqVo();
+        reqVo.setDevBid(iotDevice.getDevBid());
+        reqVo.setStartTime(startTime);
+        reqVo.setEndTime(endTime);
+
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("dataList");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+
+        TableDataInfo tableDataInfo = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        List result = tableDataInfo.getData();
+        if (result == null || result.size() < 2) {
+            return null;
+        }
+        JSONArray dataList = JSONArray.from(result);
+        String devtypeBid = iotDevice.getDevtypeBid();
+        if (DevTypeUtil.isQxSq(devtypeBid)) {
+            interval = getQxZReportInterval(dataList);
+        }
+        return interval;
     }
 
 }

+ 12 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarncountServiceImpl.java

@@ -5,6 +5,7 @@ import com.yunfeiyun.agmp.iotm.web.mapper.IotWarncountMapper;
 import com.yunfeiyun.agmp.iotm.web.service.IIotWarncountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -85,4 +86,15 @@ public class IotWarncountServiceImpl implements IIotWarncountService {
     public int deleteIotWarncountByWctBid(String wctBid, String tid){
         return iotWarncountMapper.deleteIotWarncountByWctBid(wctBid, tid);
     }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public int deleteIotWarncountByDevBidAndWcBid(String devBid, String wcBid, String tid) {
+        return iotWarncountMapper.deleteIotWarncountByDevBidAndWcBid(devBid, wcBid, tid);
+    }
+
+    @Override
+    public int deleteIotWarncountByWcBids(String[] wcBids, String tid) {
+        return iotWarncountMapper.deleteIotWarncountByWcBids(wcBids, tid);
+    }
 }

+ 138 - 37
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnindicatorServiceImpl.java

@@ -5,25 +5,25 @@ import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.exception.BizException;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
-import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
-import com.yunfeiyun.agmp.iot.common.domain.IotDevicelasteddata;
-import com.yunfeiyun.agmp.iot.common.domain.IotWarndataitem;
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
-import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
+import com.yunfeiyun.agmp.iot.common.domain.*;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.QxElementTypeUtil;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
+import com.yunfeiyun.agmp.iotm.web.domain.IotWarnPestVo;
 import com.yunfeiyun.agmp.iotm.web.mapper.IotWarndataitemMapper;
 import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnindicatorMapper;
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotWarnindicatorService;
-import io.jsonwebtoken.lang.Collections;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -44,6 +44,12 @@ public class IotWarnindicatorServiceImpl implements IIotWarnindicatorService {
     @Resource
     private IotDeviceCommonService iotDeviceCommonService;
 
+    @Autowired
+    private IIotPestService iotPestService;
+
+    @Autowired
+    private IIotDeviceService iotDeviceService;
+
     /**
      * 查询告警指标,存储所有与告警相关的指标信息
      *
@@ -112,43 +118,85 @@ public class IotWarnindicatorServiceImpl implements IIotWarnindicatorService {
 
     @Override
     public List<IotWarnindicator> query(IotDevice iotDevice) {
-        if (StringUtils.isEmpty(iotDevice.getDevtypeBid())) {
+        String devTypeBid = iotDevice.getDevtypeBid();
+        String devBid = iotDevice.getDevBid();
+        if (StringUtils.isEmpty(devTypeBid)) {
             throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不能为空");
         }
+        if (StringUtils.isEmpty(devBid)) {
+            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备标识不能为空");
+        }
+
         List<IotWarnindicator> result = new ArrayList<>();
         // 暂时只支持针对设备的告警要素查询
-        if (StringUtils.isNotEmpty(iotDevice.getDevBid())) {
-            result = warnindicatorDevQuery(iotDevice);
+        if(DevTypeUtil.isQxSq(devTypeBid)){
+            result = warnindicatorDevQueryByQxSq(iotDevice);
+        }else if(DevTypeUtil.isYfRecogCbd(devTypeBid)){
+            result = warnindicatorDevQueryByCbd(iotDevice);
         }
         return result;
     }
+
+    /**
+     * 查询气象墒情告警要素列表
+     * @param iotDevice
+     * @return
+     */
     @Override
-    public List<IotWarnindicator> warnindicatorDevQuery(IotDevice iotDevice){
+    public List<IotWarnindicator> warnindicatorDevQueryByQxSq(IotDevice iotDevice){
         // 暂不支持根据类型查询要素
         // 查询当前设备是否存在预设要素
         List<IotWarnindicator> result = new ArrayList<>();
-        if (isFactorDevice(iotDevice.getDevtypeBid())) {
-            IotDeviceDataListReqVo iotDeviceDataListReqVo = new IotDeviceDataListReqVo();
-            BeanUtils.copyProperties(iotDevice,iotDeviceDataListReqVo);
-            IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
-            iotDeviceBaseFunReqVo.setDevBid(iotDevice.getDevBid());
-            iotDeviceBaseFunReqVo.setMethodName("warnDataLatest");
-            iotDeviceBaseFunReqVo.setParam(iotDeviceDataListReqVo);
-            IotDevicelasteddata iotDevicelasteddata = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
-            if(null == iotDevicelasteddata){
-                return result;
-            }
-            JSONArray jsonArray = JSONArray.parseArray(iotDevicelasteddata.getDevldContent());
-            // 直接返回设备上报的数据
-            for (int i = 0; i < jsonArray.size(); i++) {
-                JSONObject dataItem = jsonArray.getJSONObject(i);
-                IotWarnindicator iotWarnindicator = new IotWarnindicator();
-                iotWarnindicator.setWiAddress(dataItem.getString("address"));
-                iotWarnindicator.setWiCode(dataItem.getString("factorCode"));
-                iotWarnindicator.setWiName(dataItem.getString("factorName"));
-                iotWarnindicator.setWiUnit(dataItem.getString("factorUnit"));
-                result.add(iotWarnindicator);
-            }
+        IotDeviceDataListReqVo iotDeviceDataListReqVo = new IotDeviceDataListReqVo();
+        BeanUtils.copyProperties(iotDevice,iotDeviceDataListReqVo);
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(iotDevice.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("warnDataLatest");
+        iotDeviceBaseFunReqVo.setParam(iotDeviceDataListReqVo);
+        IotDevicelasteddata iotDevicelasteddata = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        if(null == iotDevicelasteddata){
+            return result;
+        }
+        JSONArray jsonArray = JSONArray.parseArray(iotDevicelasteddata.getDevldContent());
+        // 直接返回设备上报的数据
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject dataItem = jsonArray.getJSONObject(i);
+            String factorCode = dataItem.getString("factorCode");
+            String typeName = QxElementTypeUtil.getTypeName(factorCode);
+            IotWarnindicator iotWarnindicator = new IotWarnindicator();
+            iotWarnindicator.setWiAddress(dataItem.getString("address"));
+            iotWarnindicator.setWiCode(factorCode);
+            iotWarnindicator.setWiName(dataItem.getString("factorName"));
+            iotWarnindicator.setWiUnit(dataItem.getString("factorUnit"));
+            iotWarnindicator.setTypeName(typeName);
+            result.add(iotWarnindicator);
+        }
+        return result;
+    }
+
+    /**
+     * 查询测报灯告警要素列表
+     *
+     * @param iotDevice
+     * @return
+     */
+    @Override
+    public List<IotWarnindicator> warnindicatorDevQueryByCbd(IotDevice iotDevice) {
+
+        List<String[]> factorList = new ArrayList<>();
+        factorList.add(new String[]{"pestType", "害虫种类", "类", "0"});
+        factorList.add(new String[]{"pestNum", "害虫数量", "头", "0"});
+        factorList.add(new String[]{"pestDetail", "指定害虫", "头", "1"});
+
+        List<IotWarnindicator> result = new ArrayList<>();
+        for(String[] factor : factorList){
+            IotWarnindicator iotWarnindicator = new IotWarnindicator();
+            iotWarnindicator.setWiAddress(factor[0]);
+            iotWarnindicator.setWiCode(factor[0]);
+            iotWarnindicator.setWiName(factor[1]);
+            iotWarnindicator.setWiUnit(factor[2]);
+            iotWarnindicator.setWiOptiontype(factor[3]);
+            result.add(iotWarnindicator);
         }
         return result;
     }
@@ -168,10 +216,63 @@ public class IotWarnindicatorServiceImpl implements IIotWarnindicatorService {
         return iotWarndataitemList.stream().collect(Collectors.toMap(IotWarndataitem::getWdCode, item -> item));
     }
 
-    private boolean isFactorDevice(String devTypeBid) {
-        if(Collections.contains(Arrays.asList(QxzTypeUtil.getAllQxzTypes()).iterator(),devTypeBid)){
-            return true;
+
+    /**
+     * 查询虫情列表
+     *
+     * @param iotDevice
+     * @return
+     */
+    @Override
+    public List<IotPest> pestList(String devBid) {
+        IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+        if(null == iotDevice){
+            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
+        }
+        String devtypeBid = iotDevice.getDevtypeBid();
+        String devType = null;
+        switch (devtypeBid){
+            case IotDeviceDictConst.TYPE_YF_CBD:
+            case IotDeviceDictConst.TYPE_YF_SDCBD:
+                devType = "CBD";
+                break;
+            case IotDeviceDictConst.TYPE_YF_XCT:
+                devType = "XCT";
+                break;
+            default:
+                throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "暂不支持该设备类型");
+        }
+        IotWarnPestVo iotWarnPestVo = new IotWarnPestVo();
+        iotWarnPestVo.setDevType(devType);
+        return iotPestService.selectIotWarnPestList(iotWarnPestVo);
+    }
+
+    /**
+     * 批量新增告警指标
+     *
+     * @param iotWarnindicator
+     * @return 结果
+     * @param iotWarnindicator
+     * @return
+     */
+    @Override
+    public int insertIotWarnindicatorBatch(List<IotWarnindicator> iotWarnindicator) {
+        for(IotWarnindicator item : iotWarnindicator){
+            if(StringUtils.isEmpty(item.getWiOptiontype())){
+                item.setWiOptiontype("0");
+            }
         }
-        return false;
+        return iotWarnindicatorMapper.insertIotWarnindicatorBatch(iotWarnindicator);
     }
+
+    @Override
+    public int deleteIotWarnindicatorByWcBid(String wcBid, String tid) {
+        return iotWarnindicatorMapper.deleteIotWarnindicatorByWcBid(wcBid,tid);
+    }
+
+    @Override
+    public int deleteIotWarnindicatorByWcBids(String[] wcBids, String tid) {
+        return iotWarnindicatorMapper.deleteIotWarnindicatorByWcBids(wcBids, tid);
+    }
+
 }

+ 12 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnobjectServiceImpl.java

@@ -118,4 +118,16 @@ public class IotWarnobjectServiceImpl implements IIotWarnobjectService {
     public int deleteIotWarnobjectByWoBid(String woBid, String tid){
         return iotWarnobjectMapper.deleteIotWarnobjectByWoBid(woBid, tid);
     }
+
+    /**
+     * 批量删除告警对象
+     *
+     * @param wcBids
+     * @param tid
+     * @return 结果
+     */
+    @Override
+    public int deleteIotWarnobjectByWcBids(String[] wcBids, String tid) {
+        return iotWarnobjectMapper.deleteIotWarnobjectByWcBids(wcBids, tid);
+    }
 }

+ 7 - 0
src/main/resources/mapper/IotDeviceMapper.xml

@@ -115,6 +115,13 @@
                 </foreach>
             </if>
 
+            <if test="devCodeList != null  and devCodeList.size() > 0">
+                and d.devCode in
+                <foreach collection="devCodeList" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+
         </where>
     </select>
 

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

@@ -145,4 +145,16 @@ SELECT * from  IotPest where pestBid=#{pestBid}
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectIotWarnPestList" parameterType="IotWarnPestVo" resultMap="IotPestResult">
+        <include refid="selectIotPestVo"/>
+        <where>
+            pestDelstatus = 0
+            <choose>
+                <when test="devType == 'CBD'">AND pestId REGEXP '^[0-9]+$'</when>
+                <when test="devType == 'XCT'">AND pestId LIKE 'xct%'</when>
+                <otherwise>AND id = -1</otherwise>
+            </choose>
+        </where>
+    </select>
 </mapper>

+ 7 - 5
src/main/resources/mapper/IotWarnconfigMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.yunfeiyun.agmp.iotm.web.mapper.IotWarnconfigMapper">
-    
+
     <resultMap type="IotWarnconfig" id="IotWarnconfigResult">
         <result property="id"    column="id"    />
         <result property="wcBid"    column="wcBid"    />
@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectIotWarnconfigList" parameterType="IotWarnconfig" resultMap="IotWarnconfigResult">
         <include refid="selectIotWarnconfigVo"/>
-        <where>  
+        <where>
             <if test="wcBid != null  and wcBid != ''"> and wcBid = #{wcBid}</if>
             <if test="wcName != null  and wcName != ''"> and wcName like concat('%', #{wcName}, '%')</if>
             <if test="wcDesc != null  and wcDesc != ''"> and wcDesc = #{wcDesc}</if>
@@ -45,12 +45,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tid != null  and tid != ''"> and tid = #{tid}</if>
         </where>
     </select>
-    
+
     <select id="selectIotWarnconfigByWcBid"  resultMap="IotWarnconfigResult">
         <include refid="selectIotWarnconfigVo"/>
         where wcBid = #{wcBid} and tid = #{tid}
     </select>
-        
+
     <insert id="insertIotWarnconfig" parameterType="IotWarnconfig" useGeneratedKeys="true" keyProperty="id">
         insert into IotWarnconfig
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -137,5 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="wcModifier != null  and wcModifier != ''"> and wcModifier = #{wcModifier}</if>
             <if test="tid != null  and tid != ''"> and tid = #{tid}</if>
         </where>
+        order by  wcTouchtype  desc  ,wcCreateddate desc
+
     </select>
-</mapper>
+</mapper>

+ 7 - 0
src/main/resources/mapper/IotWarncountMapper.xml

@@ -82,4 +82,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <delete id="deleteIotWarncountByDevBidAndWcBid">
         delete from IotWarncount where wcBid = #{wcBid} and devBid = #{devBid} and tid = #{tid}
     </delete>
+
+    <delete id="deleteIotWarncountByWcBids">
+        delete from IotWarncount where wcBid in
+        <foreach item="wcBid" collection="array" open="(" separator="," close=")">
+            #{wcBid}
+        </foreach>
+    </delete>
 </mapper>

+ 31 - 1
src/main/resources/mapper/IotWarnindicatorMapper.xml

@@ -23,10 +23,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="wiModifieddate"    column="wiModifieddate"    />
         <result property="wiModifier"    column="wiModifier"    />
         <result property="tid"    column="tid"    />
+        <result property="wiOptiontype"    column="wiOptiontype"    />
+        <result property="wiParentbid"    column="wiParentbid"    />
     </resultMap>
 
     <sql id="selectIotWarnindicatorVo">
-        select id, wiBid, wcBid, wdBid, wiAddress, wiCode, wiName, wiUnit,wiStatus,wiExpression, wiValue, wiCreator, wiCreateddate, wiModifieddate, wiModifier, tid from IotWarnindicator
+        select id, wiBid, wcBid, wdBid, wiAddress, wiCode, wiName, wiUnit,wiStatus,wiExpression, wiValue, wiCreator,
+            wiCreateddate, wiModifieddate, wiModifier, tid, wiOptiontype, wiParentbid
+        from IotWarnindicator
     </sql>
 
     <select id="selectIotWarnindicatorList" parameterType="IotWarnindicator" resultMap="IotWarnindicatorResult">
@@ -47,6 +51,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="wiModifieddate != null  and wiModifieddate != ''"> and wiModifieddate = #{wiModifieddate}</if>
             <if test="wiModifier != null  and wiModifier != ''"> and wiModifier = #{wiModifier}</if>
             <if test="tid != null  and tid != ''"> and tid = #{tid}</if>
+            <if test="wiOptiontype != null  and wiOptiontype != ''"> and wiOptiontype = #{wiOptiontype}</if>
+            <if test="wiParentbid != null  and wiParentbid != ''"> and wiParentbid = #{wiParentbid}</if>
         </where>
     </select>
     
@@ -93,6 +99,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
     </insert>
 
+    <insert id="insertIotWarnindicatorBatch" parameterType="IotWarnindicator">
+        insert into IotWarnindicator (
+            wiBid, wcBid, wdBid, wiAddress, wiCode, wiName, wiUnit, wiStatus,
+            wiExpression, wiValue, wiCreator, wiCreateddate, wiModifieddate, wiModifier,
+            tid, wiOptiontype, wiParentbid
+        )
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+                #{item.wiBid}, #{item.wcBid}, #{item.wdBid}, #{item.wiAddress}, #{item.wiCode}, #{item.wiName},
+                #{item.wiUnit}, #{item.wiStatus}, #{item.wiExpression}, #{item.wiValue}, #{item.wiCreator},
+                #{item.wiCreateddate}, #{item.wiModifieddate}, #{item.wiModifier}, #{item.tid},
+                #{item.wiOptiontype}, #{item.wiParentbid}
+            )
+        </foreach>
+    </insert>
+
     <update id="updateIotWarnindicator" parameterType="IotWarnindicator">
         update IotWarnindicator
         <trim prefix="SET" suffixOverrides=",">
@@ -129,4 +152,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <delete id="deleteIotWarnindicatorByWcBid">
         delete from IotWarnindicator where wcBid = #{wcBid} and tid = #{tid}
     </delete>
+
+    <delete id="deleteIotWarnindicatorByWcBids">
+        delete from IotWarnindicator where tid = #{tid} and wcBid in
+        <foreach item="wcBid" collection="array" open="(" separator="," close=")">
+            #{wcBid}
+        </foreach>
+    </delete>
 </mapper>

+ 7 - 0
src/main/resources/mapper/IotWarnobjectMapper.xml

@@ -91,4 +91,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and tid = #{tid}
         </where>
     </select>
+
+    <delete id="deleteIotWarnobjectByWcBids">
+        delete from IotWarnobject where tid = #{tid} and wcBid in
+        <foreach item="wcBid" collection="array" open="(" separator="," close=")">
+            #{wcBid}
+        </foreach>
+    </delete>
 </mapper>