by Robin at 20240411

This commit is contained in:
Leufolium 2024-04-11 21:51:46 +08:00
parent 99116d4f31
commit b4e04b8841
8 changed files with 50 additions and 23 deletions

View File

@ -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 {

View File

@ -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{

View File

@ -26,4 +26,5 @@ type ImageAudit struct {
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
NotPassScenes []string // 未通过场景
}

View File

@ -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 {

View File

@ -21,4 +21,5 @@ type TextAudit struct {
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
NotPassScenes []string //未通过场景
}

View File

@ -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 {

View File

@ -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)))
}

View File

@ -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
}
}