Sfoglia il codice sorgente

Merge branch 'develop' of com_yunfei_saas/agmp_iots into master

yf_zn 1 anno fa
parent
commit
481e58622f
32 ha cambiato i file con 3692 aggiunte e 2908 eliminazioni
  1. 1 1
      src/main/java/com/yunfeiyun/agmp/iots/core/http/ZjsfXycbHttpClient.java
  2. 119 1
      src/main/java/com/yunfeiyun/agmp/iots/device/controller/TestController.java
  3. 17 0
      src/main/java/com/yunfeiyun/agmp/iots/device/domain/WarnTestReq.java
  4. 2 0
      src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotDeviceMapper.java
  5. 0 63
      src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarnconfigMapper.java
  6. 0 63
      src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarnlogMapper.java
  7. 0 65
      src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarntypeMapper.java
  8. 41 55
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/XphYfQxzDeviceImpl.java
  9. 73 18
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfQxzDeviceImpl.java
  10. 21 1
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfScdDeviceImpl.java
  11. 2 0
      src/main/java/com/yunfeiyun/agmp/iots/service/IIotDeviceService.java
  12. 0 2
      src/main/java/com/yunfeiyun/agmp/iots/service/impl/IotCbdImgService.java
  13. 5 0
      src/main/java/com/yunfeiyun/agmp/iots/service/impl/IotDeviceServiceImpl.java
  14. 0 2253
      src/main/java/com/yunfeiyun/agmp/iots/service/impl/WarnService.java
  15. 2264 0
      src/main/java/com/yunfeiyun/agmp/iots/service/impl/WarnServiceDelete.java
  16. 13 0
      src/main/java/com/yunfeiyun/agmp/iots/startup/MongoStartup.java
  17. 33 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/job/WarnJob.java
  18. 53 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/mapper/IotWarnBussinessMapper.java
  19. 26 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnConfigInfo.java
  20. 21 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnQxSqInfoDto.java
  21. 59 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnResult.java
  22. 16 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnStatusDto.java
  23. 129 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/IotWarnBussinessService.java
  24. 132 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/ReCountService.java
  25. 451 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java
  26. 70 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/util/CompareUtil.java
  27. 35 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/util/WarnMessageBuilderUtil.java
  28. 7 0
      src/main/resources/mapper/IotDeviceMapper.xml
  29. 102 0
      src/main/resources/mapper/IotWarnBusinessMapper.xml
  30. 0 152
      src/main/resources/mapper/IotWarnconfigMapper.xml
  31. 0 130
      src/main/resources/mapper/IotWarnlogMapper.xml
  32. 0 104
      src/main/resources/mapper/IotWarntypeMapper.xml

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iots/core/http/ZjsfXycbHttpClient.java

@@ -191,7 +191,7 @@ public class ZjsfXycbHttpClient extends HttpClient {
 
         log.info("【中捷四方性诱HTTP】【开始请求:{}】参数:{}", sendUrl, sb);
         String rspBody = httpPost(sendUrl, sb.toString());
-        log.info("【中捷四方性诱HTTP】【结束请求:{}】参数:{} headers: {} 响应: {}", sendUrl, sb, headers, rspBody);
+        log.info("【中捷四方性诱HTTP】【结束请求:{}】参数:{}", sendUrl, sb);
         Map<String, Object> rspMap = JSONUtils.toMap(rspBody);
         String result = (String)rspMap.get("result");
         if(!Objects.equals(result, "success")){

+ 119 - 1
src/main/java/com/yunfeiyun/agmp/iots/device/controller/TestController.java

@@ -1,16 +1,26 @@
 package com.yunfeiyun.agmp.iots.device.controller;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.JSONUtils;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 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.iots.core.cmd.core.CmdDispatcherService;
+import com.yunfeiyun.agmp.iots.device.domain.WarnTestReq;
 import com.yunfeiyun.agmp.iots.device.mapper.IotDeviceMapper;
+import com.yunfeiyun.agmp.iots.device.service.IYfQxzDevice;
+import com.yunfeiyun.agmp.iots.device.serviceImp.YfQxzDeviceImpl;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
 import com.yunfeiyun.agmp.iots.service.IIotYfScddataService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +41,7 @@ import java.util.concurrent.CompletableFuture;
  * 测试接口
  */
 @RestController
-@RequestMapping("test")
+@RequestMapping("/test")
 @Slf4j
 public class TestController {
 
@@ -57,6 +67,15 @@ public class TestController {
     @Autowired
     private IotDeviceMapper iotDeviceMapper;
 
+    @Autowired
+    private IIotDeviceService iotDeviceService;
+
+    @Autowired
+    private IYfQxzDevice iYfQxzDevice;
+
+    @Autowired
+    private IIotDevicelasteddataService iIotDevicelasteddataService;
+
     private static final Random random = new Random();
     private static final DateTimeFormatter stampFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
 
@@ -585,5 +604,104 @@ public class TestController {
         return iotCbdimg;
     }
 
+    @PostMapping("/warn")
+    public AjaxResult warnQxzTest(@RequestBody WarnTestReq req) throws Exception {
+        String devCode = req.getDevCode();
+        JSONObject data = req.getData();
+
+        if(StringUtils.isEmpty(devCode)) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备编码为空");
+        }
+
+        if(data == null) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "数据为空");
+        }
 
+        List<IotDevice> iotDeviceList = iotDeviceService.selectIotDeviceByDevCode(devCode);
+        if (iotDeviceList == null || iotDeviceList.isEmpty()) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
+        }
+        if(iotDeviceList.size() > 1) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不唯一");
+        }
+        IotDevice iotDevice = iotDeviceList.get(0);
+        if (iotDevice == null) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
+        }
+        String devtypeBid = iotDevice.getDevtypeBid();
+        if(QxzTypeUtil.isYfCommQxz(devtypeBid)){
+            YfQxzDeviceImpl yfQxzDevice = (YfQxzDeviceImpl) iYfQxzDevice;
+            String devUpdateddate = DateUtils.dateTimeNow();
+            yfQxzDevice.processData(iotDevice, data, devUpdateddate);
+        }else{
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备类型不支持");
+        }
+        return AjaxResult.success();
+    }
+
+    public Class getTableClass(String devtypeBid) {
+        Class tableClass = null;
+        if(QxzTypeUtil.isXphYfQxSq(devtypeBid)){
+            tableClass = IotXphYfqxzdata.class;
+        }else if(QxzTypeUtil.isYfQxSq(devtypeBid)){
+            tableClass = IotYfqxzdata.class;
+        }
+//        else if (devtypeBid.equals(IotDeviceDictConst.TYPE_ADZN_GSSQ)) {
+//            tableClass = IotAdznGssqdata.class;
+//        }
+        return tableClass;
+    }
+
+
+    /**
+     * 设备上报数据
+     * @param req
+     * @return
+     * @throws Exception
+     */
+    @GetMapping("/warn/dev/data")
+    public AjaxResult getDevData(WarnTestReq req) throws Exception {
+        String devCode = req.getDevCode();
+
+        if(StringUtils.isEmpty(devCode)) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备编码为空");
+        }
+
+        List<IotDevice> iotDeviceList = iotDeviceService.selectIotDeviceByDevCode(devCode);
+        if (iotDeviceList == null || iotDeviceList.isEmpty()) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
+        }
+        if(iotDeviceList.size() > 1) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不唯一");
+        }
+        IotDevice iotDevice = iotDeviceList.get(0);
+
+        String devtypeBid = iotDevice.getDevtypeBid();
+        String devBid = iotDevice.getDevBid();
+        if(QxzTypeUtil.isYfCommQxz(devtypeBid)){
+            Class tableClass = getTableClass(devtypeBid);
+            if(tableClass == null){
+                throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
+            }
+
+            IotDevicelasteddata iotDevicelasteddata = iIotDevicelasteddataService.selectDeviceLastedDataBydevBid(devBid);
+            String devldContent = iotDevicelasteddata.getDevldContent();
+            List jsonList = JSONUtils.toList(devldContent);
+            List<Map<String, String>> dataList = new ArrayList<>();
+            for(Object dataObj : jsonList){
+                JSONObject jsonData = JSONObject.from(dataObj);
+                Map<String, String> dataMap = new HashMap<>();
+                dataMap.put("eNum", jsonData.getString("eNum"));
+                dataMap.put("eName", jsonData.getString("eName"));
+                dataMap.put("eValue", jsonData.getString("eValue"));
+                dataMap.put("eKey", jsonData.getString("eKey"));
+                dataList.add(dataMap);
+            }
+            JSONObject data = new JSONObject();
+            data.put("data", dataList);
+            return AjaxResult.success(data);
+        }else{
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备类型不支持");
+        }
+    }
 }

+ 17 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/domain/WarnTestReq.java

@@ -0,0 +1,17 @@
+package com.yunfeiyun.agmp.iots.device.domain;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.Data;
+
+@Data
+public class WarnTestReq {
+    /**
+     * 设备ID
+     */
+    private String devCode;
+
+    /**
+     * 设备数据
+     */
+    private JSONObject data;
+}

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotDeviceMapper.java

@@ -27,6 +27,8 @@ public interface IotDeviceMapper {
 
     IotDevice selectIotDeviceByDevBid(String devBid);
 
+    List<IotDevice> selectIotDeviceByDevCode(String devCode);
+
     List<IotDevice> selectIotDeviceByDevBidList(List<String> devBidList);
     List<IotDevice> selectIotDeviceByDevTypeBidList(List<String> devTypeBidList);
 

+ 0 - 63
src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarnconfigMapper.java

@@ -1,63 +0,0 @@
-package com.yunfeiyun.agmp.iots.device.mapper;
-
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotWarnconfigResVo;
-
-import java.util.List;
-
-/**
- * 预警配置Mapper接口
- * 
- * @author 杨晓辉
- * @date 2024-04-29
- */
-public interface IotWarnconfigMapper 
-{
-    /**
-     * 查询预警配置
-     * 
-     * @param id 预警配置主键
-     * @return 预警配置
-     */
-    public IotWarnconfig selectIotWarnconfigById(Long id);
-
-    /**
-     * 查询预警配置列表
-     * 
-     * @param iotWarnconfig 预警配置
-     * @return 预警配置集合
-     */
-    public List<IotWarnconfigResVo> selectIotWarnconfigList(IotWarnconfig iotWarnconfig);
-
-    /**
-     * 新增预警配置
-     * 
-     * @param iotWarnconfig 预警配置
-     * @return 结果
-     */
-    public int insertIotWarnconfig(IotWarnconfig iotWarnconfig);
-
-    /**
-     * 修改预警配置
-     * 
-     * @param iotWarnconfig 预警配置
-     * @return 结果
-     */
-    public int updateIotWarnconfig(IotWarnconfig iotWarnconfig);
-
-    /**
-     * 删除预警配置
-     * 
-     * @param id 预警配置主键
-     * @return 结果
-     */
-    public int deleteIotWarnconfigById(Long id);
-
-    /**
-     * 批量删除预警配置
-     * 
-     * @param ids 需要删除的数据主键集合
-     * @return 结果
-     */
-    public int deleteIotWarnconfigByIds(Long[] ids);
-}

+ 0 - 63
src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarnlogMapper.java

@@ -1,63 +0,0 @@
-package com.yunfeiyun.agmp.iots.device.mapper;
-
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotWarnlogResVo;
-
-import java.util.List;
-
-/**
- * 预警记录Mapper接口
- * 
- * @author MZQ
- * @date 2024-04-29
- */
-public interface IotWarnlogMapper 
-{
-    /**
-     * 查询预警记录
-     * 
-     * @param id 预警记录主键
-     * @return 预警记录
-     */
-    public IotWarnlog selectIotWarnlogById(Long id);
-    public IotWarnlogResVo selectIotWarnlogByBid(String wlBid);
-    /**
-     * 查询预警记录列表
-     * 
-     * @param iotWarnlog 预警记录
-     * @return 预警记录集合
-     */
-    public List<IotWarnlog> selectIotWarnlogList(IotWarnlog iotWarnlog);
-
-    /**
-     * 新增预警记录
-     * 
-     * @param iotWarnlog 预警记录
-     * @return 结果
-     */
-    public int insertIotWarnlog(IotWarnlog iotWarnlog);
-
-    /**
-     * 修改预警记录
-     * 
-     * @param iotWarnlog 预警记录
-     * @return 结果
-     */
-    public int updateIotWarnlog(IotWarnlog iotWarnlog);
-
-    /**
-     * 删除预警记录
-     * 
-     * @param id 预警记录主键
-     * @return 结果
-     */
-    public int deleteIotWarnlogById(Long id);
-
-    /**
-     * 批量删除预警记录
-     * 
-     * @param ids 需要删除的数据主键集合
-     * @return 结果
-     */
-    public int deleteIotWarnlogByIds(Long[] ids);
-}

+ 0 - 65
src/main/java/com/yunfeiyun/agmp/iots/device/mapper/IotWarntypeMapper.java

@@ -1,65 +0,0 @@
-package com.yunfeiyun.agmp.iots.device.mapper;
-
-import com.yunfeiyun.agmp.iot.common.domain.IotWarntype;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotWarntypeResVo;
-
-import java.util.List;
-
-/**
- * 预警类型Mapper接口
- * 
- * @author Ma
- * @date 2024-07-24
- */
-public interface IotWarntypeMapper 
-{
-    /**
-     * 查询预警类型
-     * 
-     * @param id 预警类型主键
-     * @return 预警类型
-     */
-    public IotWarntype selectIotWarntypeById(Long id);
-    public IotWarntypeResVo selectIotWarntypeByBid(String bid);
-
-    /**
-     * 查询预警类型列表
-     * 
-     * @param iotWarntype 预警类型
-     * @return 预警类型集合
-     */
-    public List<IotWarntypeResVo> selectIotWarntypeList(IotWarntype iotWarntype);
-
-    /**
-     * 新增预警类型
-     * 
-     * @param iotWarntype 预警类型
-     * @return 结果
-     */
-    public int insertIotWarntype(IotWarntype iotWarntype);
-
-    /**
-     * 修改预警类型
-     * 
-     * @param iotWarntype 预警类型
-     * @return 结果
-     */
-    public int updateIotWarntype(IotWarntype iotWarntype);
-
-    /**
-     * 删除预警类型
-     * 
-     * @param id 预警类型主键
-     * @return 结果
-     */
-    public int deleteIotWarntypeById(Long id);
-
-    /**
-     * 批量删除预警类型
-     * 
-     * @param ids 需要删除的数据主键集合
-     * @return 结果
-     */
-    public int deleteIotWarntypeByIds(Long[] ids);
-    public int deleteIotWarntypeByBids(String[] bids);
-}

+ 41 - 55
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/XphYfQxzDeviceImpl.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iots.device.serviceImp;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.JSONUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
@@ -10,22 +11,25 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
 import com.yunfeiyun.agmp.iot.common.constant.mqtt.IotMqttConstant;
 import com.yunfeiyun.agmp.iot.common.domain.*;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdModel;
-import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
 import com.yunfeiyun.agmp.iots.core.manager.MqttManager;
 import com.yunfeiyun.agmp.iots.device.common.DeviceAbstractImpl;
 import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzMsg;
-import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzReqMsg;
 import com.yunfeiyun.agmp.iots.device.service.IXphYfQxzDevice;
-import com.yunfeiyun.agmp.iots.service.*;
+import com.yunfeiyun.agmp.iots.service.IIotCmdlogService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceconfigService;
+import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
 import com.yunfeiyun.agmp.iots.service.impl.IotDeviceAddressService;
-import com.yunfeiyun.agmp.iots.service.impl.WarnService;
+import com.yunfeiyun.agmp.iots.warn.service.WarnService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.util.TextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 
@@ -53,7 +57,7 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
     private IIotDevicelasteddataService iIotDevicelasteddataService;
 
     @Autowired
-    private MongoService<IotBaseEntity> mongoService;
+    private MongoService mongoService;
 
     @Autowired
     private LocationService locationService;
@@ -65,10 +69,10 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
     private IIotCmdlogService iIotCmdlogService;
 
     @Autowired
-    private WarnService warnService;
+    private IotDeviceAddressService iotDeviceAddressService;
 
     @Autowired
-    private IotDeviceAddressService iotDeviceAddressService;
+    private WarnService warnService;
 
 
 
@@ -192,9 +196,9 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
 
         // 更新设备数据信息到数据库 mongodb
         String cId = iotDeviceOld.getTid();
-
+        List<IotXphYfqxzdata> dataList = new ArrayList<>();
         for (Object item: jarrData) {
-            JSONObject jobj = (JSONObject) item;
+            JSONObject jobj = JSONObject.from(item);
             IotXphYfqxzdata qxzdata = new IotXphYfqxzdata();
             qxzdata.setCId(cId);
             qxzdata.setDevBid(iotDeviceOld.getDevBid());
@@ -202,42 +206,23 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
             qxzdata.setEName(jobj.getString("eName"));
             qxzdata.setEKey(jobj.getString("eKey"));
             qxzdata.setEValue(jobj.getString("eValue"));
-
             qxzdata.setTime(reportDt);
 
-            mongoService.saveOne(qxzdata);
+            dataList.add(qxzdata);
 
             //把“上报时间”放里面
             jobj.put("time",DateUtils.parseDateToStr("yyyy-MM-dd'T'HH:mm:ss.SSSX",reportDt));
             jobj.put("devBid",qxzdata.getDevBid());
             jobj.put("cId",qxzdata.getCId());
         }
+        if(!dataList.isEmpty()){
+            mongoService.insertList(IotXphYfqxzdata.class, dataList);
+        }
+
         iIotDevicelasteddataService.updateDeviceLastedData(iotDeviceOld,jarrData.toString(), devUpdateddate);
 
-        //预警
-        //云飞 气象站 和 墒情站  都从这里进数据
-/*        if( IotDeviceDictConst.TYPE_YF_QXZ.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkQxzData("0","",iotDeviceOld.getDevBid());
-        }else if( IotDeviceDictConst.TYPE_YF_SQZ.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkGssqData("0","",iotDeviceOld.getDevBid());
-        }else if( IotDeviceDictConst.TYPE_YF_GXZW.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkGssqData("0","",iotDeviceOld.getDevBid());
-        }*/
-//        EnumWarnType warnType = EnumWarnType.findEnumByDevbid(iotDeviceOld.getDevtypeBid());
-//        if(warnType != null){
-//            warnService.checkSensData(warnType.getCode(),"0","",iotDeviceOld.getDevBid());
-//        }
-//
-//        if("3".equals(warnService.getWarnVer())){
-//            //要求预警检查 V3
-//            IotWarncheck warncheck = new IotWarncheck();
-//            warncheck.setDevBid(iotDeviceOld.getDevBid());
-//            // TODO
-//            //  iotsMqService.sendMsg(IotMqConstant.TOPIC_WARNCHECK, IotMqConstant.TOPIC_WARNCHECK, warncheck);
-//        }else{
-//            //预警检查 V2
-//            warnService.checkSensData("0","",iotDeviceOld.getDevBid());
-//        }
+        // 发送告警消息
+        warnService.processWarningReportData(iotDeviceOld, ext);
     }
 
 
@@ -324,26 +309,27 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
 
         iIotDeviceService.updateIotDevice(newIotDevice);
         // 主动进行查询,以确保不是误判离线
-        if("offline".equalsIgnoreCase(cmd)){
-            new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.sleep(2*1000);
-                    }catch (InterruptedException e){
-                        e.printStackTrace();
-                    }
-                    //主动进行查询,以确保不是误判离线
-                    log.info("【YFQXZ】主动进行查询,以确保不是误判离线" + iotDeviceOld);
-                    YfQxzReqMsg reqMsg = new YfQxzReqMsg();
-                    JSONObject jobjParams = new JSONObject();
-                    jobjParams.put("type","data");
-                    reqMsg.setExt(jobjParams);
-
-                    publishMsg(iotDeviceOld, reqMsg);
-                }
-            }).start();
-        }
+        // 新普惠设备不能控制,不用在查询检测
+//        if("offline".equalsIgnoreCase(cmd)){
+//            new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+//                    try {
+//                        Thread.sleep(2*1000);
+//                    }catch (InterruptedException e){
+//                        e.printStackTrace();
+//                    }
+//                    //主动进行查询,以确保不是误判离线
+//                    log.info("【YFQXZ】主动进行查询,以确保不是误判离线" + iotDeviceOld);
+//                    YfQxzReqMsg reqMsg = new YfQxzReqMsg();
+//                    JSONObject jobjParams = new JSONObject();
+//                    jobjParams.put("type","data");
+//                    reqMsg.setExt(jobjParams);
+//
+//                    publishMsg(iotDeviceOld, reqMsg);
+//                }
+//            }).start();
+//        }
     }
 
     @Override

+ 73 - 18
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfQxzDeviceImpl.java

@@ -3,18 +3,19 @@ package com.yunfeiyun.agmp.iots.device.serviceImp;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.JSONUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.constant.cmd.CmdDef;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
 import com.yunfeiyun.agmp.iot.common.constant.mqtt.IotMqttConstant;
-import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
 import com.yunfeiyun.agmp.iot.common.domain.IotBzydata;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotYfqxzdata;
+import com.yunfeiyun.agmp.iot.common.enums.EnumCommonDataFactor;
+import com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdModel;
-import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
 import com.yunfeiyun.agmp.iots.core.manager.MqttManager;
 import com.yunfeiyun.agmp.iots.device.common.DeviceAbstractImpl;
@@ -23,16 +24,19 @@ import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzLedMsg;
 import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzMsg;
 import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzReqMsg;
 import com.yunfeiyun.agmp.iots.device.service.IYfQxzDevice;
-import com.yunfeiyun.agmp.iots.service.*;
+import com.yunfeiyun.agmp.iots.service.IIotCmdlogService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceconfigService;
+import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
 import com.yunfeiyun.agmp.iots.service.impl.IotDeviceAddressService;
-import com.yunfeiyun.agmp.iots.service.impl.WarnService;
+import com.yunfeiyun.agmp.iots.warn.service.WarnService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.util.TextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
-import java.util.Objects;
+import java.text.DecimalFormat;
+import java.util.*;
 
 
 /**
@@ -59,7 +63,7 @@ public class YfQxzDeviceImpl extends DeviceAbstractImpl implements IYfQxzDevice
     private IIotDevicelasteddataService iIotDevicelasteddataService;
 
     @Autowired
-    private MongoService<IotBaseEntity> mongoService;
+    private MongoService mongoService;
 
     @Autowired
     private LocationService locationService;
@@ -71,10 +75,10 @@ public class YfQxzDeviceImpl extends DeviceAbstractImpl implements IYfQxzDevice
     private IIotCmdlogService iIotCmdlogService;
 
     @Autowired
-    private WarnService warnService;
+    private IotDeviceAddressService iotDeviceAddressService;
 
     @Autowired
-    private IotDeviceAddressService iotDeviceAddressService;
+    private WarnService warnService;
 
 
 
@@ -271,30 +275,81 @@ public class YfQxzDeviceImpl extends DeviceAbstractImpl implements IYfQxzDevice
             reportDt = DateUtils.parseDate(reportTime);
         }*/
 
+        String yuLiangEnum = EnumYfQxzElement.TYPE4.geteNum();
+        IotYfqxzdata iotYuLiangData = null;
+        Set<String> enumSet = new HashSet<>();
         // 更新设备数据信息到数据库 mongodb
-        String cId = iotDeviceOld.getTid();
-
+        List<IotYfqxzdata> iotYfqxzdataList = new ArrayList<>();
         for (Object item: jarrData) {
-            JSONObject jobj = (JSONObject) item;
+            JSONObject jobj = JSONObject.from(item);
+            String eNum = jobj.getString("eNum");
+            String eKey = jobj.getString("eKey");
+            String eValue = jobj.getString("eValue");
             IotYfqxzdata iotYfqxzdata = new IotYfqxzdata();
-            iotYfqxzdata.setCId(cId);
+            iotYfqxzdata.setCId(iotDeviceOld.getTid());
             iotYfqxzdata.setDevBid(iotDeviceOld.getDevBid());
-            iotYfqxzdata.setENum(jobj.getString("eNum"));
+            iotYfqxzdata.setENum(eNum);
             iotYfqxzdata.setEName(jobj.getString("eName"));
-            iotYfqxzdata.setEKey(jobj.getString("eKey"));
-            iotYfqxzdata.setEValue(jobj.getString("eValue"));
-
+            iotYfqxzdata.setEKey(eKey);
+            iotYfqxzdata.setEValue(eValue);
             iotYfqxzdata.setTime(reportDt);
 
-            mongoService.saveOne(iotYfqxzdata);
+            iotYfqxzdataList.add(iotYfqxzdata);
+
+            // 如果有累计雨量,则计算单次雨量
+            if(EnumYfQxzElement.TYPE14.geteNum().equals(eNum)){
+                Date selectTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.dateNow());
+                Map<String, Object> map = new HashMap<>();
+                map.put("devBid",iotDeviceOld.getDevBid());
+                map.put("gte_time", selectTime);
+                map.put("eNum", eNum);
+                IotYfqxzdata resultData = (IotYfqxzdata) mongoService.findOne(IotYfqxzdata.class, map, "time", "desc");
+
+                double ev = Double.parseDouble(eValue);
+                if(resultData != null){
+                    String oldEValue = resultData.getEValue();
+                    ev =  ev - Double.parseDouble(oldEValue);
+                }
+                if(ev < 0){
+                    ev = 0.0;
+                }
+
+                iotYuLiangData = new IotYfqxzdata();
+                iotYuLiangData.setCId(iotDeviceOld.getTid());
+                iotYuLiangData.setDevBid(iotDeviceOld.getDevBid());
+                iotYuLiangData.setENum(yuLiangEnum);
+                iotYuLiangData.setEName(EnumCommonDataFactor.TYPE_104.getCode());
+                iotYuLiangData.setEKey("e" + yuLiangEnum);
+                iotYuLiangData.setEValue(new DecimalFormat("0.00").format(ev));
+                iotYuLiangData.setTime(reportDt);
+            }
 
+            enumSet.add(eNum);
             //把“上报时间”放里面
             jobj.put("time",DateUtils.parseDateToStr("yyyy-MM-dd'T'HH:mm:ss.SSSX",reportDt));
             jobj.put("devBid",iotYfqxzdata.getDevBid());
             jobj.put("cId",iotYfqxzdata.getCId());
         }
+
+        if(!enumSet.contains(yuLiangEnum) && iotYuLiangData != null){
+            iotYfqxzdataList.add(iotYuLiangData);
+
+            JSONObject yuliangObj = new JSONObject();
+            yuliangObj.put("eNum", iotYuLiangData.getENum());
+            yuliangObj.put("eName", iotYuLiangData.getEName());
+            yuliangObj.put("eKey", iotYuLiangData.getEKey());
+            yuliangObj.put("eValue", iotYuLiangData.getEValue());
+            ext.getJSONArray("data").add(yuliangObj);
+        }
+
+        if(!iotYfqxzdataList.isEmpty()){
+            mongoService.insertList(IotYfqxzdata.class, iotYfqxzdataList);
+        }
         iIotDevicelasteddataService.updateDeviceLastedData(iotDeviceOld,jarrData.toString(), devUpdateddate);
 
+        // 发送告警消息
+        warnService.processWarningReportData(iotDeviceOld, ext);
+
         //预警
         //云飞 气象站 和 墒情站  都从这里进数据
 /*        if( IotDeviceDictConst.TYPE_YF_QXZ.equals(iotDeviceOld.getDevtypeBid()) ){

+ 21 - 1
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfScdDeviceImpl.java

@@ -90,9 +90,29 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         switch (methodName) {
             case CmdDef.YfScdCmdDef.CMD_CONFIG:{
                 JSONObject jobjParam = cmdDistribution.getJsons();
+                Map<String, String> keyMap = new HashMap<>();
+                keyMap.put("ds", "ds");
+                keyMap.put("tt", "tt");
+                keyMap.put("dat_f", "dattim");
+                keyMap.put("ts", "ts");
+                keyMap.put("st", "st");
+                keyMap.put("et", "et");
+
+                JSONObject configObj = new JSONObject();
+                for(Map.Entry<String, String> entry : keyMap.entrySet()) {
+                    String key = entry.getKey();
+                    String keyName = entry.getValue();
+
+                    if (jobjParam.containsKey(key)) {
+                        Object value = jobjParam.get(key);
+                        if (value != null) {
+                            configObj.put(keyName, value);
+                        }
+                    }
+                }
                 JSONObject devConfig = new JSONObject();
                 devConfig.put("cmd", "paramconf");
-                devConfig.put("ext", jobjParam);
+                devConfig.put("ext", configObj);
                 mqttMsgContent = devConfig.toString();
                 log.info("【杀虫灯】发送指令【config】 mqttMsgContent={}", mqttMsgContent);
                 break;

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iots/service/IIotDeviceService.java

@@ -45,6 +45,8 @@ public interface IIotDeviceService {
      */
     List<IotDevice> selectIotDeviceByDevBidList(List<String> devBidList);
 
+    List<IotDevice> selectIotDeviceByDevCode(String devCode);
+
     /**
      * 根据设备标识列表批量查询设备map
      *

+ 0 - 2
src/main/java/com/yunfeiyun/agmp/iots/service/impl/IotCbdImgService.java

@@ -43,8 +43,6 @@ public class IotCbdImgService {
     @Resource
     private IIotPestService iotPestService;
 
-    @Autowired
-    private WarnService warnService;
 
 
 

+ 5 - 0
src/main/java/com/yunfeiyun/agmp/iots/service/impl/IotDeviceServiceImpl.java

@@ -126,6 +126,11 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
         return iotDeviceMapper.selectIotDeviceByDevBidList(devBidList);
     }
 
+    @Override
+    public List<IotDevice> selectIotDeviceByDevCode(String devCode) {
+        return iotDeviceMapper.selectIotDeviceByDevCode(devCode);
+    }
+
     /**
      * 根据设备标识列表批量查询设备map
      *

File diff suppressed because it is too large
+ 0 - 2253
src/main/java/com/yunfeiyun/agmp/iots/service/impl/WarnService.java


File diff suppressed because it is too large
+ 2264 - 0
src/main/java/com/yunfeiyun/agmp/iots/service/impl/WarnServiceDelete.java


+ 13 - 0
src/main/java/com/yunfeiyun/agmp/iots/startup/MongoStartup.java

@@ -150,6 +150,19 @@ public class MongoStartup {
         return mongodbIndexEntity;
     }
 
+    public MongodbIndexEntity iotYbqEnvDataCreateIndex() {
+        log.info("开始创建IotYbqEnvData索引");
+        List<String[]> indexNameList = new ArrayList<>();
+        indexNameList.add(new String[]{"devBid"});
+        indexNameList.add(new String[]{"devBid", "ybqdataCreatedDate"});
+
+        MongodbIndexEntity mongodbIndexEntity = new MongodbIndexEntity();
+        mongodbIndexEntity.setIotBaseEntity(IotYbqEnvData.class);
+        mongodbIndexEntity.setIndexNameList(indexNameList);
+
+        return mongodbIndexEntity;
+    }
+
     @PostConstruct
     public void start() {
         log.info("开始创建mongodb索引");

+ 33 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/job/WarnJob.java

@@ -0,0 +1,33 @@
+package com.yunfeiyun.agmp.iots.warn.job;
+
+import com.yunfeiyun.agmp.iots.warn.service.ReCountService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WarnJob {
+
+    @Autowired
+    private ReCountService reCountService;
+
+    /**
+     * 每天凌晨12点清除重复次数...
+     */
+    @Scheduled(cron = "0 0 0 * * ?")
+    public void resetReCount24() {
+        log.info("【设备预警】定时清空所有重复次数,0 0 * * * ? 每天凌晨12点清除重复次数");
+        reCountService.resetAllReCount();
+    }
+
+    /**
+     * 每2时执行一次...
+     */
+    @Scheduled(cron = "0 0 0/2 * * ?")
+    public void resetReCount2() {
+        log.info("【设备预警】定时清空所有重复次数,临时配置,0 0 0/2 * * ?  每2时执行一次");
+        reCountService.resetAllReCount();
+    }
+}

+ 53 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/mapper/IotWarnBussinessMapper.java

@@ -0,0 +1,53 @@
+package com.yunfeiyun.agmp.iots.warn.mapper;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotWarncount;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
+import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface IotWarnBussinessMapper {
+    /**
+     * 查询设备+配置的重复次数
+     *
+     * @param devBid
+     * @param configId
+     * @return
+     */
+    IotWarncount selectIotWarnCountByDevAndConfig(@Param("devBid") String devBid, @Param("wcBid") String configId);
+
+    /**
+     * 增加重复次数
+     *
+     * @param devBid
+     * @param configId
+     * @return
+     */
+    int incrementReCount(@Param("devBid") String devBid, @Param("wcBid") String configId);
+
+
+    /**
+     * 重置重复次数
+     *
+     * @return
+     */
+    int resetReCount();
+
+    List<IotWarncount> getAllReCount();
+
+    /**
+     * 插入预警记录
+     *
+     * @return
+     */
+    int insertWarnRecord(IotWarnlog iotWarnlog);
+
+    int updateIncrementReCount(@Param("devBid") String devBid, @Param("wcBid") String configId);
+
+    int insertIncrementReCount(IotWarncount iotWarncount);
+
+    List<WarnConfigInfo> selectIotWarnConfigInfoList(WarnConfigInfo warnConfigInfo);
+
+    int resetReCountByDevIdAndConfigId(@Param("devBid") String devBid, @Param("wcBid") String configId);
+}

+ 26 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnConfigInfo.java

@@ -0,0 +1,26 @@
+package com.yunfeiyun.agmp.iots.warn.model;
+
+import lombok.Data;
+
+@Data
+public class WarnConfigInfo {
+    private String wcBid;
+    private String wcName;
+    private String wcLevel;
+    private String wcTouchtype;
+    private String wcCondition;
+    private String wcStatus;
+    private int wcRepeatnum;
+    private String wiBid;
+    private String wiAddress;
+    private String wiCode;
+    private String wiName;
+    private String wiUnit;
+    private String wiExpression;
+    private String wiValue;
+    private String devtypeBid;
+    private String devBid;
+    private String tid;
+    private String wiStatus;
+
+}

+ 21 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnQxSqInfoDto.java

@@ -0,0 +1,21 @@
+package com.yunfeiyun.agmp.iots.warn.model;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceTypeLv1Enum;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevicefactor;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class WarnQxSqInfoDto {
+    private IotDevice iotDevice;
+    private List<WarnConfigInfo> configList;
+    private JSONObject jsonObject;
+    private Map<String, IotDevicefactor> factorMap;
+    private IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum;
+    private Map<String, String> currentValueMap;
+
+}

+ 59 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnResult.java

@@ -0,0 +1,59 @@
+package com.yunfeiyun.agmp.iots.warn.model;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
+import lombok.Data;
+
+/**
+ * 预警结果,不是对应数据库层面的
+ */
+@Data
+public class WarnResult extends IotBaseEntity {
+    /**
+     * 是否触发预警
+     */
+    private boolean isTriggered;
+    /**
+     * 预警消息
+     */
+    private String message;
+    /**
+     * 消息标识,用来打日志用的,可用UUID生成
+     */
+    private String messageId;
+    /**
+     * 设备id
+     */
+    private String devId;
+    /**
+     * 配置id
+     */
+    private String configId;
+    /**
+     * 上报的数据,冗余存储
+     */
+    private String reportData;
+    /**
+     * 配置的重复次数阀值
+     */
+    private int targetReCount;
+
+    private String tid;
+    /**
+     * 设备型号id
+     */
+    private String devtypeBid;
+
+    /**
+     * 配置对象
+     */
+    private IotWarnconfig config;
+
+    public WarnResult(boolean isTriggered, String message) {
+        this.isTriggered = isTriggered;
+        this.message = message;
+    }
+
+    public WarnResult() {
+    }
+}

+ 16 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnStatusDto.java

@@ -0,0 +1,16 @@
+package com.yunfeiyun.agmp.iots.warn.model;
+
+import lombok.Data;
+
+@Data
+public class WarnStatusDto {
+    private String devType;
+    private String devCode;
+    private String name;
+    private String value;
+    private String unit;
+    private String opt;
+    private String indicatorValue;
+
+    private boolean isWarn;
+}

+ 129 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/service/IotWarnBussinessService.java

@@ -0,0 +1,129 @@
+package com.yunfeiyun.agmp.iots.warn.service;
+
+import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
+import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
+import com.yunfeiyun.agmp.common.utils.DateUtils;
+import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarncount;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
+import com.yunfeiyun.agmp.iots.warn.mapper.IotWarnBussinessMapper;
+import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
+import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class IotWarnBussinessService {
+
+    @Autowired
+    private IotWarnBussinessMapper iotWarncountMapper;
+
+    @Resource
+    private RedisCacheManager redisCacheManager;
+
+    public Long selectIotWarnCountByDevAndConfig(String devId, String configId) {
+        log.info("查询设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
+        Long count = redisCacheManager.getCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
+        if (count != null) {
+            log.info("从缓存中获取到重复次数: {}", count);
+            return count;
+        }
+        IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
+        if (iotWarncount == null) {
+            log.warn("数据库中未找到设备ID: {}, 配置ID: {} 的重复次数数据", devId, configId);
+            return null;
+        } else {
+            log.info("从数据库中获取到重复次数: {}, 并将其加入缓存", iotWarncount.getWctCount());
+            redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
+            return iotWarncount.getWctCount();
+        }
+    }
+
+    public int incrementReCount(Long reCount, String devId, String configId, String tid) {
+        log.info("增加设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
+        if (reCount == null) {
+            log.info("初始化重复次数为1");
+            IotWarncount iotWarncount = new IotWarncount();
+            iotWarncount.setWctBid(IdUtils.fastUUID());
+            iotWarncount.setDevBid(devId);
+            iotWarncount.setWcBid(configId);
+            iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
+            iotWarncount.setWctCount(1L);
+            iotWarncount.setTid(tid);
+            int result = iotWarncountMapper.insertIncrementReCount(iotWarncount);
+            redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
+            log.info("初始化重复次数成功, 结果: {}", result);
+            return result;
+        } else {
+            int result = iotWarncountMapper.updateIncrementReCount(devId, configId);
+            redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, reCount + 1);
+            log.info("更新重复次数成功, 新的重复次数: {}", reCount + 1);
+            return result;
+        }
+    }
+
+    public int incrementReCount(Long reCount, WarnResult warnResult) {
+        return incrementReCount(reCount, warnResult.getDevId(), warnResult.getConfigId(), warnResult.getTid());
+    }
+
+    public int resetReCount() {
+        log.info("重置所有重复次数");
+        List<IotWarncount> iotWarncounts = iotWarncountMapper.getAllReCount();
+        for (IotWarncount iotWarncount : iotWarncounts) {
+            try {
+                redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, iotWarncount.getWcBid() + ":" + iotWarncount.getDevBid());
+                log.info("重置所有重复次数:配置id:{},设备id{},成功", iotWarncount.getWcBid() , iotWarncount.getDevBid());
+            } catch (Exception e) {
+                log.info("重置所有重复次数:配置id:{},设备id{},异常:{}", iotWarncount.getWcBid() , iotWarncount.getDevBid(), e);
+            }
+        }
+        int result = iotWarncountMapper.resetReCount();
+        log.info("重置所有重复次数结果: {}", result);
+        return result;
+    }
+
+    public int resetReCountByDevIdAndConfigId(String devId, String configId) {
+        log.info("重置设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
+        redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
+        int result = iotWarncountMapper.resetReCountByDevIdAndConfigId(devId, configId);
+        log.info("重置结果: {}", result);
+        return result;
+    }
+
+    public int insertWarnRecord(IotWarnlog iotWarnlog) {
+        log.info("插入预警记录: {}", iotWarnlog);
+        int result = iotWarncountMapper.insertWarnRecord(iotWarnlog);
+        log.info("插入预警记录结果: {}", result);
+        return result;
+    }
+
+    List<WarnConfigInfo> selectIotWarnConfigInfoList(WarnConfigInfo warnConfigInfo) {
+        log.info("查询预警配置信息列表");
+        List<WarnConfigInfo> list = iotWarncountMapper.selectIotWarnConfigInfoList(warnConfigInfo);
+        log.info("查询到 {} 条预警配置信息", list.size());
+        return list;
+    }
+
+    Map<String, List<WarnConfigInfo>> selectIotWarnConfigInfoMap(WarnConfigInfo warnConfigInfo) {
+        log.info("构建预警配置信息映射");
+        List<WarnConfigInfo> warnConfigInfoList = selectIotWarnConfigInfoList(warnConfigInfo);
+        Map<String, List<WarnConfigInfo>> warnConfigInfoMap = new HashMap<>();
+        for (WarnConfigInfo info : warnConfigInfoList) {
+            String wcBid = info.getWcBid();
+            if (!warnConfigInfoMap.containsKey(wcBid)) {
+                warnConfigInfoMap.put(wcBid, new ArrayList<>());
+            }
+            warnConfigInfoMap.get(wcBid).add(info);
+        }
+        log.info("构建完成,共包含 {} 个不同的配置ID", warnConfigInfoMap.size());
+        return warnConfigInfoMap;
+    }
+}

+ 132 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/service/ReCountService.java

@@ -0,0 +1,132 @@
+package com.yunfeiyun.agmp.iots.warn.service;
+
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
+import com.yunfeiyun.agmp.common.exception.BizException;
+import com.yunfeiyun.agmp.common.utils.DateUtils;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
+import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
+import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 重复次数服务
+ */
+@Service
+@Slf4j
+public class ReCountService {
+    @Autowired
+    private IotWarnBussinessService iotWarnBussinessService;
+
+    /**
+     * 针对预警解析出来的结果进行处理
+     *
+     * @param warnResult
+     */
+    public void handlerMessage(WarnResult warnResult) {
+        // 注意必要字段必须传过来
+        validateMessageParam(warnResult);
+
+        String messageId = warnResult.getMessageId();
+        log.info("【设备预警】消息标识{}:处理数据:{}", messageId, warnResult);
+        // 触发了预警,进行校验处理
+        if (warnResult.isTriggered()) {
+            Long reCount = iotWarnBussinessService.selectIotWarnCountByDevAndConfig(warnResult.getDevId(), warnResult.getConfigId());
+            int targetReCount = warnResult.getTargetReCount();
+            int thisReCount = reCount == null ? 0 : reCount.intValue();
+            log.info("【设备预警】消息标识{}:当前设备ID:{}, 预警配置ID:{} 的重复次数为: {}", messageId, warnResult.getDevId(), warnResult.getConfigId(), thisReCount);
+            if (thisReCount + 1 > targetReCount) {
+                log.info("【设备预警】消息标识{}:达到或超过阈值, 不再增加重复次数,直接生成预警记录", messageId);
+                iotWarnBussinessService.insertWarnRecord(buildWarnMessage(messageId, warnResult));
+            }else {
+                log.info("【设备预警】消息标识{}:未达阈值, 增加重复次数", messageId);
+                iotWarnBussinessService.incrementReCount(reCount, warnResult);
+            }
+
+        } else {
+            log.info("【设备预警】消息标识{}:未触发预警, 清除之前的重复计数", messageId);
+            cleanReCount(messageId, warnResult.getDevId(), warnResult.getConfigId());
+        }
+    }
+
+    /**
+     * 验证 WarnResult 对象的所有必要参数是否有效
+     *
+     * @param warnResult 要验证的预警结果对象
+     */
+    public void validateMessageParam(WarnResult warnResult) {
+        if (StringUtils.isEmpty(warnResult.getMessageId())) {
+            log.error("【设备预警】消息标识 不可为空");
+            throw new BizException(ErrorCode.FAILURE.getCode(), "消息标识不可为空");
+        }
+        String messageId = warnResult.getMessageId();
+        if (StringUtils.isEmpty(warnResult.getReportData())) {
+            log.error("【设备预警】消息标识{}:上报数据不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "上报数据不可为空");
+        }
+        if (StringUtils.isEmpty(warnResult.getDevId())) {
+            log.error("【设备预警】消息标识{}:设备id不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "设备id不可为空");
+        }
+        if (StringUtils.isEmpty(warnResult.getConfigId())) {
+            log.error("【设备预警】消息标识{}:配置id不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "配置id不可为空");
+        }
+        if (warnResult.getTargetReCount() < 0) {
+            log.error("【设备预警】消息标识{}:重复次数阈值必须大于等于0", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "重复次数阈值必须大于等于0");
+        }
+        if (warnResult.getConfig() == null) {
+            log.error("【设备预警】消息标识{}:配置对象不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "配置对象不可为空");
+        }
+        if (StringUtils.isEmpty(warnResult.getTid())) {
+            log.error("【设备预警】消息标识{}:tid不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "tid不可为空");
+        }
+        if (StringUtils.isEmpty(warnResult.getDevtypeBid())) {
+            log.error("【设备预警】消息标识{}:设备型号id不可为空", messageId);
+            throw new BizException(ErrorCode.FAILURE.getCode(), "设备型号id不可为空");
+        }
+        log.info("【设备预警】{}:所有参数验证通过");
+    }
+
+    IotWarnlog buildWarnMessage(String messageId, WarnResult warnResult) {
+        IotWarnconfig config = warnResult.getConfig();
+        IotWarnlog iotWarnlog = new IotWarnlog();
+        iotWarnlog.setWlBid(IdUtils.fastUUID());
+        iotWarnlog.setWlName(config.getWcName());
+        iotWarnlog.setWlLevel(config.getWcLevel());
+        iotWarnlog.setWlContent(warnResult.getMessage());
+        iotWarnlog.setDevtypeBid(warnResult.getDevtypeBid());
+        iotWarnlog.setDevBid(warnResult.getDevId());
+        iotWarnlog.setStatus("0");
+        iotWarnlog.setWlCreateddate(DateUtils.dateTimeNow());
+        iotWarnlog.setWlType(config.getWcTouchtype());
+        iotWarnlog.setWlData(warnResult.getReportData());
+        iotWarnlog.setTid(config.getTid());
+        iotWarnlog.setWcBid(config.getWcBid());
+        log.info("【设备预警】消息标识{}:构建预警信息: {}", messageId, iotWarnlog);
+        return iotWarnlog;
+    }
+
+    public void cleanReCount(String messageId, String devId, String configId) {
+        Long count = iotWarnBussinessService.selectIotWarnCountByDevAndConfig(devId, configId);
+        if (count == null) {
+            log.info("【设备预警】消息标识{}:没有找到对应的重复计数, 设备ID:{}, 配置ID:{}", messageId, devId, configId);
+            return;
+        }
+        if (count != 0) {
+            log.info("【设备预警】消息标识{}:重置设备ID:{}, 配置ID:{} 的重复计数", messageId, devId, configId);
+            iotWarnBussinessService.resetReCountByDevIdAndConfigId(devId, configId);
+        }
+    }
+
+    public void resetAllReCount() {
+        log.info("清空所有重复次数");
+        iotWarnBussinessService.resetReCount();
+    }
+}

+ 451 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java

@@ -0,0 +1,451 @@
+package com.yunfeiyun.agmp.iots.warn.service;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
+import com.yunfeiyun.agmp.iot.common.constant.device.ElementFormatUtil;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceTypeLv1Enum;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevicefactor;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
+import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
+import com.yunfeiyun.agmp.iots.service.IIotDevicefactorService;
+import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
+import com.yunfeiyun.agmp.iots.warn.model.WarnQxSqInfoDto;
+import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
+import com.yunfeiyun.agmp.iots.warn.model.WarnStatusDto;
+import com.yunfeiyun.agmp.iots.warn.util.CompareUtil;
+import com.yunfeiyun.agmp.iots.warn.util.WarnMessageBuilderUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * 预警核心服务类
+ */
+@Slf4j
+@Service
+public class WarnService {
+
+    @Resource(name = "threadPoolTaskExecutor")
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
+    @Autowired
+    private ReCountService reCountService;
+
+    @Autowired
+    private IotWarnBussinessService iotWarnBussinessService;
+
+    @Autowired
+    private IIotDevicefactorService iotDevicefactorService;
+
+    private Map<String, IotDevicefactor> getDevicefactorMap(String devBid){
+        IotDevicefactor param = new IotDevicefactor();
+        param.setDevBid(devBid);
+        List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
+        Map<String, IotDevicefactor> factorMap = new HashMap<>();
+        for(IotDevicefactor factor : factorList){
+            String dfCode = factor.getDfCode();
+            String dfAddress = factor.getDfAddress();
+            String key = dfAddress + dfCode;
+            factorMap.put(key, factor);
+        }
+        return factorMap;
+    }
+
+    /**
+     * 统一处理上报数据
+     *
+     * @param data  上报的数据对象
+     * param ext   上报的原始数据
+     */
+    public void processWarningReportData(IotDevice iotDevice, JSONObject data) {
+        //转异步处理
+        processWarningReportDataSyn(iotDevice, data);
+    }
+
+
+    /**
+     * 统一处理上报数据:异步处理
+     *
+     * @param data  上报的数据对象
+     */
+    private void processWarningReportDataSyn(IotDevice iotDevice, JSONObject data) {
+        String devBid = iotDevice.getDevBid();
+        String devtypeBid = iotDevice.getDevtypeBid();
+        String devClass =  IotDeviceDictEnum.getLv1CodeByCode(devtypeBid);
+        IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = IotDeviceTypeLv1Enum.findEnumByCode(devClass);
+        if (iotDeviceTypeLv1Enum == null) {
+            log.error("[设备告警] 设备大类不存在,devBid:{}, devtypeBid:{}", devBid, devtypeBid);
+            return;
+        }
+
+        CompletableFuture.runAsync(() -> {
+            // 获取该设备有哪些告警配置
+            WarnConfigInfo warnConfigInfo = new WarnConfigInfo();
+            warnConfigInfo.setTid(iotDevice.getTid());
+            warnConfigInfo.setDevBid(devBid);
+
+            Map<String, List<WarnConfigInfo>> configMap = iotWarnBussinessService.selectIotWarnConfigInfoMap(warnConfigInfo);
+            if (configMap == null || configMap.size() == 0) {
+                log.info("[设备告警] 该设备没有配置,devBid:{}", devBid);
+                return;
+            }
+
+            Map<String, IotDevicefactor> factorMap = getDevicefactorMap(devBid);
+
+            //配置一个个检查
+            for(Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
+                List<WarnConfigInfo> configList = entry.getValue();
+                WarnResult warnResult = null;
+
+                WarnQxSqInfoDto warnQxSqInfoDto = new WarnQxSqInfoDto();
+                warnQxSqInfoDto.setIotDevice(iotDevice);
+                warnQxSqInfoDto.setConfigList(configList);
+                warnQxSqInfoDto.setJsonObject(data);
+                warnQxSqInfoDto.setFactorMap(factorMap);
+                warnQxSqInfoDto.setIotDeviceTypeLv1Enum(iotDeviceTypeLv1Enum);
+
+                try{
+                    switch (iotDeviceTypeLv1Enum) {
+                        case QXZ: {
+                            warnResult = comparableQxzReportData(warnQxSqInfoDto);
+                            break;
+                        }
+//                        case SQZ: {
+//                            warnResult = comparableSqzReportData(warnQxSqInfoDto);
+//                            break;
+//                        }
+//                        case GSSQ: {
+//                            warnResult = comparableGssqReportData(warnQxSqInfoDto);
+//                            break;
+//                        }
+//                    case "病虫害": {
+//                        warnResult = comparableBchReportData(devBid, config, data);
+//                        break;
+//                    }
+                        default:
+                            break;
+                    }
+                }catch (Exception e){
+                    log.error("[设备告警] 设备上报数据 异常,devBid:{}, config:{}, data:{}", devBid, configList, data, e);
+                }
+
+                if (warnResult != null) {
+                    handleWarnRecord(warnResult);
+                }
+            }
+        }, threadPoolTaskExecutor);
+    }
+
+    /**
+     * 基于预警结果统一处理入库操作
+     * 注:不用管是否预警,直接调用,内部有针对不触发预警的逻辑
+     *
+     * @param warnResult
+     */
+    void handleWarnRecord(WarnResult warnResult) {
+        reCountService.handlerMessage(warnResult);
+    }
+
+    /**
+     * 根据设备id获取策略,可能有多个
+     *
+     * @param devBid
+     * @return
+     */
+    List<Object> getConfigByDevId(String devBid) {
+
+        return null;
+    }
+
+    private Map<String, String> getQxzCurrentValueMap(IotDevice iotDevice, JSONArray jsonArray) {
+        String devCode = iotDevice.getDevCode();
+        BigDecimal errorValue = new BigDecimal("-99");
+        Map<String, String> currentValueMap = new HashMap<>();
+        for(Object obj : jsonArray) {
+            JSONObject ob;
+            try {
+                ob = JSONObject.from(obj);
+            } catch (Exception e) {
+                log.error("[设备告警] 数据类型转换异常,devCode:{}, obj:{}", devCode, obj);
+                continue;
+            }
+
+            String eNum = ob.getString("eNum");
+            String eName = ob.getString("eName");
+            String eKey = ob.getString("eKey");
+            String address = ElementFormatUtil.getAddress(eName, eKey);
+            String key = address + eNum;
+
+            BigDecimal eValue = null;
+            try {
+                eValue = ob.getBigDecimal("eValue");
+                if (eValue.compareTo(errorValue) <= 0) {
+                    throw new Exception();
+                }
+            } catch (Exception e) {
+                log.error("[设备告警] 数据类型转换异常,devCode:{}, eNum:{}, eName:{}, eKey:{}", devCode, eNum, eName, eKey);
+                continue;
+            }
+            currentValueMap.put(key, String.valueOf(eValue));
+        }
+        return currentValueMap;
+    }
+
+    private String getDisplayName(String key, Map<String, IotDevicefactor> factorMap){
+        String wiName = "";
+        if(factorMap.containsKey(key)){
+            IotDevicefactor iotDevicefactor = factorMap.get(key);
+            // 如果禁用,直接返回null,不进行预警判断
+            if(Objects.equals(iotDevicefactor.getDfDisable(), "1")){
+                return null;
+            }
+            String displayname = iotDevicefactor.getDfDisplayname();
+            if(StringUtils.isNotEmpty(displayname)){
+                wiName = displayname;
+            }
+        }
+
+        return wiName;
+    }
+
+    private WarnStatusDto getQxzWarnStatusDto(WarnConfigInfo config, WarnQxSqInfoDto warnQxSqInfoDto) {
+        IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
+        String devCode = iotDevice.getDevCode();
+        Map<String, String> currentValueMap = warnQxSqInfoDto.getCurrentValueMap();
+        Map<String, IotDevicefactor> factorMap = warnQxSqInfoDto.getFactorMap();
+        IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = warnQxSqInfoDto.getIotDeviceTypeLv1Enum();
+
+        String targetValue = config.getWiValue();
+        String wiAddress = config.getWiAddress();
+        String wiCode = config.getWiCode();
+        String wcStatus = config.getWcStatus();
+        String wiStatus = config.getWiStatus();
+        String key = wiAddress + wiCode;
+        String expression = config.getWiExpression();
+
+        // 如果配置禁用,或者要素禁用,直接返回null,不进行预警判断
+        boolean status = "0".equals(wcStatus) && "0".equals(wiStatus);
+        if(!status){
+            return null;
+        }
+
+        // 如果上报数据中没有预警配置中的要素,直接返回null,不进行预警判断
+        if (!currentValueMap.containsKey(key)) {
+            return null;
+        }
+
+        // 如果没有配置预警条件和值,直接返回null,不进行预警判断
+        if(StringUtils.isEmpty(expression) || StringUtils.isEmpty(targetValue)){
+            return null;
+        }
+
+        String wiName = config.getWiName();
+        // 如果禁用,直接返回null,不进行预警判断
+        String displayname = getDisplayName(key, factorMap);
+        if(displayname == null){
+            return null;
+        }
+
+        if(StringUtils.isNotEmpty(displayname)){
+            wiName = displayname;
+        }
+        String wiUnit = config.getWiUnit();
+        String currentValue = currentValueMap.get(key);
+
+        EnumWarnRuleOp warnRuleOp = EnumWarnRuleOp.findEnumByCode(expression);
+        if(warnRuleOp == null){
+            log.error("[设备告警] 表达式不正确,devCode:{}, wiAddress:{}, config:{}", devCode, wiAddress, config);
+            return null;
+        }
+
+        String ruleName = warnRuleOp.getName();
+        boolean tempSuccess = CompareUtil.comp(currentValue, expression, targetValue);
+
+        WarnStatusDto warnStatusDto = new WarnStatusDto();
+        warnStatusDto.setDevType(iotDeviceTypeLv1Enum.getName());
+        warnStatusDto.setDevCode(devCode);
+        warnStatusDto.setName(wiName);
+        warnStatusDto.setValue(currentValue);
+        warnStatusDto.setUnit(wiUnit);
+        warnStatusDto.setOpt(ruleName);
+        warnStatusDto.setIndicatorValue(targetValue);
+        warnStatusDto.setWarn(tempSuccess);
+        return warnStatusDto;
+    }
+
+    /**
+     * 【气象站】比较该设备上报的任一要素否达到预警条件
+     * @param warnResult
+     * @param configList
+     * @param factorMap
+     * @param currentValueMap
+     * @param devCode
+     * @return
+     */
+    public WarnResult comparableQxzSingleIndicator(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
+        WarnStatusDto warnStatusDto = null;
+        for (WarnConfigInfo config : configList) {
+            warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
+            // 如果没有预警配置,直接返回null,不进行预警判断
+            if(warnStatusDto == null){
+                continue;
+            }
+            if(warnStatusDto.isWarn()){
+                break;
+            }
+        }
+        if(warnStatusDto != null && warnStatusDto.isWarn()){
+            String message = WarnMessageBuilderUtil.buildQxzWarningMessage(
+                    warnStatusDto.getDevType(),
+                    warnStatusDto.getDevCode(),
+                    warnStatusDto.getName(),
+                    warnStatusDto.getValue(),
+                    warnStatusDto.getUnit(),
+                    warnStatusDto.getOpt(),
+                    warnStatusDto.getIndicatorValue()
+            );
+            warnResult.setTriggered(true);
+            warnResult.setMessage(message);
+        }
+
+        return warnResult;
+    }
+
+    /**
+     * 处理多个指标是否同时满足预警条件。
+     *
+     * @param devId      设备ID
+     * @param config     告警规则
+     * @param jsonObject 上报的数据
+     * @return WarnResult 包含是否触发告警的信息
+     */
+    public WarnResult comparableQxzMultipleIndicators(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
+        WarnStatusDto warnStatusDto = null;
+        List<WarnStatusDto> warnStatusDtos = new ArrayList<>();
+        for (WarnConfigInfo config : configList) {
+            warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
+            // 如果没有预警配置,直接返回null,不进行预警判断
+            if(warnStatusDto == null){
+                continue;
+            }
+            if(!warnStatusDto.isWarn()){
+                return warnResult;
+            }
+            warnStatusDtos.add(warnStatusDto);
+        }
+        if(warnStatusDtos.isEmpty()){
+            return warnResult;
+        }
+
+        StringBuilder messageBuilder = new StringBuilder();
+        for(int i = 0; i < warnStatusDtos.size(); i++){
+            warnStatusDto = warnStatusDtos.get(i);
+            String devType = null;
+            String dCode = null;
+            if(i == 0){
+                devType = warnStatusDto.getDevType();
+                dCode = warnStatusDto.getDevCode();
+            }
+            String message = WarnMessageBuilderUtil.buildQxzWarningMessage(
+                    devType,
+                    dCode,
+                    warnStatusDto.getName(),
+                    warnStatusDto.getValue(),
+                    warnStatusDto.getUnit(),
+                    warnStatusDto.getOpt(),
+                    warnStatusDto.getIndicatorValue()
+            );
+            messageBuilder.append(message).append("\n");
+        }
+        warnResult.setTriggered(true);
+        warnResult.setMessage(messageBuilder.toString());
+        return warnResult;
+    }
+
+
+    /**
+     * 【气象站】比较该设备上报的要素和配置是否达到预警条件
+     *
+     * @param devBid      设备id
+     * @param config     对应的配置
+     * @param jsonObject 上报的数据
+     */
+    private WarnResult comparableQxzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
+        JSONObject jsonObject = warnQxSqInfoDto.getJsonObject();
+        JSONArray jsonArray = jsonObject.getJSONArray("data");
+        Map<String, String> currentValueMap = getQxzCurrentValueMap(iotDevice, jsonArray);
+
+        warnQxSqInfoDto.setCurrentValueMap(currentValueMap);
+
+        String devBid = iotDevice.getDevBid();
+        WarnConfigInfo configInfo = configList.get(0);
+        String wcCondition = configInfo.getWcCondition();
+
+        IotWarnconfig iotWarnconfig = new IotWarnconfig();
+        BeanUtils.copyProperties(configInfo, iotWarnconfig);
+
+        WarnResult warnResult = new WarnResult();
+        warnResult.setMessageId(warnResult.getUUId());
+        warnResult.setDevId(devBid);
+        warnResult.setTid(iotDevice.getTid());
+        warnResult.setConfigId(configInfo.getWcBid());
+        warnResult.setReportData(jsonObject.toJSONString());
+        warnResult.setTargetReCount(configInfo.getWcRepeatnum());
+        warnResult.setDevtypeBid(iotDevice.getDevtypeBid());
+        warnResult.setConfig(iotWarnconfig);
+        warnResult.setTriggered(false);
+
+        if("0".equals(wcCondition)){
+            warnResult = comparableQxzSingleIndicator(warnResult, warnQxSqInfoDto);
+        } else {
+            warnResult = comparableQxzMultipleIndicators(warnResult, warnQxSqInfoDto);
+        }
+        return warnResult;
+    }
+
+
+    /**
+     * 【墒情站】比较该设备上报的要素和配置是否达到预警条件
+     *
+     */
+    WarnResult comparableSqzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        return comparableQxzReportData(warnQxSqInfoDto);
+
+    }
+
+    /**
+     * 【管式墒情】比较该设备上报的要素和配置是否达到预警条件
+     *
+     */
+    WarnResult comparableGssqReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        return comparableQxzReportData(warnQxSqInfoDto);
+
+    }
+
+    /**
+     * 【病虫害】比较该设备上报的要素和配置是否达到预警条件,暂不实现,预留
+     *
+     * @param devId
+     * @param config
+     * @param jsonObject
+     */
+    WarnResult comparableBchReportData(String devId, Object config, JSONObject jsonObject) {
+        return null;
+
+    }
+
+}

+ 70 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/util/CompareUtil.java

@@ -0,0 +1,70 @@
+package com.yunfeiyun.agmp.iots.warn.util;
+
+import com.yunfeiyun.agmp.common.utils.StringUtils;
+import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
+
+import java.math.BigDecimal;
+
+public class CompareUtil {
+
+    /**
+     * @param currentValue 当前值
+     * @param opCode       表达式
+     * @param targetValue  对比值,如果是范围,则10-100
+     * @return
+     */
+    public static boolean comp(String currentValue, String opCode, String targetValue) {
+        if (StringUtils.isEmpty(currentValue)) {
+            return false;
+        }
+        boolean ret = false;
+        if (EnumWarnRuleOp.GREATER_THAN.equal(opCode)) {
+            int compRet = new BigDecimal(currentValue).compareTo(new BigDecimal(targetValue));
+            if (compRet > 0) {
+                ret = true;
+            }
+        } else if (EnumWarnRuleOp.LESS_THAN.equal(opCode)) {
+            int compRet = new BigDecimal(currentValue).compareTo(new BigDecimal(targetValue));
+            if (compRet < 0) {
+                ret = true;
+            }
+        } else if (EnumWarnRuleOp.GT_EQUAL.equal(opCode)) {
+            int compRet = new BigDecimal(currentValue).compareTo(new BigDecimal(targetValue));
+            if (compRet > 0 || compRet == 0) {
+                ret = true;
+            }
+        } else if (EnumWarnRuleOp.LT_EQUAL.equal(opCode)) {
+            int compRet = new BigDecimal(currentValue).compareTo(new BigDecimal(targetValue));
+            if (compRet < 0 || compRet == 0) {
+                ret = true;
+            }
+        } else if (EnumWarnRuleOp.BETWEEN.equal(opCode)) {
+            String[] value = targetValue.split("-");
+            //大于等于min 且 小于等于max
+            boolean ret1 = false;
+            int compRet = new BigDecimal(currentValue).compareTo(new BigDecimal(value[0]));
+            if (compRet > 0 || compRet == 0) {
+                ret1 = true;
+            }
+
+            boolean ret2 = false;
+            int compRet2 = new BigDecimal(currentValue).compareTo(new BigDecimal(value[1]));
+            if (compRet2 < 0 || compRet2 == 0) {
+                ret2 = true;
+            }
+            ret = ret1 && ret2;
+        } else if (EnumWarnRuleOp.NO_BETWEEN.equal(opCode)) {
+            // 当前值不在[min, max]范围内
+            String[] value = targetValue.split("-");
+            BigDecimal min = new BigDecimal(value[0]);
+            BigDecimal max = new BigDecimal(value[1]);
+            BigDecimal current = new BigDecimal(currentValue);
+            ret = current.compareTo(min) < 0 || current.compareTo(max) > 0;
+        }
+        return ret;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(comp("3.9", "notBetween", "99-99"));
+    }
+}

+ 35 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/util/WarnMessageBuilderUtil.java

@@ -0,0 +1,35 @@
+package com.yunfeiyun.agmp.iots.warn.util;
+
+public class WarnMessageBuilderUtil {
+    /**
+     * 构建告警信息。
+     *
+     * @param devType        设备类型,例如“气象站设备”。
+     * @param devCode        设备唯一编码,例如“87872877485”。
+     * @param name           告警参数名,例如“温度”。
+     * @param value          当前值,例如42。
+     * @param unit           单位,例如“℃”。
+     * @param opt            触发预警目标值的动作,例如超过,低于、大于等。
+     * @param indicatorValue 设定的目标对比值,例如“10-35℃”。
+     * @return 格式化后的告警信息。
+     */
+    public static String buildQxzWarningMessage(String devType, String devCode, String name, String value, String unit, String opt, String indicatorValue) {
+        // 格式化字符串,将设备类型、设备唯一编码、告警参数名、当前值、单位、动作和目标对比值插入到模板中
+        String tag = "";
+        if(devType != null && devCode != null){
+            tag = String.format("%s设备(%s), 触发告警,告警原因: \n", devType, devCode);
+        }
+        return String.format("%s %s 上报值 %s%s,%s设置的阀值%s。",
+                tag,
+                name,
+                value,
+                unit,
+                opt,
+                indicatorValue);
+    }
+
+    public static void main(String[] args) {
+        String message = buildQxzWarningMessage("气象站", "87872877485", "温度", "42", "℃", "超过", "10-35℃");
+        System.out.println(message);
+    }
+}

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

@@ -54,6 +54,13 @@
         </where>
     </select>
 
+    <select id="selectIotDeviceByDevCode" resultType="com.yunfeiyun.agmp.iot.common.domain.IotDevice">
+        <include refid="selectIotDeviceVo"/>
+        <where>
+            devCode = #{devCode} and devDelstatus = '0'
+        </where>
+    </select>
+
     <select id="selectIotDeviceByDevBidList" parameterType="java.util.List"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotDevice">
         <include refid="selectIotDeviceVo"/>

+ 102 - 0
src/main/resources/mapper/IotWarnBusinessMapper.xml

@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.yunfeiyun.agmp.iots.warn.mapper.IotWarnBussinessMapper">
+
+    <insert id="insertWarnRecord" parameterType="IotWarnlog" useGeneratedKeys="true" keyProperty="id">
+        insert into IotWarnlog
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="wlBid != null">wlBid,</if>
+            <if test="wlName != null">wlName,</if>
+            <if test="wlType != null">wlType,</if>
+            <if test="wlContent != null">wlContent,</if>
+            <if test="wlLevel != null">wlLevel,</if>
+            <if test="devtypeBid != null">devtypeBid,</if>
+            <if test="devBid != null">devBid,</if>
+            <if test="status != null">status,</if>
+            <if test="wlDealuserid != null">wlDealuserid,</if>
+            <if test="wlDealresult != null">wlDealresult,</if>
+            <if test="wlDealtime != null">wlDealtime,</if>
+            <if test="wlCreateddate != null">wlCreateddate,</if>
+            <if test="wlData != null">wlData,</if>
+            <if test="tid != null and tid != ''">tid,</if>
+            <if test="wcBid != null and wcBid != ''">wcBid,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="wlBid != null">#{wlBid},</if>
+            <if test="wlName != null">#{wlName},</if>
+            <if test="wlType != null">#{wlType},</if>
+            <if test="wlContent != null">#{wlContent},</if>
+            <if test="wlLevel != null">#{wlLevel},</if>
+            <if test="devtypeBid != null">#{devtypeBid},</if>
+            <if test="devBid != null">#{devBid},</if>
+            <if test="status != null">#{status},</if>
+            <if test="wlDealuserid != null">#{wlDealuserid},</if>
+            <if test="wlDealresult != null">#{wlDealresult},</if>
+            <if test="wlDealtime != null">#{wlDealtime},</if>
+            <if test="wlCreateddate != null">#{wlCreateddate},</if>
+            <if test="wlData != null">#{wlData},</if>
+            <if test="tid != null and tid != ''">#{tid},</if>
+            <if test="wcBid != null and wcBid != ''">#{wcBid},</if>
+        </trim>
+    </insert>
+    <insert id="insertIncrementReCount" parameterType="IotWarncount" useGeneratedKeys="true" keyProperty="id">
+        insert into IotWarncount
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="wctBid != null">wctBid,</if>
+            <if test="wcBid != null">wcBid,</if>
+            <if test="devBid != null">devBid,</if>
+            <if test="wctCount != null">wctCount,</if>
+            <if test="lastUpdateTime != null">lastUpdateTime,</if>
+            <if test="tid != null and tid != ''">tid,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="wctBid != null">#{wctBid},</if>
+            <if test="wcBid != null">#{wcBid},</if>
+            <if test="devBid != null">#{devBid},</if>
+            <if test="wctCount != null">#{wctCount},</if>
+            <if test="lastUpdateTime != null">#{lastUpdateTime},</if>
+            <if test="tid != null and tid != ''">#{tid},</if>
+        </trim>
+    </insert>
+    <update id="incrementReCount">
+             update IotWarncount set wctCount=wctCount+1 where devBid=#{devBid} and wcBid=#{wcBid};
+    </update>
+
+    <update id="resetReCount">
+            update IotWarncount set wctCount=0;
+    </update>
+    <update id="updateIncrementReCount">
+             update IotWarncount set wctCount=wctCount+1 where devBid=#{devBid} and wcBid=#{wcBid};
+    </update>
+    <update id="resetReCountByDevIdAndConfigId">
+              update IotWarncount set wctCount=0 where devBid=#{devBid} and wcBid=#{wcBid};
+    </update>
+
+    <select id="selectIotWarnCountByDevAndConfig"
+            resultType="com.yunfeiyun.agmp.iot.common.domain.IotWarncount">
+        select  * from IotWarncount where devBid=#{devBid} and wcBid=#{wcBid};
+    </select>
+
+    <select id="selectIotWarnConfigInfoList" parameterType="com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo" resultType="com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo">
+        SELECT wc.*, wi.wiBid, wi.wiAddress,
+            wi.wiCode, wi.wiName, wi.wiUnit, wi.wiExpression, wi.wiValue, wi.wiStatus
+        FROM IotWarnconfig AS wc
+            LEFT JOIN IotWarnindicator AS wi ON wi.wcBid = wc.wcBid
+            <if test="devBid != null">
+                LEFT JOIN IotWarnobject AS wo ON wo.wcBid = wc.wcBid
+            </if>
+
+        WHERE wc.tid = #{tid} AND wi.wiBid IS NOT NULL
+            <if test="devBid != null">
+                AND wo.devBid = #{devBid} AND wo.woBid IS NOT NULL
+            </if>
+            <if test="devtypeBid!= null">
+                AND wc.devtypeBid = #{devtypeBid}
+            </if>
+    </select>
+    <select id="getAllReCount" resultType="com.yunfeiyun.agmp.iot.common.domain.IotWarncount">
+        select  * from IotWarncount
+    </select>
+</mapper>

+ 0 - 152
src/main/resources/mapper/IotWarnconfigMapper.xml

@@ -1,152 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.yunfeiyun.agmp.iots.device.mapper.IotWarnconfigMapper">
-    
-    <resultMap type="IotWarnconfig" id="IotWarnconfigResult">
-        <result property="id"    column="id"    />
-        <result property="wcBid"    column="wcBid"    />
-        <result property="wcName"    column="wcName"    />
-        <result property="wcType"    column="wcType"    />
-        <result property="wcLevel"    column="wcLevel"    />
-        <result property="wcNoticetype"    column="wcNoticetype"    />
-        <result property="wcRule"    column="wcRule"    />
-        <result property="wcPushtype"    column="wcPushtype"    />
-        <result property="wcPushtime"    column="wcPushtime"    />
-        <result property="devBid"    column="devBid"    />
-        <result property="wcRevrole"    column="wcRevrole"    />
-        <result property="wcRecvuser"    column="wcRecvuser"    />
-        <result property="wcAlvstatus"    column="wcAlvstatus"    />
-        <result property="wcDelstatus"    column="wcDelstatus"    />
-        <result property="wcTimerange"    column="wcTimerange"    />
-        <result property="wcSuggestion"    column="wcSuggestion"    />
-        <result property="wcCreator"    column="wcCreator"    />
-        <result property="wcCreateddate"    column="wcCreateddate"    />
-        <result property="wcModifier"    column="wcModifier"    />
-        <result property="wcModifieddate"    column="wcModifieddate"    />
-    </resultMap>
-
-    <sql id="selectIotWarnconfigVo">
-        select IotWarnconfig.id, wcBid, wcName, wcType, wcLevel, wcNoticetype, wcRule, wcPushtype, wcPushtime
-        , devBid, wcRevrole, wcRecvuser, wcAlvstatus, wcDelstatus, wcTimerange, wcSuggestion
-        , wcCreator, wcCreateddate, wcModifier, wcModifieddate
-        ,IotWarntype.wtCata
-        from IotWarnconfig
-        left join IotWarntype on IotWarntype.wtBid = IotWarnconfig.wcType
-    </sql>
-
-    <select id="selectIotWarnconfigList" parameterType="IotWarnconfigReqVo" resultType="IotWarnconfigResVo">
-        <include refid="selectIotWarnconfigVo"/>
-        <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="wcType != null  and wcType != ''"> and wcType = #{wcType}</if>
-            <if test="wtCata != null  and wtCata != ''"> and wtCata = #{wtCata}</if>
-            <if test="wcLevel != null  and wcLevel != ''"> and wcLevel = #{wcLevel}</if>
-            <if test="wcNoticetype != null  and wcNoticetype != ''"> and wcNoticetype = #{wcNoticetype}</if>
-            <if test="wcRule != null  and wcRule != ''"> and wcRule = #{wcRule}</if>
-            <if test="wcPushtype != null  and wcPushtype != ''"> and wcPushtype = #{wcPushtype}</if>
-            <if test="wcPushtime != null  and wcPushtime != ''"> and wcPushtime = #{wcPushtime}</if>
-            <if test="devBid != null  and devBid != ''"> and FIND_IN_SET(#{devBid},devBid)>0</if>
-            <if test="wcRevrole != null  and wcRevrole != ''"> and wcRevrole = #{wcRevrole}</if>
-            <if test="wcRecvuser != null  and wcRecvuser != ''"> and wcRecvuser = #{wcRecvuser}</if>
-            <if test="wcAlvstatus != null  and wcAlvstatus != ''"> and wcAlvstatus = #{wcAlvstatus}</if>
-            <if test="wcDelstatus != null  and wcDelstatus != ''"> and wcDelstatus = #{wcDelstatus}</if>
-            <if test="wcTimerange != null  and wcTimerange != ''"> and wcTimerange = #{wcTimerange}</if>
-            <if test="wcSuggestion != null  and wcSuggestion != ''"> and wcSuggestion like concat('%', #{wcSuggestion}, '%')</if>
-            <if test="wcCreator != null  and wcCreator != ''"> and wcCreator = #{wcCreator}</if>
-            <if test="wcCreateddate != null  and wcCreateddate != ''"> and wcCreateddate = #{wcCreateddate}</if>
-            <if test="wcModifier != null  and wcModifier != ''"> and wcModifier = #{wcModifier}</if>
-            <if test="wcModifieddate != null  and wcModifieddate != ''"> and wcModifieddate = #{wcModifieddate}</if>
-        </where>
-    </select>
-    
-    <select id="selectIotWarnconfigById" parameterType="Long" resultMap="IotWarnconfigResult">
-        <include refid="selectIotWarnconfigVo"/>
-        where id = #{id}
-    </select>
-        
-    <insert id="insertIotWarnconfig" parameterType="IotWarnconfig" useGeneratedKeys="true" keyProperty="id">
-        insert into IotWarnconfig
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="wcBid != null">wcBid,</if>
-            <if test="wcName != null">wcName,</if>
-            <if test="wcType != null">wcType,</if>
-            <if test="wcLevel != null">wcLevel,</if>
-            <if test="wcNoticetype != null">wcNoticetype,</if>
-            <if test="wcRule != null">wcRule,</if>
-            <if test="wcPushtype != null">wcPushtype,</if>
-            <if test="wcPushtime != null">wcPushtime,</if>
-            <if test="devBid != null">devBid,</if>
-            <if test="wcRevrole != null">wcRevrole,</if>
-            <if test="wcRecvuser != null">wcRecvuser,</if>
-            <if test="wcAlvstatus != null">wcAlvstatus,</if>
-            <if test="wcDelstatus != null">wcDelstatus,</if>
-            <if test="wcTimerange != null">wcTimerange,</if>
-            <if test="wcSuggestion != null">wcSuggestion,</if>
-            <if test="wcCreator != null">wcCreator,</if>
-            <if test="wcCreateddate != null">wcCreateddate,</if>
-            <if test="wcModifier != null">wcModifier,</if>
-            <if test="wcModifieddate != null">wcModifieddate,</if>
-         </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="wcBid != null">#{wcBid},</if>
-            <if test="wcName != null">#{wcName},</if>
-            <if test="wcType != null">#{wcType},</if>
-            <if test="wcLevel != null">#{wcLevel},</if>
-            <if test="wcNoticetype != null">#{wcNoticetype},</if>
-            <if test="wcRule != null">#{wcRule},</if>
-            <if test="wcPushtype != null">#{wcPushtype},</if>
-            <if test="wcPushtime != null">#{wcPushtime},</if>
-            <if test="devBid != null">#{devBid},</if>
-            <if test="wcRevrole != null">#{wcRevrole},</if>
-            <if test="wcRecvuser != null">#{wcRecvuser},</if>
-            <if test="wcAlvstatus != null">#{wcAlvstatus},</if>
-            <if test="wcDelstatus != null">#{wcDelstatus},</if>
-            <if test="wcTimerange != null">#{wcTimerange},</if>
-            <if test="wcSuggestion != null">#{wcSuggestion},</if>
-            <if test="wcCreator != null">#{wcCreator},</if>
-            <if test="wcCreateddate != null">#{wcCreateddate},</if>
-            <if test="wcModifier != null">#{wcModifier},</if>
-            <if test="wcModifieddate != null">#{wcModifieddate},</if>
-         </trim>
-    </insert>
-
-    <update id="updateIotWarnconfig" parameterType="IotWarnconfig">
-        update IotWarnconfig
-        <trim prefix="SET" suffixOverrides=",">
-            <if test="wcBid != null">wcBid = #{wcBid},</if>
-            <if test="wcName != null">wcName = #{wcName},</if>
-            <if test="wcType != null">wcType = #{wcType},</if>
-            <if test="wcLevel != null">wcLevel = #{wcLevel},</if>
-            <if test="wcNoticetype != null">wcNoticetype = #{wcNoticetype},</if>
-            <if test="wcRule != null">wcRule = #{wcRule},</if>
-            <if test="wcPushtype != null">wcPushtype = #{wcPushtype},</if>
-            <if test="wcPushtime != null">wcPushtime = #{wcPushtime},</if>
-            <if test="devBid != null">devBid = #{devBid},</if>
-            <if test="wcRevrole != null">wcRevrole = #{wcRevrole},</if>
-            <if test="wcRecvuser != null">wcRecvuser = #{wcRecvuser},</if>
-            <if test="wcAlvstatus != null">wcAlvstatus = #{wcAlvstatus},</if>
-            <if test="wcDelstatus != null">wcDelstatus = #{wcDelstatus},</if>
-            <if test="wcTimerange != null">wcTimerange = #{wcTimerange},</if>
-            <if test="wcSuggestion != null">wcSuggestion = #{wcSuggestion},</if>
-            <if test="wcCreator != null">wcCreator = #{wcCreator},</if>
-            <if test="wcCreateddate != null">wcCreateddate = #{wcCreateddate},</if>
-            <if test="wcModifier != null">wcModifier = #{wcModifier},</if>
-            <if test="wcModifieddate != null">wcModifieddate = #{wcModifieddate},</if>
-        </trim>
-        where id = #{id}
-    </update>
-
-    <delete id="deleteIotWarnconfigById" parameterType="Long">
-        delete from IotWarnconfig where id = #{id}
-    </delete>
-
-    <delete id="deleteIotWarnconfigByIds" parameterType="String">
-        delete from IotWarnconfig where id in 
-        <foreach item="id" collection="array" open="(" separator="," close=")">
-            #{id}
-        </foreach>
-    </delete>
-</mapper>

+ 0 - 130
src/main/resources/mapper/IotWarnlogMapper.xml

@@ -1,130 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.yunfeiyun.agmp.iots.device.mapper.IotWarnlogMapper">
-    
-    <resultMap type="IotWarnlog" id="IotWarnlogResult">
-        <result property="id"    column="id"    />
-        <result property="wlBid"    column="wlBid"    />
-        <result property="wcBid"    column="wcBid"    />
-        <result property="wlContent"    column="wlContent"    />
-        <result property="wlContentsimple"    column="wlContentsimple"    />
-        <result property="wlTime"    column="wlTime"    />
-        <result property="msgBatchid"    column="msgBatchid"    />
-        <result property="devBid"    column="devBid"    />
-        <result property="wlPushstatus"    column="wlPushstatus"    />
-        <result property="wlDelstatus"    column="wlDelstatus"    />
-        <result property="wlCreator"    column="wlCreator"    />
-        <result property="wlCreateddate"    column="wlCreateddate"    />
-        <result property="wlModifier"    column="wlModifier"    />
-        <result property="wlModifieddate"    column="wlModifieddate"    />
-    </resultMap>
-
-    <sql id="selectIotWarnlogVo">
-        select IotWarnlog.id, wlBid, IotWarnlog.wcBid, wlContent, wlContentsimple, wlTime, msgBatchid
-        , wlDelstatus, wlCreator, wlCreateddate, wlModifier, wlModifieddate
-        ,IotWarnlog.devBid,IotWarnlog.wlPushstatus
-        ,IotWarnconfig.wcName,IotWarnconfig.wcType,IotWarnconfig.devBid,IotWarnconfig.wcLevel
-        ,IotWarnconfig.wcNoticetype,IotWarnconfig.wcRevrole,IotWarnconfig.wcRecvuser
-        ,IotWarnconfig.wcTimerange, IotWarnconfig.wcSuggestion, IotWarnconfig.wcPushtype
-        ,IotDevice.devName,IotDevice.devCode
-        from IotWarnlog
-        left join IotWarnconfig on IotWarnconfig.wcBid = IotWarnlog.wcBid
-        left join IotDevice on IotDevice.devBid = IotWarnconfig.devBid
-    </sql>
-
-    <select id="selectIotWarnlogList" parameterType="IotWarnlog" resultMap="IotWarnlogResult">
-        <include refid="selectIotWarnlogVo"/>
-        <where>  
-            <if test="wlBid != null  and wlBid != ''"> and wlBid = #{wlBid}</if>
-            <if test="wcBid != null  and wcBid != ''"> and wcBid = #{wcBid}</if>
-            <if test="wlContent != null  and wlContent != ''"> and wlContent like concat('%', #{wlContent}, '%')</if>
-            <if test="wlContentsimple != null  and wlContentsimple != ''"> and wlContentsimple like concat('%', #{wlContentsimple}, '%')</if>
-            <if test="wlTime != null  and wlTime != ''"> and wlTime = #{wlTime}</if>
-            <if test="msgBatchid != null  and msgBatchid != ''"> and msgBatchid = #{msgBatchid}</if>
-            <if test="devBid != null  and devBid != ''"> and devBid = #{devBid}</if>
-            <if test="wlPushstatus != null  and wlPushstatus != ''"> and wlPushstatus = #{wlPushstatus}</if>
-            <if test="wlDelstatus != null  and wlDelstatus != ''"> and wlDelstatus = #{wlDelstatus}</if>
-            <if test="wlCreator != null  and wlCreator != ''"> and wlCreator = #{wlCreator}</if>
-            <if test="wlCreateddate != null  and wlCreateddate != ''"> and wlCreateddate = #{wlCreateddate}</if>
-            <if test="wlModifier != null  and wlModifier != ''"> and wlModifier = #{wlModifier}</if>
-            <if test="wlModifieddate != null  and wlModifieddate != ''"> and wlModifieddate = #{wlModifieddate}</if>
-        </where>
-    </select>
-    
-    <select id="selectIotWarnlogById" parameterType="Long" resultMap="IotWarnlogResult">
-        <include refid="selectIotWarnlogVo"/>
-        where id = #{id}
-    </select>
-
-    <select id="selectIotWarnlogByBid" parameterType="String" resultType="IotWarnlogResVo">
-        <include refid="selectIotWarnlogVo"/>
-        where wlBid = #{wlBid}
-    </select>
-        
-    <insert id="insertIotWarnlog" parameterType="IotWarnlog" useGeneratedKeys="true" keyProperty="id">
-        insert into IotWarnlog
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="wlBid != null">wlBid,</if>
-            <if test="wcBid != null">wcBid,</if>
-            <if test="wlContent != null">wlContent,</if>
-            <if test="wlContentsimple != null">wlContentsimple,</if>
-            <if test="wlTime != null">wlTime,</if>
-            <if test="msgBatchid != null">msgBatchid,</if>
-            <if test="devBid != null">devBid,</if>
-            <if test="wlPushstatus != null">wlPushstatus,</if>
-            <if test="wlDelstatus != null">wlDelstatus,</if>
-            <if test="wlCreator != null">wlCreator,</if>
-            <if test="wlCreateddate != null">wlCreateddate,</if>
-            <if test="wlModifier != null">wlModifier,</if>
-            <if test="wlModifieddate != null">wlModifieddate,</if>
-         </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="wlBid != null">#{wlBid},</if>
-            <if test="wcBid != null">#{wcBid},</if>
-            <if test="wlContent != null">#{wlContent},</if>
-            <if test="wlContentsimple != null">#{wlContentsimple},</if>
-            <if test="wlTime != null">#{wlTime},</if>
-            <if test="msgBatchid != null">#{msgBatchid},</if>
-            <if test="devBid != null">#{devBid},</if>
-            <if test="wlPushstatus != null">#{wlPushstatus},</if>
-            <if test="wlDelstatus != null">#{wlDelstatus},</if>
-            <if test="wlCreator != null">#{wlCreator},</if>
-            <if test="wlCreateddate != null">#{wlCreateddate},</if>
-            <if test="wlModifier != null">#{wlModifier},</if>
-            <if test="wlModifieddate != null">#{wlModifieddate},</if>
-         </trim>
-    </insert>
-
-    <update id="updateIotWarnlog" parameterType="IotWarnlog">
-        update IotWarnlog
-        <trim prefix="SET" suffixOverrides=",">
-            <if test="wlBid != null">wlBid = #{wlBid},</if>
-            <if test="wcBid != null">wcBid = #{wcBid},</if>
-            <if test="wlContent != null">wlContent = #{wlContent},</if>
-            <if test="wlContentsimple != null">wlContentsimple = #{wlContentsimple},</if>
-            <if test="wlTime != null">wlTime = #{wlTime},</if>
-            <if test="msgBatchid != null">msgBatchid = #{msgBatchid},</if>
-            <if test="devBid != null">devBid = #{devBid},</if>
-            <if test="wlPushstatus != null">wlPushstatus = #{wlPushstatus},</if>
-            <if test="wlDelstatus != null">wlDelstatus = #{wlDelstatus},</if>
-            <if test="wlCreator != null">wlCreator = #{wlCreator},</if>
-            <if test="wlCreateddate != null">wlCreateddate = #{wlCreateddate},</if>
-            <if test="wlModifier != null">wlModifier = #{wlModifier},</if>
-            <if test="wlModifieddate != null">wlModifieddate = #{wlModifieddate},</if>
-        </trim>
-        where wlBid = #{wlBid}
-    </update>
-
-    <delete id="deleteIotWarnlogById" parameterType="Long">
-        delete from IotWarnlog where id = #{id}
-    </delete>
-
-    <delete id="deleteIotWarnlogByIds" parameterType="String">
-        delete from IotWarnlog where id in 
-        <foreach item="id" collection="array" open="(" separator="," close=")">
-            #{id}
-        </foreach>
-    </delete>
-</mapper>

+ 0 - 104
src/main/resources/mapper/IotWarntypeMapper.xml

@@ -1,104 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.yunfeiyun.agmp.iots.device.mapper.IotWarntypeMapper">
-    
-    <resultMap type="IotWarntype" id="IotWarntypeResult">
-        <result property="id"    column="id"    />
-        <result property="cId"    column="cId"    />
-        <result property="wtBid"    column="wtBid"    />
-        <result property="wtName"    column="wtName"    />
-        <result property="wtCata"    column="wtCata"    />
-        <result property="devtypeBid"    column="devtypeBid"    />
-        <result property="wtDelstatus"    column="wtDelstatus"    />
-        <result property="wtCreator"    column="wtCreator"    />
-        <result property="wtCreateddate"    column="wtCreateddate"    />
-        <result property="wtModifier"    column="wtModifier"    />
-        <result property="wtModifieddate"    column="wtModifieddate"    />
-    </resultMap>
-
-    <sql id="selectIotWarntypeVo">
-        select id, cId, wtBid, wtName, wtCata, devtypeBid, wtDelstatus, wtCreator, wtCreateddate, wtModifier, wtModifieddate from IotWarntype
-    </sql>
-
-    <select id="selectIotWarntypeList" parameterType="IotWarntype" resultType="IotWarntypeResVo">
-        <include refid="selectIotWarntypeVo"/>
-        <where>
-            wtDelstatus = '0'
-            <if test="cId != null  and cId != ''"> and cId = #{cId}</if>
-            <if test="wtName != null  and wtName != ''"> and wtName like concat('%', #{wtName}, '%')</if>
-            <if test="wtCata != null  and wtCata != ''"> and wtCata = #{wtCata}</if>
-            <if test="devtypeBid != null  and devtypeBid != ''"> and devtypeBid = #{devtypeBid}</if>
-            <if test="wtDelstatus != null  and wtDelstatus != ''"> and wtDelstatus = #{wtDelstatus}</if>
-            <if test="wtCreator != null  and wtCreator != ''"> and wtCreator = #{wtCreator}</if>
-            <if test="wtCreateddate != null  and wtCreateddate != ''"> and wtCreateddate = #{wtCreateddate}</if>
-            <if test="wtModifier != null  and wtModifier != ''"> and wtModifier = #{wtModifier}</if>
-            <if test="wtModifieddate != null  and wtModifieddate != ''"> and wtModifieddate = #{wtModifieddate}</if>
-        </where>
-    </select>
-    
-    <select id="selectIotWarntypeById" parameterType="Long" resultMap="IotWarntypeResult">
-        <include refid="selectIotWarntypeVo"/>
-        where id = #{id}
-    </select>
-
-    <select id="selectIotWarntypeByBid" parameterType="String" resultType="IotWarntypeResVo">
-        <include refid="selectIotWarntypeVo"/>
-        where wtDelstatus = '0' and wtBid = #{wtBid}
-    </select>
-        
-    <insert id="insertIotWarntype" parameterType="IotWarntype" useGeneratedKeys="true" keyProperty="id">
-        insert into IotWarntype
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="cId != null">cId,</if>
-            <if test="wtBid != null">wtBid,</if>
-            <if test="wtName != null">wtName,</if>
-            <if test="wtCata != null">wtCata,</if>
-            <if test="devtypeBid != null">devtypeBid,</if>
-            <if test="wtDelstatus != null">wtDelstatus,</if>
-            <if test="wtCreator != null">wtCreator,</if>
-            <if test="wtCreateddate != null">wtCreateddate,</if>
-            <if test="wtModifier != null">wtModifier,</if>
-            <if test="wtModifieddate != null">wtModifieddate,</if>
-         </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="cId != null">#{cId},</if>
-            <if test="wtBid != null">#{wtBid},</if>
-            <if test="wtName != null">#{wtName},</if>
-            <if test="wtCata != null">#{wtCata},</if>
-            <if test="devtypeBid != null">#{devtypeBid},</if>
-            <if test="wtDelstatus != null">#{wtDelstatus},</if>
-            <if test="wtCreator != null">#{wtCreator},</if>
-            <if test="wtCreateddate != null">#{wtCreateddate},</if>
-            <if test="wtModifier != null">#{wtModifier},</if>
-            <if test="wtModifieddate != null">#{wtModifieddate},</if>
-         </trim>
-    </insert>
-
-    <update id="updateIotWarntype" parameterType="IotWarntype">
-        update IotWarntype
-        <trim prefix="SET" suffixOverrides=",">
-            <if test="wtName != null">wtName = #{wtName},</if>
-            <if test="wtCata != null">wtCata = #{wtCata},</if>
-            <if test="devtypeBid != null">devtypeBid = #{devtypeBid},</if>
-            <if test="wtDelstatus != null">wtDelstatus = #{wtDelstatus},</if>
-            <if test="wtCreator != null">wtCreator = #{wtCreator},</if>
-            <if test="wtCreateddate != null">wtCreateddate = #{wtCreateddate},</if>
-            <if test="wtModifier != null">wtModifier = #{wtModifier},</if>
-            <if test="wtModifieddate != null">wtModifieddate = #{wtModifieddate},</if>
-        </trim>
-        where wtBid = #{wtBid}
-    </update>
-
-    <delete id="deleteIotWarntypeById" parameterType="Long">
-        delete from IotWarntype where id = #{id}
-    </delete>
-
-    <delete id="deleteIotWarntypeByBids" parameterType="String">
-        update IotWarntype set wtDelstatus = '1' where wtBid in
-        <foreach item="wtBid" collection="array" open="(" separator="," close=")">
-            #{wtBid}
-        </foreach>
-    </delete>
-</mapper>