service/vendor/library/contentaudit/imageaudit/client.go

88 lines
2.8 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
}
var defaultImageAuditClient *imageaudit.Client
var _DefaultImageAudit ImageAuditService
var _DefaultImageAuditTask ImageAuditTaskService
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) {
_DefaultImageAuditTask = service
}