by Robin at 20240403

This commit is contained in:
Leufolium 2024-04-03 04:56:21 +08:00
parent ea6eea1ccf
commit 50f7e16608
7 changed files with 137 additions and 2 deletions

View File

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

View File

@ -2161,6 +2161,9 @@ func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
}
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
}

View File

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

View File

@ -3179,6 +3179,9 @@ func (s *Service) OpCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpCr
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) // 等待复审
err := _DefaultZoneMoment.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)

View File

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

View File

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

View File

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