package textaudit import ( "service/api/consts" textauditproto "service/api/proto/textaudit/proto" textaudittaskproto "service/api/proto/textaudittask/proto" "service/dbstruct" "service/library/logger" "github.com/gin-gonic/gin" goproto "google.golang.org/protobuf/proto" ) func AddTasks(tasks []*dbstruct.TextAuditTask) error { for _, task := range tasks { err := AddTask(task) if err != nil { return err } } return nil } func AddTask(task *dbstruct.TextAuditTask) error { // 若非对齐任务,则进行插入前预处理 task.BatchId = goproto.String(defaultTextAuditTaskScheduler.batchId) if !task.IsForAlignment() { if task == nil || task.AuditedText == nil { return nil } task.Status = goproto.Int64(consts.TextAudit_Created) // 1.写入文字审核表 ctx := &gin.Context{} textAudit := &dbstruct.TextAudit{ AuditedText: task.AuditedText, BatchId: task.BatchId, Status: goproto.Int64(consts.TextAudit_Created), } if err := _DefaultTextAudit.OpCreate(ctx, &textauditproto.OpCreateReq{ TextAudit: textAudit, }); err != nil { logger.Error("Textaudit OpCreate failed: %v", err) return err } task.TextAuditId = textAudit.Id } // 2.写入文字审核任务表 if err := _DefaultTextAuditTask.OpCreate(&gin.Context{}, &textaudittaskproto.OpCreateReq{ TextAuditTask: task, }); err != nil { logger.Error("Textaudittask OpCreate failed: %v", err) return err } return nil }