95 lines
3.4 KiB
Go
95 lines
3.4 KiB
Go
package service
|
||
|
||
import (
|
||
"fmt"
|
||
"service/api/consts"
|
||
zonemomentproto "service/api/proto/zonemoment/proto"
|
||
"service/bizcommon/util"
|
||
"service/dbstruct"
|
||
"strings"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
goproto "google.golang.org/protobuf/proto"
|
||
)
|
||
|
||
var DefaultVideoModerationTaskResultHandler *VideoModerationTaskResultHandler
|
||
|
||
type VideoModerationTaskResultHandler struct {
|
||
// 图像审核任务通过及回退方法生成器map
|
||
videoModerationTaskUpdateFuncGeneratorMap map[string](func(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) func() error)
|
||
}
|
||
|
||
func NewVideoModerationTaskResultHandler() *VideoModerationTaskResultHandler {
|
||
handler := &VideoModerationTaskResultHandler{}
|
||
handler.initVideoModerationTaskUpdateFuncGeneratorMap()
|
||
return handler
|
||
}
|
||
|
||
func (handler *VideoModerationTaskResultHandler) Handle(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) error {
|
||
return handler.getVideoModerationTaskUpdateFunc(ctx, task, option)()
|
||
}
|
||
|
||
func (handler *VideoModerationTaskResultHandler) initVideoModerationTaskUpdateFuncGeneratorMap() {
|
||
handler.videoModerationTaskUpdateFuncGeneratorMap = make(map[string]func(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) func() error)
|
||
|
||
handler.generateZoneMomentMediaComponentUpdateFunc()
|
||
}
|
||
|
||
func (handler *VideoModerationTaskResultHandler) getVideoModerationTaskUpdateFunc(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) func() error {
|
||
|
||
db := util.DerefString(task.AssociativeDatabase)
|
||
table := util.DerefString(task.AssociativeTableName)
|
||
column := util.DerefString(task.AssociativeTableColumn)
|
||
|
||
key := fmt.Sprintf("%v|%v|%v", db, table, column)
|
||
updateFuncGenerator := handler.videoModerationTaskUpdateFuncGeneratorMap[key]
|
||
updateFunc := updateFuncGenerator(ctx, task, option)
|
||
|
||
return updateFunc
|
||
|
||
}
|
||
|
||
// 私密动态表->图像内容,若不通过,则写入不通过的原因
|
||
func (handler *VideoModerationTaskResultHandler) generateZoneMomentMediaComponentUpdateFunc() {
|
||
handler.videoModerationTaskUpdateFuncGeneratorMap["zone_moment|zone_moment|media_component"] = func(ctx *gin.Context, task *dbstruct.VideoModerationTask, option int) func() error {
|
||
return func() error {
|
||
if option == consts.VideoModerationTaskUpdate_Success {
|
||
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
|
||
ZoneMoment: &dbstruct.ZoneMoment{
|
||
Id: task.AssociativeTableId,
|
||
ImageAuditStatus: goproto.Int64(consts.VideoModeration_Passed),
|
||
},
|
||
})
|
||
if err != nil {
|
||
return err
|
||
}
|
||
return _DefaultZoneMoment.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
|
||
}
|
||
|
||
videoModerationOpinion := &strings.Builder{}
|
||
if task.GetStatus() == consts.VideoModeration_ServiceFailed {
|
||
videoModerationOpinion.WriteString("机审失败")
|
||
} else {
|
||
// 写入具体原因
|
||
for i, pass := range task.AuditedMediaResults {
|
||
if !pass {
|
||
videoModerationOpinion.WriteString(fmt.Sprintf("视频%d:%s ", i+1, task.Description[i]))
|
||
}
|
||
}
|
||
}
|
||
|
||
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
|
||
ZoneMoment: &dbstruct.ZoneMoment{
|
||
Id: task.AssociativeTableId,
|
||
ImageAuditStatus: task.Status,
|
||
ImageAuditOpinion: goproto.String(videoModerationOpinion.String()),
|
||
},
|
||
})
|
||
if err != nil {
|
||
return err
|
||
}
|
||
return _DefaultZoneMoment.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
|
||
}
|
||
}
|
||
}
|