by Robin at 20241029
This commit is contained in:
parent
5d4ff4fb54
commit
8fdac4d4f2
|
@ -65,6 +65,7 @@ const (
|
|||
ClassResultMapKey = "class_result_map"
|
||||
DefaultZoneTextKey = "default_zone_text"
|
||||
AuditTaskCollectionReflectKey = "audit_task_collection_reflect"
|
||||
NotifBannerInfoKey = "notif_banner_info"
|
||||
)
|
||||
|
||||
// del_flag
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
// op 列表
|
||||
type ApiListByMidReq struct {
|
||||
base.BaseRequest
|
||||
NType int64 `json:"n_type"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
|
|
@ -48,22 +48,25 @@ type OpUpdateResp struct {
|
|||
}
|
||||
|
||||
// op 列表
|
||||
type OpListByMidReq struct {
|
||||
type OpListReq struct {
|
||||
base.BaseRequest
|
||||
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"`
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package apollostruct
|
||||
|
||||
type NotifBannerInfoCfg struct {
|
||||
List []string `json:"list"`
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
// 慧用工下发打款历史表
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"` // 删除标记
|
||||
|
|
Loading…
Reference in New Issue