2024-04-26 10:46:37 +08:00
|
|
|
|
package videomoderation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"service/dbstruct"
|
|
|
|
|
"service/library/logger"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 批次视频审核任务控制块
|
|
|
|
|
type VideoModerationTaskBatchControlBlock struct {
|
|
|
|
|
BatchId string // 批次号
|
|
|
|
|
TaskCtrlBlockMap map[string]*VideoModerationTaskControlBlock // 视频审核任务表id->任务控制块map
|
|
|
|
|
VidmodId2taskMap map[string]*VideoModerationTaskControlBlock // 视频审核表id->任务控制块map
|
|
|
|
|
ActionMap map[string]*VideoModerationAction // 动作Id号-action的map
|
2024-04-27 11:14:44 +08:00
|
|
|
|
Ct int64 // 创建时间戳
|
|
|
|
|
TaskNum int64 // 任务数量
|
|
|
|
|
FinishedTaskNum int64 // 已完成任务数量
|
2024-04-26 10:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ctrlBlock *VideoModerationTaskBatchControlBlock) RecordAction(taskCtrlBlock *VideoModerationTaskControlBlock) {
|
|
|
|
|
ctx := &gin.Context{}
|
|
|
|
|
// 写map记录
|
|
|
|
|
if ctrlBlock.ActionMap[taskCtrlBlock.ActionId] == nil { // 写入ctrlBlock.ActionMap
|
|
|
|
|
ctrlBlock.ActionMap[taskCtrlBlock.ActionId] = NewVideoModerationAction()
|
|
|
|
|
// 将此前批次对该元素未成功,待处理的审核全部置为已失效
|
|
|
|
|
if err := _DefaultVideoModerationTask.OpHandleOverdue(ctx, taskCtrlBlock.VideoModerationTask, taskCtrlBlock.VideoModerationTask.GetBatchId()); err != nil {
|
|
|
|
|
logger.Error("_DefaultVideoModerationTask OpHandleOverdue fail :%v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ctrlBlock.ActionMap[taskCtrlBlock.ActionId].Record(taskCtrlBlock)
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-27 11:14:44 +08:00
|
|
|
|
func (ctrlBlock *VideoModerationTaskBatchControlBlock) IsBatchFinished() bool {
|
|
|
|
|
return ctrlBlock.TaskNum <= ctrlBlock.FinishedTaskNum
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ctrlBlock *VideoModerationTaskBatchControlBlock) FinishATask() {
|
|
|
|
|
ctrlBlock.FinishedTaskNum++
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:46:37 +08:00
|
|
|
|
// 视频审核任务控制块
|
|
|
|
|
// ActionId设计初衷:由于视频审核是定时任务触发的批量作业,如果在一次作业间隔有针对同一个视频媒体的多次更新,则会提交关于它的多次审核,需要保证数据一致性
|
|
|
|
|
type VideoModerationTaskControlBlock struct {
|
|
|
|
|
// 静态元素
|
|
|
|
|
ActionId string // 审核动作id号,由视频审核实体数据库四要素拼接而成,用于指示对数据库-表-单条数据-视频字段的审核动作
|
|
|
|
|
VideoModerationTask *dbstruct.VideoModerationTask // 审核任务
|
|
|
|
|
|
|
|
|
|
// 动态元素
|
|
|
|
|
IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义
|
|
|
|
|
AuditedFragmentsNum int // 已完成审核任务的分片数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新建视频审核任务块
|
|
|
|
|
func NewVideoModerationTaskControlBlock(task *dbstruct.VideoModerationTask) (tcb *VideoModerationTaskControlBlock) {
|
|
|
|
|
tcb = &VideoModerationTaskControlBlock{
|
|
|
|
|
ActionId: fmt.Sprintf("%v%v%v%v", task.GetAssociativeDatabase(), task.GetAssociativeTableName(),
|
|
|
|
|
task.GetAssociativeTableId(), task.GetAssociativeTableColumn()),
|
|
|
|
|
VideoModerationTask: task,
|
|
|
|
|
IsTaskPassed: true,
|
|
|
|
|
AuditedFragmentsNum: 0,
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|