58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
|
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
|
||
|
}
|