by Robin at 20240702

This commit is contained in:
Leufolium 2024-07-02 19:53:29 +08:00
parent 6b730ba361
commit 0836a4baea
4 changed files with 23 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package controller
import ( import (
video_moderation_proto "service/api/proto/video_moderation/proto" video_moderation_proto "service/api/proto/video_moderation/proto"
"service/app/mix/service"
"service/bizcommon/util" "service/bizcommon/util"
videomoderation "service/library/contentaudit/video_moderation" videomoderation "service/library/contentaudit/video_moderation"
"service/library/logger" "service/library/logger"
@ -18,11 +19,19 @@ func VideoModerationCallback(ctx *gin.Context) {
return return
} }
err = videomoderation.HandleVideoModerationContent(req.Content) batchId, isBatchFinished, err := videomoderation.HandleVideoModerationContent(req.Content)
if err != nil { if err != nil {
logger.Error("HandleVideoModerationContent fail, req: %v, err: %v", util.ToJson(req), err) logger.Error("HandleVideoModerationContent fail, req: %v, err: %v", util.ToJson(req), err)
return return
} }
// 同步批次视频审核结果
if isBatchFinished {
err = service.DefaultService.SyncVideoModerationTaskResultByBatchId(&gin.Context{}, batchId)
if err != nil {
logger.Error("ERROR : batchId : %v, video moderation tasks of this batchId have failed to syncronize, err :%v", batchId, err)
}
}
ctx.String(200, "success") ctx.String(200, "success")
} }

View File

@ -2095,9 +2095,9 @@ func (s *Service) utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds []
return return
} }
// 同步图像审核结果 // 同步视频审核结果
func (s *Service) utilSyncVideoModerationTaskResultByBatchId(ctx *gin.Context, batchId string) (err error) { func (s *Service) SyncVideoModerationTaskResultByBatchId(ctx *gin.Context, batchId string) (err error) {
// 查询得到该批次所有有关动态的图像审核任务 // 查询得到该批次所有有关动态的视频审核任务
videomoderationtasks, err := _DefaultVideoModerationTask.OpList(ctx, &video_moderation_task_proto.OpListReq{ videomoderationtasks, err := _DefaultVideoModerationTask.OpList(ctx, &video_moderation_task_proto.OpListReq{
AssociativeDatabase: goproto.String(dao.DBMoment), AssociativeDatabase: goproto.String(dao.DBMoment),
AssociativeTableName: goproto.String(dao.COLMoment), AssociativeTableName: goproto.String(dao.COLMoment),
@ -2109,7 +2109,7 @@ func (s *Service) utilSyncVideoModerationTaskResultByBatchId(ctx *gin.Context, b
return return
} }
// 将有关动态的图像审核任务审核结果同步到动态审核表 // 将有关动态的视频审核任务审核结果同步到动态审核表
_map := make(map[int64][]string) _map := make(map[int64][]string)
for _, videomoderationtask := range videomoderationtasks { for _, videomoderationtask := range videomoderationtasks {
ids := _map[videomoderationtask.GetStatus()] ids := _map[videomoderationtask.GetStatus()]

View File

@ -552,11 +552,6 @@ func (s *CronService) VideoModerationBatch(ctx context.Context, param *xxl.RunRe
} else { } else {
handleMsg.WriteString(fmt.Sprintf("batchId : %v, video moderation tasks of this batchId have finished, successNum: %v, failNum: %v", batchId, successNum, failNum)) handleMsg.WriteString(fmt.Sprintf("batchId : %v, video moderation tasks of this batchId have finished, successNum: %v, failNum: %v", batchId, successNum, failNum))
} }
// 同步视频审核结果
err = DefaultService.utilSyncVideoModerationTaskResultByBatchId(&gin.Context{}, batchId)
if err != nil {
handleMsg.WriteString(fmt.Sprintf("ERROR : batchId : %v, video moderation tasks of this batchId have failed to syncronize, err :%v", batchId, err))
}
logger.Info("Video moderation batch ends...") logger.Info("Video moderation batch ends...")
return handleMsg.String() return handleMsg.String()
@ -574,11 +569,6 @@ func (s *CronService) VideoModerationBatchHis(ctx context.Context, param *xxl.Ru
} else { } else {
handleMsg.WriteString(fmt.Sprintf("batchId : %v, video moderation tasks of this batchId have finished, successNum: %v, failNum: %v", batchId, successNum, failNum)) handleMsg.WriteString(fmt.Sprintf("batchId : %v, video moderation tasks of this batchId have finished, successNum: %v, failNum: %v", batchId, successNum, failNum))
} }
// 同步视频审核结果
err = DefaultService.utilSyncVideoModerationTaskResultByBatchId(&gin.Context{}, batchId)
if err != nil {
handleMsg.WriteString(fmt.Sprintf("ERROR : batchId : %v, video moderation tasks of this batchId have failed to syncronize, err :%v", batchId, err))
}
logger.Info("Video moderation batch ends...") logger.Info("Video moderation batch ends...")
return handleMsg.String() return handleMsg.String()

View File

@ -17,7 +17,7 @@ import (
goproto "google.golang.org/protobuf/proto" goproto "google.golang.org/protobuf/proto"
) )
func HandleVideoModerationContent(content string) (err error) { func HandleVideoModerationContent(content string) (batchId string, isBatchFinished bool, err error) {
// 获取ResponseBody解析出batchId和视频审核表id // 获取ResponseBody解析出batchId和视频审核表id
logger.Info("Unmarshaling ResponseBody...") logger.Info("Unmarshaling ResponseBody...")
result := &green20220302.VideoModerationResultResponseBody{} result := &green20220302.VideoModerationResultResponseBody{}
@ -27,11 +27,14 @@ func HandleVideoModerationContent(content string) (err error) {
return return
} }
err = handleVideoModerationResultResponseBody(result) batchId, isBatchFinished, err = handleVideoModerationResultResponseBody(result)
return return
} }
func handleVideoModerationResultResponseBody(result *green20220302.VideoModerationResultResponseBody) (err error) { func handleVideoModerationResultResponseBody(result *green20220302.VideoModerationResultResponseBody) (batchId string, isBatchFinished bool, err error) {
batchId = ""
isBatchFinished = false
isTaskCompleted := false isTaskCompleted := false
isActionCompleted := false isActionCompleted := false
@ -80,15 +83,16 @@ func handleVideoModerationResultResponseBody(result *green20220302.VideoModerati
logger.Info("video moderation task of id %v has finished...", tcb.VideoModerationTask.GetId()) logger.Info("video moderation task of id %v has finished...", tcb.VideoModerationTask.GetId())
// 如果批次任务已经完成从map中移除该批次任务控制块 // 如果批次任务已经完成从map中移除该批次任务控制块
batchId := btcb.BatchId batchId = btcb.BatchId
btcb.FinishATask() btcb.FinishATask()
if btcb.IsBatchFinished() { if btcb.IsBatchFinished() {
isBatchFinished = true
removeBtcb(btcb.BatchId) removeBtcb(btcb.BatchId)
} }
logger.Info("video moderation batch task of batch_id %v has finished and been removed, all referenced request will be regarded as expired...", batchId) logger.Info("video moderation batch task of batch_id %v has finished and been removed, all referenced request will be regarded as expired...", batchId)
} }
return nil return
} }
func handleVideoModeration(result *green20220302.VideoModerationResultResponseBody) (isPassed bool, videomoderation *dbstruct.VideoModeration, err error) { func handleVideoModeration(result *green20220302.VideoModerationResultResponseBody) (isPassed bool, videomoderation *dbstruct.VideoModeration, err error) {