service/library/contentaudit/textaudit/client.go

86 lines
2.7 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package textaudit
import (
"fmt"
"service/dbstruct"
"service/library/configcenter"
"service/library/logger"
2023-12-21 22:17:40 +08:00
"strings"
textauditproto "service/api/proto/textaudit/proto"
textaudittaskproto "service/api/proto/textaudittask/proto"
textaudit "github.com/alibabacloud-go/imageaudit-20191230/v3/client"
"github.com/gin-gonic/gin"
)
// 数据库接口
type TextAuditService interface {
OpCreate(ctx *gin.Context, req *textauditproto.OpCreateReq) error
OpUpdate(ctx *gin.Context, req *textauditproto.OpUpdateReq) error
OpDelete(ctx *gin.Context, id string) error
OpList(ctx *gin.Context, req *textauditproto.OpListReq) (*dbstruct.TextAudit, error)
OpUpdateByIds(ctx *gin.Context, req *textauditproto.OpUpdateByIdsReq) error
OpUpdateByBatchId(ctx *gin.Context, batchId string, textaudit *dbstruct.TextAudit) error
}
type TextAuditTaskService interface {
OpCreate(ctx *gin.Context, req *textaudittaskproto.OpCreateReq) error
OpUpdate(ctx *gin.Context, req *textaudittaskproto.OpUpdateReq) error
OpDelete(ctx *gin.Context, id string) error
OpList(ctx *gin.Context, req *textaudittaskproto.OpListReq) ([]*dbstruct.TextAuditTask, error)
OpUpdateByIds(ctx *gin.Context, req *textaudittaskproto.OpUpdateByIdsReq) error
OpUpdateByBatchId(ctx *gin.Context, batchId string, textaudittask *dbstruct.TextAuditTask) error
2024-01-04 21:55:00 +08:00
OpHandleOverdue(ctx *gin.Context, task *dbstruct.TextAuditTask, batchId string) error
2023-12-21 22:17:40 +08:00
}
type ContentAuditRTIService interface {
GetAndUpdateTextAuditBatchId(ctx *gin.Context, batchId string) (string, error)
}
2024-01-20 18:48:38 +08:00
type TextAuditTaskResultHandler interface {
Handle(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) error
}
2023-12-21 22:17:40 +08:00
var defaultTextAuditClient *textaudit.Client
var _DefaultTextAudit TextAuditService
var _DefaultTextAuditTask TextAuditTaskService
2024-01-20 18:48:38 +08:00
var _DefaultResultHandler TextAuditTaskResultHandler
var _DefaultContentAuditRTI ContentAuditRTIService
2023-12-21 22:17:40 +08:00
var labels []string
func ConnectToTextAuditClient(client *textaudit.Client) {
defaultTextAuditClient = client
}
func Init(cfg *configcenter.TextAuditConfig) (err error) {
if defaultTextAuditClient == nil {
return fmt.Errorf("text audit client has not been connected")
}
// 初始化审核选项
labels = strings.Split(cfg.Labels, " ")
_, err = RefreshBatchId()
if err != nil {
logger.Error("RefreshBatchId fail, err: %v", err)
return
}
2023-12-21 22:17:40 +08:00
return
}
func ConnectToTextAuditService(serivce TextAuditService) {
_DefaultTextAudit = serivce
}
2024-01-20 18:48:38 +08:00
func ConnectToTextAuditTaskService(service TextAuditTaskService, handler TextAuditTaskResultHandler) {
2023-12-21 22:17:40 +08:00
_DefaultTextAuditTask = service
2024-01-20 18:48:38 +08:00
_DefaultResultHandler = handler
2023-12-21 22:17:40 +08:00
}
func ConnectToContentAuditRTIService(service ContentAuditRTIService) {
_DefaultContentAuditRTI = service
}