service/app/mix/service/textaudittask_result_handle...

399 lines
14 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"fmt"
"service/api/consts"
accountproto "service/api/proto/account/proto"
momentproto "service/api/proto/moment/proto"
streamerproto "service/api/proto/streamer/proto"
streamerauthapprovaldetailsproto "service/api/proto/streamerauthapprovaldetails/proto"
zoneproto "service/api/proto/zone/proto"
zonemomentproto "service/api/proto/zonemoment/proto"
"service/bizcommon/util"
"service/dbstruct"
"strings"
"github.com/gin-gonic/gin"
"github.com/mozillazg/go-pinyin"
goproto "google.golang.org/protobuf/proto"
)
var DefaultTextAuditTaskResultHandler *TextAuditTaskResultHandler
type TextAuditTaskResultHandler struct {
// 图像审核任务通过及回退方法生成器map
textAuditTaskUpdateFuncGeneratorMap map[string](func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error)
}
func NewTextAuditTaskResultHandler() *TextAuditTaskResultHandler {
handler := &TextAuditTaskResultHandler{}
handler.initTextAuditTaskUpdateFuncGeneratorMap()
return handler
}
func (handler *TextAuditTaskResultHandler) Handle(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) error {
return handler.getTextAuditTaskUpdateFunc(ctx, task, option)()
}
func (handler *TextAuditTaskResultHandler) initTextAuditTaskUpdateFuncGeneratorMap() {
handler.textAuditTaskUpdateFuncGeneratorMap = make(map[string]func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error)
handler.generateAccountNameUpdateFunc()
handler.generateStreamerBioUpdateFunc()
handler.generateStreamerAutoResponseMessageUpdateFunc()
handler.generateMomentTextUpdateFunc()
handler.generateZoneMomentTextUpdateFunc()
handler.generateStreamerAuthApprovalDetailsBioUpdateFunc()
handler.generateStreamerAuthApprovalDetailsAutoResponseMessageUpdateFunc()
handler.generateZoneProfileUpdateFunc()
}
func (handler *TextAuditTaskResultHandler) getTextAuditTaskUpdateFunc(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
db := util.DerefString(task.AssociativeDatabase)
table := util.DerefString(task.AssociativeTableName)
column := util.DerefString(task.AssociativeTableColumn)
key := fmt.Sprintf("%v|%v|%v", db, table, column)
updateFuncGenerator := handler.textAuditTaskUpdateFuncGeneratorMap[key]
updateFunc := updateFuncGenerator(ctx, task, option)
return updateFunc
}
// 用户表->姓名
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 {
name = task.AuditedText
} else {
name = task.OldText
}
err := _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
Account: &dbstruct.Account{
Mid: mid,
Name: name,
},
})
if err != nil {
return err
}
acct, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: mid,
})
if err != nil {
return err
}
if acct.GetRole() == consts.Streamer {
return _DefaultStreamerAcct.OpUpdate(ctx, &dbstruct.EsStreamerAcct{
Mid: util.DerefInt64(mid),
Name: util.DerefString(name),
PinYin: strings.Join(pinyin.LazyConvert(util.DerefString(name), nil), ""),
})
}
return nil
}
}
}
// 主播表->个性签名
func (handler *TextAuditTaskResultHandler) generateStreamerBioUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["streamer|streamer|bio"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error {
mid := task.AssociativeTableId
auditcomp, reviewcomp, finalText := getTextUpdateInfo(task, option)
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
Streamer: &dbstruct.Streamer{
Mid: mid,
Bio: finalText,
BioAudit: auditcomp,
BioReview: reviewcomp,
},
})
}
}
}
// 主播表->自动回复消息
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 {
mid := task.AssociativeTableId
auditcomp, reviewcomp, finalText := getTextUpdateInfo(task, option)
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
Streamer: &dbstruct.Streamer{
Mid: mid,
AutoResponseMessage: finalText,
AutoResponseMessageAudit: auditcomp,
AutoResponseMessageReview: reviewcomp,
},
})
}
}
}
// 动态表->文字内容,若不通过,则将文字设置为默认文字,并修改动态审核表状态
func (handler *TextAuditTaskResultHandler) generateMomentTextUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["moment|moment|text"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error {
// 20240703同步动态审核表触发人审的逻辑改到handler实现
// moment_audit_task有text_audit_task_id的索引以该索引作为更新依据
// text_audit_task有associative_table_id的内容以该id去触发moment的更新
// 通过逻辑只做恢复,不包含任何触发人审的操作
//20240403更新: 增加成功后处理的切面
if option == consts.TextAuditTaskUpdate_Success {
return tryToFinishTextAuditTaskOfMoment(ctx, task)
}
momentId := task.AssociativeTableId
var text *string
if option == consts.TextAuditTaskUpdate_Pass {
text = task.AuditedText
} else {
text = task.OldText
}
if err := _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{
Id: momentId,
Text: text,
},
}); err != nil {
return err
}
if err := _DefaultMomentAuditTask.OpUpdateByTextAuditTaskIds(ctx, &dbstruct.MomentAuditTask{
FinalText: text,
}, []string{util.DerefString(task.Id)}); err != nil {
return err
}
return tryToFinishTextAuditTaskOfMoment(ctx, task)
}
}
}
// 私密动态表->文字内容,若不通过,则写入不通过的原因
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 {
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
ZoneMoment: &dbstruct.ZoneMoment{
Id: task.AssociativeTableId,
TextAuditStatus: goproto.Int64(consts.TextAudit_Passed),
},
})
if err != nil {
return err
}
return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId))
}
var textAuditOpinion string
if util.DerefInt64(task.Status) == consts.TextAudit_ServiceFailed {
textAuditOpinion = "机审失败"
} else {
textAuditOpinion = fmt.Sprintf("%s", strings.Join(task.TextAudit.NotPassScenes, ","))
}
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
ZoneMoment: &dbstruct.ZoneMoment{
Id: task.AssociativeTableId,
TextAuditStatus: task.Status,
TextAuditOpinion: goproto.String(textAuditOpinion),
},
})
if err != nil {
return err
}
return _DefaultZoneMoment.TryToCompleteAudit(ctx, util.DerefInt64(task.AssociativeTableId))
}
}
}
// 空间表->简介
func (handler *TextAuditTaskResultHandler) generateZoneProfileUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["zone|zone|profile"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error {
id := task.AssociativeTableId
auditcomp, reviewcomp, finalText := getTextUpdateInfo(task, option)
return _DefaultZone.OpUpdate(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: id,
Profile: finalText,
ProfileAudit: auditcomp,
ProfileReview: reviewcomp,
},
})
}
}
}
// 尝试完成审核
func tryToFinishTextAuditTaskOfMoment(ctx *gin.Context, task *dbstruct.TextAuditTask) error {
// 机审通过尝试触发moment_audit_task的人审
isFinished, err := _DefaultMomentAuditTask.TryToFinishTextAuditTask(ctx, task, "")
if err != nil {
return err
}
if isFinished { // 机审完成通知moment表机审已完成
err = _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{
Id: task.AssociativeTableId,
Status: goproto.Int64(consts.Moment_ManuallyReviewing),
},
})
if err != nil {
return err
}
}
return nil
}
// 主播表->个性签名
func (handler *TextAuditTaskResultHandler) generateStreamerAuthApprovalDetailsBioUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["streamer_auth_approval_details|streamer_auth_approval_details|bio"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error {
// 成功后切面
if option == consts.TextAuditTaskUpdate_Success {
err := _DefaultStreamerAuthApprovalDetails.OpUpdate(ctx, &streamerauthapprovaldetailsproto.OpUpdateReq{
StreamerAuthApprovalDetails: &dbstruct.StreamerAuthApprovalDetails{
Id: task.AssociativeTableId,
BioAudit: &dbstruct.AuditComponent{
AuditStatus: goproto.Int64(consts.TextAudit_Passed),
AuditOpinion: goproto.String("机审通过"),
},
},
})
if err != nil {
return err
}
return _DefaultStreamerAuthApprovalDetails.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
}
// 非成功后切面
var textAuditOpinion string
if task.GetStatus() == consts.TextAudit_ServiceFailed {
textAuditOpinion = "机审失败"
} else {
textAuditOpinion = fmt.Sprintf("%s", strings.Join(task.TextAudit.NotPassScenes, ","))
}
err := _DefaultStreamerAuthApprovalDetails.OpUpdate(ctx, &streamerauthapprovaldetailsproto.OpUpdateReq{
StreamerAuthApprovalDetails: &dbstruct.StreamerAuthApprovalDetails{
Id: task.AssociativeTableId,
BioAudit: &dbstruct.AuditComponent{
AuditStatus: task.Status,
AuditOpinion: goproto.String(textAuditOpinion),
},
},
})
if err != nil {
return err
}
return _DefaultStreamerAuthApprovalDetails.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
}
}
}
// 主播表->个性签名
func (handler *TextAuditTaskResultHandler) generateStreamerAuthApprovalDetailsAutoResponseMessageUpdateFunc() {
handler.textAuditTaskUpdateFuncGeneratorMap["streamer_auth_approval_details|streamer_auth_approval_details|auto_response_message"] = func(ctx *gin.Context, task *dbstruct.TextAuditTask, option int) func() error {
return func() error {
// 成功后切面
if option == consts.TextAuditTaskUpdate_Success {
err := _DefaultStreamerAuthApprovalDetails.OpUpdate(ctx, &streamerauthapprovaldetailsproto.OpUpdateReq{
StreamerAuthApprovalDetails: &dbstruct.StreamerAuthApprovalDetails{
Id: task.AssociativeTableId,
AutoResponseMessageAudit: &dbstruct.AuditComponent{
AuditStatus: goproto.Int64(consts.TextAudit_Passed),
AuditOpinion: goproto.String("机审通过"),
},
},
})
if err != nil {
return err
}
return _DefaultStreamerAuthApprovalDetails.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
}
// 非成功后切面
var textAuditOpinion string
if task.GetStatus() == consts.TextAudit_ServiceFailed {
textAuditOpinion = "机审失败"
} else {
textAuditOpinion = fmt.Sprintf("%s", strings.Join(task.TextAudit.NotPassScenes, ","))
}
err := _DefaultStreamerAuthApprovalDetails.OpUpdate(ctx, &streamerauthapprovaldetailsproto.OpUpdateReq{
StreamerAuthApprovalDetails: &dbstruct.StreamerAuthApprovalDetails{
Id: task.AssociativeTableId,
AutoResponseMessageAudit: &dbstruct.AuditComponent{
AuditStatus: task.Status,
AuditOpinion: goproto.String(textAuditOpinion),
},
},
})
if err != nil {
return err
}
return _DefaultStreamerAuthApprovalDetails.TryToCompleteAudit(ctx, task.GetAssociativeTableId())
}
}
}
func getTextUpdateInfo(task *dbstruct.TextAuditTask, option int) (auditcomp *dbstruct.AuditComponent, reviewcomp *dbstruct.AuditComponent, finalText *string) {
// 机审成功后切面
if option == consts.TextAuditTaskUpdate_Success {
auditcomp = &dbstruct.AuditComponent{}
auditcomp.AuditStatus = goproto.Int64(consts.TextAudit_Passed)
auditcomp.AuditOpinion = goproto.String("机审通过")
}
// 机审失败后切面将机审信息写入streamer表
if option == consts.TextAuditTaskUpdate_Rollback {
auditcomp = &dbstruct.AuditComponent{}
var textAuditOpinion string
if task.GetStatus() == consts.TextAudit_ServiceFailed {
textAuditOpinion = "机审失败"
} else {
textAuditOpinion = fmt.Sprintf("%s", strings.Join(task.TextAudit.NotPassScenes, ","))
}
auditcomp.AuditStatus = task.Status
auditcomp.AuditOpinion = goproto.String(textAuditOpinion)
}
// 人审通过后切面,执行更新
if option == consts.TextAuditTaskUpdate_Pass {
reviewcomp = &dbstruct.AuditComponent{}
reviewcomp.AuditStatus = goproto.Int64(consts.TextManuallyReview_Passed)
reviewcomp.AuditOpinion = task.Remarks
finalText = task.AuditedText
}
// 人审拒绝后切面
if option == consts.TextAuditTaskUpdate_Reject {
reviewcomp = &dbstruct.AuditComponent{}
reviewcomp.AuditStatus = goproto.Int64(consts.TextManuallyReview_Rejected)
reviewcomp.AuditOpinion = task.Remarks
}
return
}