From 6158600853d49a884294cf8e01658b744083fe75 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 1 May 2024 01:04:50 +0800 Subject: [PATCH 1/2] by Robin at 20240501 --- api/proto/zonemoment/proto/not_null_def_op.go | 35 +++++- app/mix/service/service.go | 118 +++++++++++++++--- 2 files changed, 138 insertions(+), 15 deletions(-) diff --git a/api/proto/zonemoment/proto/not_null_def_op.go b/api/proto/zonemoment/proto/not_null_def_op.go index f4515a31..3d2e0230 100644 --- a/api/proto/zonemoment/proto/not_null_def_op.go +++ b/api/proto/zonemoment/proto/not_null_def_op.go @@ -2,6 +2,7 @@ package proto import ( "service/api/consts" + "service/bizcommon/util" "service/library/validator" ) @@ -9,10 +10,42 @@ func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = make([]*validator.JsonParam, 0) params = append(params, validator.NewInt64PtrParam("请确认创建动态的所属空间id!", p.ZoneMoment.Zid)) - params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.Status)) + params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.CType)) + params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体类型!", p.ZoneMoment.MType)) params = append(params, validator.NewStringPtrParam("请确认创建动态的文案!", p.Text)) params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp)) + switch util.DerefInt64(p.ZoneMoment.CType) { + case consts.ZoneMomentCType_Paid: + params = append(params, validator.NewInt64PtrParam("请确认创建动态的文字可见范围!", p.ZoneMoment.TextVisibleRange)) + params = append(params, validator.NewInt64PtrParam("请确认创建动态的价格!", p.ZoneMoment.Price)) + switch util.DerefInt64(p.ZoneMoment.MType) { + case consts.MediaTypeImg: + params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体可见范围!", p.ZoneMoment.MediaVisibleRange)) + case consts.MediaTypeVideo: + params = append(params, validator.NewInt64PtrParam("请确认创建动态是否要模糊封面!", p.ZoneMoment.IsBlurringCover)) + } + + } + + return +} + +func (p *OpUpdateReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + + params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.CType)) + params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体类型!", p.ZoneMoment.MType)) + + switch util.DerefInt64(p.ZoneMoment.CType) { + case consts.ZoneMomentCType_Paid: + if p.Text != nil { + params = append(params, validator.NewStringPtrParam("请确认创建动态的文案!", p.Text)) + } + if p.MediaComp != nil { + params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp)) + } + } return } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 623b4586..88d9cf24 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3255,23 +3255,89 @@ func (s *Service) OpCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpCr req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds()))) } else { - req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Passed) // 视频贴默认已通过 + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.VideoModeration_Created) req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetVideoIds()))) } req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 - _, err := _DefaultZoneMoment.OpCreate(ctx, req) + + momentId, err := _DefaultZoneMoment.OpCreate(ctx, req) if err != nil { logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneMomentSrvFail return } + + // 添加审核任务 + imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment) + textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment) + videomoderationtasks := s.CreateZoneMomentVideoModeration(ctx, req.ZoneMoment) + imageaudit.AddTasks(imageaudittasks) + textaudit.AddTasks(textaudittasks) + videomoderation.AddTasks(videomoderationtasks) + + // 设置价格 + if req.ZoneMoment.GetCType() == consts.ZoneMomentCType_Paid { + err = _DefaultVas.UpdateZoneMomentPrice(ctx, &vasproto.UpdateZoneMomentPriceReq{ + ZoneMomentPrice: &dbstruct.ZoneMomentPrice{ + MomentId: momentId, + Zid: *req.ZoneMoment.Zid, + Mid: *req.ZoneMoment.Mid, + Price: *req.ZoneMoment.Price, + }, + }) + if err != nil { + logger.Error("UpdateZoneMomentPrice fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + } + } return } func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk - err := _DefaultZoneMoment.OpUpdate(ctx, req) + + zonemoment, err := _DefaultZoneMoment.GetById(ctx, req.ZoneMoment.GetId()) + if err != nil { + logger.Error("_DefaultZoneMoment GetById fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + } + if zonemoment == nil { + ec = errcode.ErrCodeZoneMomentNotExist + return + } + + zmStatus := zonemoment.GetStatus() + + // 抹消审核信息,回退到初始 + isReauditRequired := false + if req.ZoneMoment.MediaComp != nil && req.ZoneMoment.GetMType() == consts.MediaTypeImg { + isReauditRequired = true + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 + req.ZoneMoment.ImageAuditOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds()))) + } + if req.ZoneMoment.MediaComp != nil && req.ZoneMoment.GetMType() == consts.MediaTypeVideo { + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.VideoModeration_Created) // 创建 + req.ZoneMoment.ImageAuditOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetVideoIds()))) + } + if req.ZoneMoment.Text != nil { + isReauditRequired = true + req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 + req.ZoneMoment.TextAuditOpinion = goproto.String("") // 信息抹除 + } + + if isReauditRequired { + req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 正在审核中 + req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 + req.ZoneMoment.ManuallyReviewOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.ManuallyReviewOperator = goproto.Int64(0) // 信息抹除 + } + + err = _DefaultZoneMoment.OpUpdate(ctx, req) if err == qmgo.ErrNoSuchDocuments { ec = errcode.ErrCodeZoneMomentNotExist err = nil @@ -3282,6 +3348,27 @@ func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUp ec = errcode.ErrCodeZoneMomentSrvFail return } + + // 回退空间内统计总数,只回退公开的情况 + if zmStatus == consts.ZoneMoment_Public && isReauditRequired { + mediaCountInc := len(zonemoment.MediaComp.GetImageIds()) + videoCountInc := len(zonemoment.MediaComp.GetVideoIds()) + err := _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -1, -int64(mediaCountInc), -int64(videoCountInc)) + if err != nil { + logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + } + + // 添加审核任务 + imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment) + textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment) + videomoderationtasks := s.CreateZoneMomentVideoModeration(ctx, req.ZoneMoment) + imageaudit.AddTasks(imageaudittasks) + textaudit.AddTasks(textaudittasks) + videomoderation.AddTasks(videomoderationtasks) + return } @@ -3328,7 +3415,7 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe Id: goproto.Int64(zid), LastZoneMomentCt: goproto.Int64(0), }, - }, util.DerefInt64(zone.LastZoneMomentCt)) + }, zone.GetLastZoneMomentCt()) if err != nil { logger.Error("OpUpdate fail, err: %v", err) ec = errcode.ErrCodeZoneMomentSrvFail @@ -3337,13 +3424,13 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe } else { //还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨 lastzonemoment := list[0] - if util.DerefInt64(lastzonemoment.Ut) < util.DerefInt64(zonemoment.Ut) { + if lastzonemoment.GetUt() < zonemoment.GetUt() { err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{ Zone: &dbstruct.Zone{ Id: goproto.Int64(zid), LastZoneMomentCt: lastzonemoment.Ut, }, - }, util.DerefInt64(zone.LastZoneMomentCt)) + }, zone.GetLastZoneMomentCt()) if err != nil { logger.Error("OpUpdate fail, err: %v", err) ec = errcode.ErrCodeZoneMomentSrvFail @@ -3352,15 +3439,18 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe } } - // 回退空间内统计总数 - mediaCountInc := len(zonemoment.MediaComp.GetImageIds()) - videoCountInc := len(zonemoment.MediaComp.GetVideoIds()) - err = _DefaultZone.RecordStatisticsById(ctx, util.DerefInt64(zonemoment.Zid), -1, -int64(mediaCountInc), -int64(videoCountInc)) - if err != nil { - logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err) - ec = errcode.ErrCodeZoneSrvFail - return + // 回退空间内统计总数,只回退公开的情况 + if zonemoment.GetStatus() == consts.ZoneMoment_Public { + mediaCountInc := len(zonemoment.MediaComp.GetImageIds()) + videoCountInc := len(zonemoment.MediaComp.GetVideoIds()) + err = _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -1, -int64(mediaCountInc), -int64(videoCountInc)) + if err != nil { + logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } } + return } From aca92810875fe9639e1acf29ad330a2f6a168326 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 1 May 2024 01:54:47 +0800 Subject: [PATCH 2/2] by Robin at 20240501; fix upload fail video mod --- .../contentaudit/video_moderation/handler.go | 106 +++++++++++------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/library/contentaudit/video_moderation/handler.go b/library/contentaudit/video_moderation/handler.go index 902bdb16..8df4bf1b 100644 --- a/library/contentaudit/video_moderation/handler.go +++ b/library/contentaudit/video_moderation/handler.go @@ -115,13 +115,21 @@ func handleVideoModeration(result *green20220302.VideoModerationResultResponseBo audioResult := result.Data.AudioResult // 解析信息 - frameSummaries, isFramesPassed := buildFrameSummaries(frameResult.FrameSummarys) - frameDetails := buildFrameDetails(frameResult.Frames) - audioSummaries, isAudioPassed := buildAudioSummaries(audioResult.AudioSummarys) - audioDetails := buildAudioDetails(result.Data.AudioResult.SliceDetails) - - videomoderation.FrameNum = frameResult.FrameNum - videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails).SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) + isFramesPassed := true + isAudioPassed := true + if frameResult != nil { + var frameSummaries []*dbstruct.FrameSummary + frameSummaries, isFramesPassed = buildFrameSummaries(frameResult.FrameSummarys) + frameDetails := buildFrameDetails(frameResult.Frames) + videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails) + videomoderation.FrameNum = frameResult.FrameNum + } + if audioResult != nil { + var audioSummaries []*dbstruct.AudioSummary + audioSummaries, isAudioPassed = buildAudioSummaries(audioResult.AudioSummarys) + audioDetails := buildAudioDetails(audioResult.SliceDetails) + videomoderation.SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) + } // 判定检测结果 if isFramesPassed && isAudioPassed { @@ -165,12 +173,14 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons isPassed = true frameSummaries = make([]*dbstruct.FrameSummary, 0) for _, summary := range summaries { - frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ - Label: summary.Label, - LabelSum: summary.LabelSum, - }) - if util.DerefString(summary.Label) != VideoModerationPassLabel { - isPassed = false + if summary != nil { + frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ + Label: summary.Label, + LabelSum: summary.LabelSum, + }) + if util.DerefString(summary.Label) != VideoModerationPassLabel { + isPassed = false + } } } return @@ -179,11 +189,13 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) { frameDetails = make([]*dbstruct.FrameDetail, 0) for _, detail := range details { - frameDetail := &dbstruct.FrameDetail{ - Offset: detail.Offset, + if detail != nil { + frameDetail := &dbstruct.FrameDetail{ + Offset: detail.Offset, + } + frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results)) + frameDetails = append(frameDetails, frameDetail) } - frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results)) - frameDetails = append(frameDetails, frameDetail) } return } @@ -191,11 +203,13 @@ func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBod func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) { frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0) for _, detail := range details { - frameServiceDetail := &dbstruct.FrameServiceDetail{ - Service: detail.Service, + if detail != nil { + frameServiceDetail := &dbstruct.FrameServiceDetail{ + Service: detail.Service, + } + frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result)) + frameServiceDetails = append(frameServiceDetails, frameServiceDetail) } - frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result)) - frameServiceDetails = append(frameServiceDetails, frameServiceDetail) } return } @@ -203,10 +217,12 @@ func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResp func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) { frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0) for _, detail := range details { - frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ - Confidence: detail.Confidence, - Label: detail.Label, - }) + if detail != nil { + frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ + Confidence: detail.Confidence, + Label: detail.Label, + }) + } } return } @@ -215,12 +231,14 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons isPassed = true audioSummaries = make([]*dbstruct.AudioSummary, 0) for _, summary := range summaries { - audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ - Label: summary.Label, - LabelSum: summary.LabelSum, - }) - if util.DerefString(summary.Label) != AudioModerationPassLabel { - isPassed = false + if summary != nil { + audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ + Label: summary.Label, + LabelSum: summary.LabelSum, + }) + if util.DerefString(summary.Label) != AudioModerationPassLabel { + isPassed = false + } } } return @@ -229,18 +247,20 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) { audioDetails = make([]*dbstruct.AudioDetail, 0) for _, detail := range details { - audioDetails = append(audioDetails, &dbstruct.AudioDetail{ - EndTime: detail.EndTime, - EndTimestamp: detail.EndTimestamp, - Extend: detail.Extend, - Labels: detail.Labels, - RiskTips: detail.RiskTips, - RiskWords: detail.RiskWords, - Score: detail.Score, - StartTime: detail.StartTime, - StartTimestamp: detail.StartTimestamp, - Text: detail.Text, - }) + if detail != nil { + audioDetails = append(audioDetails, &dbstruct.AudioDetail{ + EndTime: detail.EndTime, + EndTimestamp: detail.EndTimestamp, + Extend: detail.Extend, + Labels: detail.Labels, + RiskTips: detail.RiskTips, + RiskWords: detail.RiskWords, + Score: detail.Score, + StartTime: detail.StartTime, + StartTimestamp: detail.StartTimestamp, + Text: detail.Text, + }) + } } return }