diff --git a/api/consts/consts.go b/api/consts/consts.go index e3716bb9..3e670a0e 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -65,6 +65,7 @@ const ( ClassResultMapKey = "class_result_map" DefaultZoneTextKey = "default_zone_text" AuditTaskCollectionReflectKey = "audit_task_collection_reflect" + NotifBannerInfoKey = "notif_banner_info" ) // del_flag diff --git a/api/proto/notification/proto/notification_api.go b/api/proto/notification/proto/notification_api.go index d1d43ffa..4f7e25f0 100644 --- a/api/proto/notification/proto/notification_api.go +++ b/api/proto/notification/proto/notification_api.go @@ -8,8 +8,9 @@ import ( // op 列表 type ApiListByMidReq struct { base.BaseRequest - Offset int `json:"offset"` - Limit int `json:"limit"` + NType int64 `json:"n_type"` + Offset int `json:"offset"` + Limit int `json:"limit"` } type ApiListByMidData struct { diff --git a/api/proto/notification/proto/notification_op.go b/api/proto/notification/proto/notification_op.go index 400e798c..6f7fc74e 100644 --- a/api/proto/notification/proto/notification_op.go +++ b/api/proto/notification/proto/notification_op.go @@ -48,22 +48,25 @@ type OpUpdateResp struct { } // op 列表 -type OpListByMidReq struct { +type OpListReq struct { base.BaseRequest - Uid *int64 `json:"mid"` - Offset int `json:"offset"` - Limit int `json:"limit"` + Uid *int64 `json:"mid"` + NType *int64 `json:"n_type"` + PushTime *int64 `json:"push_time"` + Status *int64 `json:"status"` + Offset int `json:"offset"` + Limit int `json:"limit"` } -type OpListByMidData struct { +type OpListData struct { List []*dbstruct.Notification `json:"list"` Offset int `json:"offset"` More int `json:"more"` } -type OpListByMidResp struct { +type OpListResp struct { base.BaseResponse - Data *OpListByMidData `json:"data"` + Data *OpListData `json:"data"` } // op 撤销 @@ -79,3 +82,12 @@ type OpCancelResp struct { base.BaseResponse Data *OpCancelData `json:"data"` } + +// op 列表 +type OpListNotifReceivesByMidReq struct { + base.BaseRequest + Uid *int64 `json:"mid"` + NType *int64 `json:"n_type"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} diff --git a/apollostruct/notif_banner_info.go b/apollostruct/notif_banner_info.go new file mode 100644 index 00000000..03235de8 --- /dev/null +++ b/apollostruct/notif_banner_info.go @@ -0,0 +1,5 @@ +package apollostruct + +type NotifBannerInfoCfg struct { + List []string `json:"list"` +} diff --git a/app/mix/controller/config_op.go b/app/mix/controller/config_op.go index 6ca3a051..92d7a7ab 100644 --- a/app/mix/controller/config_op.go +++ b/app/mix/controller/config_op.go @@ -81,3 +81,14 @@ func OpGetIsMomentImageEncryptEnabled(ctx *gin.Context) { ReplyOk(ctx, isEnabled) } + +func OpGetBannerInfo(ctx *gin.Context) { + list, ec := service.DefaultConfigService.OpGetBannerInfo(ctx) + if ec != errcode.ErrCodeOk { + logger.Error("OpGetBannerInfo fail, ec: %v", ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + ReplyOk(ctx, list) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index b0e57d09..367fd979 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -300,6 +300,7 @@ func Init(r *gin.Engine) { apiNotificationGroup := r.Group("/api/notification", PrepareToC()) apiNotificationGroup.POST("list_by_mid", middleware.JSONParamValidator(notificationproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetNotificationListByMid) apiNotificationGroup.POST("receive", middleware.JSONParamValidator(notificationproto.ApiReceiveReq{}), middleware.JwtAuthenticator(), ApiReceiveAllBcstedNotifs) + apiMomentGroup.POST("get_banner_info", middleware.JSONParamValidator(base.BaseRequest{}), OpGetBannerInfo) // =============================== 以下是服务,只允许内网调用 =============================== @@ -602,7 +603,7 @@ func Init(r *gin.Engine) { opNotificationGroup.POST("create", middleware.JSONParamValidator(notificationproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateNotification) //opNotificationGroup.POST("update", middleware.JSONParamValidator(notificationproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateNotification) opNotificationGroup.POST("delete", middleware.JSONParamValidator(notificationproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteNotification) - opNotificationGroup.POST("list_by_mid", middleware.JSONParamValidator(notificationproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetNotificationListByMid) + opNotificationGroup.POST("list", middleware.JSONParamValidator(notificationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetNotificationList) opNotificationGroup.POST("cancel", middleware.JSONParamValidator(notificationproto.OpCancelReq{}), middleware.JwtAuthenticator(), OpCancelNotification) // 慧用工下发打款历史表 diff --git a/app/mix/controller/notification_op.go b/app/mix/controller/notification_op.go index 2b0592e4..cead1157 100644 --- a/app/mix/controller/notification_op.go +++ b/app/mix/controller/notification_op.go @@ -47,22 +47,22 @@ func OpDeleteNotification(ctx *gin.Context) { ReplyOk(ctx, nil) } -func OpGetNotificationListByMid(ctx *gin.Context) { - req := ctx.MustGet("client_req").(*notificationproto.OpListByMidReq) +func OpGetNotificationList(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*notificationproto.OpListReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } - list, ec := service.DefaultService.OpGetNotificationListByMid(ctx, req) + list, ec := service.DefaultService.OpGetNotificationList(ctx, req) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpGetNotificationList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } - data := ¬ificationproto.OpListByMidData{ + data := ¬ificationproto.OpListData{ List: list, Offset: req.Offset + len(list), } diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index f2b23f5c..a781d16d 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -6254,13 +6254,25 @@ func (m *Mongo) DeleteNotification(ctx *gin.Context, id int64) error { return err } -func (m *Mongo) GetNotificationListByMid(ctx *gin.Context, req *notificationproto.OpListByMidReq) ([]*dbstruct.Notification, error) { +func (m *Mongo) GetNotificationList(ctx *gin.Context, req *notificationproto.OpListReq) ([]*dbstruct.Notification, error) { list := make([]*dbstruct.Notification, 0) col := m.getColNotification() query := qmgo.M{ - "obj_mid": util.DerefInt64(req.Uid), "del_flag": 0, } + if req.Uid != nil { + query["obj_mid"] = util.DerefInt64(req.Uid) + } + if req.NType != nil { + query["n_type"] = util.DerefInt64(req.NType) + } + if req.PushTime != nil { + query["push_time"] = util.DerefInt64(req.PushTime) + } + if req.Status != nil { + query["status"] = util.DerefInt64(req.Status) + } + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil @@ -6463,15 +6475,22 @@ func (m *Mongo) DeleteNotifReceiveByIds(ctx *gin.Context, ids []int64) error { return err } -func (m *Mongo) GetNotifReceiveListByObjMid(ctx *gin.Context, objMid, offset, limit int64) ([]*dbstruct.NotifReceive, error) { +func (m *Mongo) GetNotifReceiveListByObjMid(ctx *gin.Context, req *notificationproto.OpListNotifReceivesByMidReq) ([]*dbstruct.NotifReceive, error) { list := make([]*dbstruct.NotifReceive, 0) col := m.getColNotifReceive() query := qmgo.M{ - "obj_mid": objMid, "del_flag": 0, } - err := col.Find(ctx, query).Sort("-ct").Skip(offset).Limit(limit).All(&list) + + if req.Uid != nil { + query["obj_mid"] = util.DerefInt64(req.Uid) + } + if req.NType != nil { + query["n_type"] = util.DerefInt64(req.NType) + } + + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil return list, err diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index ccac1182..8f6cf350 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -4261,7 +4261,12 @@ func (s *Service) ApiGetNotificationListByMid(ctx *gin.Context, req *notificatio ec = errcode.ErrCodeNotificationSrvOk // 查询得到已经拉取到的通知 - notifReceives, err := _DefaultNotifReceive.OpListByObjMid(ctx, req.BaseRequest.Mid, int64(req.Offset), int64(req.Limit)) + notifReceives, err := _DefaultNotifReceive.OpListByObjMid(ctx, ¬ificationproto.OpListNotifReceivesByMidReq{ + Uid: goproto.Int64(req.BaseRequest.Mid), + NType: goproto.Int64(req.NType), + Offset: req.Offset, + Limit: req.Limit, + }) if err != nil { logger.Error("OpListByObjMid fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeNotificationSrvFail diff --git a/app/mix/service/configservice.go b/app/mix/service/configservice.go index 415a5a62..b3de0501 100644 --- a/app/mix/service/configservice.go +++ b/app/mix/service/configservice.go @@ -215,3 +215,17 @@ func (s *ConfigService) OpGetIsMomentImageEncryptEnabled(ctx *gin.Context) (isEn return } + +func (s *ConfigService) OpGetBannerInfo(ctx *gin.Context) (list []string, ec errcode.ErrCode) { + ec = errcode.ErrCodeOk + + ver := &apollostruct.NotifBannerInfoCfg{} + err := apollo.GetJson(consts.NotifBannerInfoKey, ver, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + ec = errcode.ErrCodeApolloReadFail + return + } + + return +} diff --git a/app/mix/service/logic/notif_receive.go b/app/mix/service/logic/notif_receive.go index 1a26efc9..0315eae6 100644 --- a/app/mix/service/logic/notif_receive.go +++ b/app/mix/service/logic/notif_receive.go @@ -7,6 +7,8 @@ import ( "service/library/logger" "time" + notificationproto "service/api/proto/notification/proto" + "github.com/gin-gonic/gin" ) @@ -51,8 +53,8 @@ func (p *NotifReceive) OpDeleteByIds(ctx *gin.Context, ids []int64) error { return nil } -func (p *NotifReceive) OpListByObjMid(ctx *gin.Context, objMid, offset, limit int64) ([]*dbstruct.NotifReceive, error) { - list, err := p.store.GetNotifReceiveListByObjMid(ctx, objMid, offset, limit) +func (p *NotifReceive) OpListByObjMid(ctx *gin.Context, req *notificationproto.OpListNotifReceivesByMidReq) ([]*dbstruct.NotifReceive, error) { + list, err := p.store.GetNotifReceiveListByObjMid(ctx, req) if err != nil { logger.Error("GetNotifReceiveListByObjMid fail, err: %v", err) return make([]*dbstruct.NotifReceive, 0), err diff --git a/app/mix/service/logic/notification.go b/app/mix/service/logic/notification.go index 29f2b807..94008e14 100644 --- a/app/mix/service/logic/notification.go +++ b/app/mix/service/logic/notification.go @@ -63,10 +63,10 @@ func (p *Notification) OpDelete(ctx *gin.Context, id int64) error { return nil } -func (p *Notification) OpListByMid(ctx *gin.Context, req *notificationproto.OpListByMidReq) ([]*dbstruct.Notification, error) { - list, err := p.store.GetNotificationListByMid(ctx, req) +func (p *Notification) OpList(ctx *gin.Context, req *notificationproto.OpListReq) ([]*dbstruct.Notification, error) { + list, err := p.store.GetNotificationList(ctx, req) if err != nil { - logger.Error("GetNotificationListByMid fail, err: %v", err) + logger.Error("GetNotificationList fail, err: %v", err) return make([]*dbstruct.Notification, 0), err } return list, nil diff --git a/app/mix/service/notification_center.go b/app/mix/service/notification_center.go index 2bf4a7b7..5325550e 100644 --- a/app/mix/service/notification_center.go +++ b/app/mix/service/notification_center.go @@ -154,14 +154,32 @@ func (s *NotifBcstCenter) pullAllBcstedNotifs(ctx *gin.Context, vers, receiveVer return err } notifReceives := make([]*dbstruct.NotifReceive, 0) + notifReceiveMap := make(map[int64]*dbstruct.NotifReceive) + nids := make([]int64, 0) for _, notifBcst := range notifBcsts { for _, nid := range notifBcst.Nids { - notifReceives = append(notifReceives, &dbstruct.NotifReceive{ + notifReceive := &dbstruct.NotifReceive{ ObjMid: objMid, Nid: nid, - }) + } + notifReceives = append(notifReceives, notifReceive) + notifReceiveMap[nid] = notifReceive + nids = append(nids, nid) } } + + notifs, err := _DefaultNotification.GetListByIds(ctx, nids) + if err != nil { + logger.Error("GetNotificationListByIds fail, err: %v", err) + return err + } + for _, notif := range notifs { + ntf, ok := notifReceiveMap[notif.GetId()] + if ok { + ntf.NType = notif.GetNType() + } + } + err = _DefaultNotifReceive.OpCreateBatch(ctx, notifReceives) if err != nil { logger.Error("OpCreateBatch fail, err: %v", err) diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 0716684f..f9f25b98 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -5072,9 +5072,9 @@ func (s *Service) OpDeleteNotification(ctx *gin.Context, id int64) (ec errcode.E return } -func (s *Service) OpGetNotificationListByMid(ctx *gin.Context, req *notificationproto.OpListByMidReq) (list []*dbstruct.Notification, ec errcode.ErrCode) { +func (s *Service) OpGetNotificationList(ctx *gin.Context, req *notificationproto.OpListReq) (list []*dbstruct.Notification, ec errcode.ErrCode) { ec = errcode.ErrCodeNotificationSrvOk - list, err := _DefaultNotification.OpListByMid(ctx, req) + list, err := _DefaultNotification.OpList(ctx, req) if err != nil { logger.Error("OpGetNotificationList fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeNotificationSrvFail diff --git a/dbstruct/notification.go b/dbstruct/notification.go index 3274f0e5..94541900 100644 --- a/dbstruct/notification.go +++ b/dbstruct/notification.go @@ -47,6 +47,13 @@ func (p *Notification) GetPushTime() int64 { return 0 } +func (p *Notification) GetNType() int64 { + if p != nil && p.NType != nil { + return *p.NType + } + return 0 +} + type NotifBcst struct { Id int64 `json:"id" bson:"_id"` // 通知广播表id Nids []int64 `json:"nids" bson:"nids"` // 系统通知表ids @@ -69,6 +76,7 @@ type NotifReceive struct { Id int64 `json:"id" bson:"_id"` // 通知接收表id ObjMid int64 `json:"obj_mid" bson:"obj_mid"` // 通知接收人mid Nid int64 `json:"nid" bson:"nid"` // 系统通知表id + NType int64 `json:"n_type" bson:"n_type"` // 消息类型 Ct int64 `json:"ct" bson:"ct"` // 创建时间 Ut int64 `json:"ut" bson:"ut"` // 更新时间 DelFlag int64 `json:"del_flag" bson:"del_flag"` // 删除标记