|
|
@@ -26,7 +26,7 @@ import java.util.Map;
|
|
|
public class IotWarnBussinessService {
|
|
|
|
|
|
@Autowired
|
|
|
- private IotWarnBussinessMapper iotWarncountMapper;
|
|
|
+ private IotWarnBussinessMapper iotWarnBussinessMapper;
|
|
|
|
|
|
@Resource
|
|
|
private RedisCacheManager redisCacheManager;
|
|
|
@@ -38,7 +38,7 @@ public class IotWarnBussinessService {
|
|
|
log.info("从缓存中获取到重复次数: {}", count);
|
|
|
return count;
|
|
|
}
|
|
|
- IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
|
|
|
+ IotWarncount iotWarncount = iotWarnBussinessMapper.selectIotWarnCountByDevAndConfig(devId, configId);
|
|
|
if (iotWarncount == null) {
|
|
|
log.warn("数据库中未找到设备ID: {}, 配置ID: {} 的重复次数数据", devId, configId);
|
|
|
return null;
|
|
|
@@ -60,12 +60,12 @@ public class IotWarnBussinessService {
|
|
|
iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
|
|
|
iotWarncount.setWctCount(1L);
|
|
|
iotWarncount.setTid(tid);
|
|
|
- int result = iotWarncountMapper.insertIncrementReCount(iotWarncount);
|
|
|
+ int result = iotWarnBussinessMapper.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);
|
|
|
+ int result = iotWarnBussinessMapper.updateIncrementReCount(devId, configId);
|
|
|
redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, reCount + 1);
|
|
|
log.info("更新重复次数成功, 新的重复次数: {}", reCount + 1);
|
|
|
return result;
|
|
|
@@ -78,7 +78,7 @@ public class IotWarnBussinessService {
|
|
|
|
|
|
public int resetReCount() {
|
|
|
log.info("重置所有重复次数");
|
|
|
- List<IotWarncount> iotWarncounts = iotWarncountMapper.getAllReCount();
|
|
|
+ List<IotWarncount> iotWarncounts = iotWarnBussinessMapper.getAllReCount();
|
|
|
for (IotWarncount iotWarncount : iotWarncounts) {
|
|
|
try {
|
|
|
redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, iotWarncount.getWcBid() + ":" + iotWarncount.getDevBid());
|
|
|
@@ -87,7 +87,7 @@ public class IotWarnBussinessService {
|
|
|
log.info("重置所有重复次数:配置id:{},设备id{},异常:{}", iotWarncount.getWcBid(), iotWarncount.getDevBid(), e);
|
|
|
}
|
|
|
}
|
|
|
- int result = iotWarncountMapper.resetReCount();
|
|
|
+ int result = iotWarnBussinessMapper.resetReCount();
|
|
|
log.info("重置所有重复次数结果: {}", result);
|
|
|
return result;
|
|
|
}
|
|
|
@@ -95,28 +95,28 @@ public class IotWarnBussinessService {
|
|
|
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);
|
|
|
+ int result = iotWarnBussinessMapper.resetReCountByDevIdAndConfigId(devId, configId);
|
|
|
log.info("重置结果: {}", result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public int insertWarnRecord(IotWarnlog iotWarnlog) {
|
|
|
log.info("插入预警记录: {}", iotWarnlog);
|
|
|
- int result = iotWarncountMapper.insertWarnRecord(iotWarnlog);
|
|
|
+ int result = iotWarnBussinessMapper.insertWarnRecord(iotWarnlog);
|
|
|
log.info("插入预警记录结果: {}", result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public List<WarnConfigInfo> selectIotWarnConfigInfoList(WarnConfigInfo warnConfigInfo) {
|
|
|
log.info("查询预警配置信息列表");
|
|
|
- List<WarnConfigInfo> list = iotWarncountMapper.selectIotWarnConfigInfoList(warnConfigInfo);
|
|
|
+ List<WarnConfigInfo> list = iotWarnBussinessMapper.selectIotWarnConfigInfoList(warnConfigInfo);
|
|
|
log.info("查询到 {} 条预警配置信息", list.size());
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public IotWarnconfig selectIotWarnOfflineConfigInfo(String tid) {
|
|
|
log.info("查询预警离线配置tid:{}", tid);
|
|
|
- IotWarnconfig list = iotWarncountMapper.selectIotWarnOfflineConfigInfo(tid);
|
|
|
+ IotWarnconfig list = iotWarnBussinessMapper.selectIotWarnOfflineConfigInfo(tid);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@@ -136,9 +136,14 @@ public class IotWarnBussinessService {
|
|
|
}
|
|
|
|
|
|
public List<String> selectAllTid() {
|
|
|
- return iotWarncountMapper.selectAllTid();
|
|
|
+ return iotWarnBussinessMapper.selectAllTid();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 插入离线告警规则
|
|
|
+ * @param tid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public int insertIotOfflineWarnConfig(String tid) {
|
|
|
IotWarnconfig iotWarnconfig = new IotWarnconfig();
|
|
|
iotWarnconfig.setWcBid(IdUtils.fastUUID());
|
|
|
@@ -150,6 +155,19 @@ public class IotWarnBussinessService {
|
|
|
iotWarnconfig.setWcCreator("system");
|
|
|
iotWarnconfig.setWcCreateddate(DateUtils.dateTimeNow());
|
|
|
iotWarnconfig.setTid(tid);
|
|
|
- return iotWarncountMapper.insertIotOfflineWarnconfig(iotWarnconfig);
|
|
|
+ return iotWarnBussinessMapper.insertIotOfflineWarnconfig(iotWarnconfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备若正常上报数据后,则离线告警自动处理
|
|
|
+ * @param devId
|
|
|
+ */
|
|
|
+ public void autoDealWarnOfflineLog(String devId) {
|
|
|
+ IotWarnlog iotWarnlog = new IotWarnlog();
|
|
|
+ iotWarnlog.setDevBid(devId);
|
|
|
+ iotWarnlog.setWlDealtime(DateUtils.dateTimeNow());
|
|
|
+ iotWarnlog.setWlDealresult("该设备已于" + DateUtils.dateTimeNow() + "上报数据,离线告警自动恢复。");
|
|
|
+ iotWarnlog.setStatus("1");
|
|
|
+ iotWarnBussinessMapper.autoDealWarnOfflineLog(iotWarnlog);
|
|
|
}
|
|
|
}
|