diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 9e71bd35..205895d4 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -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 diff --git a/app/mix/dao/mongo_idseq.go b/app/mix/dao/mongo_idseq.go index 16c689cb..b61b539b 100644 --- a/app/mix/dao/mongo_idseq.go +++ b/app/mix/dao/mongo_idseq.go @@ -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 ¬ificationIdSeqInstance, 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, ¬ifReceiveIdSeqInstance); err != nil { + logger.Error("change error : %v", err) + return + } + + return ¬ifReceiveIdSeqInstance, err +} diff --git a/app/mix/service/logic/notif_bcst.go b/app/mix/service/logic/notif_bcst.go new file mode 100644 index 00000000..fe30d722 --- /dev/null +++ b/app/mix/service/logic/notif_bcst.go @@ -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 +} diff --git a/app/mix/service/logic/notif_bcst_center.go b/app/mix/service/logic/notif_bcst_center.go deleted file mode 100644 index 4c79103d..00000000 --- a/app/mix/service/logic/notif_bcst_center.go +++ /dev/null @@ -1 +0,0 @@ -package logic diff --git a/app/mix/service/logic/notif_bcst_vers.go b/app/mix/service/logic/notif_bcst_vers.go new file mode 100644 index 00000000..265fdb24 --- /dev/null +++ b/app/mix/service/logic/notif_bcst_vers.go @@ -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 +} diff --git a/app/mix/service/logic/notif_receive.go b/app/mix/service/logic/notif_receive.go new file mode 100644 index 00000000..1a26efc9 --- /dev/null +++ b/app/mix/service/logic/notif_receive.go @@ -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 +} diff --git a/dbstruct/idSeq.go b/dbstruct/idSeq.go index e1a29395..d35ef23d 100644 --- a/dbstruct/idSeq.go +++ b/dbstruct/idSeq.go @@ -96,3 +96,7 @@ type RavenIQTestIdSeq struct { type NotificationIdSeq struct { Seq int64 //用户Id序列号 } + +type NotifReceiveIdSeq struct { + Seq int64 //用户Id序列号 +} diff --git a/dbstruct/notification.go b/dbstruct/notification.go index a32fbe7d..3f333248 100644 --- a/dbstruct/notification.go +++ b/dbstruct/notification.go @@ -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"` // 删除标记 diff --git a/library/idgenerator/genid.go b/library/idgenerator/genid.go index a4ceaab2..b808deb8 100644 --- a/library/idgenerator/genid.go +++ b/library/idgenerator/genid.go @@ -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 +}