service/library/contentaudit/textaudit/control_block.go

77 lines
2.9 KiB
Go
Raw Permalink Normal View History

2024-01-20 18:48:38 +08:00
package textaudit
import (
"fmt"
2024-07-23 16:37:16 +08:00
"service/api/consts"
2024-01-20 18:48:38 +08:00
"service/bizcommon/util"
"service/dbstruct"
"service/library/logger"
"github.com/gin-gonic/gin"
)
// 批次图像审核任务控制块
type TextAuditTaskBatchControlBlock struct {
BatchId string // 批次号
TaskCtrlBlocks []*TextAuditTaskControlBlock // 任务控制块
ActionMap map[string]*TextAuditAction // 动作Id号-action的map
}
func NewTextAuditTaskBatchControlBlock(tasks []*dbstruct.TextAuditTask, batchId string) *TextAuditTaskBatchControlBlock {
if len(tasks) == 0 {
return nil
}
ctrlBlock := &TextAuditTaskBatchControlBlock{
BatchId: batchId,
TaskCtrlBlocks: make([]*TextAuditTaskControlBlock, 0),
ActionMap: make(map[string]*TextAuditAction),
}
for _, task := range tasks {
taskCtrlBlock := NewTextAuditTaskControlBlock(task)
ctrlBlock.TaskCtrlBlocks = append(ctrlBlock.TaskCtrlBlocks, taskCtrlBlock)
ctrlBlock.RecordAction(taskCtrlBlock)
}
return ctrlBlock
}
func (ctrlBlock *TextAuditTaskBatchControlBlock) RecordAction(taskCtrlBlock *TextAuditTaskControlBlock) {
ctx := &gin.Context{}
// 写map记录
if ctrlBlock.ActionMap[taskCtrlBlock.ActionId] == nil { // 写入ctrlBlock.ActionMap
ctrlBlock.ActionMap[taskCtrlBlock.ActionId] = NewTextAuditAction()
// 将此前批次对该元素未成功,待处理的审核全部置为已失效
2024-07-23 16:37:16 +08:00
failStatuses := []int64{consts.TextAudit_Rollbacked, consts.TextAudit_ServiceFailed}
if err := _DefaultTextAuditTask.OpHandleOverdue(ctx, taskCtrlBlock.TextAuditTask, util.DerefString(taskCtrlBlock.TextAuditTask.BatchId), failStatuses); err != nil {
2024-01-20 18:48:38 +08:00
logger.Error("_DefaultTextAuditTask OpHandleOverdue fail :%v", err)
}
}
ctrlBlock.ActionMap[taskCtrlBlock.ActionId].Record(taskCtrlBlock)
}
// 文字审核任务控制块
// ActionId设计初衷由于文字审核是定时任务触发的批量作业如果在一次作业间隔有针对同一个文字媒体的多次更新则会提交关于它的多次审核需要配合乐观锁保证数据一致性
type TextAuditTaskControlBlock struct {
// 静态元素
ActionId string // 审核动作id号由文字审核实体数据库四要素拼接而成用于指示对数据库-表-单条数据-文字字段的审核动作
TextAuditTask *dbstruct.TextAuditTask // 审核任务
// 动态元素
IsTaskPassed bool // 任务状态,仅当任务已完成时有效
IsGivingNoticeToBatch bool // 是否进行批处理
}
// 新建文字审核任务块
func NewTextAuditTaskControlBlock(task *dbstruct.TextAuditTask) (tcb *TextAuditTaskControlBlock) {
tcb = &TextAuditTaskControlBlock{
ActionId: fmt.Sprintf("%v%v%v%v", util.DerefString(task.AssociativeDatabase), util.DerefString(task.AssociativeTableName),
util.DerefInt64(task.AssociativeTableId), util.DerefString(task.AssociativeTableColumn)),
TextAuditTask: task,
IsTaskPassed: true,
IsGivingNoticeToBatch: false,
}
return
}