73 lines
2.3 KiB
Go
73 lines
2.3 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
|
|
OpHandleOverdue(ctx *gin.Context, task *dbstruct.TextAuditTask, batchId 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 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)
|
|
|
|
return
|
|
}
|
|
|
|
func ConnectToTextAuditService(serivce TextAuditService) {
|
|
_DefaultTextAudit = serivce
|
|
}
|
|
|
|
func ConnectToTextAuditTaskService(service TextAuditTaskService, handler TextAuditTaskResultHandler) {
|
|
_DefaultTextAuditTask = service
|
|
_DefaultResultHandler = handler
|
|
}
|