86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package textaudit
|
|
|
|
import (
|
|
"fmt"
|
|
"service/dbstruct"
|
|
"service/library/configcenter"
|
|
"service/library/logger"
|
|
"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
|
|
OpHandleOverdue(ctx *gin.Context, task *dbstruct.TextAuditTask, batchId string) error
|
|
}
|
|
|
|
type ContentAuditRTIService interface {
|
|
GetAndUpdateTextAuditBatchId(ctx *gin.Context, batchId string) (string, error)
|
|
}
|
|
|
|
type TextAuditTaskResultHandler interface {
|
|
Handle(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) error
|
|
}
|
|
|
|
var defaultTextAuditClient *textaudit.Client
|
|
var _DefaultTextAudit TextAuditService
|
|
var _DefaultTextAuditTask TextAuditTaskService
|
|
var _DefaultResultHandler TextAuditTaskResultHandler
|
|
var _DefaultContentAuditRTI ContentAuditRTIService
|
|
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
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func ConnectToTextAuditService(serivce TextAuditService) {
|
|
_DefaultTextAudit = serivce
|
|
}
|
|
|
|
func ConnectToTextAuditTaskService(service TextAuditTaskService, handler TextAuditTaskResultHandler) {
|
|
_DefaultTextAuditTask = service
|
|
_DefaultResultHandler = handler
|
|
}
|
|
|
|
func ConnectToContentAuditRTIService(service ContentAuditRTIService) {
|
|
_DefaultContentAuditRTI = service
|
|
}
|