service/library/contentaudit/textaudit/task.go

58 lines
1.3 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
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"
)
2024-01-20 18:48:38 +08:00
func AddTasks(tasks []*dbstruct.TextAuditTask) error {
for _, task := range tasks {
err := AddTask(task)
if err != nil {
return err
}
}
return nil
2023-12-21 22:17:40 +08:00
}
2024-01-20 18:48:38 +08:00
func AddTask(task *dbstruct.TextAuditTask) error {
2024-02-22 21:50:34 +08:00
if task == nil || task.AuditedText == nil {
return nil
}
2023-12-21 22:17:40 +08:00
2024-02-22 21:50:34 +08:00
task.BatchId = goproto.String(defaultTextAuditTaskScheduler.batchId)
task.Status = goproto.Int64(consts.TextAudit_Created)
2023-12-21 22:17:40 +08:00
2024-02-22 21:50:34 +08:00
// 1.写入文字审核表
ctx := &gin.Context{}
2023-12-21 22:17:40 +08:00
2024-02-22 21:50:34 +08:00
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
2024-02-07 12:07:28 +08:00
}
2023-12-21 22:17:40 +08:00
2024-02-22 21:50:34 +08:00
task.TextAuditId = textAudit.Id
2023-12-21 22:17:40 +08:00
// 2.写入文字审核任务表
if err := _DefaultTextAuditTask.OpCreate(&gin.Context{}, &textaudittaskproto.OpCreateReq{
2024-01-20 18:48:38 +08:00
TextAuditTask: task,
2023-12-21 22:17:40 +08:00
}); err != nil {
logger.Error("Textaudittask OpCreate failed: %v", err)
return err
}
return nil
}