From 04b65a72d2401b5a70b13f327755c68c0dd06ef1 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 19 Jan 2024 17:31:38 +0800 Subject: [PATCH] by Robin at 20240119; fix --- .../imageaudittask/proto/imageaudittask_op.go | 1 + .../textaudittask/proto/textaudittask_op.go | 1 + app/mix/dao/mongo.go | 12 ++++- .../contentaudit/imageaudit/control_block.go | 46 +++++++------------ library/contentaudit/imageaudit/imageaudit.go | 9 ++++ 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/api/proto/imageaudittask/proto/imageaudittask_op.go b/api/proto/imageaudittask/proto/imageaudittask_op.go index 3975e6e5..ccc11ff0 100644 --- a/api/proto/imageaudittask/proto/imageaudittask_op.go +++ b/api/proto/imageaudittask/proto/imageaudittask_op.go @@ -59,6 +59,7 @@ type OpListReq struct { Status *int64 `json:"status"` Offset int `json:"offset"` Limit int `json:"limit"` + Sort string } type OpListData struct { diff --git a/api/proto/textaudittask/proto/textaudittask_op.go b/api/proto/textaudittask/proto/textaudittask_op.go index 4abae12f..e32c10a0 100644 --- a/api/proto/textaudittask/proto/textaudittask_op.go +++ b/api/proto/textaudittask/proto/textaudittask_op.go @@ -59,6 +59,7 @@ type OpListReq struct { Status *int64 `json:"status"` Offset int `json:"offset"` Limit int `json:"limit"` + Sort string } type OpListData struct { diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 2dd9b501..5f20d299 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -2371,7 +2371,11 @@ func (m *Mongo) GetImageAuditTaskList(ctx *gin.Context, req *imageaudittaskproto if req.Status != nil { query["status"] = util.DerefInt64(req.Status) } - err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + sortClause := "-ct" + if req.Sort != "" { + sortClause = req.Sort + } + err := col.Find(ctx, query).Sort(sortClause).Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil return list, err @@ -2581,7 +2585,11 @@ func (m *Mongo) GetTextAuditTaskList(ctx *gin.Context, req *textaudittaskproto.O if req.Status != nil { query["status"] = util.DerefInt64(req.Status) } - err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + sortClause := "-ct" + if req.Sort != "" { + sortClause = req.Sort + } + err := col.Find(ctx, query).Sort(sortClause).Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil return list, err diff --git a/library/contentaudit/imageaudit/control_block.go b/library/contentaudit/imageaudit/control_block.go index 6b4da948..14727174 100644 --- a/library/contentaudit/imageaudit/control_block.go +++ b/library/contentaudit/imageaudit/control_block.go @@ -2,15 +2,21 @@ package imageaudit import ( "fmt" - "service/api/consts" "service/bizcommon/util" "service/dbstruct" - - goproto "google.golang.org/protobuf/proto" ) +// 批次图像审核任务控制块 +type ImageAuditTaskBatchControlBlock struct { + batchId int64 // 批次号 + tcbs []*ImageAuditTaskControlBlock // 任务控制块 + images []*dbstruct.MediaComponent // 送审图像序列 + img2taskIndexMap map[int]int // 图像审核序列下标->任务序列下标的映射map + actionMap map[string]*ImageAuditAction // 动作Id号-action的map +} + // 图像审核任务控制块 -// ActionId设计初衷:由于图像审核是定时任务触发的批量作业,如果在一次作业间隔有针对同一个图像媒体的多次更新,则会提交关于它的多次审核,需要配合乐观锁保证数据一致性 +// ActionId设计初衷:由于图像审核是定时任务触发的批量作业,如果在一次作业间隔有针对同一个图像媒体的多次更新,则会提交关于它的多次审核,需要保证数据一致性 type ImageAuditTaskControlBlock struct { // 静态元素 ActionId string // 审核动作id号,由图像审核实体数据库四要素拼接而成,用于指示对数据库-表-单条数据-图像字段的审核动作 @@ -21,39 +27,19 @@ type ImageAuditTaskControlBlock struct { Images []*dbstruct.MediaComponent // 被审核的图像序列 // 动态元素 - IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义 - AuditedFragmentsNum int // 已完成审核任务的分片数 - IsGivingNoticeToBatch bool // 是否进行批处理 + IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义 + AuditedFragmentsNum int // 已完成审核任务的分片数 } // 新建图像审核任务块 func NewImageAuditTaskControlBlock(task *dbstruct.ImageAuditTask, rollbackFunc func() error) (tcb *ImageAuditTaskControlBlock) { - if task == nil || task.AuditedMedia == nil { - return - } - fragmentNum := len(util.DerefInt64Slice(task.AuditedMedia.ImageIds)) - if fragmentNum == 0 { - return - } - - task.BatchId = goproto.String(defaultImageAuditTaskScheduler.batchId) - task.Status = goproto.Int64(consts.ImageAudit_Created) - if fragmentNum == 1 { - task.IsFragmented = goproto.Int64(0) - task.FragmentsNum = goproto.Int64(1) - } else { - task.IsFragmented = goproto.Int64(1) - task.FragmentsNum = goproto.Int64(int64(fragmentNum)) - } - 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)), - ImageAuditTask: task, - RollbackFunc: rollbackFunc, - IsTaskPassed: true, - AuditedFragmentsNum: 0, - IsGivingNoticeToBatch: false, + ImageAuditTask: task, + RollbackFunc: rollbackFunc, + IsTaskPassed: true, + AuditedFragmentsNum: 0, } return } diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index e6392032..9a803ac4 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -30,7 +30,16 @@ func Run() (err error) { imageaudittasks, err := _DefaultImageAuditTask.OpList(&gin.Context{}, &imageaudittaskproto.OpListReq{ BatchId: goproto.String(batchId), Status: goproto.Int64(consts.ImageAudit_Created), + Sort: "ct", }) + + // 上锁 + defaultImageAuditTaskScheduler.lock() + + createImageAuditTaskControlBlocks(tasks) + + // 解锁 + defaultImageAuditTaskScheduler.unLock() } // 图像审核主逻辑