diff --git a/api/consts/consts.go b/api/consts/consts.go index fa27f2d0..5f86b535 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -42,6 +42,7 @@ const ( VideoIdForUploadFail = "video_id_for_upload_fail" RestrictedVisitorKey = "restricted_visitor" MaxDailyMomentCreateTimesKey = "max_daily_moment_create_times" + DefaultMomentTextKey = "default_moment_text" ) // del_flag diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 4238f109..9578173c 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1586,9 +1586,21 @@ func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateRe 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) - textaudittasks := s.CreateMomentTextAudit(ctx, req.Moment) + textaudittasks := s.CreateMomentTextAudit(ctx, oldMoment, req.Moment) imageaudit.AddTasks(imageaudittasks) textaudit.AddTasks(textaudittasks) @@ -1618,9 +1630,21 @@ func (s *Service) ApiUpdateMoment(ctx *gin.Context, req *momentproto.ApiUpdateRe 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) - textaudittasks := s.CreateMomentTextAudit(ctx, req.Moment) + textaudittasks := s.CreateMomentTextAudit(ctx, oldMoment, req.Moment) imageaudit.AddTasks(imageaudittasks) textaudit.AddTasks(textaudittasks) return diff --git a/app/mix/service/imageaudittask_result_handler.go b/app/mix/service/imageaudittask_result_handler.go index 9071331f..a87b964e 100644 --- a/app/mix/service/imageaudittask_result_handler.go +++ b/app/mix/service/imageaudittask_result_handler.go @@ -10,7 +10,6 @@ import ( "service/dbstruct" "github.com/gin-gonic/gin" - goproto "google.golang.org/protobuf/proto" ) var DefaultImageAuditTaskResultHandler *ImageAuditTaskResultHandler @@ -116,23 +115,39 @@ func (handler *ImageAuditTaskResultHandler) generateStreamerAlbumUpdateFunc() { } } -// 动态表->图像内容,若不通过,则将状态设置为仅自己可见 +// 动态表->图像内容,若不通过,则删掉审核不通过的图片 func (handler *ImageAuditTaskResultHandler) generateMomentMediaComponentUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["moment|moment|media_component"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { momentId := task.AssociativeTableId - var status int64 + var mediaComp *dbstruct.MediaComponent if option == consts.ImageAuditTaskUpdate_Pass { - status = consts.Moment_Public + mediaComp = task.AuditedMedia } 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), - }, - }) } } } diff --git a/app/mix/service/textauditservice.go b/app/mix/service/textauditservice.go index 908b6e9a..8988c3c6 100644 --- a/app/mix/service/textauditservice.go +++ b/app/mix/service/textauditservice.go @@ -60,7 +60,7 @@ func (s *Service) CreateUpdateStreamerTextAudit(ctx *gin.Context, oldStreamer *d 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所有图像和文字审核均对齐,便于后续查询 if newMoment.Text != nil { @@ -71,7 +71,7 @@ func (s *Service) CreateMomentTextAudit(ctx *gin.Context, newMoment *dbstruct.Mo AssociativeTableId: newMoment.Id, AssociativeTableColumn: goproto.String("text"), AuditedText: newMoment.Text, - OldText: nil, + OldText: oldMoment.Text, IsAligned: goproto.Int64(consts.TextAuditIsAligned_Yes), }) } else { diff --git a/app/mix/service/textaudittask_result_handler.go b/app/mix/service/textaudittask_result_handler.go index 92e81460..3facc5b7 100644 --- a/app/mix/service/textaudittask_result_handler.go +++ b/app/mix/service/textaudittask_result_handler.go @@ -10,7 +10,6 @@ import ( "service/dbstruct" "github.com/gin-gonic/gin" - goproto "google.golang.org/protobuf/proto" ) var DefaultTextAuditTaskResultHandler *TextAuditTaskResultHandler @@ -116,21 +115,21 @@ func (handler *TextAuditTaskResultHandler) generateStreamerAutoResponseMessageUp } } -// 动态表->文字内容,若不通过,则将状态设置为仅自己可见 +// 动态表->文字内容,若不通过,则将文字设置为默认文字 func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["moment|moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { momentId := task.AssociativeTableId - var status int64 + var text *string if option == consts.ImageAuditTaskUpdate_Pass { - status = consts.Moment_Public + text = task.AuditedText } else { - status = consts.Moment_Private + text = task.OldText } return _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{ Moment: &dbstruct.Moment{ - Id: momentId, - Status: goproto.Int64(status), + Id: momentId, + Text: text, }, }) } diff --git a/dbstruct/imageaudittask.go b/dbstruct/imageaudittask.go index e74e4f45..08db9b3e 100644 --- a/dbstruct/imageaudittask.go +++ b/dbstruct/imageaudittask.go @@ -25,6 +25,8 @@ type ImageAuditTask struct { Ct *int64 `json:"ct" bson:"ct"` // 创建时间 Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + + AuditedMediaResults []bool // 每个任务是否审核通过 } func (p *ImageAuditTask) IsEmpty() bool { diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index 08560282..f350f95f 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -175,6 +175,7 @@ func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDat // 处理task,若task已分片,在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功 func handleTask(task *ImageAuditTaskControlBlock, pass bool) (isTaskCompleted bool) { + task.ImageAuditTask.AuditedMediaResults = append(task.ImageAuditTask.AuditedMediaResults, pass) task.IsTaskPassed = task.IsTaskPassed && pass task.AuditedFragmentsNum++