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 {
2023-12-21 22:17:40 +08:00
if task == nil || task.AuditedText == nil {
2024-01-20 18:48:38 +08:00
return nil
2023-12-21 22:17:40 +08:00
}
task.BatchId = goproto.String(defaultTextAuditTaskScheduler.batchId)
task.Status = goproto.Int64(consts.TextAudit_Created)
// 1.写入文字审核表
ctx := &gin.Context{}
textAudit := &dbstruct.TextAudit{
2024-01-20 18:48:38 +08:00
AuditedText: task.AuditedText,
BatchId: task.BatchId,
2023-12-21 22:17:40 +08:00
Status: goproto.Int64(consts.TextAudit_Created),
}
2024-01-20 18:48:38 +08:00
if err := _DefaultTextAudit.OpCreate(ctx, &textauditproto.OpCreateReq{
2023-12-21 22:17:40 +08:00
TextAudit: textAudit,
}); err != nil {
logger.Error("Textaudit OpCreate failed: %v", err)
2024-01-20 18:48:38 +08:00
return err
2023-12-21 22:17:40 +08:00
}
2024-01-20 18:48:38 +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
}