227 lines
7.1 KiB
Go
227 lines
7.1 KiB
Go
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"
|
||
zonemomentproto "service/api/proto/zonemoment/proto"
|
||
"service/bizcommon/util"
|
||
"service/dbstruct"
|
||
"strings"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
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()
|
||
}
|
||
|
||
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 _DefaultAccount.OpUpdateStreamerAcctName(ctx, util.DerefInt64(mid), util.DerefString(name))
|
||
}
|
||
|
||
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 {
|
||
//20240403更新: 增加成功后处理的切面
|
||
if option == consts.TextAuditTaskUpdate_Success {
|
||
return nil
|
||
}
|
||
|
||
mid := task.AssociativeTableId
|
||
var bio *string
|
||
if option == consts.TextAuditTaskUpdate_Pass {
|
||
bio = task.AuditedText
|
||
} else {
|
||
bio = task.OldText
|
||
}
|
||
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
||
Streamer: &dbstruct.Streamer{
|
||
Mid: mid,
|
||
Bio: bio,
|
||
},
|
||
})
|
||
}
|
||
}
|
||
}
|
||
|
||
// 主播表->自动回复消息
|
||
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 {
|
||
autoResponseMessage = task.AuditedText
|
||
} else {
|
||
autoResponseMessage = task.OldText
|
||
}
|
||
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
||
Streamer: &dbstruct.Streamer{
|
||
Mid: mid,
|
||
AutoResponseMessage: autoResponseMessage,
|
||
},
|
||
})
|
||
}
|
||
}
|
||
}
|
||
|
||
// 动态表->文字内容,若不通过,则将文字设置为默认文字,并修改动态审核表状态
|
||
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 {
|
||
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 nil
|
||
}
|
||
}
|
||
}
|
||
|
||
// 私密动态表->文字内容,若不通过,则写入不通过的原因
|
||
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))
|
||
}
|
||
}
|
||
}
|