fix(video): 修复任务状态查询逻辑并优化Redis过期策略

- 修改人脸模板渲染状态存储逻辑,增加默认过期时间
- 移除AppTaskController中冗余的JwtInfo获取代码
- 优化GoodsServiceImpl中任务状态判断逻辑,增强空值检查
- 修复视频任务状态返回不准确的问题,完善边界条件处理
This commit is contained in:
2025-12-17 16:42:09 +08:00
parent 171932c05c
commit c8560e3aca
3 changed files with 7 additions and 6 deletions

View File

@@ -249,8 +249,7 @@ public class FaceStatusManager {
return; return;
} }
String key = String.format(FACE_TEMPLATE_RENDER_KEY, faceId, templateId); String key = String.format(FACE_TEMPLATE_RENDER_KEY, faceId, templateId);
// 渲染状态不设置过期时间,永久保存 redisTemplate.opsForValue().set(key, String.valueOf(status.getCode()), DEFAULT_EXPIRE_SECONDS, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(key, String.valueOf(status.getCode()));
log.debug("设置模板渲染状态: faceId={}, templateId={}, status={}", faceId, templateId, status.getDescription()); log.debug("设置模板渲染状态: faceId={}, templateId={}, status={}", faceId, templateId, status.getDescription());
} }

View File

@@ -27,7 +27,6 @@ public class AppTaskController {
@GetMapping("/face/{faceId}") @GetMapping("/face/{faceId}")
@IgnoreLogReq @IgnoreLogReq
public ApiResponse<VideoTaskStatusVO> getTaskStatusByFaceId(@PathVariable("faceId") Long faceId) { public ApiResponse<VideoTaskStatusVO> getTaskStatusByFaceId(@PathVariable("faceId") Long faceId) {
JwtInfo worker = JwtTokenUtil.getWorker();
return ApiResponse.success(goodsService.getTaskStatusByFaceId(faceId)); return ApiResponse.success(goodsService.getTaskStatusByFaceId(faceId));
} }
@GetMapping("/scenic/{scenicId}") @GetMapping("/scenic/{scenicId}")
@@ -49,7 +48,6 @@ public class AppTaskController {
@GetMapping("/face/{faceId}/template/{templateId}") @GetMapping("/face/{faceId}/template/{templateId}")
@IgnoreLogReq @IgnoreLogReq
public ApiResponse<VideoTaskStatusVO> getTemplateTaskStatus(@PathVariable("faceId") Long faceId, @PathVariable("templateId") Long templateId) { public ApiResponse<VideoTaskStatusVO> getTemplateTaskStatus(@PathVariable("faceId") Long faceId, @PathVariable("templateId") Long templateId) {
JwtInfo worker = JwtTokenUtil.getWorker();
return ApiResponse.success(goodsService.getTaskStatusByTemplateId(faceId, templateId)); return ApiResponse.success(goodsService.getTaskStatusByTemplateId(faceId, templateId));
} }

View File

@@ -356,7 +356,11 @@ public class GoodsServiceImpl implements GoodsService {
if (status == FaceCutStatus.COMPLETED) { if (status == FaceCutStatus.COMPLETED) {
// 切片已完成,查询该人脸关联的视频信息 // 切片已完成,查询该人脸关联的视频信息
List<MemberVideoEntity> taskList = videoMapper.listRelationByFace(faceId); List<MemberVideoEntity> taskList = videoMapper.listRelationByFace(faceId);
if (taskList == null || taskList.isEmpty() || taskList.getLast().getVideoId() == null) { if (taskList == null || taskList.isEmpty()) {
response.setStatus(VideoTaskStatus.PENDING.getCode());
return response;
}
if (taskList.getLast().getVideoId() == null) {
response.setStatus(VideoTaskStatus.PROCESSING.getCode()); response.setStatus(VideoTaskStatus.PROCESSING.getCode());
return response; return response;
} }
@@ -464,7 +468,7 @@ public class GoodsServiceImpl implements GoodsService {
// 该模板已渲染完成,查询对应的视频信息 // 该模板已渲染完成,查询对应的视频信息
List<MemberVideoEntity> taskList = videoMapper.listRelationByFaceAndTemplate(faceId, templateId); List<MemberVideoEntity> taskList = videoMapper.listRelationByFaceAndTemplate(faceId, templateId);
if (taskList.isEmpty() || taskList.getLast().getVideoId() == null) { if (taskList == null || taskList.isEmpty() || taskList.getLast().getVideoId() == null) {
// 理论上不应该出现:渲染完成但无视频记录 // 理论上不应该出现:渲染完成但无视频记录
// 可能是数据不一致,返回待制作状态 // 可能是数据不一致,返回待制作状态
response.setStatus(VideoTaskStatus.PROCESSING.getCode()); response.setStatus(VideoTaskStatus.PROCESSING.getCode());