by Robin at 20240221; change moment audit logic

This commit is contained in:
Leufolium 2024-02-21 18:04:01 +08:00
parent 1f44a063f7
commit 19de07fbe4
7 changed files with 64 additions and 22 deletions

View File

@ -42,6 +42,7 @@ const (
VideoIdForUploadFail = "video_id_for_upload_fail" VideoIdForUploadFail = "video_id_for_upload_fail"
RestrictedVisitorKey = "restricted_visitor" RestrictedVisitorKey = "restricted_visitor"
MaxDailyMomentCreateTimesKey = "max_daily_moment_create_times" MaxDailyMomentCreateTimesKey = "max_daily_moment_create_times"
DefaultMomentTextKey = "default_moment_text"
) )
// del_flag // del_flag

View File

@ -1586,9 +1586,21 @@ func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateRe
return return
} }
//读取默认动态文字配置
defaultMomentText, err := apollo.GetStringValue(consts.DefaultMomentTextKey, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
oldMoment := &dbstruct.Moment{
Text: goproto.String(defaultMomentText),
}
// 添加审核任务 // 添加审核任务
imageaudittasks := s.CreateMomentImageAudit(ctx, req.Moment) imageaudittasks := s.CreateMomentImageAudit(ctx, req.Moment)
textaudittasks := s.CreateMomentTextAudit(ctx, req.Moment) textaudittasks := s.CreateMomentTextAudit(ctx, oldMoment, req.Moment)
imageaudit.AddTasks(imageaudittasks) imageaudit.AddTasks(imageaudittasks)
textaudit.AddTasks(textaudittasks) textaudit.AddTasks(textaudittasks)
@ -1618,9 +1630,21 @@ func (s *Service) ApiUpdateMoment(ctx *gin.Context, req *momentproto.ApiUpdateRe
return return
} }
//读取默认动态文字配置
defaultMomentText, err := apollo.GetStringValue(consts.DefaultMomentTextKey, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
oldMoment := &dbstruct.Moment{
Text: goproto.String(defaultMomentText),
}
// 添加审核任务 // 添加审核任务
imageaudittasks := s.CreateMomentImageAudit(ctx, req.Moment) imageaudittasks := s.CreateMomentImageAudit(ctx, req.Moment)
textaudittasks := s.CreateMomentTextAudit(ctx, req.Moment) textaudittasks := s.CreateMomentTextAudit(ctx, oldMoment, req.Moment)
imageaudit.AddTasks(imageaudittasks) imageaudit.AddTasks(imageaudittasks)
textaudit.AddTasks(textaudittasks) textaudit.AddTasks(textaudittasks)
return return

View File

@ -10,7 +10,6 @@ import (
"service/dbstruct" "service/dbstruct"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
goproto "google.golang.org/protobuf/proto"
) )
var DefaultImageAuditTaskResultHandler *ImageAuditTaskResultHandler var DefaultImageAuditTaskResultHandler *ImageAuditTaskResultHandler
@ -116,23 +115,39 @@ func (handler *ImageAuditTaskResultHandler) generateStreamerAlbumUpdateFunc() {
} }
} }
// 动态表->图像内容,若不通过,则将状态设置为仅自己可见 // 动态表->图像内容,若不通过,则删掉审核不通过的图片
func (handler *ImageAuditTaskResultHandler) generateMomentMediaComponentUpdateFunc() { func (handler *ImageAuditTaskResultHandler) generateMomentMediaComponentUpdateFunc() {
handler.imageAuditTaskUpdateFuncGeneratorMap["moment|moment|media_component"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { handler.imageAuditTaskUpdateFuncGeneratorMap["moment|moment|media_component"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error {
return func() error { return func() error {
momentId := task.AssociativeTableId momentId := task.AssociativeTableId
var status int64 var mediaComp *dbstruct.MediaComponent
if option == consts.ImageAuditTaskUpdate_Pass { if option == consts.ImageAuditTaskUpdate_Pass {
status = consts.Moment_Public mediaComp = task.AuditedMedia
} else { } else {
status = consts.Moment_Private auditedImageIds := util.DerefInt64Slice(task.AuditedMedia.ImageIds)
imageIds := make([]int64, 0)
for i, pass := range task.AuditedMediaResults {
if pass {
imageIds = append(imageIds, auditedImageIds[i])
}
}
if len(imageIds) != 0 {
mediaComp = &dbstruct.MediaComponent{
ImageIds: &imageIds,
}
}
}
// 如果旧媒体内容为空
if mediaComp == nil {
return _DefaultMoment.OpDelete(ctx, util.DerefInt64(momentId))
} else {
return _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{
Id: momentId,
MediaComp: mediaComp,
},
})
} }
return _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{
Id: momentId,
Status: goproto.Int64(status),
},
})
} }
} }
} }

View File

@ -60,7 +60,7 @@ func (s *Service) CreateUpdateStreamerTextAudit(ctx *gin.Context, oldStreamer *d
return return
} }
func (s *Service) CreateMomentTextAudit(ctx *gin.Context, newMoment *dbstruct.Moment) (tasks []*dbstruct.TextAuditTask) { func (s *Service) CreateMomentTextAudit(ctx *gin.Context, oldMoment *dbstruct.Moment, newMoment *dbstruct.Moment) (tasks []*dbstruct.TextAuditTask) {
// 内容为空则创建一个对齐任务保证Moment所有图像和文字审核均对齐便于后续查询 // 内容为空则创建一个对齐任务保证Moment所有图像和文字审核均对齐便于后续查询
if newMoment.Text != nil { if newMoment.Text != nil {
@ -71,7 +71,7 @@ func (s *Service) CreateMomentTextAudit(ctx *gin.Context, newMoment *dbstruct.Mo
AssociativeTableId: newMoment.Id, AssociativeTableId: newMoment.Id,
AssociativeTableColumn: goproto.String("text"), AssociativeTableColumn: goproto.String("text"),
AuditedText: newMoment.Text, AuditedText: newMoment.Text,
OldText: nil, OldText: oldMoment.Text,
IsAligned: goproto.Int64(consts.TextAuditIsAligned_Yes), IsAligned: goproto.Int64(consts.TextAuditIsAligned_Yes),
}) })
} else { } else {

View File

@ -10,7 +10,6 @@ import (
"service/dbstruct" "service/dbstruct"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
goproto "google.golang.org/protobuf/proto"
) )
var DefaultTextAuditTaskResultHandler *TextAuditTaskResultHandler var DefaultTextAuditTaskResultHandler *TextAuditTaskResultHandler
@ -116,21 +115,21 @@ func (handler *TextAuditTaskResultHandler) generateStreamerAutoResponseMessageUp
} }
} }
// 动态表->文字内容,若不通过,则将状态设置为仅自己可见 // 动态表->文字内容,若不通过,则将文字设置为默认文字
func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() { func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["moment|moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { handler.textAuditTaskUpdateFuncGeneratorMap["moment|moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error { return func() error {
momentId := task.AssociativeTableId momentId := task.AssociativeTableId
var status int64 var text *string
if option == consts.ImageAuditTaskUpdate_Pass { if option == consts.ImageAuditTaskUpdate_Pass {
status = consts.Moment_Public text = task.AuditedText
} else { } else {
status = consts.Moment_Private text = task.OldText
} }
return _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{ return _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{ Moment: &dbstruct.Moment{
Id: momentId, Id: momentId,
Status: goproto.Int64(status), Text: text,
}, },
}) })
} }

View File

@ -25,6 +25,8 @@ type ImageAuditTask struct {
Ct *int64 `json:"ct" bson:"ct"` // 创建时间 Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间 Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
AuditedMediaResults []bool // 每个任务是否审核通过
} }
func (p *ImageAuditTask) IsEmpty() bool { func (p *ImageAuditTask) IsEmpty() bool {

View File

@ -175,6 +175,7 @@ func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDat
// 处理task若task已分片在task中记录本分片结果并累积已到达的分片数直到所有分片到达决定该任务是否成功 // 处理task若task已分片在task中记录本分片结果并累积已到达的分片数直到所有分片到达决定该任务是否成功
func handleTask(task *ImageAuditTaskControlBlock, pass bool) (isTaskCompleted bool) { func handleTask(task *ImageAuditTaskControlBlock, pass bool) (isTaskCompleted bool) {
task.ImageAuditTask.AuditedMediaResults = append(task.ImageAuditTask.AuditedMediaResults, pass)
task.IsTaskPassed = task.IsTaskPassed && pass task.IsTaskPassed = task.IsTaskPassed && pass
task.AuditedFragmentsNum++ task.AuditedFragmentsNum++