You've already forked FrameTour-BE
fix(video): 修复设备视频连续性检查缓存覆盖问题
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
- 为VideoContinuityReportReq的gaps字段添加空列表默认值 - 在设备不支持连续性检查时检查Redis中是否已存在外部上报的缓存记录 - 避免已有的外部上报缓存被内部检查结果覆盖 - 保持已有缓存记录的完整性,仅在无缓存时进行存储
This commit is contained in:
@@ -6,6 +6,9 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -72,7 +75,7 @@ public class VideoContinuityReportReq {
|
||||
/**
|
||||
* 间隙列表(选填,当continuous=false时应提供)
|
||||
*/
|
||||
private List<GapInfoReq> gaps;
|
||||
private List<GapInfoReq> gaps = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* 间隙信息
|
||||
|
||||
@@ -158,13 +158,23 @@ public class DeviceVideoContinuityCheckTask {
|
||||
// 执行连续性检查(允许2秒间隙)
|
||||
VideoContinuityResult result = operator.checkVideoContinuity(startDate, endDate, 2000L);
|
||||
|
||||
// 如果设备不支持连续性检查,检查是否已有外部上报的缓存记录
|
||||
String redisKey = REDIS_KEY_PREFIX + device.getId();
|
||||
if (!result.isSupport()) {
|
||||
String existingCache = redisTemplate.opsForValue().get(redisKey);
|
||||
if (existingCache != null) {
|
||||
// 已有缓存记录(可能是外部工具上报的),不覆盖
|
||||
log.debug("设备 {} 不支持内部连续性检查,但已有缓存记录,跳过覆盖", device.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建缓存对象
|
||||
DeviceVideoContinuityCache cache = DeviceVideoContinuityCache.fromResult(
|
||||
device.getId(), result, startDate, endDate
|
||||
);
|
||||
|
||||
// 存储到Redis
|
||||
String redisKey = REDIS_KEY_PREFIX + device.getId();
|
||||
String cacheJson = objectMapper.writeValueAsString(cache);
|
||||
redisTemplate.opsForValue().set(redisKey, cacheJson, CACHE_TTL_HOURS, TimeUnit.HOURS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user