You've already forked FrameTour-BE
feat(basic): 添加模板片段更新状态缓存支持
- 在FaceStatusManager中新增按模板ID区分的人脸片段更新状态缓存键 - 更新TaskTaskServiceImpl以设置模板渲染状态 - 在任务回调逻辑中增加对模板渲染状态的更新操作 - 修改任务删除逻辑为更新状态加10的临时解决方案 - 移除旧有的切割任务状态更新逻辑,统一使用模板渲染状态管理
This commit is contained in:
65
src/main/java/com/ycwl/basic/enums/FaceCutStatus.java
Normal file
65
src/main/java/com/ycwl/basic/enums/FaceCutStatus.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
/**
|
||||
* 人脸视频切片状态枚举
|
||||
*/
|
||||
public enum FaceCutStatus {
|
||||
|
||||
/**
|
||||
* 正在切片中
|
||||
*/
|
||||
CUTTING(0, "正在切片中"),
|
||||
|
||||
/**
|
||||
* 切片已完成
|
||||
*/
|
||||
COMPLETED(1, "切片已完成"),
|
||||
|
||||
/**
|
||||
* 等待用户选择模板
|
||||
*/
|
||||
WAITING_USER_SELECT(2, "等待用户选择模板");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
FaceCutStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static FaceCutStatus fromCode(int code) {
|
||||
for (FaceCutStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown FaceCutStatus code: " + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举,如果不存在则返回默认值
|
||||
* @param code 状态码
|
||||
* @param defaultStatus 默认状态
|
||||
* @return 枚举值
|
||||
*/
|
||||
public static FaceCutStatus fromCodeOrDefault(int code, FaceCutStatus defaultStatus) {
|
||||
for (FaceCutStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return defaultStatus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
/**
|
||||
* 人脸片段更新状态枚举
|
||||
* 用于标记人脸对应的视频片段是否有新增更新
|
||||
*/
|
||||
public enum FacePieceUpdateStatus {
|
||||
|
||||
/**
|
||||
* 有新片段
|
||||
* Redis键不存在时的默认状态,代表有新的视频片段产生
|
||||
*/
|
||||
HAS_NEW_PIECES(0, "有新片段"),
|
||||
|
||||
/**
|
||||
* 无新片段
|
||||
* Redis键存在时的状态,代表当前没有新的视频片段
|
||||
*/
|
||||
NO_NEW_PIECES(1, "无新片段");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
FacePieceUpdateStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static FacePieceUpdateStatus fromCode(int code) {
|
||||
for (FacePieceUpdateStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown FacePieceUpdateStatus code: " + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Redis键是否存在判断状态
|
||||
* @param keyExists Redis键是否存在
|
||||
* @return 键存在返回NO_NEW_PIECES,键不存在返回HAS_NEW_PIECES
|
||||
*/
|
||||
public static FacePieceUpdateStatus fromKeyExists(boolean keyExists) {
|
||||
return keyExists ? NO_NEW_PIECES : HAS_NEW_PIECES;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有新片段
|
||||
*/
|
||||
public boolean hasNewPieces() {
|
||||
return this == HAS_NEW_PIECES;
|
||||
}
|
||||
}
|
||||
75
src/main/java/com/ycwl/basic/enums/TemplateRenderStatus.java
Normal file
75
src/main/java/com/ycwl/basic/enums/TemplateRenderStatus.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
/**
|
||||
* 人脸对应模板渲染状态枚举
|
||||
*/
|
||||
public enum TemplateRenderStatus {
|
||||
|
||||
NONE(0, "没有渲染"),
|
||||
/**
|
||||
* 正在渲染中
|
||||
*/
|
||||
RENDERING(1, "正在渲染中"),
|
||||
|
||||
/**
|
||||
* 已渲染完成
|
||||
*/
|
||||
RENDERED(2, "已渲染完成");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
TemplateRenderStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static TemplateRenderStatus fromCode(int code) {
|
||||
for (TemplateRenderStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown TemplateRenderStatus code: " + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举,如果不存在则返回默认值
|
||||
* @param code 状态码
|
||||
* @param defaultStatus 默认状态
|
||||
* @return 枚举值
|
||||
*/
|
||||
public static TemplateRenderStatus fromCodeOrDefault(int code, TemplateRenderStatus defaultStatus) {
|
||||
for (TemplateRenderStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return defaultStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已完成渲染
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return this == RENDERED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否正在渲染
|
||||
*/
|
||||
public boolean isRendering() {
|
||||
return this == RENDERING;
|
||||
}
|
||||
}
|
||||
159
src/main/java/com/ycwl/basic/enums/VideoTaskStatus.java
Normal file
159
src/main/java/com/ycwl/basic/enums/VideoTaskStatus.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
/**
|
||||
* 视频任务状态枚举
|
||||
* 用于前端展示任务状态
|
||||
*/
|
||||
public enum VideoTaskStatus {
|
||||
|
||||
/**
|
||||
* 无效人脸(景区级别)
|
||||
*/
|
||||
INVALID_FACE_SCENIC(-2, "尚未录入有效人脸"),
|
||||
|
||||
/**
|
||||
* 无效人脸(人脸级别)
|
||||
*/
|
||||
INVALID_FACE(-1, "尚未录入有效人脸"),
|
||||
|
||||
/**
|
||||
* 待制作
|
||||
* 人脸已录入,但尚未开始合成视频
|
||||
*/
|
||||
PENDING(0, "专属视频待制作"),
|
||||
|
||||
/**
|
||||
* 合成成功
|
||||
* 已为用户合成视频
|
||||
*/
|
||||
SUCCESS(1, "AI已为您合成视频"),
|
||||
|
||||
/**
|
||||
* 合成中
|
||||
* 正在合成专属视频
|
||||
*/
|
||||
PROCESSING(2, "专属视频合成中"),
|
||||
|
||||
/**
|
||||
* 合成失败
|
||||
*/
|
||||
FAILED(3, "视频合成失败"),
|
||||
|
||||
/**
|
||||
* 切片中
|
||||
* 正在检索新的视频片段
|
||||
*/
|
||||
CUTTING(4, "正在检索新的视频片段");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
VideoTaskStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static VideoTaskStatus fromCode(int code) {
|
||||
for (VideoTaskStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown VideoTaskStatus code: " + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举,如果不存在则返回默认值
|
||||
* @param code 状态码
|
||||
* @param defaultStatus 默认状态
|
||||
* @return 枚举值
|
||||
*/
|
||||
public static VideoTaskStatus fromCodeOrDefault(int code, VideoTaskStatus defaultStatus) {
|
||||
for (VideoTaskStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return defaultStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取前端展示文案
|
||||
* @param count 已合成视频数量(仅SUCCESS状态使用)
|
||||
* @return 展示文案
|
||||
*/
|
||||
public String getDisplayText(long count) {
|
||||
if (this == SUCCESS && count > 0) {
|
||||
return "AI已为您合成" + count + "个视频";
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务逻辑判断最终展示状态
|
||||
* @param taskStatus 任务状态码
|
||||
* @param cutStatus 切片状态码(来自FaceCutStatus)
|
||||
* @param count 已合成视频数量
|
||||
* @return 最终展示的状态
|
||||
*/
|
||||
public static VideoTaskStatus resolveDisplayStatus(int taskStatus, int cutStatus, long count) {
|
||||
VideoTaskStatus status = fromCodeOrDefault(taskStatus, PENDING);
|
||||
|
||||
// 优先级1: 无效人脸状态
|
||||
if (status == INVALID_FACE_SCENIC || status == INVALID_FACE) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// 优先级2: 切片状态优先(当任务状态为待制作且切片状态为正在切片时)
|
||||
if (status == PENDING && cutStatus == 0) {
|
||||
return CUTTING;
|
||||
}
|
||||
|
||||
// 优先级3: 返回任务状态
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最终展示文案
|
||||
* @param taskStatus 任务状态码
|
||||
* @param cutStatus 切片状态码
|
||||
* @param count 已合成视频数量
|
||||
* @return 展示文案
|
||||
*/
|
||||
public static String getDisplayText(int taskStatus, int cutStatus, long count) {
|
||||
VideoTaskStatus status = resolveDisplayStatus(taskStatus, cutStatus, count);
|
||||
return status.getDisplayText(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为成功状态
|
||||
*/
|
||||
public boolean isSuccess() {
|
||||
return this == SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为处理中状态
|
||||
*/
|
||||
public boolean isProcessing() {
|
||||
return this == PROCESSING || this == CUTTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为失败状态
|
||||
*/
|
||||
public boolean isFailed() {
|
||||
return this == FAILED || this == INVALID_FACE || this == INVALID_FACE_SCENIC;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user