diff --git a/app/mix/cmd/main.go b/app/mix/cmd/main.go index 8e75e502..d6202ae2 100644 --- a/app/mix/cmd/main.go +++ b/app/mix/cmd/main.go @@ -89,6 +89,7 @@ func main() { service.DefaultImageAuditTaskResultHandler = service.NewImageAuditTaskResultHandler() service.DefaultTextAuditTaskResultHandler = service.NewTextAuditTaskResultHandler() service.DefaultVideoModerationTaskResultHandler = service.NewVideoModerationTaskResultHandler() + service.DefaultNotifBuilderHandler = service.NewNotifBuilderHandler() service.DefaultEsbService = service.NewEsbService() service.DefaultHvyogoService = service.NewHvyogoService(cfg.Hvyogo) err = service.DefaultService.Init(cfg) diff --git a/app/mix/cmd_offline/main.go b/app/mix/cmd_offline/main.go index 9fd50691..8e6c9ff4 100644 --- a/app/mix/cmd_offline/main.go +++ b/app/mix/cmd_offline/main.go @@ -78,6 +78,7 @@ func main() { service.DefaultImageAuditTaskResultHandler = service.NewImageAuditTaskResultHandler() service.DefaultTextAuditTaskResultHandler = service.NewTextAuditTaskResultHandler() service.DefaultVideoModerationTaskResultHandler = service.NewVideoModerationTaskResultHandler() + service.DefaultNotifBuilderHandler = service.NewNotifBuilderHandler() service.DefaultStreamerRecommService = service.NewStreamerRecommService() service.DefaultNotifBcstCenter = service.NewNotifBcstCenter() err = service.DefaultService.Init(cfg) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index bb6e3d83..f260ce6f 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -164,7 +164,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB return } // 写入自动发送消息的标签 - s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_FirstLogin, account.GetMid()) + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_FirstLogin, account) } else if ec != errcode.ErrCodeLoginSrvOk { return } @@ -328,7 +328,7 @@ func (s *Service) ApiUpdatePassword(ctx *gin.Context, req *loginproto.ApiUpdateP } // 4.发送通知 - s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_PswdChanged, login.GetMid()) + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_PswdChanged, login) return } @@ -649,7 +649,7 @@ func (s *Service) ApiCancelAccount(ctx *gin.Context, req *accountproto.ApiCancel } // 发送通知 - s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_AcctCancellationApplied, account.GetMid()) + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_AcctCancellationApplied, account) return @@ -2728,32 +2728,34 @@ func (s *Service) ApiCreateZone(ctx *gin.Context, req *zoneproto.ApiCreateReq) ( req.Zone.Profile = goproto.String(profile) s.CreateZoneTextAudit(ctx, nil, req.Zone) - // 创建默认动态 - cfg := apollostruct.ReferentialZoneMoment{} - err = apollo.GetJson(consts.ReferentialZoneMomentKey, &cfg, apollo.ApolloOpts().SetNamespace("zone")) - if err != nil { - logger.Error("Apollo read failed : %v", err) - return errcode.ErrCodeApolloReadFail - } + go func() { + // 创建默认动态 + cfg := apollostruct.ReferentialZoneMoment{} + err = apollo.GetJson(consts.ReferentialZoneMomentKey, &cfg, apollo.ApolloOpts().SetNamespace("zone")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + } - _, err = _DefaultZoneMoment.OpCreate(ctx, &zonemomentproto.OpCreateReq{ - ZoneMoment: &dbstruct.ZoneMoment{ - Mid: req.Zone.Mid, - Zid: goproto.Int64(zid), - CType: goproto.Int64(consts.ZoneMomentCType_Free), - Text: cfg.Text, - MediaComp: cfg.MediaComp, - MType: cfg.MType, - Status: cfg.Status, - MediaAmount: cfg.MediaAmount, - MediaVisibleRange: cfg.MediaVisibleRange, - }, - }) - if err != nil { - logger.Error("_DefaultZoneMoment OpCreate fail, req: %v, err: %v", util.ToJson(req), err) - ec = errcode.ErrCodeZoneSrvFail - return - } + _, err = _DefaultZoneMoment.OpCreate(ctx, &zonemomentproto.OpCreateReq{ + ZoneMoment: &dbstruct.ZoneMoment{ + Mid: req.Zone.Mid, + Zid: goproto.Int64(zid), + CType: goproto.Int64(consts.ZoneMomentCType_Free), + Text: cfg.Text, + MediaComp: cfg.MediaComp, + MType: cfg.MType, + Status: cfg.Status, + MediaAmount: cfg.MediaAmount, + MediaVisibleRange: cfg.MediaVisibleRange, + }, + }) + if err != nil { + logger.Error("_DefaultZoneMoment OpCreate fail, req: %v, err: %v", util.ToJson(req), err) + return + } + }() + + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_ZoneCreated, req.Zone) return } diff --git a/app/mix/service/notif_builder_handler.go b/app/mix/service/notif_builder_handler.go new file mode 100644 index 00000000..91419815 --- /dev/null +++ b/app/mix/service/notif_builder_handler.go @@ -0,0 +1,85 @@ +package service + +import ( + "service/api/consts" + "service/bizcommon/util" + "service/dbstruct" + + "github.com/gin-gonic/gin" +) + +var DefaultNotifBuilderHandler *NotifBuilderHandler + +type NotifBuilderHandler struct { + // 处理器map + handlerMap map[int64]func(ctx *gin.Context, args ...any) +} + +func (handler *NotifBuilderHandler) Handle(ctx *gin.Context, scene int64, args ...any) { + handler.handlerMap[scene](ctx, args...) +} + +func NewNotifBuilderHandler() *NotifBuilderHandler { + handler := &NotifBuilderHandler{} + handler.init() + return handler +} + +func (handler *NotifBuilderHandler) init() { + handler.handleSysFirstLogin() + handler.handleSysStreamerPunished() + handler.handleSysPswdChanged() + handler.handleSysAcctCancellationApplied() + handler.handleSysStreamerAuthApprovalPassed() + handler.handleSysZoneCreated() +} + +func (handler *NotifBuilderHandler) handleSysFirstLogin() { + handler.handlerMap[consts.SysNotifTemp_FirstLogin] = func(ctx *gin.Context, args ...any) { + account := args[0].(*dbstruct.Account) + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_FirstLogin, account.GetMid()) + } +} + +func (handler *NotifBuilderHandler) handleSysStreamerPunished() { + handler.handlerMap[consts.SysNotifTemp_StreamerPunished] = func(ctx *gin.Context, args ...any) { + acctpunishment := args[0].(*dbstruct.AccountPunishment) + // 封禁通知 + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_StreamerPunished, acctpunishment.GetMid(), + consts.AccountPunishmentMap[acctpunishment.GetType()], util.FormatTsAsNotifT(acctpunishment.GetEndTime())) + // 解禁通知 + if !acctpunishment.IsPermanent() { + DefaultService.utilWriteCrontabNotifInfo(ctx, consts.SysNotifTemp_StreamerPunishmentEnds, acctpunishment.GetMid(), acctpunishment.GetEndTime()) + } + } +} + +func (handler *NotifBuilderHandler) handleSysPswdChanged() { + handler.handlerMap[consts.SysNotifTemp_PswdChanged] = func(ctx *gin.Context, args ...any) { + login := args[0].(*dbstruct.Login) + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_PswdChanged, login.GetMid()) + } +} + +func (handler *NotifBuilderHandler) handleSysAcctCancellationApplied() { + handler.handlerMap[consts.SysNotifTemp_AcctCancellationApplied] = func(ctx *gin.Context, args ...any) { + account := args[0].(*dbstruct.Account) + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_AcctCancellationApplied, account.GetMid()) + } +} + +func (handler *NotifBuilderHandler) handleSysStreamerAuthApprovalPassed() { + handler.handlerMap[consts.SysNotifTemp_AcctCancellationApplied] = func(ctx *gin.Context, args ...any) { + mids := args[0].([]int64) + for _, mid := range mids { + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_StreamerAuthApprovalPassed, mid) + } + } +} + +func (handler *NotifBuilderHandler) handleSysZoneCreated() { + handler.handlerMap[consts.SysNotifTemp_ZoneCreated] = func(ctx *gin.Context, args ...any) { + zone := args[0].(*dbstruct.Zone) + DefaultService.utilWriteNotifInfo(ctx, consts.SysNotifTemp_ZoneCreated, zone.GetMid()) + } +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 14eed503..fc1a691e 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -2313,6 +2313,9 @@ func (s *Service) OpApproveStreamerAuthApprovalDetails(ctx *gin.Context, req *st ec = errcode.ErrCodeAccountSrvFail return } + + // 发送通知 + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_StreamerAuthApprovalPassed, mids) } return @@ -3755,12 +3758,7 @@ func (s *Service) OpCreateAccountPunishment(ctx *gin.Context, req *accountpunish } // 封禁通知 - s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_StreamerPunished, req.AccountPunishment.GetMid(), - consts.AccountPunishmentMap[req.AccountPunishment.GetType()], req.AccountPunishment.GetEndTimeFormatAsChinese()) - // 解禁通知 - if !req.AccountPunishment.IsPermanent() { - s.utilWriteCrontabNotifInfo(ctx, consts.SysNotifTemp_StreamerPunishmentEnds, req.AccountPunishment.GetMid(), req.AccountPunishment.GetEndTime()) - } + DefaultNotifBuilderHandler.Handle(ctx, consts.SysNotifTemp_StreamerPunished, req.AccountPunishment) return } diff --git a/bizcommon/util/util.go b/bizcommon/util/util.go index d8899cbb..bf065cd6 100644 --- a/bizcommon/util/util.go +++ b/bizcommon/util/util.go @@ -373,3 +373,11 @@ func GetLastLessOrEqualForFloat64(arr []float64, target float64) int { return result } + +func FormatTs(timestamp int64, format string) string { + return time.Unix(timestamp, 0).Local().Format(format) +} + +func FormatTsAsNotifT(timestamp int64) string { + return FormatTs(timestamp, "2006年1月2日 15时04分") +} diff --git a/codecreate/codecreate.go b/codecreate/codecreate.go index 42eeaab5..9a7afdc8 100644 --- a/codecreate/codecreate.go +++ b/codecreate/codecreate.go @@ -9,10 +9,10 @@ import ( func main() { genSource := &generator.GenSource{ - EntityName: "Notification", - ModuleName: "notification", - EntityCNName: "系统通知表", - ErrCodeSeq: "46", + EntityName: "FrontendRoute", + ModuleName: "frontend_route", + EntityCNName: "前端页面路由表", + ErrCodeSeq: "47", } generator.CreateFileDirectory(genSource) diff --git a/codecreate/resource/EntityDefine.xlsx b/codecreate/resource/EntityDefine.xlsx index 93b325b2..2f271532 100644 Binary files a/codecreate/resource/EntityDefine.xlsx and b/codecreate/resource/EntityDefine.xlsx differ