From 50f7e166082051c8a935f0f30f01ea576a11487a Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 3 Apr 2024 04:56:21 +0800 Subject: [PATCH] by Robin at 20240403 --- api/consts/option.go | 2 ++ app/mix/service/apiservice.go | 30 ++++++++++++++++++- .../service/imageaudittask_result_handler.go | 25 ++++++++++++++++ app/mix/service/service.go | 5 +++- .../service/textaudittask_result_handler.go | 25 ++++++++++++++++ library/contentaudit/imageaudit/imageaudit.go | 26 ++++++++++++++++ library/contentaudit/textaudit/textaudit.go | 26 ++++++++++++++++ 7 files changed, 137 insertions(+), 2 deletions(-) diff --git a/api/consts/option.go b/api/consts/option.go index dbbd057b..08767131 100644 --- a/api/consts/option.go +++ b/api/consts/option.go @@ -3,11 +3,13 @@ package consts const ( ImageAuditTaskUpdate_Pass = 0 ImageAuditTaskUpdate_Rollback = 1 + ImageAuditTaskUpdate_Success = 2 ) const ( TextAuditTaskUpdate_Pass = 0 TextAuditTaskUpdate_Rollback = 1 + TextAuditTaskUpdate_Success = 2 ) const ( diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index d8d9ca91..87b98efd 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2160,7 +2160,10 @@ func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api return } - req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 默认正在审核中 + req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 默认正在审核中 + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 + req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 + req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 err := _DefaultZoneMoment.OpCreate(ctx, &zonemomentproto.OpCreateReq{ BaseRequest: req.BaseRequest, ZoneMoment: req.ZoneMoment, @@ -2170,11 +2173,29 @@ func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api ec = errcode.ErrCodeZoneMomentSrvFail return } + + // 添加审核任务 + imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment) + textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment) + imageaudit.AddTasks(imageaudittasks) + textaudit.AddTasks(textaudittasks) + return } func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.ApiUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk + + // 抹消所有审核信息,回退到初始 + req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 正在审核中 + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 + req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 + req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 + req.ZoneMoment.ImageAuditOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.TextAuditOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.ManuallyReviewOpinion = goproto.String("") // 信息抹除 + req.ZoneMoment.ManuallyReviewOperator = goproto.Int64(0) // 信息抹除 + err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{ BaseRequest: req.BaseRequest, ZoneMoment: req.ZoneMoment, @@ -2189,6 +2210,13 @@ func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api ec = errcode.ErrCodeZoneMomentSrvFail return } + + // 添加审核任务 + imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment) + textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment) + imageaudit.AddTasks(imageaudittasks) + textaudit.AddTasks(textaudittasks) + return } diff --git a/app/mix/service/imageaudittask_result_handler.go b/app/mix/service/imageaudittask_result_handler.go index ba31c82d..31811991 100644 --- a/app/mix/service/imageaudittask_result_handler.go +++ b/app/mix/service/imageaudittask_result_handler.go @@ -60,6 +60,11 @@ func (handler *ImageAuditTaskResultHandler) getImageAuditTaskUpdateFunc(ctx *gin func (handler *ImageAuditTaskResultHandler) generateAccountAvatarUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["account|account|avatar"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.ImageAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var avatar *dbstruct.MediaComponent if option == consts.ImageAuditTaskUpdate_Pass { @@ -81,6 +86,11 @@ func (handler *ImageAuditTaskResultHandler) generateAccountAvatarUpdateFunc() { func (handler *ImageAuditTaskResultHandler) generateStreamerCoverUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["streamer|streamer|cover"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.ImageAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var cover *dbstruct.MediaComponent if option == consts.ImageAuditTaskUpdate_Pass { @@ -102,6 +112,11 @@ func (handler *ImageAuditTaskResultHandler) generateStreamerCoverUpdateFunc() { func (handler *ImageAuditTaskResultHandler) generateStreamerAlbumUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["streamer|streamer|album"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.ImageAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var album *dbstruct.MediaComponent if option == consts.ImageAuditTaskUpdate_Pass { @@ -123,6 +138,11 @@ func (handler *ImageAuditTaskResultHandler) generateStreamerAlbumUpdateFunc() { func (handler *ImageAuditTaskResultHandler) generateMomentMediaComponentUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["moment|moment|media_component"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.ImageAuditTaskUpdate_Success { + return nil + } + if option == consts.ImageAuditTaskUpdate_Pass { return passMomentImageAuditTask(ctx, task) @@ -137,6 +157,11 @@ func (handler *ImageAuditTaskResultHandler) generateMomentMediaComponentUpdateFu func (handler *ImageAuditTaskResultHandler) generateZoneMomentMediaComponentUpdateFunc() { handler.imageAuditTaskUpdateFuncGeneratorMap["zone_moment|zone_moment|media_comp"] = func(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面,尝试触发完成审核的逻辑 + if option == consts.ImageAuditTaskUpdate_Success { + return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId)) + } + notPassedImageIndexes := make([]string, 0) for i, pass := range task.AuditedMediaResults { if pass { diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 525124dd..0cec093d 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3178,7 +3178,10 @@ func (s *Service) OpGetZoneList(ctx *gin.Context, req *zoneproto.OpListReq) (lis func (s *Service) OpCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk - req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 默认正在审核中 + req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 默认正在审核中 + req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建 + req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建 + req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审 err := _DefaultZoneMoment.OpCreate(ctx, req) if err != nil { logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) diff --git a/app/mix/service/textaudittask_result_handler.go b/app/mix/service/textaudittask_result_handler.go index 44e1c846..e25ac762 100644 --- a/app/mix/service/textaudittask_result_handler.go +++ b/app/mix/service/textaudittask_result_handler.go @@ -59,6 +59,11 @@ func (handler *TextAuditTaskResultHandler) getTextAuditTaskUpdateFunc(ctx *gin.C func (handler *TextAuditTaskResultHandler) generateAccountNameUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["account|account|name"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.TextAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var name *string if option == consts.TextAuditTaskUpdate_Pass { @@ -80,6 +85,11 @@ func (handler *TextAuditTaskResultHandler) generateAccountNameUpdateFunc() { func (handler *TextAuditTaskResultHandler) generateStreamerBioUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["streamer|streamer|bio"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.TextAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var bio *string if option == consts.TextAuditTaskUpdate_Pass { @@ -101,6 +111,11 @@ func (handler *TextAuditTaskResultHandler) generateStreamerBioUpdateFunc() { func (handler *TextAuditTaskResultHandler) generateStreamerAutoResponseMessageUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["streamer|streamer|auto_response_message"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.TextAuditTaskUpdate_Success { + return nil + } + mid := task.AssociativeTableId var autoResponseMessage *string if option == consts.TextAuditTaskUpdate_Pass { @@ -122,6 +137,11 @@ func (handler *TextAuditTaskResultHandler) generateStreamerAutoResponseMessageUp func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["moment|moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面 + if option == consts.TextAuditTaskUpdate_Success { + return nil + } + momentId := task.AssociativeTableId var text *string if option == consts.TextAuditTaskUpdate_Pass { @@ -151,6 +171,11 @@ func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() { func (handler *TextAuditTaskResultHandler) generateZoneMomentTextUpdateFunc() { handler.textAuditTaskUpdateFuncGeneratorMap["zone_moment|zone_moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error { return func() error { + //20240403更新: 增加成功后处理的切面,尝试触发完成审核的逻辑 + if option == consts.TextAuditTaskUpdate_Success { + return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId)) + } + textAuditOpinion := fmt.Sprintf("文字违规") err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{ ZoneMoment: &dbstruct.ZoneMoment{ diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index eb3f5e04..3ad6377a 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -240,6 +240,13 @@ func finalizeTask(action *ImageAuditAction) (err error) { return } + // 终态成功,执行成功后操作 + if action.IsPassed() { + if err = handleSuccess(action.TaskChain[len(action.TaskChain)-1].ImageAuditTask); err != nil { + return + } + } + logger.Info("action statuses : %v", statuses) return @@ -323,6 +330,25 @@ func executeRollBack(lastValidTask *dbstruct.ImageAuditTask) (err error) { return } +func handleSuccess(task *dbstruct.ImageAuditTask) (err error) { + ctx := &gin.Context{} + task.Status = goproto.Int64(consts.ImageAudit_Passed) + if err = _DefaultResultHandler.Handle(ctx, task, consts.ImageAuditTaskUpdate_Success); err != nil { + logger.Error("Handle success taskId:%v fail:%v", util.DerefString(task.Id), err) + if err = _DefaultImageAuditTask.OpUpdate(ctx, &imageaudittaskproto.OpUpdateReq{ + ImageAuditTask: &dbstruct.ImageAuditTask{ + Id: task.Id, + Status: goproto.Int64(consts.ImageAudit_Failed), + Remarks: goproto.String("任务审核成功,执行成功后操作失败,请联系管理员排查"), + }, + }); err != nil { + logger.Error("_DefaultImageAuditTask OpUpdate fail: %v\n", err) + } + return + } + return +} + func updatePassedTasks(passTaskIds []string) (err error) { ctx := &gin.Context{} if err = _DefaultImageAuditTask.OpUpdateByIds(ctx, &imageaudittaskproto.OpUpdateByIdsReq{ diff --git a/library/contentaudit/textaudit/textaudit.go b/library/contentaudit/textaudit/textaudit.go index 813a282b..1e8133db 100644 --- a/library/contentaudit/textaudit/textaudit.go +++ b/library/contentaudit/textaudit/textaudit.go @@ -193,6 +193,13 @@ func finalizeTask(action *TextAuditAction) (err error) { return } + // 终态成功,执行成功后操作 + if action.IsPassed() { + if err = handleSuccess(action.TaskChain[len(action.TaskChain)-1].TextAuditTask); err != nil { + return + } + } + logger.Info("action statuses : %v", statuses) return @@ -274,6 +281,25 @@ func executeRollBack(lastValidTask *dbstruct.TextAuditTask) (err error) { return } +func handleSuccess(task *dbstruct.TextAuditTask) (err error) { + ctx := &gin.Context{} + task.Status = goproto.Int64(consts.TextAudit_Passed) + if err = _DefaultResultHandler.Handle(ctx, task, consts.TextAuditTaskUpdate_Success); err != nil { + logger.Error("Handle success taskId:%v fail:%v", util.DerefString(task.Id), err) + if err = _DefaultTextAuditTask.OpUpdate(ctx, &textaudittaskproto.OpUpdateReq{ + TextAuditTask: &dbstruct.TextAuditTask{ + Id: task.Id, + Status: goproto.Int64(consts.TextAudit_Failed), + Remarks: goproto.String("任务审核成功,执行成功后操作失败,请联系管理员排查"), + }, + }); err != nil { + logger.Error("_DefaultTextAuditTask OpUpdate fail: %v\n", err) + } + return + } + return +} + func updatePassedTasks(passTaskIds []string) (err error) { ctx := &gin.Context{} if err = _DefaultTextAuditTask.OpUpdateByIds(ctx, &textaudittaskproto.OpUpdateByIdsReq{