fix:设备电话通知和告警,以及设备历史数据,增加设备有效期判断。
This commit is contained in:
@@ -412,6 +412,12 @@ public class DeviceDataHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设备已过期,不触发告警
|
||||
if (device.getDeadTime() != null && device.getDeadTime().before(new java.util.Date())) {
|
||||
log.debug("[告警] 设备已过期,跳过告警检查: {}", deviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
Long deviceId = device.getId();
|
||||
Long userId = device.getUserId();
|
||||
|
||||
@@ -1183,6 +1189,8 @@ public class DeviceDataHandler {
|
||||
Device device = deviceMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSerialNum, deviceName)
|
||||
.select(Device::getId, Device::getSerialNum, Device::getDeviceName,
|
||||
Device::getPondId, Device::getUserId, Device::getDeadTime)
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (device == null) {
|
||||
@@ -1190,6 +1198,12 @@ public class DeviceDataHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设备已过期,不触发故障告警
|
||||
if (device.getDeadTime() != null && device.getDeadTime().before(new java.util.Date())) {
|
||||
log.debug("[设备故障] 设备已过期,跳过故障告警: {}", deviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
Long deviceId = device.getId();
|
||||
Long userId = device.getUserId();
|
||||
if (userId == null) {
|
||||
@@ -1326,12 +1340,20 @@ public class DeviceDataHandler {
|
||||
Device device = deviceMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSerialNum, deviceName)
|
||||
.select(Device::getId, Device::getSerialNum, Device::getDeviceName, Device::getWarnCode,
|
||||
Device::getPondId, Device::getUserId, Device::getDeadTime)
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设备已过期,不处理故障码
|
||||
if (device.getDeadTime() != null && device.getDeadTime().before(new java.util.Date())) {
|
||||
log.debug("[故障码] 设备已过期,跳过处理: {}", deviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (errorCode == 0) {
|
||||
// 清除所有故障码
|
||||
clearErrorCodeRecords(device);
|
||||
@@ -1795,17 +1817,23 @@ public class DeviceDataHandler {
|
||||
}
|
||||
int sensorErrorCode = rawCode;
|
||||
|
||||
// 查询设备,需要 id / warnCode / isOxygenUsed / pondId
|
||||
// 查询设备,需要 id / warnCode / isOxygenUsed / pondId / deadTime
|
||||
Device device = deviceMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSerialNum, deviceName)
|
||||
.select(Device::getId, Device::getWarnCode, Device::getIsOxygenUsed, Device::getPondId)
|
||||
.select(Device::getId, Device::getWarnCode, Device::getIsOxygenUsed, Device::getPondId, Device::getDeadTime)
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设备已过期,不处理探头错误码
|
||||
if (device.getDeadTime() != null && device.getDeadTime().before(new java.util.Date())) {
|
||||
log.debug("[探头错误码] 设备已过期,跳过处理: {}", deviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
int currentCode = device.getWarnCode() != null ? device.getWarnCode() : 0;
|
||||
int newCode = currentCode;
|
||||
|
||||
@@ -2269,18 +2297,25 @@ public class DeviceDataHandler {
|
||||
*/
|
||||
private void handleLinkedCtrl(String deviceName, double dissolvedOxygen) {
|
||||
try {
|
||||
// 查询当前设备(需要 id、iotId、pondId)
|
||||
// 查询当前设备(需要 id、iotId、pondId、deadTime)
|
||||
Device currentDevice = deviceMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSerialNum, deviceName)
|
||||
.select(Device::getId, Device::getIotId, Device::getSerialNum, Device::getDeviceName,
|
||||
Device::getPondId, Device::getValueDissolvedOxygen, Device::getUserId)
|
||||
Device::getPondId, Device::getValueDissolvedOxygen, Device::getUserId,
|
||||
Device::getDeadTime)
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (currentDevice == null || currentDevice.getId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设备已过期,不执行联动控制
|
||||
if (currentDevice.getDeadTime() != null && currentDevice.getDeadTime().before(new java.util.Date())) {
|
||||
log.debug("[联动控制] 设备已过期,跳过处理: {}", deviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
// 先更新当前设备的实时溶解氧(确保后续取最低值时已包含本次上报值)
|
||||
// 注意:updateDeviceRealTimeData 在 handleLinkedCtrl 调用前已执行,此处直接使用传入值
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.intc.tdengine.mapper;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 设备到期信息Mapper(查询MySQL主库)
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface DeviceExpireMapper {
|
||||
|
||||
/**
|
||||
* 根据设备序列号查询服务到期时间
|
||||
*
|
||||
* @param serialNum 设备序列号
|
||||
* @return 服务到期时间,设备不存在时返回null
|
||||
*/
|
||||
@DS("master")
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Date getDeadTimeBySerialNum(@Param("serialNum") String serialNum);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.intc.tdengine.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import com.intc.tdengine.mapper.DeviceExpireMapper;
|
||||
import com.intc.tdengine.mapper.DeviceSensorDataMapper;
|
||||
import com.intc.tdengine.service.IDeviceSensorDataService;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@@ -17,6 +19,9 @@ import java.util.List;
|
||||
public class DeviceSensorDataService implements IDeviceSensorDataService {
|
||||
@Resource
|
||||
private DeviceSensorDataMapper deviceSensorDataMapper;
|
||||
|
||||
@Resource
|
||||
private DeviceExpireMapper deviceExpireMapper;
|
||||
|
||||
/**
|
||||
* 已创建的子表缓存(设备序列号)
|
||||
@@ -203,6 +208,13 @@ public class DeviceSensorDataService implements IDeviceSensorDataService {
|
||||
public List<DeviceSensorData> getHistoryDataList(String serialNum, String startTime, String endTime, Integer intervalType) {
|
||||
List<DeviceSensorData> list = new ArrayList<>();
|
||||
try {
|
||||
// 检查设备是否已过期
|
||||
Date deadTime = deviceExpireMapper.getDeadTimeBySerialNum(serialNum);
|
||||
if (deadTime != null && deadTime.before(new Date())) {
|
||||
log.info("设备已过期,不返回历史数据: serialNum={}, deadTime={}", serialNum, deadTime);
|
||||
return list;
|
||||
}
|
||||
|
||||
// 默认为原始数据
|
||||
if (intervalType == null) {
|
||||
intervalType = 1;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?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.intc.tdengine.mapper.DeviceExpireMapper">
|
||||
|
||||
<select id="getDeadTimeBySerialNum" resultType="java.util.Date">
|
||||
SELECT dead_time FROM aqu_device WHERE serial_num = #{serialNum} LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user