|
|
@ -31,20 +31,10 @@ import java.util.*; |
|
|
import java.util.function.Function; |
|
|
import java.util.function.Function; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 批量设备消息处理器 |
|
|
|
|
|
* <p> |
|
|
|
|
|
* 核心优化: |
|
|
|
|
|
* 1. 批量获取基础数据(租户信息、设备信息、报警规则) |
|
|
|
|
|
* 2. 内存中完成所有业务逻辑计算 |
|
|
|
|
|
* 3. 批量执行所有数据库写操作 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Component |
|
|
@Component |
|
|
public class BatchDeviceMessageProcessor { |
|
|
public class BatchDeviceMessageProcessor { |
|
|
|
|
|
|
|
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private RedisUtil redisUtil; |
|
|
private RedisUtil redisUtil; |
|
|
@Resource |
|
|
@Resource |
|
|
@ -194,7 +184,7 @@ public class BatchDeviceMessageProcessor { |
|
|
processFenceAlarm(handVo, context); |
|
|
processFenceAlarm(handVo, context); |
|
|
|
|
|
|
|
|
// 9. 保存处理后的数据日志
|
|
|
// 9. 保存处理后的数据日志
|
|
|
context.processedLogs.add(createTdengineDataVo(handVo)); |
|
|
|
|
|
|
|
|
context.processedLogs.add(createTdengineDataVo(handVo,tenantId)); |
|
|
|
|
|
|
|
|
// 10. 记录需要更新到 Redis 的数据
|
|
|
// 10. 记录需要更新到 Redis 的数据
|
|
|
context.redisUpdates.put(sn, handVo); |
|
|
context.redisUpdates.put(sn, handVo); |
|
|
@ -556,7 +546,7 @@ public class BatchDeviceMessageProcessor { |
|
|
Integer newLevel = alarmRule.getAlarmLevel(); |
|
|
Integer newLevel = alarmRule.getAlarmLevel(); |
|
|
|
|
|
|
|
|
// 首次报警
|
|
|
// 首次报警
|
|
|
if (!isCurrentlyAlarming) { |
|
|
|
|
|
|
|
|
if (!isCurrentlyAlarming && newLevel != null) { |
|
|
handVo.setFirstValue(handVo.getValue()); |
|
|
handVo.setFirstValue(handVo.getValue()); |
|
|
handVo.setTAlarmStart(now); |
|
|
handVo.setTAlarmStart(now); |
|
|
handVo.setMaxValue(handVo.getValue()); |
|
|
handVo.setMaxValue(handVo.getValue()); |
|
|
@ -652,6 +642,8 @@ public class BatchDeviceMessageProcessor { |
|
|
newAlarm.setTenantId(handVo.getTenantId()); |
|
|
newAlarm.setTenantId(handVo.getTenantId()); |
|
|
newAlarm.setCreator("system"); |
|
|
newAlarm.setCreator("system"); |
|
|
newAlarm.setCreateTime(now); |
|
|
newAlarm.setCreateTime(now); |
|
|
|
|
|
newAlarm.setDeptId(handVo.getDeptId()); |
|
|
|
|
|
newAlarm.setAlarmLevel(HandAlarmType.ALARM.getType()); |
|
|
|
|
|
|
|
|
context.gasAlarmsToCreate.add(newAlarm); |
|
|
context.gasAlarmsToCreate.add(newAlarm); |
|
|
handVo.setBatteryStatus(EnableStatus.ENABLED.value()); |
|
|
handVo.setBatteryStatus(EnableStatus.ENABLED.value()); |
|
|
@ -921,9 +913,9 @@ public class BatchDeviceMessageProcessor { |
|
|
/** |
|
|
/** |
|
|
* 创建处理后的日志对象 |
|
|
* 创建处理后的日志对象 |
|
|
*/ |
|
|
*/ |
|
|
private TdengineDataVo createTdengineDataVo(HandDataVo handVo) { |
|
|
|
|
|
|
|
|
private TdengineDataVo createTdengineDataVo(HandDataVo handVo, Long tenantId) { |
|
|
TdengineDataVo vo = BeanUtils.toBean(handVo, TdengineDataVo.class); |
|
|
TdengineDataVo vo = BeanUtils.toBean(handVo, TdengineDataVo.class); |
|
|
vo.setTenantId(handVo.getTenantId()); |
|
|
|
|
|
|
|
|
vo.setTenantId(tenantId); |
|
|
vo.setTs(new Timestamp(System.currentTimeMillis())); |
|
|
vo.setTs(new Timestamp(System.currentTimeMillis())); |
|
|
return vo; |
|
|
return vo; |
|
|
} |
|
|
} |
|
|
|