From b4e04b8841d11b398f5010a7c9212c0e466b3308 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 11 Apr 2024 21:51:46 +0800 Subject: [PATCH] by Robin at 20240411 --- .../service/imageaudittask_result_handler.go | 23 +++++++--------- .../service/textaudittask_result_handler.go | 3 ++- dbstruct/imageaudit.go | 1 + dbstruct/imageaudittask.go | 3 ++- dbstruct/textaudit.go | 1 + dbstruct/textaudittask.go | 1 + library/contentaudit/imageaudit/imageaudit.go | 26 +++++++++++++++---- library/contentaudit/textaudit/textaudit.go | 15 ++++++++--- 8 files changed, 50 insertions(+), 23 deletions(-) diff --git a/app/mix/service/imageaudittask_result_handler.go b/app/mix/service/imageaudittask_result_handler.go index 09465555..1f73048a 100644 --- a/app/mix/service/imageaudittask_result_handler.go +++ b/app/mix/service/imageaudittask_result_handler.go @@ -171,27 +171,24 @@ func (handler *ImageAuditTaskResultHandler) generateZoneMomentMediaComponentUpda return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId)) } - notPassedImageIndexes := make([]string, 0) - for i, pass := range task.AuditedMediaResults { - if pass { - notPassedImageIndexes = append(notPassedImageIndexes, fmt.Sprint(i)) - } - } - if len(notPassedImageIndexes) == 0 { - notPassedImageIndexes = append(notPassedImageIndexes, fmt.Sprint(0)) - } - var imageAuditOpinion string + imageAuditOpinion := &strings.Builder{} if util.DerefInt64(task.Status) == consts.ImageAudit_ServiceFailed { - imageAuditOpinion = "机审失败" + imageAuditOpinion.WriteString("机审失败") } else { - imageAuditOpinion = fmt.Sprintf("第%s张图片违规", strings.Join(notPassedImageIndexes, ", ")) + // 写入具体原因 + for i, pass := range task.AuditedMediaResults { + if !pass { + imageaudit := task.ImageAudits[i] + imageAuditOpinion.WriteString(fmt.Sprintf("图片%d未通过机审,退回原因:%s\n", i, strings.Join(imageaudit.NotPassScenes, ","))) + } + } } err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{ ZoneMoment: &dbstruct.ZoneMoment{ Id: task.AssociativeTableId, ImageAuditStatus: task.Status, - ImageAuditOpinion: goproto.String(imageAuditOpinion), + ImageAuditOpinion: goproto.String(imageAuditOpinion.String()), }, }) if err != nil { diff --git a/app/mix/service/textaudittask_result_handler.go b/app/mix/service/textaudittask_result_handler.go index d2712289..b97393ed 100644 --- a/app/mix/service/textaudittask_result_handler.go +++ b/app/mix/service/textaudittask_result_handler.go @@ -9,6 +9,7 @@ import ( zonemomentproto "service/api/proto/zonemoment/proto" "service/bizcommon/util" "service/dbstruct" + "strings" "github.com/gin-gonic/gin" goproto "google.golang.org/protobuf/proto" @@ -189,7 +190,7 @@ func (handler *TextAuditTaskResultHandler) generateZoneMomentTextUpdateFunc() { if util.DerefInt64(task.Status) == consts.TextAudit_ServiceFailed { textAuditOpinion = "机审失败" } else { - textAuditOpinion = fmt.Sprintf("文字违规") + textAuditOpinion = fmt.Sprintf("机审违规:含有 %s 关键词", strings.Join(task.TextAudit.NotPassScenes, ",")) } err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{ ZoneMoment: &dbstruct.ZoneMoment{ diff --git a/dbstruct/imageaudit.go b/dbstruct/imageaudit.go index 6ac39ff9..bbdaab45 100644 --- a/dbstruct/imageaudit.go +++ b/dbstruct/imageaudit.go @@ -26,4 +26,5 @@ type ImageAudit struct { Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + NotPassScenes []string // 未通过场景 } diff --git a/dbstruct/imageaudittask.go b/dbstruct/imageaudittask.go index b51fe793..3c1658fd 100644 --- a/dbstruct/imageaudittask.go +++ b/dbstruct/imageaudittask.go @@ -25,7 +25,8 @@ type ImageAuditTask struct { Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 - AuditedMediaResults []bool // 每个任务是否审核通过 + AuditedMediaResults []bool // 每个任务是否审核通过 + ImageAudits []*ImageAudit // 每个任务的结果 } func (p *ImageAuditTask) IsEmpty() bool { diff --git a/dbstruct/textaudit.go b/dbstruct/textaudit.go index e5eeb589..637715c0 100644 --- a/dbstruct/textaudit.go +++ b/dbstruct/textaudit.go @@ -21,4 +21,5 @@ type TextAudit struct { Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + NotPassScenes []string //未通过场景 } diff --git a/dbstruct/textaudittask.go b/dbstruct/textaudittask.go index 163afeee..51339e2c 100644 --- a/dbstruct/textaudittask.go +++ b/dbstruct/textaudittask.go @@ -22,6 +22,7 @@ type TextAuditTask struct { Ut *int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + TextAudit *TextAudit // 任务的结果 } func (p *TextAuditTask) IsEmpty() bool { diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index 3ad6377a..5ea73d74 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -126,7 +126,7 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i // 2.立即在imageaudit-imageaudit中更新该次审核结果 logger.Info("Handling its audit record...") - pass, err := handleImageAudit(dataId, result) + pass, imageAudit, err := handleImageAudit(dataId, result) if err != nil { logger.Error("handleImageAudit fail: %v", err) } @@ -138,7 +138,7 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i // 4.在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功(非分片任务分片数为1) logger.Info("Recording it to task...") - isTaskCompleted = handleTask(task, pass) + isTaskCompleted = handleTask(task, pass, imageAudit) // 5.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态 logger.Info("Recording the task result...") @@ -158,9 +158,9 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i return } -func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDataResults) (pass bool, err error) { +func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDataResults) (pass bool, imageaudit *dbstruct.ImageAudit, err error) { ctx := &gin.Context{} - imageaudit := &dbstruct.ImageAudit{ + imageaudit = &dbstruct.ImageAudit{ Id: goproto.String(dataId), } pass, err = copyScanResultInfo(imageaudit, result) @@ -178,8 +178,9 @@ func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDat } // 处理task,若task已分片,在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功 -func handleTask(task *ImageAuditTaskControlBlock, pass bool) (isTaskCompleted bool) { +func handleTask(task *ImageAuditTaskControlBlock, pass bool, imageAudit *dbstruct.ImageAudit) (isTaskCompleted bool) { task.ImageAuditTask.AuditedMediaResults = append(task.ImageAuditTask.AuditedMediaResults, pass) + task.ImageAuditTask.ImageAudits = append(task.ImageAuditTask.ImageAudits, imageAudit) task.IsTaskPassed = task.IsTaskPassed && pass task.AuditedFragmentsNum++ @@ -263,26 +264,41 @@ func copyScanResultInfo(imageaudit *dbstruct.ImageAudit, result *imageaudit.Scan imageaudit.PornSceneSuggestion = subresult.Suggestion imageaudit.PornSceneLabel = subresult.Label imageaudit.PornSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate))) + if !util.StringsContains(PornPassLabels, util.DerefString(subresult.Label)) { + imageaudit.NotPassScenes = append(imageaudit.NotPassScenes, "色情") + } pass = pass && (util.StringsContains(PornPassLabels, util.DerefString(subresult.Label))) case Terrorism: imageaudit.TerrorismSceneSuggestion = subresult.Suggestion imageaudit.TerrorismSceneLabel = subresult.Label imageaudit.TerrorismSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate))) + if !util.StringsContains(TerrorismPassLabels, util.DerefString(subresult.Label)) { + imageaudit.NotPassScenes = append(imageaudit.NotPassScenes, "暴恐") + } pass = pass && (util.StringsContains(TerrorismPassLabels, util.DerefString(subresult.Label))) case Ad: imageaudit.AdSceneSuggestion = subresult.Suggestion imageaudit.AdSceneLabel = subresult.Label imageaudit.AdSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate))) + if !util.StringsContains(AdPassLabels, util.DerefString(subresult.Label)) { + imageaudit.NotPassScenes = append(imageaudit.NotPassScenes, "广告") + } pass = pass && (util.StringsContains(AdPassLabels, util.DerefString(subresult.Label))) case Live: imageaudit.LiveSceneSuggestion = subresult.Suggestion imageaudit.LiveSceneLabel = subresult.Label imageaudit.LiveSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate))) + if !util.StringsContains(LivePassLabels, util.DerefString(subresult.Label)) { + imageaudit.NotPassScenes = append(imageaudit.NotPassScenes, "不良") + } pass = pass && (util.StringsContains(LivePassLabels, util.DerefString(subresult.Label))) case Logo: imageaudit.LogoSceneSuggestion = subresult.Suggestion imageaudit.LogoSceneLabel = subresult.Label imageaudit.LogoSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate))) + if !util.StringsContains(LogoPassLabels, util.DerefString(subresult.Label)) { + imageaudit.NotPassScenes = append(imageaudit.NotPassScenes, "logo") + } pass = pass && (util.StringsContains(LogoPassLabels, util.DerefString(subresult.Label))) } diff --git a/library/contentaudit/textaudit/textaudit.go b/library/contentaudit/textaudit/textaudit.go index 1e8133db..195ac85e 100644 --- a/library/contentaudit/textaudit/textaudit.go +++ b/library/contentaudit/textaudit/textaudit.go @@ -101,13 +101,14 @@ func handleScanTextResponse(ctrlBlock *TextAuditTaskBatchControlBlock, resp *tex action := &TextAuditAction{} // 1.立即在textaudit-textaudit中更新该次审核结果 - pass, err := handleTextAudit(taskCtrlBlocks[i].TextAuditTask.TextAuditId, result) + pass, textaudit, err := handleTextAudit(taskCtrlBlocks[i].TextAuditTask.TextAuditId, result) if err != nil { logger.Error("handleTextAudit fail: %v", err) } // 2.更新任务状态 taskCtrlBlocks[i].IsTaskPassed = pass + taskCtrlBlocks[i].TextAuditTask.TextAudit = textaudit // 3.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态 isActionCompleted, action = handleTaskAction(taskCtrlBlocks[i], actionMap) @@ -122,9 +123,9 @@ func handleScanTextResponse(ctrlBlock *TextAuditTaskBatchControlBlock, resp *tex return } -func handleTextAudit(id *string, result *textaudit.ScanTextResponseBodyDataElements) (pass bool, err error) { +func handleTextAudit(id *string, result *textaudit.ScanTextResponseBodyDataElements) (pass bool, textaudit *dbstruct.TextAudit, err error) { ctx := &gin.Context{} - textaudit := &dbstruct.TextAudit{ + textaudit = &dbstruct.TextAudit{ Id: id, } pass, err = copyScanResultInfo(textaudit, result) @@ -223,20 +224,28 @@ func copyScanResultInfo(textaudit *dbstruct.TextAudit, elements *textaudit.ScanT contexts := parseDetailsContexts(detail.Contexts) switch label { case Spam: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "垃圾内容") textaudit.SpamLabelDetails = &contexts case Politics: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "敏感内容") textaudit.PoliticsLabelDetails = &contexts case Abuse: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "辱骂内容") textaudit.AbuseLabelDetails = &contexts case Terrorism: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "暴恐内容") textaudit.TerrorismLabelDetails = &contexts case Porn: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "色情内容") textaudit.PornLabelDetails = &contexts case Flood: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "灌水内容") textaudit.FloodLabelDetails = &contexts case Contraband: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "违禁内容") textaudit.ContrabandLabelDetails = &contexts case Ad: + textaudit.NotPassScenes = append(textaudit.NotPassScenes, "广告内容") textaudit.AdLabelDetails = &contexts } }