You've already forked FrameTour-BE
feat(face): 优化模板渲染状态查询逻辑
- 引入 TaskMapper 依赖以支持任务查询 - 移除带过期时间的模板渲染状态设置方法 - 在缓存缺失时查询最新任务记录以确定渲染状态 - 新增 listLastFaceTemplateTask 方法用于获取最新的人脸模板任务 - 实现根据任务状态自动设置模板渲染状态的逻辑 - 添加对任务状态为 1 和 2 时的渲染状态映射处理
This commit is contained in:
@@ -3,11 +3,14 @@ package com.ycwl.basic.biz;
|
||||
import com.ycwl.basic.enums.FaceCutStatus;
|
||||
import com.ycwl.basic.enums.FacePieceUpdateStatus;
|
||||
import com.ycwl.basic.enums.TemplateRenderStatus;
|
||||
import com.ycwl.basic.mapper.TaskMapper;
|
||||
import com.ycwl.basic.model.pc.task.entity.TaskEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -55,6 +58,8 @@ public class FaceStatusManager {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private TaskMapper taskMapper;
|
||||
|
||||
// ==================== 切片状态相关方法 ====================
|
||||
|
||||
@@ -249,24 +254,6 @@ public class FaceStatusManager {
|
||||
log.debug("设置模板渲染状态: faceId={}, templateId={}, status={}", faceId, templateId, status.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置人脸模板渲染状态(带过期时间)
|
||||
* @param faceId 人脸ID
|
||||
* @param templateId 模板ID
|
||||
* @param status 渲染状态
|
||||
* @param expireSeconds 过期时间(秒)
|
||||
*/
|
||||
public void setTemplateRenderStatus(Long faceId, Long templateId, TemplateRenderStatus status, long expireSeconds) {
|
||||
if (faceId == null || templateId == null || status == null) {
|
||||
log.warn("设置模板渲染状态参数为空: faceId={}, templateId={}, status={}", faceId, templateId, status);
|
||||
return;
|
||||
}
|
||||
String key = String.format(FACE_TEMPLATE_RENDER_KEY, faceId, templateId);
|
||||
redisTemplate.opsForValue().set(key, String.valueOf(status.getCode()), expireSeconds, TimeUnit.SECONDS);
|
||||
log.debug("设置模板渲染状态(带过期): faceId={}, templateId={}, status={}, expireSeconds={}",
|
||||
faceId, templateId, status.getDescription(), expireSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取人脸模板渲染状态
|
||||
* @param faceId 人脸ID
|
||||
@@ -282,7 +269,19 @@ public class FaceStatusManager {
|
||||
String value = redisTemplate.opsForValue().get(key);
|
||||
if (value == null) {
|
||||
log.debug("模板渲染状态缓存不存在: faceId={}, templateId={}", faceId, templateId);
|
||||
return null;
|
||||
// 查一下
|
||||
TaskEntity task = taskMapper.listLastFaceTemplateTask(faceId, templateId);
|
||||
if (task == null) {
|
||||
setTemplateRenderStatus(faceId, templateId, TemplateRenderStatus.NONE);
|
||||
return TemplateRenderStatus.NONE;
|
||||
}
|
||||
if (Integer.valueOf(2).equals(task.getStatus())) {
|
||||
setTemplateRenderStatus(faceId, templateId, TemplateRenderStatus.RENDERING);
|
||||
}
|
||||
if (Integer.valueOf(1).equals(task.getStatus())) {
|
||||
setTemplateRenderStatus(faceId, templateId, TemplateRenderStatus.RENDERED);
|
||||
}
|
||||
return TemplateRenderStatus.NONE;
|
||||
}
|
||||
try {
|
||||
int code = Integer.parseInt(value);
|
||||
@@ -293,28 +292,6 @@ public class FaceStatusManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断模板是否已渲染完成
|
||||
* @param faceId 人脸ID
|
||||
* @param templateId 模板ID
|
||||
* @return true=已渲染,false=未渲染或正在渲染
|
||||
*/
|
||||
public boolean isTemplateRendered(Long faceId, Long templateId) {
|
||||
TemplateRenderStatus status = getTemplateRenderStatus(faceId, templateId);
|
||||
return status != null && status.isRendered();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断模板是否正在渲染
|
||||
* @param faceId 人脸ID
|
||||
* @param templateId 模板ID
|
||||
* @return true=正在渲染,false=未渲染或已完成
|
||||
*/
|
||||
public boolean isTemplateRendering(Long faceId, Long templateId) {
|
||||
TemplateRenderStatus status = getTemplateRenderStatus(faceId, templateId);
|
||||
return status != null && status.isRendering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除人脸模板渲染状态缓存
|
||||
* @param faceId 人脸ID
|
||||
|
||||
@@ -57,4 +57,6 @@ public interface TaskMapper {
|
||||
List<TaskRespVO> selectNotRunningByScenicList(String scenicOnly);
|
||||
|
||||
List<TaskEntity> selectAllFailed();
|
||||
|
||||
TaskEntity listLastFaceTemplateTask(Long faceId, Long templateId);
|
||||
}
|
||||
|
||||
@@ -356,6 +356,10 @@ public class GoodsServiceImpl implements GoodsService {
|
||||
if (status == FaceCutStatus.COMPLETED) {
|
||||
// 切片已完成,查询该人脸关联的视频信息
|
||||
List<MemberVideoEntity> taskList = videoMapper.listRelationByFace(faceId);
|
||||
if (taskList == null || taskList.isEmpty() || taskList.getLast().getVideoId() == null) {
|
||||
response.setStatus(VideoTaskStatus.PROCESSING.getCode());
|
||||
return response;
|
||||
}
|
||||
|
||||
// 设置最新的视频信息(取最后一个)
|
||||
response.setTaskId(taskList.getLast().getTaskId());
|
||||
@@ -460,10 +464,10 @@ public class GoodsServiceImpl implements GoodsService {
|
||||
// 该模板已渲染完成,查询对应的视频信息
|
||||
List<MemberVideoEntity> taskList = videoMapper.listRelationByFaceAndTemplate(faceId, templateId);
|
||||
|
||||
if (taskList.isEmpty()) {
|
||||
if (taskList.isEmpty() || taskList.getLast().getVideoId() == null) {
|
||||
// 理论上不应该出现:渲染完成但无视频记录
|
||||
// 可能是数据不一致,返回待制作状态
|
||||
response.setStatus(VideoTaskStatus.PENDING.getCode());
|
||||
response.setStatus(VideoTaskStatus.PROCESSING.getCode());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,4 +144,11 @@
|
||||
from task
|
||||
where status = 3
|
||||
</select>
|
||||
<select id="listLastFaceTemplateTask" resultType="com.ycwl.basic.model.pc.task.entity.TaskEntity">
|
||||
select *
|
||||
from task
|
||||
where face_id = #{faceId} and template_id = #{templateId}
|
||||
order by create_time desc
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user