service/library/contentaudit/imageaudit/client.go

95 lines
3.2 KiB
Go

package imageaudit
import (
"service/bizcommon/util"
"service/dbstruct"
"service/library/configcenter"
"service/library/contentaudit/textaudit"
"service/library/logger"
"strings"
imageauditproto "service/api/proto/imageaudit/proto"
imageaudittaskproto "service/api/proto/imageaudittask/proto"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
imageaudit "github.com/alibabacloud-go/imageaudit-20191230/v3/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/gin-gonic/gin"
)
// 数据库接口
type ImageAuditService interface {
OpCreate(ctx *gin.Context, req *imageauditproto.OpCreateReq) error
OpUpdate(ctx *gin.Context, req *imageauditproto.OpUpdateReq) error
OpDelete(ctx *gin.Context, id string) error
OpList(ctx *gin.Context, req *imageauditproto.OpListReq) (*dbstruct.ImageAudit, error)
OpCreateFragmentGroup(ctx *gin.Context, req *imageauditproto.OpCreateBatchReq) error
OpUpdateByIds(ctx *gin.Context, req *imageauditproto.OpUpdateByIdsReq) error
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudit *dbstruct.ImageAudit) error
}
type ImageAuditTaskService interface {
OpCreate(ctx *gin.Context, req *imageaudittaskproto.OpCreateReq) error
OpUpdate(ctx *gin.Context, req *imageaudittaskproto.OpUpdateReq) error
OpDelete(ctx *gin.Context, id string) error
OpList(ctx *gin.Context, req *imageaudittaskproto.OpListReq) ([]*dbstruct.ImageAuditTask, error)
OpUpdateByIds(ctx *gin.Context, req *imageaudittaskproto.OpUpdateByIdsReq) error
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudittask *dbstruct.ImageAuditTask) error
OpHandleOverdue(ctx *gin.Context, task *dbstruct.ImageAuditTask, batchId string) error
}
type ImageAuditTaskResultHandler interface {
Handle(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) error
}
var defaultImageAuditClient *imageaudit.Client
var _DefaultImageAudit ImageAuditService
var _DefaultImageAuditTask ImageAuditTaskService
var _DefaultResultHandler ImageAuditTaskResultHandler
var scenes []*string
func Init(cfg *configcenter.ImageAuditConfig) (err error) {
config := &openapi.Config{
AccessKeyId: tea.String(cfg.AccessKeyId),
AccessKeySecret: tea.String(cfg.AccessKeySecret),
}
config.Endpoint = tea.String("imageaudit.cn-shanghai.aliyuncs.com")
defaultImageAuditClient, err = imageaudit.NewClient(config)
if err != nil {
logger.Error("NewImageAuditClient fail, cfg: %v, err: %v", util.ToJson(config), err)
return
}
// 让文字审核连接到这个服务
textaudit.ConnectToTextAuditClient(defaultImageAuditClient)
// 初始化审核选项
scenelist := strings.Split(cfg.Scenes, " ")
scenes = make([]*string, len(scenelist))
for i, scene := range scenelist {
scenes[i] = tea.String(scene)
}
// 初始化调度器
initScheduler(cfg)
// // 启动调度任务
// defaultImageAuditTaskScheduler.Run()
return
}
// func GiveNoticeToBatch() {
// defaultImageAuditTaskScheduler.GiveNoticeToBatch()
// }
func ConnectToImageAuditService(serivce ImageAuditService) {
_DefaultImageAudit = serivce
}
func ConnectToImageAuditTaskService(service ImageAuditTaskService, handler ImageAuditTaskResultHandler) {
_DefaultImageAuditTask = service
_DefaultResultHandler = handler
}