101 lines
3.7 KiB
Go
101 lines
3.7 KiB
Go
package videomoderation
|
||
|
||
import (
|
||
"service/bizcommon/util"
|
||
"service/dbstruct"
|
||
"service/library/configcenter"
|
||
"service/library/logger"
|
||
|
||
video_moderation_proto "service/api/proto/video_moderation/proto"
|
||
video_moderation_task_proto "service/api/proto/video_moderation_task/proto"
|
||
|
||
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||
green20220302 "github.com/alibabacloud-go/green-20220302/client"
|
||
"github.com/alibabacloud-go/tea/tea"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
// 数据库接口
|
||
type VideoModerationService interface {
|
||
OpCreate(ctx *gin.Context, req *video_moderation_proto.OpCreateReq) error
|
||
OpUpdate(ctx *gin.Context, req *video_moderation_proto.OpUpdateReq) error
|
||
OpDelete(ctx *gin.Context, id string) error
|
||
OpList(ctx *gin.Context, req *video_moderation_proto.OpListReq) (*dbstruct.VideoModeration, error)
|
||
OpCreateFragmentGroup(ctx *gin.Context, req *video_moderation_proto.OpCreateBatchReq) error
|
||
OpUpdateByIds(ctx *gin.Context, req *video_moderation_proto.OpUpdateByIdsReq) error
|
||
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudit *dbstruct.VideoModeration) error
|
||
}
|
||
|
||
type VideoModerationTaskService interface {
|
||
OpCreate(ctx *gin.Context, req *video_moderation_task_proto.OpCreateReq) error
|
||
OpUpdate(ctx *gin.Context, req *video_moderation_task_proto.OpUpdateReq) error
|
||
OpDelete(ctx *gin.Context, id string) error
|
||
OpList(ctx *gin.Context, req *video_moderation_task_proto.OpListReq) ([]*dbstruct.VideoModerationTask, error)
|
||
OpUpdateByIds(ctx *gin.Context, req *video_moderation_task_proto.OpUpdateByIdsReq) error
|
||
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudittask *dbstruct.VideoModerationTask) error
|
||
OpHandleOverdue(ctx *gin.Context, task *dbstruct.VideoModerationTask, batchId string, statuses []int64) error
|
||
}
|
||
|
||
type ContentAuditRTIService interface {
|
||
GetAndUpdateVideoModerationBatchId(ctx *gin.Context, batchId string) (string, error)
|
||
}
|
||
|
||
type VideoModerationTaskResultHandler interface {
|
||
Handle(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) error
|
||
}
|
||
|
||
var defaultVideoModerationClient *green20220302.Client
|
||
var _DefaultVideoModeration VideoModerationService
|
||
var _DefaultVideoModerationTask VideoModerationTaskService
|
||
var _DefaultResultHandler VideoModerationTaskResultHandler
|
||
var _DefaultContentAuditRTI ContentAuditRTIService
|
||
var _defaultConfig *configcenter.VideoModerationConfig
|
||
|
||
func Init(cfg *configcenter.VideoModerationConfig) (err error) {
|
||
config := &openapi.Config{
|
||
AccessKeyId: tea.String(cfg.AccessKeyId),
|
||
AccessKeySecret: tea.String(cfg.AccessKeySecret),
|
||
|
||
RegionId: tea.String("cn-shanghai"),
|
||
Endpoint: tea.String("green-cip.cn-shanghai.aliyuncs.com"),
|
||
/**
|
||
* 请设置超时时间。服务端全链路处理超时时间为10秒,请做相应设置。
|
||
* 如果您设置的ReadTimeout小于服务端处理的时间,程序中会获得一个ReadTimeout异常。
|
||
*/
|
||
ConnectTimeout: tea.Int(3000),
|
||
ReadTimeout: tea.Int(6000),
|
||
}
|
||
|
||
defaultVideoModerationClient, err = green20220302.NewClient(config)
|
||
if err != nil {
|
||
logger.Error("NewVideoModerationClient fail, cfg: %v, err: %v", util.ToJson(config), err)
|
||
return
|
||
}
|
||
|
||
_, err = RefreshBatchId()
|
||
if err != nil {
|
||
logger.Error("RefreshBatchId fail, cfg: %v, err: %v", util.ToJson(config), err)
|
||
return
|
||
}
|
||
|
||
// 初始化调度器
|
||
initScheduler(cfg)
|
||
|
||
_defaultConfig = cfg
|
||
|
||
return
|
||
}
|
||
|
||
func ConnectToVideoModerationService(serivce VideoModerationService) {
|
||
_DefaultVideoModeration = serivce
|
||
}
|
||
|
||
func ConnectToVideoModerationTaskService(service VideoModerationTaskService, handler VideoModerationTaskResultHandler) {
|
||
_DefaultVideoModerationTask = service
|
||
_DefaultResultHandler = handler
|
||
}
|
||
|
||
func ConnectToContentAuditRTIService(service ContentAuditRTIService) {
|
||
_DefaultContentAuditRTI = service
|
||
}
|