fix(iot): 修复 3D11 编解码器上报时间和数据过滤
- reportTime 改用 time 字段(设备上传时间)而非 endTime - 新增 24 小时数据过滤,超时数据舍弃并返回 null - 数据舍弃时仍返回成功响应,避免设备反复重试 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import com.viewsh.module.iot.gateway.codec.camera3d11.dto.Camera3D11DataUploadRe
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
@@ -48,11 +49,17 @@ public class IotCamera3D11Codec implements IotDeviceMessageCodec {
|
||||
params.put("stat_start_time", payload.getStartTime());
|
||||
params.put("stat_end_time", payload.getEndTime());
|
||||
|
||||
// 3. 使用 endTime 作为上报时间
|
||||
// 3. 使用 time 作为上报时间,超过 24 小时的数据舍弃
|
||||
LocalDateTime reportTime = LocalDateTime.now();
|
||||
if (payload.getEndTime() != null) {
|
||||
if (payload.getTime() != null) {
|
||||
reportTime = LocalDateTime.ofInstant(
|
||||
Instant.ofEpochSecond(payload.getEndTime()), ZoneId.systemDefault());
|
||||
Instant.ofEpochSecond(payload.getTime()), ZoneId.systemDefault());
|
||||
long hoursDiff = Math.abs(Duration.between(reportTime, LocalDateTime.now()).toHours());
|
||||
if (hoursDiff > 24) {
|
||||
log.warn("[decode][设备时间超过24小时,舍弃数据: time={}, 时间差: {}小时]",
|
||||
payload.getTime(), hoursDiff);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return IotDeviceMessage.requestOf(IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod(), params)
|
||||
|
||||
@@ -130,13 +130,11 @@ public class IotCameraUpstreamHandler implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 解码并发送消息
|
||||
// 3. 解码并发送消息(解码失败或数据过期时仍返回成功,避免设备重试)
|
||||
IotDeviceMessage message = deviceMessageService.decodeDeviceMessage(bytes, IotCamera3D11Codec.TYPE);
|
||||
if (message == null) {
|
||||
IotHttpAbstractHandler.writeResponse(context, Camera3D11Resp.error("消息解码失败"));
|
||||
return;
|
||||
if (message != null) {
|
||||
deviceMessageService.sendDeviceMessage(message, productKey, req.getSn(), null);
|
||||
}
|
||||
deviceMessageService.sendDeviceMessage(message, productKey, req.getSn(), null);
|
||||
|
||||
// 4. 构建响应
|
||||
long currentTime = LocalDateTime.now().atZone(ZONE_SHANGHAI).toEpochSecond();
|
||||
|
||||
Reference in New Issue
Block a user