by Robin at 20240411
This commit is contained in:
parent
99116d4f31
commit
b4e04b8841
|
@ -171,27 +171,24 @@ func (handler *ImageAuditTaskResultHandler) generateZoneMomentMediaComponentUpda
|
||||||
return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId))
|
return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId))
|
||||||
}
|
}
|
||||||
|
|
||||||
notPassedImageIndexes := make([]string, 0)
|
imageAuditOpinion := &strings.Builder{}
|
||||||
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
|
|
||||||
if util.DerefInt64(task.Status) == consts.ImageAudit_ServiceFailed {
|
if util.DerefInt64(task.Status) == consts.ImageAudit_ServiceFailed {
|
||||||
imageAuditOpinion = "机审失败"
|
imageAuditOpinion.WriteString("机审失败")
|
||||||
} else {
|
} 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{
|
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
|
||||||
ZoneMoment: &dbstruct.ZoneMoment{
|
ZoneMoment: &dbstruct.ZoneMoment{
|
||||||
Id: task.AssociativeTableId,
|
Id: task.AssociativeTableId,
|
||||||
ImageAuditStatus: task.Status,
|
ImageAuditStatus: task.Status,
|
||||||
ImageAuditOpinion: goproto.String(imageAuditOpinion),
|
ImageAuditOpinion: goproto.String(imageAuditOpinion.String()),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
zonemomentproto "service/api/proto/zonemoment/proto"
|
zonemomentproto "service/api/proto/zonemoment/proto"
|
||||||
"service/bizcommon/util"
|
"service/bizcommon/util"
|
||||||
"service/dbstruct"
|
"service/dbstruct"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
goproto "google.golang.org/protobuf/proto"
|
goproto "google.golang.org/protobuf/proto"
|
||||||
|
@ -189,7 +190,7 @@ func (handler *TextAuditTaskResultHandler) generateZoneMomentTextUpdateFunc() {
|
||||||
if util.DerefInt64(task.Status) == consts.TextAudit_ServiceFailed {
|
if util.DerefInt64(task.Status) == consts.TextAudit_ServiceFailed {
|
||||||
textAuditOpinion = "机审失败"
|
textAuditOpinion = "机审失败"
|
||||||
} else {
|
} else {
|
||||||
textAuditOpinion = fmt.Sprintf("文字违规")
|
textAuditOpinion = fmt.Sprintf("机审违规:含有 %s 关键词", strings.Join(task.TextAudit.NotPassScenes, ","))
|
||||||
}
|
}
|
||||||
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
|
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
|
||||||
ZoneMoment: &dbstruct.ZoneMoment{
|
ZoneMoment: &dbstruct.ZoneMoment{
|
||||||
|
|
|
@ -26,4 +26,5 @@ type ImageAudit struct {
|
||||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
|
||||||
|
NotPassScenes []string // 未通过场景
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ type ImageAuditTask struct {
|
||||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
|
||||||
AuditedMediaResults []bool // 每个任务是否审核通过
|
AuditedMediaResults []bool // 每个任务是否审核通过
|
||||||
|
ImageAudits []*ImageAudit // 每个任务的结果
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ImageAuditTask) IsEmpty() bool {
|
func (p *ImageAuditTask) IsEmpty() bool {
|
||||||
|
|
|
@ -21,4 +21,5 @@ type TextAudit struct {
|
||||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
|
||||||
|
NotPassScenes []string //未通过场景
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ type TextAuditTask struct {
|
||||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
|
||||||
|
TextAudit *TextAudit // 任务的结果
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TextAuditTask) IsEmpty() bool {
|
func (p *TextAuditTask) IsEmpty() bool {
|
||||||
|
|
|
@ -126,7 +126,7 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i
|
||||||
|
|
||||||
// 2.立即在imageaudit-imageaudit中更新该次审核结果
|
// 2.立即在imageaudit-imageaudit中更新该次审核结果
|
||||||
logger.Info("Handling its audit record...")
|
logger.Info("Handling its audit record...")
|
||||||
pass, err := handleImageAudit(dataId, result)
|
pass, imageAudit, err := handleImageAudit(dataId, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("handleImageAudit fail: %v", err)
|
logger.Error("handleImageAudit fail: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i
|
||||||
|
|
||||||
// 4.在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功(非分片任务分片数为1)
|
// 4.在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功(非分片任务分片数为1)
|
||||||
logger.Info("Recording it to task...")
|
logger.Info("Recording it to task...")
|
||||||
isTaskCompleted = handleTask(task, pass)
|
isTaskCompleted = handleTask(task, pass, imageAudit)
|
||||||
|
|
||||||
// 5.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态
|
// 5.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态
|
||||||
logger.Info("Recording the task result...")
|
logger.Info("Recording the task result...")
|
||||||
|
@ -158,9 +158,9 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i
|
||||||
return
|
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{}
|
ctx := &gin.Context{}
|
||||||
imageaudit := &dbstruct.ImageAudit{
|
imageaudit = &dbstruct.ImageAudit{
|
||||||
Id: goproto.String(dataId),
|
Id: goproto.String(dataId),
|
||||||
}
|
}
|
||||||
pass, err = copyScanResultInfo(imageaudit, result)
|
pass, err = copyScanResultInfo(imageaudit, result)
|
||||||
|
@ -178,8 +178,9 @@ func handleImageAudit(dataId string, result *imageaudit.ScanImageResponseBodyDat
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理task,若task已分片,在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功
|
// 处理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.AuditedMediaResults = append(task.ImageAuditTask.AuditedMediaResults, pass)
|
||||||
|
task.ImageAuditTask.ImageAudits = append(task.ImageAuditTask.ImageAudits, imageAudit)
|
||||||
task.IsTaskPassed = task.IsTaskPassed && pass
|
task.IsTaskPassed = task.IsTaskPassed && pass
|
||||||
task.AuditedFragmentsNum++
|
task.AuditedFragmentsNum++
|
||||||
|
|
||||||
|
@ -263,26 +264,41 @@ func copyScanResultInfo(imageaudit *dbstruct.ImageAudit, result *imageaudit.Scan
|
||||||
imageaudit.PornSceneSuggestion = subresult.Suggestion
|
imageaudit.PornSceneSuggestion = subresult.Suggestion
|
||||||
imageaudit.PornSceneLabel = subresult.Label
|
imageaudit.PornSceneLabel = subresult.Label
|
||||||
imageaudit.PornSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate)))
|
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)))
|
pass = pass && (util.StringsContains(PornPassLabels, util.DerefString(subresult.Label)))
|
||||||
case Terrorism:
|
case Terrorism:
|
||||||
imageaudit.TerrorismSceneSuggestion = subresult.Suggestion
|
imageaudit.TerrorismSceneSuggestion = subresult.Suggestion
|
||||||
imageaudit.TerrorismSceneLabel = subresult.Label
|
imageaudit.TerrorismSceneLabel = subresult.Label
|
||||||
imageaudit.TerrorismSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate)))
|
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)))
|
pass = pass && (util.StringsContains(TerrorismPassLabels, util.DerefString(subresult.Label)))
|
||||||
case Ad:
|
case Ad:
|
||||||
imageaudit.AdSceneSuggestion = subresult.Suggestion
|
imageaudit.AdSceneSuggestion = subresult.Suggestion
|
||||||
imageaudit.AdSceneLabel = subresult.Label
|
imageaudit.AdSceneLabel = subresult.Label
|
||||||
imageaudit.AdSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate)))
|
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)))
|
pass = pass && (util.StringsContains(AdPassLabels, util.DerefString(subresult.Label)))
|
||||||
case Live:
|
case Live:
|
||||||
imageaudit.LiveSceneSuggestion = subresult.Suggestion
|
imageaudit.LiveSceneSuggestion = subresult.Suggestion
|
||||||
imageaudit.LiveSceneLabel = subresult.Label
|
imageaudit.LiveSceneLabel = subresult.Label
|
||||||
imageaudit.LiveSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate)))
|
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)))
|
pass = pass && (util.StringsContains(LivePassLabels, util.DerefString(subresult.Label)))
|
||||||
case Logo:
|
case Logo:
|
||||||
imageaudit.LogoSceneSuggestion = subresult.Suggestion
|
imageaudit.LogoSceneSuggestion = subresult.Suggestion
|
||||||
imageaudit.LogoSceneLabel = subresult.Label
|
imageaudit.LogoSceneLabel = subresult.Label
|
||||||
imageaudit.LogoSceneRate = goproto.Float64(float64(util.DerefFloat32(subresult.Rate)))
|
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)))
|
pass = pass && (util.StringsContains(LogoPassLabels, util.DerefString(subresult.Label)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,13 +101,14 @@ func handleScanTextResponse(ctrlBlock *TextAuditTaskBatchControlBlock, resp *tex
|
||||||
action := &TextAuditAction{}
|
action := &TextAuditAction{}
|
||||||
|
|
||||||
// 1.立即在textaudit-textaudit中更新该次审核结果
|
// 1.立即在textaudit-textaudit中更新该次审核结果
|
||||||
pass, err := handleTextAudit(taskCtrlBlocks[i].TextAuditTask.TextAuditId, result)
|
pass, textaudit, err := handleTextAudit(taskCtrlBlocks[i].TextAuditTask.TextAuditId, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("handleTextAudit fail: %v", err)
|
logger.Error("handleTextAudit fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.更新任务状态
|
// 2.更新任务状态
|
||||||
taskCtrlBlocks[i].IsTaskPassed = pass
|
taskCtrlBlocks[i].IsTaskPassed = pass
|
||||||
|
taskCtrlBlocks[i].TextAuditTask.TextAudit = textaudit
|
||||||
|
|
||||||
// 3.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态
|
// 3.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态
|
||||||
isActionCompleted, action = handleTaskAction(taskCtrlBlocks[i], actionMap)
|
isActionCompleted, action = handleTaskAction(taskCtrlBlocks[i], actionMap)
|
||||||
|
@ -122,9 +123,9 @@ func handleScanTextResponse(ctrlBlock *TextAuditTaskBatchControlBlock, resp *tex
|
||||||
return
|
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{}
|
ctx := &gin.Context{}
|
||||||
textaudit := &dbstruct.TextAudit{
|
textaudit = &dbstruct.TextAudit{
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
pass, err = copyScanResultInfo(textaudit, result)
|
pass, err = copyScanResultInfo(textaudit, result)
|
||||||
|
@ -223,20 +224,28 @@ func copyScanResultInfo(textaudit *dbstruct.TextAudit, elements *textaudit.ScanT
|
||||||
contexts := parseDetailsContexts(detail.Contexts)
|
contexts := parseDetailsContexts(detail.Contexts)
|
||||||
switch label {
|
switch label {
|
||||||
case Spam:
|
case Spam:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "垃圾内容")
|
||||||
textaudit.SpamLabelDetails = &contexts
|
textaudit.SpamLabelDetails = &contexts
|
||||||
case Politics:
|
case Politics:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "敏感内容")
|
||||||
textaudit.PoliticsLabelDetails = &contexts
|
textaudit.PoliticsLabelDetails = &contexts
|
||||||
case Abuse:
|
case Abuse:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "辱骂内容")
|
||||||
textaudit.AbuseLabelDetails = &contexts
|
textaudit.AbuseLabelDetails = &contexts
|
||||||
case Terrorism:
|
case Terrorism:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "暴恐内容")
|
||||||
textaudit.TerrorismLabelDetails = &contexts
|
textaudit.TerrorismLabelDetails = &contexts
|
||||||
case Porn:
|
case Porn:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "色情内容")
|
||||||
textaudit.PornLabelDetails = &contexts
|
textaudit.PornLabelDetails = &contexts
|
||||||
case Flood:
|
case Flood:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "灌水内容")
|
||||||
textaudit.FloodLabelDetails = &contexts
|
textaudit.FloodLabelDetails = &contexts
|
||||||
case Contraband:
|
case Contraband:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "违禁内容")
|
||||||
textaudit.ContrabandLabelDetails = &contexts
|
textaudit.ContrabandLabelDetails = &contexts
|
||||||
case Ad:
|
case Ad:
|
||||||
|
textaudit.NotPassScenes = append(textaudit.NotPassScenes, "广告内容")
|
||||||
textaudit.AdLabelDetails = &contexts
|
textaudit.AdLabelDetails = &contexts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue