by Robin at 20240119; fix
This commit is contained in:
parent
1602de1156
commit
04b65a72d2
|
@ -59,6 +59,7 @@ type OpListReq struct {
|
|||
Status *int64 `json:"status"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort string
|
||||
}
|
||||
|
||||
type OpListData struct {
|
||||
|
|
|
@ -59,6 +59,7 @@ type OpListReq struct {
|
|||
Status *int64 `json:"status"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort string
|
||||
}
|
||||
|
||||
type OpListData struct {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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号,由图像审核实体数据库四要素拼接而成,用于指示对数据库-表-单条数据-图像字段的审核动作
|
||||
|
@ -23,29 +29,10 @@ type ImageAuditTaskControlBlock struct {
|
|||
// 动态元素
|
||||
IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义
|
||||
AuditedFragmentsNum int // 已完成审核任务的分片数
|
||||
IsGivingNoticeToBatch bool // 是否进行批处理
|
||||
}
|
||||
|
||||
// 新建图像审核任务块
|
||||
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)),
|
||||
|
@ -53,7 +40,6 @@ func NewImageAuditTaskControlBlock(task *dbstruct.ImageAuditTask, rollbackFunc f
|
|||
RollbackFunc: rollbackFunc,
|
||||
IsTaskPassed: true,
|
||||
AuditedFragmentsNum: 0,
|
||||
IsGivingNoticeToBatch: false,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
// 图像审核主逻辑
|
||||
|
|
Loading…
Reference in New Issue