247 lines
7.9 KiB
Go
247 lines
7.9 KiB
Go
package service
|
|
|
|
import (
|
|
"service/api/consts"
|
|
"service/dbstruct"
|
|
"service/library/logger"
|
|
|
|
textauditproto "service/api/proto/textaudit/proto"
|
|
textaudittaskproto "service/api/proto/textaudittask/proto"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (s *Service) CreateUpdateAccountTextAudit(ctx *gin.Context, oldAccount *dbstruct.Account, newAccount *dbstruct.Account) (tasks []*dbstruct.TextAuditTask) {
|
|
tasks = make([]*dbstruct.TextAuditTask, 0)
|
|
|
|
if newAccount.Name == nil {
|
|
return
|
|
}
|
|
if oldAccount.GetName() == newAccount.GetName() {
|
|
return
|
|
}
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: newAccount.Mid,
|
|
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,
|
|
})
|
|
|
|
addTextAuditTasks(ctx, tasks)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateUpdateStreamerTextAudit(ctx *gin.Context, oldStreamer *dbstruct.Streamer, newStreamer *dbstruct.Streamer) (tasks []*dbstruct.TextAuditTask) {
|
|
tasks = make([]*dbstruct.TextAuditTask, 0)
|
|
|
|
if newStreamer.Bio != nil && oldStreamer.GetBio() != newStreamer.GetBio() {
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: oldStreamer.Mid,
|
|
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,
|
|
})
|
|
}
|
|
|
|
if newStreamer.AutoResponseMessage != nil && oldStreamer.GetAutoResponseMessage() != newStreamer.GetAutoResponseMessage() {
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: oldStreamer.Mid,
|
|
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,
|
|
})
|
|
}
|
|
|
|
addTextAuditTasks(ctx, tasks, true)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateMomentTextAudit(ctx *gin.Context, oldMoment *dbstruct.Moment, newMoment *dbstruct.Moment) (tasks []*dbstruct.TextAuditTask) {
|
|
|
|
if newMoment.Text != nil {
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: newMoment.Mid,
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("moment"),
|
|
AssociativeTableName: goproto.String("moment"),
|
|
AssociativeTableId: newMoment.Id,
|
|
AssociativeTableColumn: goproto.String("text"),
|
|
AuditedText: newMoment.Text,
|
|
OldText: oldMoment.Text,
|
|
IsAligned: goproto.Int64(consts.TextAuditIsAligned_Yes),
|
|
})
|
|
}
|
|
|
|
addTextAuditTasks(ctx, tasks)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateZoneMomentTextAudit(ctx *gin.Context, newZoneMoment *dbstruct.ZoneMoment) (tasks []*dbstruct.TextAuditTask) {
|
|
|
|
if newZoneMoment.Text != nil {
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: newZoneMoment.Mid,
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("zone_moment"),
|
|
AssociativeTableName: goproto.String("zone_moment"),
|
|
AssociativeTableId: newZoneMoment.Id,
|
|
AssociativeTableColumn: goproto.String("text"),
|
|
AuditedText: newZoneMoment.Text,
|
|
IsAligned: goproto.Int64(consts.TextAuditIsAligned_Yes),
|
|
})
|
|
}
|
|
|
|
addTextAuditTasks(ctx, tasks)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateStreamerAuthApprovalDetailsTextAudit(ctx *gin.Context, newStreamerAuthApprovalDetails *dbstruct.StreamerAuthApprovalDetails) (tasks []*dbstruct.TextAuditTask) {
|
|
tasks = make([]*dbstruct.TextAuditTask, 0)
|
|
|
|
if newStreamerAuthApprovalDetails.Bio != nil {
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: newStreamerAuthApprovalDetails.Mid,
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("streamer_auth_approval_details"),
|
|
AssociativeTableName: goproto.String("streamer_auth_approval_details"),
|
|
AssociativeTableId: newStreamerAuthApprovalDetails.Id,
|
|
AssociativeTableColumn: goproto.String("bio"),
|
|
AuditedText: newStreamerAuthApprovalDetails.Bio,
|
|
OldText: goproto.String(""),
|
|
})
|
|
}
|
|
|
|
if newStreamerAuthApprovalDetails.AutoResponseMessage != nil {
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: newStreamerAuthApprovalDetails.Mid,
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("streamer_auth_approval_details"),
|
|
AssociativeTableName: goproto.String("streamer_auth_approval_details"),
|
|
AssociativeTableId: newStreamerAuthApprovalDetails.Id,
|
|
AssociativeTableColumn: goproto.String("auto_response_message"),
|
|
AuditedText: newStreamerAuthApprovalDetails.AutoResponseMessage,
|
|
OldText: goproto.String(""),
|
|
})
|
|
}
|
|
|
|
addTextAuditTasks(ctx, tasks)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) CreateZoneTextAudit(ctx *gin.Context, oldZone *dbstruct.Zone, newZone *dbstruct.Zone) (tasks []*dbstruct.TextAuditTask) {
|
|
tasks = make([]*dbstruct.TextAuditTask, 0)
|
|
|
|
midp := newZone.Mid
|
|
|
|
if newZone.Profile != nil {
|
|
|
|
oldTextPtr := goproto.String("")
|
|
if oldZone != nil {
|
|
oldTextPtr = oldZone.Profile
|
|
midp = oldZone.Mid
|
|
}
|
|
|
|
tasks = append(tasks, &dbstruct.TextAuditTask{
|
|
Mid: midp,
|
|
RouteUrl: goproto.String(ctx.Request.URL.Path),
|
|
AssociativeDatabase: goproto.String("zone"),
|
|
AssociativeTableName: goproto.String("zone"),
|
|
AssociativeTableId: newZone.Id,
|
|
AssociativeTableColumn: goproto.String("profile"),
|
|
AuditedText: newZone.Profile,
|
|
OldText: oldTextPtr,
|
|
})
|
|
}
|
|
|
|
addTextAuditTasks(ctx, tasks, true)
|
|
|
|
return
|
|
}
|
|
|
|
func addTextAuditTasks(ctx *gin.Context, tasks []*dbstruct.TextAuditTask, options ...any) error {
|
|
for _, task := range tasks {
|
|
err := addTextAuditTask(ctx, task, options...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func addTextAuditTask(ctx *gin.Context, task *dbstruct.TextAuditTask, options ...any) error {
|
|
if task == nil || task.AuditedText == nil {
|
|
return nil
|
|
}
|
|
|
|
batchId, err := _DefaultContentAuditRTI.GetTextAuditBatchId(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
task.BatchId = goproto.String(batchId)
|
|
task.Status = goproto.Int64(consts.TextAudit_Created)
|
|
|
|
// 1.写入文字审核表
|
|
textAudit := &dbstruct.TextAudit{
|
|
AuditedText: task.AuditedText,
|
|
BatchId: task.BatchId,
|
|
Status: goproto.Int64(consts.TextAudit_Created),
|
|
}
|
|
if err := _DefaultTextAudit.OpCreate(ctx, &textauditproto.OpCreateReq{
|
|
TextAudit: textAudit,
|
|
}); err != nil {
|
|
logger.Error("Textaudit OpCreate failed: %v", err)
|
|
return err
|
|
}
|
|
|
|
task.TextAuditId = textAudit.Id
|
|
|
|
var (
|
|
isDistinct = false
|
|
)
|
|
if len(options) > 0 {
|
|
isDistinct = options[0].(bool)
|
|
}
|
|
|
|
if isDistinct {
|
|
// 将对待处理对象所有未完成的处理全部置为失效
|
|
ovderduedStatuses := []int64{consts.TextAudit_Created, consts.TextAudit_Passed, consts.TextAudit_Rejected, consts.TextAudit_Rollbacked, consts.TextAudit_ServiceFailed}
|
|
if err := _DefaultTextAuditTask.OpHandleOverdue(ctx, task, "", ovderduedStatuses); err != nil {
|
|
logger.Error("Textaudittask OpHandleOverdue failed: %v", err)
|
|
return err
|
|
}
|
|
}
|
|
|
|
// 2.写入文字审核任务表
|
|
if err := _DefaultTextAuditTask.OpCreate(&gin.Context{}, &textaudittaskproto.OpCreateReq{
|
|
TextAuditTask: task,
|
|
}); err != nil {
|
|
logger.Error("Textaudittask OpCreate failed: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|