2024-01-18 18:19:31 +08:00
|
|
|
|
package imageaudit
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2024-07-23 16:37:16 +08:00
|
|
|
|
"service/api/consts"
|
2024-01-18 18:19:31 +08:00
|
|
|
|
"service/bizcommon/util"
|
|
|
|
|
"service/dbstruct"
|
2024-01-20 06:33:10 +08:00
|
|
|
|
"service/library/logger"
|
|
|
|
|
"service/library/mediafiller"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-01-18 18:19:31 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-01-19 17:31:38 +08:00
|
|
|
|
// 批次图像审核任务控制块
|
|
|
|
|
type ImageAuditTaskBatchControlBlock struct {
|
2024-01-20 06:33:10 +08:00
|
|
|
|
BatchId string // 批次号
|
|
|
|
|
TaskCtrlBlocks []*ImageAuditTaskControlBlock // 任务控制块
|
|
|
|
|
Images []*dbstruct.MediaComponent // 送审图像序列
|
|
|
|
|
ImageAuditIds []string // 送审图像对应的图像审核表id
|
|
|
|
|
Img2taskIndexMap map[int]int // 图像审核序列下标->任务序列下标的映射map
|
|
|
|
|
ActionMap map[string]*ImageAuditAction // 动作Id号-action的map
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewImageAuditTaskBatchControlBlock(tasks []*dbstruct.ImageAuditTask, batchId string) *ImageAuditTaskBatchControlBlock {
|
|
|
|
|
if len(tasks) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
ctrlBlock := &ImageAuditTaskBatchControlBlock{
|
|
|
|
|
BatchId: batchId,
|
|
|
|
|
TaskCtrlBlocks: make([]*ImageAuditTaskControlBlock, 0),
|
|
|
|
|
Images: make([]*dbstruct.MediaComponent, 0),
|
|
|
|
|
ImageAuditIds: make([]string, 0),
|
|
|
|
|
Img2taskIndexMap: make(map[int]int),
|
|
|
|
|
ActionMap: make(map[string]*ImageAuditAction),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imageIndex := 0
|
|
|
|
|
taskIndex := 0
|
|
|
|
|
mediaFillables := make([]mediafiller.MediaFillable, 0)
|
|
|
|
|
for _, task := range tasks {
|
|
|
|
|
taskCtrlBlock := NewImageAuditTaskControlBlock(task)
|
|
|
|
|
ctrlBlock.TaskCtrlBlocks = append(ctrlBlock.TaskCtrlBlocks, taskCtrlBlock)
|
|
|
|
|
ctrlBlock.RecordAction(taskCtrlBlock)
|
2024-02-29 01:48:51 +08:00
|
|
|
|
imageIndex, taskIndex = ctrlBlock.RecordImage(taskCtrlBlock, &mediaFillables, imageIndex, taskIndex)
|
2024-01-20 06:33:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 10:16:57 +08:00
|
|
|
|
mediafiller.FillListInternal(&gin.Context{}, mediaFillables)
|
2024-01-20 06:33:10 +08:00
|
|
|
|
|
|
|
|
|
return ctrlBlock
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ctrlBlock *ImageAuditTaskBatchControlBlock) RecordAction(taskCtrlBlock *ImageAuditTaskControlBlock) {
|
|
|
|
|
ctx := &gin.Context{}
|
|
|
|
|
// 写map记录
|
|
|
|
|
if ctrlBlock.ActionMap[taskCtrlBlock.ActionId] == nil { // 写入ctrlBlock.ActionMap
|
|
|
|
|
ctrlBlock.ActionMap[taskCtrlBlock.ActionId] = NewImageAuditAction()
|
|
|
|
|
// 将此前批次对该元素未成功,待处理的审核全部置为已失效
|
2024-07-23 16:37:16 +08:00
|
|
|
|
failStatuses := []int64{consts.ImageAudit_Rollbacked, consts.ImageAudit_ServiceFailed}
|
|
|
|
|
if err := _DefaultImageAuditTask.OpHandleOverdue(ctx, taskCtrlBlock.ImageAuditTask, util.DerefString(taskCtrlBlock.ImageAuditTask.BatchId), failStatuses); err != nil {
|
2024-01-20 06:33:10 +08:00
|
|
|
|
logger.Error("_DefaultImageAuditTask OpHandleOverdue fail :%v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ctrlBlock.ActionMap[taskCtrlBlock.ActionId].Record(taskCtrlBlock)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 01:48:51 +08:00
|
|
|
|
func (ctrlBlock *ImageAuditTaskBatchControlBlock) RecordImage(taskCtrlBlock *ImageAuditTaskControlBlock, mediaFillables *[]mediafiller.MediaFillable, imageIndex int, taskIndex int) (newImageIndex int, newTaskIndex int) {
|
2024-01-20 06:33:10 +08:00
|
|
|
|
|
|
|
|
|
// 未分片
|
|
|
|
|
if util.DerefInt64(taskCtrlBlock.ImageAuditTask.IsFragmented) == 0 {
|
|
|
|
|
ctrlBlock.Images = append(ctrlBlock.Images, taskCtrlBlock.ImageAuditTask.AuditedMedia)
|
2024-01-20 18:48:38 +08:00
|
|
|
|
*mediaFillables = append(*mediaFillables, taskCtrlBlock.ImageAuditTask.AuditedMedia)
|
2024-01-20 06:33:10 +08:00
|
|
|
|
ctrlBlock.Img2taskIndexMap[imageIndex] = taskIndex
|
|
|
|
|
ctrlBlock.ImageAuditIds = append(ctrlBlock.ImageAuditIds, util.DerefString(taskCtrlBlock.ImageAuditTask.ImageAuditId))
|
|
|
|
|
imageIndex++
|
|
|
|
|
} else { // 已分片
|
|
|
|
|
imageIds := taskCtrlBlock.ImageAuditTask.AuditedMedia.GetImageIds()
|
|
|
|
|
imageAuditIds := util.DerefStringSlice(taskCtrlBlock.ImageAuditTask.ImageAuditFragmentIds)
|
|
|
|
|
for i, imageId := range imageIds {
|
|
|
|
|
image := &dbstruct.MediaComponent{
|
|
|
|
|
ImageIds: util.Int64Slice([]int64{imageId}),
|
|
|
|
|
}
|
|
|
|
|
ctrlBlock.Images = append(ctrlBlock.Images, image)
|
2024-01-20 18:48:38 +08:00
|
|
|
|
*mediaFillables = append(*mediaFillables, image)
|
2024-01-20 06:33:10 +08:00
|
|
|
|
ctrlBlock.ImageAuditIds = append(ctrlBlock.ImageAuditIds, imageAuditIds[i])
|
|
|
|
|
ctrlBlock.Img2taskIndexMap[imageIndex] = taskIndex
|
|
|
|
|
imageIndex++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taskIndex++
|
2024-02-29 01:48:51 +08:00
|
|
|
|
return imageIndex, taskIndex
|
2024-01-19 17:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 18:19:31 +08:00
|
|
|
|
// 图像审核任务控制块
|
2024-01-19 17:31:38 +08:00
|
|
|
|
// ActionId设计初衷:由于图像审核是定时任务触发的批量作业,如果在一次作业间隔有针对同一个图像媒体的多次更新,则会提交关于它的多次审核,需要保证数据一致性
|
2024-01-18 18:19:31 +08:00
|
|
|
|
type ImageAuditTaskControlBlock struct {
|
|
|
|
|
// 静态元素
|
|
|
|
|
ActionId string // 审核动作id号,由图像审核实体数据库四要素拼接而成,用于指示对数据库-表-单条数据-图像字段的审核动作
|
|
|
|
|
ImageAuditTask *dbstruct.ImageAuditTask // 审核任务
|
|
|
|
|
|
|
|
|
|
// 动态元素
|
2024-01-19 17:31:38 +08:00
|
|
|
|
IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义
|
|
|
|
|
AuditedFragmentsNum int // 已完成审核任务的分片数
|
2024-01-18 18:19:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新建图像审核任务块
|
2024-01-20 06:33:10 +08:00
|
|
|
|
func NewImageAuditTaskControlBlock(task *dbstruct.ImageAuditTask) (tcb *ImageAuditTaskControlBlock) {
|
2024-01-18 18:19:31 +08:00
|
|
|
|
tcb = &ImageAuditTaskControlBlock{
|
|
|
|
|
ActionId: fmt.Sprintf("%v%v%v%v", util.DerefString(task.AssociativeDatabase), util.DerefString(task.AssociativeTableName),
|
|
|
|
|
util.DerefInt64(task.AssociativeTableId), util.DerefString(task.AssociativeTableColumn)),
|
2024-01-19 17:31:38 +08:00
|
|
|
|
ImageAuditTask: task,
|
|
|
|
|
IsTaskPassed: true,
|
|
|
|
|
AuditedFragmentsNum: 0,
|
2024-01-18 18:19:31 +08:00
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|