by Robin at 20241212

This commit is contained in:
Robin 2024-12-12 17:46:16 +08:00
parent cf680f293d
commit 2a42b0c38a
5 changed files with 183 additions and 1 deletions

View File

@ -6602,6 +6602,21 @@ func (m *Mongo) GetActivityHotByMidAndStatus(ctx *gin.Context, mid int64, status
return one, err
}
func (m *Mongo) GetActivityHotById(ctx *gin.Context, id int64) (*dbstruct.ActivityHot, error) {
one := &dbstruct.ActivityHot{}
col := m.getColActivityHot()
query := qmgo.M{
"_id": id,
"del_flag": 0,
}
err := col.Find(ctx, query).One(one)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, err
}
return one, err
}
func (m *Mongo) GetActivityHotListByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.ActivityHot, error) {
list := make([]*dbstruct.ActivityHot, 0)
col := m.getColActivityHot()
@ -6663,6 +6678,57 @@ func (m *Mongo) EndActivityHotAtDueTime(ctx *gin.Context, nt int64) error {
return err
}
func (m *Mongo) BeforeInsertActivityHotPriority(ctx *gin.Context, to int64) error {
col := m.getColActivityHot()
up := qmgo.M{
"$inc": qmgo.M{
"priority": 1,
},
}
filter := qmgo.M{
"priority": qmgo.M{
"$gte": to,
},
"status": qmgo.M{
"$in": []int64{consts.ActivityHotStatus_Normal, consts.ActivityHotStatus_Paused},
},
}
_, err := col.UpdateAll(ctx, filter, up)
return err
}
func (m *Mongo) BeforeUpdateActivityHotPriority(ctx *gin.Context, from, to int64) error {
col := m.getColActivityHot()
up := qmgo.M{
"$inc": qmgo.M{
"priority": -1,
},
}
filter := qmgo.M{
"priority": qmgo.M{
"$and": []qmgo.M{
{
"$gt": to,
},
{
"$lte": to,
},
},
},
"status": qmgo.M{
"$in": []int64{consts.ActivityHotStatus_Normal, consts.ActivityHotStatus_Paused},
},
}
_, err := col.UpdateAll(ctx, filter, up)
return err
}
// 活动banner表相关
func (m *Mongo) CreateActivityBanner(ctx *gin.Context, activity_banner *dbstruct.ActivityBanner) error {
col := m.getColActivityBanner()
@ -6786,3 +6852,54 @@ func (m *Mongo) EndActivityBannerAtDueTime(ctx *gin.Context, nt int64) error {
_, err := col.UpdateAll(ctx, query, up)
return err
}
func (m *Mongo) BeforeInsertActivityBannerPriority(ctx *gin.Context, to int64) error {
col := m.getColActivityBanner()
up := qmgo.M{
"$inc": qmgo.M{
"priority": 1,
},
}
filter := qmgo.M{
"priority": qmgo.M{
"$gte": to,
},
"status": qmgo.M{
"$in": []int64{consts.ActivityBannerStatus_Normal, consts.ActivityBannerStatus_Paused},
},
}
_, err := col.UpdateAll(ctx, filter, up)
return err
}
func (m *Mongo) BeforeUpdateActivityBannerPriority(ctx *gin.Context, from, to int64) error {
col := m.getColActivityBanner()
up := qmgo.M{
"$inc": qmgo.M{
"priority": -1,
},
}
filter := qmgo.M{
"priority": qmgo.M{
"$and": []qmgo.M{
{
"$gt": from,
},
{
"$lte": to,
},
},
},
"status": qmgo.M{
"$in": []int64{consts.ActivityBannerStatus_Normal, consts.ActivityBannerStatus_Paused},
},
}
_, err := col.UpdateAll(ctx, filter, up)
return err
}

View File

@ -102,3 +102,21 @@ func (p *ActivityBanner) Sync(ctx *gin.Context, nt int64) error {
}
return nil
}
func (p *ActivityBanner) BeforeInsert(ctx *gin.Context, to int64) error {
err := p.store.BeforeInsertActivityBannerPriority(ctx, to)
if err != nil {
logger.Error("BeforeInsertActivityBannerPriority fail", err)
return err
}
return nil
}
func (p *ActivityBanner) BeforeUpdate(ctx *gin.Context, from, to int64) error {
err := p.store.BeforeUpdateActivityBannerPriority(ctx, from, to)
if err != nil {
logger.Error("BeforeUpdateActivityBannerPriority fail", err)
return err
}
return nil
}

View File

@ -80,6 +80,15 @@ func (p *ActivityHot) GetByMidAndStatus(ctx *gin.Context, id int64, status int64
return one, nil
}
func (p *ActivityHot) GetById(ctx *gin.Context, id int64) (*dbstruct.ActivityHot, error) {
list, err := p.store.GetActivityHotById(ctx, id)
if err != nil {
logger.Error("GetActivityHotById fail, id: %v, err: %v", id, err)
return nil, err
}
return list, nil
}
func (p *ActivityHot) GetByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.ActivityHot, error) {
list, err := p.store.GetActivityHotListByIds(ctx, ids)
if err != nil {
@ -102,3 +111,21 @@ func (p *ActivityHot) Sync(ctx *gin.Context, nt int64) error {
}
return nil
}
func (p *ActivityHot) BeforeInsert(ctx *gin.Context, to int64) error {
err := p.store.BeforeInsertActivityHotPriority(ctx, to)
if err != nil {
logger.Error("BeforeInsertActivityHotPriority fail", err)
return err
}
return nil
}
func (p *ActivityHot) BeforeUpdate(ctx *gin.Context, from, to int64) error {
err := p.store.BeforeUpdateActivityHotPriority(ctx, from, to)
if err != nil {
logger.Error("BeforeUpdateActivityHotPriority fail", err)
return err
}
return nil
}

View File

@ -5069,7 +5069,15 @@ func (s *Service) OpCreateActivityHot(ctx *gin.Context, req *activity_hot_proto.
req.ActivityHot.Status = goproto.Int64(consts.ActivityBannerStatus_Normal)
}
err := _DefaultActivityHot.OpCreate(ctx, req)
// 优先级修改
err := _DefaultActivityHot.BeforeInsert(ctx, req.ActivityHot.GetPriority())
if err != nil {
logger.Error("BeforeInsert fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeActivityHotSrvFail
return
}
err = _DefaultActivityHot.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeActivityHotSrvFail
@ -5080,6 +5088,11 @@ func (s *Service) OpCreateActivityHot(ctx *gin.Context, req *activity_hot_proto.
func (s *Service) OpUpdateActivityHot(ctx *gin.Context, req *activity_hot_proto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeActivityHotSrvOk
if req.ActivityHot.GetPriority() != 0 {
oldActivityHot, err := _DefaultActivityHot.GetById(req.ActivityHot.Id)
}
err := _DefaultActivityHot.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeActivityHotNotExist

View File

@ -57,3 +57,10 @@ func (p *ActivityHot) GetStatus() int64 {
}
return *p.Status
}
func (p *ActivityHot) GetPriority() int64 {
if p == nil || p.Priority == nil {
return 0
}
return *p.Priority
}