package textaudit import ( "fmt" "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() // 将此前批次对该元素未成功,待处理的审核全部置为已失效 if err := _DefaultTextAuditTask.OpHandleOverdue(ctx, taskCtrlBlock.TextAuditTask, util.DerefString(taskCtrlBlock.TextAuditTask.BatchId)); err != nil { 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 }