From 680cefa72492901a734bf4e6f8a8742fb84cd88d Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 1 Nov 2024 15:35:45 +0800 Subject: [PATCH] 1 --- api/consts/notif_template.go | 24 +++++++++++++ apollostruct/notif_template.go | 8 +++++ app/mix/service/apiservice.go | 2 ++ etc/mix/mix-local.yaml | 2 +- etc/mix/mix-prod-offline.yaml | 2 +- etc/mix/mix-prod.yaml | 2 +- etc/mix/mix-test-offline.yaml | 2 +- etc/mix/mix-test.yaml | 2 +- library/middleware/notif_sender.go | 57 ++++++++++++++++++++++++++++++ 9 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 api/consts/notif_template.go create mode 100644 apollostruct/notif_template.go create mode 100644 library/middleware/notif_sender.go diff --git a/api/consts/notif_template.go b/api/consts/notif_template.go new file mode 100644 index 00000000..fbd7290e --- /dev/null +++ b/api/consts/notif_template.go @@ -0,0 +1,24 @@ +package consts + +// notif_template +const ( + SysNotifTemp_FirstLogin = 0 + SysNotifTemp_StreamerPunished = 1 + SysNotifTemp_StreamerPunishmentEnds = 2 + SysNotifTemp_PswdChanged = 3 + SysNotifTemp_AcctCancellationApplied = 4 + SysNotifTemp_AcctCancelled = 5 + + AudNotifTemp_AvatarChanged = 100 + AudNotifTemp_AvatarRollbacked = 101 + AudNotifTemp_NameChanged = 102 + AudNotifTemp_NameRollbacked = 103 + AudNotifTemp_StreamerBasicInfoApplied = 104 + AudNotifTemp_StreamerBasicInfoRejected = 105 + AudNotifTemp_StreamerDetailsApplied = 106 + AudNotifTemp_StreamerDetailsPassed = 107 + AudNotifTemp_StreamerDetailsRejected = 108 + AudNotifTemp_WithdrawlInfoApplied = 109 + AudNotifTemp_WithdrawlInfoPassed = 110 + AudNotifTemp_WithdrawlInfoRejected = 111 +) diff --git a/apollostruct/notif_template.go b/apollostruct/notif_template.go new file mode 100644 index 00000000..d6037f1f --- /dev/null +++ b/apollostruct/notif_template.go @@ -0,0 +1,8 @@ +package apollostruct + +type NotifTemplateCfg struct { + NotifTemplate string `json:"notif_template"` + NType int64 `json:"n_type"` + LinkTextTemplate string `json:"link_text_template"` + Action string `json:"string"` +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 8f6cf350..cbfd0db2 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1060,6 +1060,8 @@ func (s *Service) ApiCreateStreamerAuthApprovalBasic(ctx *gin.Context, req *stre ec = errcode.ErrCodeStreamerAuthApprovalBasicSrvFail return } + + ctx.Set("notif_template_id", consts.AudNotifTemp_StreamerBasicInfoApplied) return } diff --git a/etc/mix/mix-local.yaml b/etc/mix/mix-local.yaml index 9e175d14..0d63bd14 100644 --- a/etc/mix/mix-local.yaml +++ b/etc/mix/mix-local.yaml @@ -101,7 +101,7 @@ apollo: app_id: "wishpal_live_service" cluster: "dev" ip: "http://localhost:8080" - namespace_name: "application,tag,account_init,platform,support_wx_id,Raven_IQ_test" + namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test,notif_template" secret: "" is_back_up_config: true sync_server_timeout: 2 diff --git a/etc/mix/mix-prod-offline.yaml b/etc/mix/mix-prod-offline.yaml index 690ea82e..57519da9 100644 --- a/etc/mix/mix-prod-offline.yaml +++ b/etc/mix/mix-prod-offline.yaml @@ -103,7 +103,7 @@ apollo: app_id: "wishpal_live_service" cluster: "dev" ip: "http://172.16.0.186:8080" - namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test" + namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test,notif_template" secret: "" is_back_up_config: true sync_server_timeout: 2 diff --git a/etc/mix/mix-prod.yaml b/etc/mix/mix-prod.yaml index edb58270..5910d9f5 100644 --- a/etc/mix/mix-prod.yaml +++ b/etc/mix/mix-prod.yaml @@ -111,7 +111,7 @@ apollo: app_id: "wishpal_live_service" cluster: "dev" ip: "http://172.16.0.186:8080" - namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test" + namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test,notif_template" secret: "" is_back_up_config: true sync_server_timeout: 2 diff --git a/etc/mix/mix-test-offline.yaml b/etc/mix/mix-test-offline.yaml index 4f75cee0..29db97b9 100644 --- a/etc/mix/mix-test-offline.yaml +++ b/etc/mix/mix-test-offline.yaml @@ -97,7 +97,7 @@ apollo: app_id: "wishpal_live_service" cluster: "dev" ip: "http://localhost:8080" - namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test" + namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test,notif_template" secret: "" is_back_up_config: true sync_server_timeout: 2 diff --git a/etc/mix/mix-test.yaml b/etc/mix/mix-test.yaml index 1265d059..7f3d0f80 100644 --- a/etc/mix/mix-test.yaml +++ b/etc/mix/mix-test.yaml @@ -112,7 +112,7 @@ apollo: app_id: "wishpal_live_service" cluster: "dev" ip: "http://172.31.37.71:8080" - namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test" + namespace_name: "application,tag,account_init,platform,support_wx_id,version,zone,Raven_IQ_test,notif_template" secret: "" is_back_up_config: true sync_server_timeout: 2 diff --git a/library/middleware/notif_sender.go b/library/middleware/notif_sender.go new file mode 100644 index 00000000..4e5eaf99 --- /dev/null +++ b/library/middleware/notif_sender.go @@ -0,0 +1,57 @@ +package middleware + +import ( + "service/app/mix/service" + "service/app/mix/service/logic" + "service/dbstruct" + "service/library/logger" + + "service/api/consts" + notificationproto "service/api/proto/notification/proto" + + goproto "google.golang.org/protobuf/proto" + + "github.com/gin-gonic/gin" +) + +var ( + DefaultNotifSender gin.HandlerFunc +) + +func InitNotifSender(_DefaultNotification *logic.Notification, _DefaultNotifBcstCenter service.NotifBcstCenter) { + DefaultNotifSender = func(ctx *gin.Context) { + notifTempId := ctx.MustGet("notif_template_id").(int64) + notifTempParams := ctx.MustGet("notif_template_params").([]string) + + notification := &dbstruct.Notification{} + // 通知接收人mids不为空则默认认为是自定义发送 + if len(notif.ObjMids) > 0 { + notification.ObjType = goproto.Int64(consts.Notification_ObjType_Customized) + } + + notification.SubMid = goproto.Int64(0) + notification.PushTime = goproto.Int64(0) + + err := _DefaultNotification.OpCreate(ctx, ¬ificationproto.OpCreateReq{ + Notification: notification, + }) + if err != nil { + logger.Error("通知创建失败:%v", err) + ctx.Next() + } + + nids := make([]int64, 0) + nids = append(nids, notification.GetId()) + + err = _DefaultNotifBcstCenter.BcstNotifs(ctx, nids, notification.GetObjType(), notification.ObjMids) + if err != nil { + logger.Error("通知广播失败:%v", err) + ctx.Next() + } + ctx.Next() + } +} + +func NotifSender() gin.HandlerFunc { + return DefaultNotifSender +}