by Robin at 20241203

This commit is contained in:
Robin 2024-12-03 14:52:07 +08:00
parent 89e840ec75
commit 495980a255
8 changed files with 65 additions and 99 deletions

View File

@ -127,3 +127,8 @@ const (
const (
Notification_PushTime_Instant = 0 // 即时推送
)
const (
FrontendRouteAction_Inward = "inward"
FrontendRouteAction_Outward = "outward"
)

View File

@ -8,7 +8,6 @@ func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) {
params = append(params, validator.NewInt64PtrParam("请确认前端路由表id", p.FrontendRoute.Id))
params = append(params, validator.NewStringPtrParam("请确认APP前端路由表路径", p.FrontendRoute.AppRoutePath))
params = append(params, validator.NewStringPtrParam("请确认H5前端路由表路径", p.FrontendRoute.H5RoutePath))
params = append(params, validator.NewStringPtrParam("请确认前端路由表跳转类型!", p.FrontendRoute.Action))
params = append(params, validator.NewStringPtrParam("请确认前端路由表描述!", p.FrontendRoute.Desc))
return

View File

@ -5,4 +5,5 @@ type NotifTemplateCfg struct {
NotifTemplate string `json:"notif_template"`
NType int64 `json:"n_type"`
LinkTextTemplate string `json:"link_text_template"`
FrontendRouteId int64 `json:"frontend_route_id"`
}

View File

@ -229,24 +229,6 @@ func (handler *NotifBuilderHandler) handleSysZoneCreated() {
handler.handlerMap[consts.SysNotifTemp_ZoneCreated] = func(ctx *gin.Context, args ...any) {
zone := args[0].(*dbstruct.Zone)
// 获取跳转路径
frontendroute, err := _DefaultFrontendRoute.GetById(ctx, consts.FrontendRouteId_Zone)
if err != nil {
logger.Error("_DefaultFrontendRoute GetById fail, err: %v", err)
}
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.AppRoutePath,
})
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.H5RoutePath,
})
// 获取缩略图
preview, err := DefaultService.utilGetZonePreviews(ctx, zone.GetId())
if err != nil {
@ -254,8 +236,8 @@ func (handler *NotifBuilderHandler) handleSysZoneCreated() {
}
argsMap := make(map[string]any)
argsMap["hyperlinks"] = hyperlinks
argsMap["thumbnail"] = preview
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
DefaultService.utilWriteNotifInfoByMap(ctx, consts.SysNotifTemp_ZoneCreated, zone.GetMid(), argsMap)
}
@ -539,24 +521,6 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentRejected() {
return
}
// 获取跳转路径
frontendroute, err := _DefaultFrontendRoute.GetById(ctx, consts.FrontendRouteId_ZoneMomentEdit)
if err != nil {
logger.Error("_DefaultFrontendRoute GetById fail, err: %v", err)
}
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.AppRoutePath,
})
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.H5RoutePath,
})
// 获取缩略图
preview := &dbstruct.MediaComponent{}
if zonemoment.GetMType() == consts.MediaTypeImg { // 取首图
@ -574,8 +538,8 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentRejected() {
mTypeDesc := consts.MTypeDescMap[zonemoment.GetMType()]
argsMap := make(map[string]any)
argsMap["template_params"] = []any{ctStr, cTypeDesc, mTypeDesc, remarks}
argsMap["hyperlinks"] = hyperlinks
argsMap["thumbnail"] = preview
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
DefaultService.utilWriteNotifInfoByMap(ctx, consts.AudNotifTemp_ZoneMomentRejected, zonemoment.GetMid(), argsMap)
}
@ -611,24 +575,6 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentReeditionRejected() {
return
}
// 获取跳转路径
frontendroute, err := _DefaultFrontendRoute.GetById(ctx, consts.FrontendRouteId_ZoneMomentEdit)
if err != nil {
logger.Error("_DefaultFrontendRoute GetById fail, err: %v", err)
}
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.AppRoutePath,
})
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.H5RoutePath,
})
// 获取缩略图
preview := &dbstruct.MediaComponent{}
if zonemoment.GetMType() == consts.MediaTypeImg { // 取首图
@ -646,8 +592,8 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentReeditionRejected() {
mTypeDesc := consts.MTypeDescMap[zonemoment.GetMType()]
argsMap := make(map[string]any)
argsMap["template_params"] = []any{ctStr, cTypeDesc, mTypeDesc, remarks}
argsMap["hyperlinks"] = hyperlinks
argsMap["thumbnail"] = preview
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
DefaultService.utilWriteNotifInfoByMap(ctx, consts.AudNotifTemp_ZoneMomentReeditionRejected, zonemoment.GetMid(), argsMap)
}
@ -692,28 +638,10 @@ func (handler *NotifBuilderHandler) handleVasZoneSuperfanshipPurchased_User() {
order := args[0].(*dbstruct.Order)
streamer, _ := _DefaultStreamer.OpListByMid(ctx, &streamerproto.OpListByMidReq{Mid: goproto.Int64(order.GetUid())})
// 获取跳转路径
frontendroute, err := _DefaultFrontendRoute.GetById(ctx, consts.FrontendRouteId_Zone)
if err != nil {
logger.Error("_DefaultFrontendRoute GetById fail, err: %v", err)
}
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.AppRoutePath,
})
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: frontendroute.Action,
Params: frontendroute.H5RoutePath,
})
argsMap := make(map[string]any)
argsMap["template_params"] = util.FormatTsAsNotifT(order.GetSuperfanshipUntil())
argsMap["hyperlinks"] = hyperlinks
argsMap["thumbnail"] = streamer.Album
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
DefaultService.utilWriteNotifInfoByMap(ctx, consts.VasNotifTemp_ZoneSuperfanshipPurchased_User, order.GetMid(), argsMap)
}

View File

@ -2282,6 +2282,11 @@ func (s *Service) utilWriteNotifInfoByMap(ctx *gin.Context, notifTempId int64, o
notifBuilder.SetNid = setNidObj.(func(ctx *gin.Context, nid int64) error)
}
buildHyperLink, ok := mp["build_hyperlink"]
if ok {
notifBuilder.BuildHyperLink = buildHyperLink.(func(ctx *gin.Context, frontendRouteId int64) ([]*dbstruct.NotifHyperlink, error))
}
notifBuilders = append(notifBuilders, notifBuilder)
ctx.Set("notif_builders", notifBuilders)
}
@ -2306,3 +2311,27 @@ func (s *Service) utilCalcAccountPunishmentEndNotifTime(acctpunishment *dbstruct
}
return notifTime, nil
}
func (s *Service) utilBuildInwardHyperLink(ctx *gin.Context, frontendRouteId int64) ([]*dbstruct.NotifHyperlink, error) {
// 获取跳转路径
frontendroute, err := _DefaultFrontendRoute.GetById(ctx, frontendRouteId)
if err != nil {
logger.Error("_DefaultFrontendRoute GetById fail, err: %v", err)
return make([]*dbstruct.NotifHyperlink, 0), err
}
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: goproto.String(consts.FrontendRouteAction_Inward),
Params: frontendroute.AppRoutePath,
})
hyperlinks = append(hyperlinks, &dbstruct.NotifHyperlink{
Action: goproto.String(consts.FrontendRouteAction_Inward),
Params: frontendroute.H5RoutePath,
})
return hyperlinks, nil
}

View File

@ -4,7 +4,6 @@ type FrontendRoute struct {
Id *int64 `json:"id" bson:"_id"` // 前端页面路由表id
AppRoutePath *string `json:"app_route_path" bson:"app_route_path"` // app前端页面路由地址
H5RoutePath *string `json:"h5_route_path" bson:"h5_route_path"` // h5前端页面路由地址
Action *string `json:"action" bson:"action"` // 跳转类型
Desc *string `json:"desc" bson:"desc"` // 前端页面描述
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
@ -32,13 +31,6 @@ func (p *FrontendRoute) GetH5RoutePath() string {
return *p.H5RoutePath
}
func (p *FrontendRoute) GetAction() string {
if p == nil || p.Action == nil {
return ""
}
return *p.Action
}
func (p *FrontendRoute) GetDesc() string {
if p == nil || p.Desc == nil {
return ""

View File

@ -100,16 +100,17 @@ type NotifReceivePull struct {
}
type NotifBuilder struct {
TemplateId int64 // 模板id
TemplateParams []any // 模板参数
ObjMids []int64 // 目标Mids
ObjType int64 // 目标类型
LinkTextTemplateParams []any // 链接模板参数
Thumbnail *MediaComponent // 缩略图
HyperLinks []*NotifHyperlink // 超链接数组
PushTime int64 // 推送时间
SetNid func(ctx *gin.Context, nid int64) error // nid存储函数一般用于取消推送
GetNid func() int64 // nid访问器
TemplateId int64 // 模板id
TemplateParams []any // 模板参数
ObjMids []int64 // 目标Mids
ObjType int64 // 目标类型
LinkTextTemplateParams []any // 链接模板参数
Thumbnail *MediaComponent // 缩略图
HyperLinks []*NotifHyperlink // 超链接数组
PushTime int64 // 推送时间
SetNid func(ctx *gin.Context, nid int64) error // nid存储函数一般用于取消推送
GetNid func() int64 // nid访问器
BuildHyperLink func(ctx *gin.Context, frontendRouteId int64) ([]*NotifHyperlink, error) // 超链接组装函数
}
// 消息内超链接信息

View File

@ -44,7 +44,7 @@ func InitNotifSender(_DefaultNotification *logic.Notification, _DefaultNotifBcst
}
// 组装通知
notification, err := AssembleNotification(notifBuilder)
notification, err := AssembleNotification(ctx, notifBuilder)
if err != nil {
logger.Error("通知组装失败:%v", err)
continue
@ -139,7 +139,7 @@ func SyncNotifBcstVers(ctx *gin.Context, notifBuilder *dbstruct.NotifBuilder, no
}
func AssembleNotification(notifBuilder *dbstruct.NotifBuilder) (*dbstruct.Notification, error) {
func AssembleNotification(ctx *gin.Context, notifBuilder *dbstruct.NotifBuilder) (*dbstruct.Notification, error) {
notification := &dbstruct.Notification{}
notification.SubMid = goproto.Int64(0)
@ -168,12 +168,23 @@ func AssembleNotification(notifBuilder *dbstruct.NotifBuilder) (*dbstruct.Notifi
msg := fmt.Sprintf(cfg.NotifTemplate, notifBuilder.TemplateParams...)
notification.Message = goproto.String(msg)
// 链接信息
// 超链接信息
hyperlinks := make([]*dbstruct.NotifHyperlink, 0)
if len(notifBuilder.HyperLinks) > 0 {
hyperlinks = notifBuilder.HyperLinks
} else if notifBuilder.BuildHyperLink != nil && cfg.FrontendRouteId > 0 {
hyperlinks, err = notifBuilder.BuildHyperLink(ctx, cfg.FrontendRouteId)
if err != nil {
logger.Error("BuildHyperLink fail, err: %v", err)
}
}
// 链接信息
if len(hyperlinks) > 0 {
linkText := fmt.Sprintf(cfg.LinkTextTemplate, notifBuilder.LinkTextTemplateParams...)
notification.LinkText = goproto.String(linkText)
notification.Thumbnail = notifBuilder.Thumbnail
notification.HyperLinks = notifBuilder.HyperLinks
notification.HyperLinks = hyperlinks
}
// 推送时间