141 lines
4.4 KiB
Go
141 lines
4.4 KiB
Go
package service
|
|
|
|
import (
|
|
accountproto "service/api/proto/account/proto"
|
|
streamerproto "service/api/proto/streamer/proto"
|
|
"service/app/mix/dao"
|
|
"service/bizcommon/util"
|
|
"service/dbstruct"
|
|
"service/library/contentaudit/textaudit"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (s *Service) CreateUpdateAccountTextAudit(ctx *gin.Context, oldAccount *dbstruct.Account, newAccount *dbstruct.Account) (task *textaudit.TextAuditTaskControlBlock) {
|
|
if newAccount.Name == nil {
|
|
return
|
|
}
|
|
|
|
rollBackFunc := func() error {
|
|
return _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
|
|
Account: &dbstruct.Account{
|
|
Mid: oldAccount.Mid,
|
|
Name: oldAccount.Name,
|
|
},
|
|
})
|
|
}
|
|
|
|
task = textaudit.NewTextAuditTaskControlBlock(&dbstruct.TextAuditTask{
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("account"),
|
|
AssociativeTableName: goproto.String("account"),
|
|
AssociativeTableId: newAccount.Mid,
|
|
AssociativeTableColumn: goproto.String("name"),
|
|
AuditedText: newAccount.Name,
|
|
OldText: oldAccount.Name,
|
|
}, rollBackFunc)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateUpdateStreamerTextAudit(ctx *gin.Context, oldStreamer *dbstruct.Streamer, newStreamer *dbstruct.Streamer) (tasks []*textaudit.TextAuditTaskControlBlock) {
|
|
tasks = make([]*textaudit.TextAuditTaskControlBlock, 0)
|
|
|
|
if newStreamer.Bio != nil {
|
|
rollBackFunc := func() error {
|
|
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
|
Streamer: &dbstruct.Streamer{
|
|
Mid: oldStreamer.Mid,
|
|
Bio: oldStreamer.Bio,
|
|
},
|
|
})
|
|
}
|
|
|
|
tasks = append(tasks, textaudit.NewTextAuditTaskControlBlock(&dbstruct.TextAuditTask{
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("streamer"),
|
|
AssociativeTableName: goproto.String("streamer"),
|
|
AssociativeTableId: oldStreamer.Mid,
|
|
AssociativeTableColumn: goproto.String("bio"),
|
|
AuditedText: newStreamer.Bio,
|
|
OldText: oldStreamer.Bio,
|
|
}, rollBackFunc))
|
|
}
|
|
|
|
if newStreamer.AutoResponseMessage != nil {
|
|
rollBackFunc := func() error {
|
|
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
|
Streamer: &dbstruct.Streamer{
|
|
Mid: oldStreamer.Mid,
|
|
AutoResponseMessage: oldStreamer.AutoResponseMessage,
|
|
},
|
|
})
|
|
}
|
|
|
|
tasks = append(tasks, textaudit.NewTextAuditTaskControlBlock(&dbstruct.TextAuditTask{
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("streamer"),
|
|
AssociativeTableName: goproto.String("streamer"),
|
|
AssociativeTableId: oldStreamer.Mid,
|
|
AssociativeTableColumn: goproto.String("auto_response_message"),
|
|
AuditedText: newStreamer.AutoResponseMessage,
|
|
OldText: oldStreamer.AutoResponseMessage,
|
|
}, rollBackFunc))
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) GetUpdateTextFunc(ctx *gin.Context, task *dbstruct.TextAuditTask) func() error {
|
|
db := util.DerefString(task.AssociativeDatabase)
|
|
table := util.DerefString(task.AssociativeTableName)
|
|
column := util.DerefString(task.AssociativeTableColumn)
|
|
|
|
if db == dao.DBAccount && table == dao.DBAccount {
|
|
return s.GetAccountUpdateTextFunc(ctx, column, task.AuditedText, task.AssociativeTableId)
|
|
}
|
|
if db == dao.DBStreamer && table == dao.DBStreamer {
|
|
return s.GetStreamerUpdateTextFunc(ctx, column, task.AuditedText, task.AssociativeTableId)
|
|
}
|
|
return func() error { return nil }
|
|
}
|
|
|
|
func (s *Service) GetAccountUpdateTextFunc(ctx *gin.Context, column string, text *string, id *int64) func() error {
|
|
if column == "name" {
|
|
return func() error {
|
|
return _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
|
|
Account: &dbstruct.Account{
|
|
Mid: id,
|
|
Name: text,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
return func() error { return nil }
|
|
}
|
|
|
|
func (s *Service) GetStreamerUpdateTextFunc(ctx *gin.Context, column string, text *string, id *int64) func() error {
|
|
switch column {
|
|
case "bio":
|
|
return func() error {
|
|
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
|
Streamer: &dbstruct.Streamer{
|
|
Mid: id,
|
|
Bio: text,
|
|
},
|
|
})
|
|
}
|
|
case "auto_response_message":
|
|
return func() error {
|
|
return _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
|
|
Streamer: &dbstruct.Streamer{
|
|
Mid: id,
|
|
AutoResponseMessage: text,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
return func() error { return nil }
|
|
}
|