service/library/contentaudit/textaudit/client.go

73 lines
2.1 KiB
Go

package textaudit
import (
"fmt"
"service/dbstruct"
"service/library/configcenter"
"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
}
var defaultTextAuditClient *textaudit.Client
var _DefaultTextAudit TextAuditService
var _DefaultTextAuditTask TextAuditTaskService
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, " ")
// 初始化调度器
initScheduler(cfg)
// 启动调度任务
defaultTextAuditTaskScheduler.Run()
return
}
func GiveNoticeToBatch() {
defaultTextAuditTaskScheduler.GiveNoticeToBatch()
}
func ConnectToTextAuditService(serivce TextAuditService) {
_DefaultTextAudit = serivce
}
func ConnectToTextAuditTaskService(service TextAuditTaskService) {
_DefaultTextAuditTask = service
}