Merge pull request 'conf' (#394) from conf into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/394
This commit is contained in:
chenhao 2024-05-01 03:28:07 +08:00
commit 4019cf0dd1
4 changed files with 202 additions and 59 deletions

View File

@ -51,8 +51,8 @@ const (
DefaultMomentTextKey = "default_moment_text" DefaultMomentTextKey = "default_moment_text"
MaxDailyZoneMomentCreateTimesKey = "max_daily_zone_moment_create_times" MaxDailyZoneMomentCreateTimesKey = "max_daily_zone_moment_create_times"
ReferentialZoneMomentKey = "referential_zone_moment" ReferentialZoneMomentKey = "referential_zone_moment"
RestrictedVisitorMomentKey = "restricted_visitor_moment"
IsMomentImageEncryptEnabledKey = "is_moment_image_encrypt_enabled" IsMomentImageEncryptEnabledKey = "is_moment_image_encrypt_enabled"
RestrictedVisitorMomentKey = "restricted_visitor_moment"
) )
// del_flag // del_flag

View File

@ -2,6 +2,7 @@ package proto
import ( import (
"service/api/consts" "service/api/consts"
"service/bizcommon/util"
"service/library/validator" "service/library/validator"
) )
@ -9,10 +10,42 @@ func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) {
params = make([]*validator.JsonParam, 0) params = make([]*validator.JsonParam, 0)
params = append(params, validator.NewInt64PtrParam("请确认创建动态的所属空间id", p.ZoneMoment.Zid)) 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.NewStringPtrParam("请确认创建动态的文案!", p.Text))
params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp)) 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 return
} }

View File

@ -3255,23 +3255,89 @@ func (s *Service) OpCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpCr
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建
req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds()))) req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds())))
} else { } 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.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetVideoIds())))
} }
req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建
req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审
_, err := _DefaultZoneMoment.OpCreate(ctx, req)
momentId, err := _DefaultZoneMoment.OpCreate(ctx, req)
if err != nil { if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return 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 return
} }
func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUpdateReq) (ec errcode.ErrCode) { func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneMomentSrvOk 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 { if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeZoneMomentNotExist ec = errcode.ErrCodeZoneMomentNotExist
err = nil err = nil
@ -3282,6 +3348,27 @@ func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUp
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return 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 return
} }
@ -3328,7 +3415,7 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
Id: goproto.Int64(zid), Id: goproto.Int64(zid),
LastZoneMomentCt: goproto.Int64(0), LastZoneMomentCt: goproto.Int64(0),
}, },
}, util.DerefInt64(zone.LastZoneMomentCt)) }, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
logger.Error("OpUpdate fail, err: %v", err) logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
@ -3337,13 +3424,13 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
} else { } else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨 //还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨
lastzonemoment := list[0] lastzonemoment := list[0]
if util.DerefInt64(lastzonemoment.Ut) < util.DerefInt64(zonemoment.Ut) { if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{ err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{ Zone: &dbstruct.Zone{
Id: goproto.Int64(zid), Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut, LastZoneMomentCt: lastzonemoment.Ut,
}, },
}, util.DerefInt64(zone.LastZoneMomentCt)) }, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
logger.Error("OpUpdate fail, err: %v", err) logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
@ -3352,15 +3439,18 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
} }
} }
// 回退空间内统计总数 // 回退空间内统计总数,只回退公开的情况
mediaCountInc := len(zonemoment.MediaComp.GetImageIds()) if zonemoment.GetStatus() == consts.ZoneMoment_Public {
videoCountInc := len(zonemoment.MediaComp.GetVideoIds()) mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
err = _DefaultZone.RecordStatisticsById(ctx, util.DerefInt64(zonemoment.Zid), -1, -int64(mediaCountInc), -int64(videoCountInc)) videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
if err != nil { err = _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -1, -int64(mediaCountInc), -int64(videoCountInc))
logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err) if err != nil {
ec = errcode.ErrCodeZoneSrvFail logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err)
return ec = errcode.ErrCodeZoneSrvFail
return
}
} }
return return
} }

View File

@ -115,13 +115,21 @@ func handleVideoModeration(result *green20220302.VideoModerationResultResponseBo
audioResult := result.Data.AudioResult audioResult := result.Data.AudioResult
// 解析信息 // 解析信息
frameSummaries, isFramesPassed := buildFrameSummaries(frameResult.FrameSummarys) isFramesPassed := true
frameDetails := buildFrameDetails(frameResult.Frames) isAudioPassed := true
audioSummaries, isAudioPassed := buildAudioSummaries(audioResult.AudioSummarys) if frameResult != nil {
audioDetails := buildAudioDetails(result.Data.AudioResult.SliceDetails) var frameSummaries []*dbstruct.FrameSummary
frameSummaries, isFramesPassed = buildFrameSummaries(frameResult.FrameSummarys)
videomoderation.FrameNum = frameResult.FrameNum frameDetails := buildFrameDetails(frameResult.Frames)
videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails).SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) 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 { if isFramesPassed && isAudioPassed {
@ -165,12 +173,14 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = true isPassed = true
frameSummaries = make([]*dbstruct.FrameSummary, 0) frameSummaries = make([]*dbstruct.FrameSummary, 0)
for _, summary := range summaries { for _, summary := range summaries {
frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ if summary != nil {
Label: summary.Label, frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{
LabelSum: summary.LabelSum, Label: summary.Label,
}) LabelSum: summary.LabelSum,
if util.DerefString(summary.Label) != VideoModerationPassLabel { })
isPassed = false if util.DerefString(summary.Label) != VideoModerationPassLabel {
isPassed = false
}
} }
} }
return return
@ -179,11 +189,13 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons
func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) { func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) {
frameDetails = make([]*dbstruct.FrameDetail, 0) frameDetails = make([]*dbstruct.FrameDetail, 0)
for _, detail := range details { for _, detail := range details {
frameDetail := &dbstruct.FrameDetail{ if detail != nil {
Offset: detail.Offset, 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 return
} }
@ -191,11 +203,13 @@ func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBod
func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) { func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) {
frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0) frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0)
for _, detail := range details { for _, detail := range details {
frameServiceDetail := &dbstruct.FrameServiceDetail{ if detail != nil {
Service: detail.Service, 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 return
} }
@ -203,10 +217,12 @@ func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResp
func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) { func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) {
frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0) frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0)
for _, detail := range details { for _, detail := range details {
frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ if detail != nil {
Confidence: detail.Confidence, frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{
Label: detail.Label, Confidence: detail.Confidence,
}) Label: detail.Label,
})
}
} }
return return
} }
@ -215,12 +231,14 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = true isPassed = true
audioSummaries = make([]*dbstruct.AudioSummary, 0) audioSummaries = make([]*dbstruct.AudioSummary, 0)
for _, summary := range summaries { for _, summary := range summaries {
audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ if summary != nil {
Label: summary.Label, audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{
LabelSum: summary.LabelSum, Label: summary.Label,
}) LabelSum: summary.LabelSum,
if util.DerefString(summary.Label) != AudioModerationPassLabel { })
isPassed = false if util.DerefString(summary.Label) != AudioModerationPassLabel {
isPassed = false
}
} }
} }
return return
@ -229,18 +247,20 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons
func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) { func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) {
audioDetails = make([]*dbstruct.AudioDetail, 0) audioDetails = make([]*dbstruct.AudioDetail, 0)
for _, detail := range details { for _, detail := range details {
audioDetails = append(audioDetails, &dbstruct.AudioDetail{ if detail != nil {
EndTime: detail.EndTime, audioDetails = append(audioDetails, &dbstruct.AudioDetail{
EndTimestamp: detail.EndTimestamp, EndTime: detail.EndTime,
Extend: detail.Extend, EndTimestamp: detail.EndTimestamp,
Labels: detail.Labels, Extend: detail.Extend,
RiskTips: detail.RiskTips, Labels: detail.Labels,
RiskWords: detail.RiskWords, RiskTips: detail.RiskTips,
Score: detail.Score, RiskWords: detail.RiskWords,
StartTime: detail.StartTime, Score: detail.Score,
StartTimestamp: detail.StartTimestamp, StartTime: detail.StartTime,
Text: detail.Text, StartTimestamp: detail.StartTimestamp,
}) Text: detail.Text,
})
}
} }
return return
} }