by Robin at 20241106

This commit is contained in:
Leufolium 2024-11-06 15:58:37 +08:00
parent 5954bea877
commit 31d9260a5a
8 changed files with 133 additions and 38 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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
}

View File

@ -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())
}
}

View File

@ -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
}

View File

@ -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分")
}

View File

@ -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)