by Robin at 20241017; notif center logic

This commit is contained in:
Leufolium 2024-10-17 15:51:27 +08:00
parent f30f710981
commit 9d9209be23
9 changed files with 239 additions and 7 deletions

View File

@ -245,6 +245,7 @@ const (
COLNotifBcst = "notif_bcst"
COLNotifBcstVers = "notif_bcst_vers"
COLNotifBcstReceiveVers = "notif_bcst_receive_vers"
COLNotifReceiveIdSeq = "notif_receive_id_seq"
DBRavenIQTest = "Raven_IQ_test"
COLRavenIQTest = "Raven_IQ_test"
@ -6341,13 +6342,13 @@ func (m *Mongo) GetAndUpdateNotifBcstReceiveVers(ctx *gin.Context, mid int64, ve
}
// 通知广播表
func (m *Mongo) CreateNotifBcsts(ctx *gin.Context, notifBcsts []*dbstruct.NotifBcst) error {
func (m *Mongo) CreateNotifBcst(ctx *gin.Context, notifBcst *dbstruct.NotifBcst) error {
col := m.getColNotifBcst()
_, err := col.InsertMany(ctx, notifBcsts)
_, err := col.InsertOne(ctx, notifBcst)
return err
}
func (m *Mongo) DeleteNotifBcsts(ctx *gin.Context, ids []int64) error {
func (m *Mongo) DeleteNotifBcstByIds(ctx *gin.Context, ids []int64) error {
col := m.getColNotifBcst()
update := qmgo.M{
"$set": qmgo.M{
@ -6363,13 +6364,57 @@ func (m *Mongo) DeleteNotifBcsts(ctx *gin.Context, ids []int64) error {
return err
}
func (m *Mongo) GetNotifBcstListByVersRange(ctx *gin.Context, vers_lb int64, vers_up int64) ([]*dbstruct.NotifBcst, error) {
func (m *Mongo) GetNotifBcstListByVersRange(ctx *gin.Context, vers_lb, vers_ub, offset, limit int64) ([]*dbstruct.NotifBcst, error) {
list := make([]*dbstruct.NotifBcst, 0)
col := m.getColNotifBcst()
query := qmgo.M{
"vers": qmgo.M{
"$gte": vers_lb,
"$lte": vers_ub,
},
"del_flag": 0,
}
err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list)
err := col.Find(ctx, query).Sort("-ct").Skip(offset).Limit(limit).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return list, err
}
return list, err
}
// 通知接收表
func (m *Mongo) CreateNotifReceives(ctx *gin.Context, notifReceives []*dbstruct.NotifReceive) error {
col := m.getColNotifReceive()
_, err := col.InsertMany(ctx, notifReceives)
return err
}
func (m *Mongo) DeleteNotifReceiveByIds(ctx *gin.Context, ids []int64) error {
col := m.getColNotifReceive()
update := qmgo.M{
"$set": qmgo.M{
"del_flag": 1,
},
}
filter := qmgo.M{
"_id": qmgo.M{
"$in": ids,
},
}
_, err := col.UpdateAll(ctx, filter, update)
return err
}
func (m *Mongo) GetNotifReceiveListByObjMid(ctx *gin.Context, objMid, offset, limit int64) ([]*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 err == qmgo.ErrNoSuchDocuments {
err = nil
return list, err

View File

@ -187,6 +187,11 @@ func (m *Mongo) getColNotificationIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBNotificationIdSeq).Collection(COLNotificationIdSeq)
}
// NotifReceiveIdSeq序列表
func (m *Mongo) getColNotifReceiveIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBNotification).Collection(COLNotifReceiveIdSeq)
}
// account_id发号器
func (m *Mongo) GetAndUpdateAccountIdSeq(ctx *gin.Context) (accountIdSeq *dbstruct.AccountIdSeq, err error) {
col := m.getColAccountIdSeq()
@ -673,3 +678,22 @@ func (m *Mongo) GetAndUpdateNotificationIdSeq(ctx *gin.Context) (notificationIdS
return &notificationIdSeqInstance, err
}
// notif_receive_id发号器
func (m *Mongo) GetAndUpdateNotifReceiveIdSeq(ctx *gin.Context) (notifReceiveIdSeq *dbstruct.NotifReceiveIdSeq, err error) {
col := m.getColNotifReceiveIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
notifReceiveIdSeqInstance := dbstruct.NotifReceiveIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "notif_receive_id_seq_id"}).Apply(change, &notifReceiveIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &notifReceiveIdSeqInstance, err
}

View File

@ -0,0 +1,55 @@
package logic
import (
"service/api/consts"
"service/app/mix/dao"
"service/dbstruct"
"service/library/idgenerator"
"service/library/logger"
"time"
"github.com/gin-gonic/gin"
)
type NotifBcst struct {
store *dao.Store
}
func NewNotifBcst(store *dao.Store) (a *NotifBcst) {
a = &NotifBcst{
store: store,
}
return
}
func (p *NotifBcst) OpCreate(ctx *gin.Context, notifBcst *dbstruct.NotifBcst) error {
notifBcst.Id = idgenerator.GenNotifBcstId()
notifBcst.Ct = time.Now().Unix()
notifBcst.Ut = time.Now().Unix()
notifBcst.DelFlag = consts.Exist
err := p.store.CreateNotifBcst(ctx, notifBcst)
if err != nil {
logger.Error("CreateNotifBcst fail, err: %v", err)
return err
}
return nil
}
func (p *NotifBcst) OpDeleteByIds(ctx *gin.Context, ids []int64) error {
err := p.store.DeleteNotifBcstByIds(ctx, ids)
if err != nil {
logger.Error("DeleteNotifBcstByIds fail, err: %v", err)
return err
}
return nil
}
func (p *NotifBcst) OpListByByVersRange(ctx *gin.Context, vers_lb, vers_ub, offset, limit int64) ([]*dbstruct.NotifBcst, error) {
list, err := p.store.GetNotifBcstListByVersRange(ctx, vers_lb, vers_ub, offset, limit)
if err != nil {
logger.Error("GetNotificationListByMid fail, err: %v", err)
return make([]*dbstruct.NotifBcst, 0), err
}
return list, nil
}

View File

@ -1 +0,0 @@
package logic

View File

@ -0,0 +1,38 @@
package logic
import (
"service/app/mix/dao"
"service/dbstruct"
"service/library/logger"
"github.com/gin-gonic/gin"
)
type NotifBcstVers struct {
store *dao.Store
}
func NewZoneNotifBcstVers(store *dao.Store) (a *NotifBcstVers) {
a = &NotifBcstVers{
store: store,
}
return
}
func (p *NotifBcstVers) GetAndUpdateNotifBcstVers(ctx *gin.Context, objType int64) (*dbstruct.NotifBcstVers, error) {
vers, err := p.store.GetAndUpdateNotifBcstVers(ctx, objType)
if err != nil {
logger.Error("GetAndUpdateNotifBcstVers fail, err: %v", err)
return nil, err
}
return vers, err
}
func (p *NotifBcstVers) GetAndUpdateNotifBcstReceiveVers(ctx *gin.Context, mid int64, vers int64) (*dbstruct.NotifBcstReceiveVers, error) {
receiveVers, err := p.store.GetAndUpdateNotifBcstReceiveVers(ctx, mid, vers)
if err != nil {
logger.Error("GetAndUpdateNotifBcstReceiveVers fail, err: %v", err)
return nil, err
}
return receiveVers, err
}

View File

@ -0,0 +1,61 @@
package logic
import (
"service/api/consts"
"service/app/mix/dao"
"service/dbstruct"
"service/library/logger"
"time"
"github.com/gin-gonic/gin"
)
type NotifReceive struct {
store *dao.Store
}
func NewNotifReceive(store *dao.Store) (a *NotifReceive) {
a = &NotifReceive{
store: store,
}
return
}
func (p *NotifReceive) OpCreateBatch(ctx *gin.Context, notifReceives []*dbstruct.NotifReceive) error {
for _, notifReceive := range notifReceives {
notifReceiveIdSeq, err := p.store.GetAndUpdateNotifReceiveIdSeq(ctx)
if err != nil {
logger.Error("GetAndUpdateNotifReceiveIdSeq fail, err: %v", err)
return err
}
notifReceive.Id = notifReceiveIdSeq.Seq
notifReceive.Ct = time.Now().Unix()
notifReceive.Ut = time.Now().Unix()
notifReceive.DelFlag = consts.Exist
}
err := p.store.CreateNotifReceives(ctx, notifReceives)
if err != nil {
logger.Error("CreateNotifReceives fail, err: %v", err)
return err
}
return nil
}
func (p *NotifReceive) OpDeleteByIds(ctx *gin.Context, ids []int64) error {
err := p.store.DeleteNotifReceiveByIds(ctx, ids)
if err != nil {
logger.Error("DeleteNotifBcstByIds fail, err: %v", err)
return err
}
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)
if err != nil {
logger.Error("GetNotifReceiveListByObjMid fail, err: %v", err)
return make([]*dbstruct.NotifReceive, 0), err
}
return list, nil
}

View File

@ -96,3 +96,7 @@ type RavenIQTestIdSeq struct {
type NotificationIdSeq struct {
Seq int64 //用户Id序列号
}
type NotifReceiveIdSeq struct {
Seq int64 //用户Id序列号
}

View File

@ -39,7 +39,6 @@ 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
IsRead int64 `json:"is_read" bson:"is_read"` // 是否已读
Ct int64 `json:"ct" bson:"ct"` // 创建时间
Ut int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag int64 `json:"del_flag" bson:"del_flag"` // 删除标记

View File

@ -57,6 +57,7 @@ const (
NodeWorkerId // node 用户职业者id映射表
NodeSingleDistributeHis // node 慧用工下发打款历史表
NodeNotification // node 系统通知表
NodeNotifBcst // node 系统通知广播表
)
func GenIdInt64(node int64) (int64, error) {
@ -280,3 +281,9 @@ func GenNotificationId() int64 {
id, _ := GenIdInt64(NodeNotification)
return id
}
// notif_bcst
func GenNotifBcstId() int64 {
id, _ := GenIdInt64(NodeNotifBcst)
return id
}