Merge pull request 'feat-IRONFANS-250-Robin' (#889) from feat-IRONFANS-250-Robin into test
Reviewed-on: https://git.wishpal.cn/wishpal_ironfan/service/pulls/889
This commit is contained in:
commit
af9696285e
|
@ -7270,6 +7270,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()
|
||||
|
@ -7331,6 +7346,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()
|
||||
|
@ -7454,3 +7520,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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -5517,8 +5517,22 @@ func (s *Service) OpCreateActivityHot(ctx *gin.Context, req *activity_hot_proto.
|
|||
}
|
||||
|
||||
// 新创建的活动默认直接生效
|
||||
req.ActivityHot.Status = goproto.Int64(consts.ActivityHotStatus_Normal)
|
||||
err := _DefaultActivityHot.OpCreate(ctx, req)
|
||||
nt := time.Now().Unix()
|
||||
if req.ActivityHot.GetSt() > nt {
|
||||
req.ActivityHot.Status = goproto.Int64(consts.ActivityBannerStatus_Waiting)
|
||||
} else {
|
||||
req.ActivityHot.Status = goproto.Int64(consts.ActivityBannerStatus_Normal)
|
||||
}
|
||||
|
||||
// 优先级修改
|
||||
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
|
||||
|
@ -5529,6 +5543,37 @@ 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(ctx, req.ActivityHot.GetId())
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
ec = errcode.ErrCodeActivityHotNotExist
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
var beforeFunc func() error
|
||||
if oldActivityHot.GetPriority() != 0 {
|
||||
beforeFunc = func() error {
|
||||
return _DefaultActivityHot.BeforeUpdate(ctx, oldActivityHot.GetPriority(), req.ActivityHot.GetPriority())
|
||||
}
|
||||
} else {
|
||||
beforeFunc = func() error { return _DefaultActivityHot.BeforeInsert(ctx, req.ActivityHot.GetPriority()) }
|
||||
}
|
||||
|
||||
// 优先级修改
|
||||
if err = beforeFunc(); err != nil {
|
||||
logger.Error("BeforeUpdate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err := _DefaultActivityHot.OpUpdate(ctx, req)
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
ec = errcode.ErrCodeActivityHotNotExist
|
||||
|
@ -5581,8 +5626,22 @@ func (s *Service) OpCreateActivityBanner(ctx *gin.Context, req *activity_banner_
|
|||
ec = errcode.ErrCodeActivityBannerSrvOk
|
||||
|
||||
// 新创建的活动默认直接生效
|
||||
req.ActivityBanner.Status = goproto.Int64(consts.ActivityBannerStatus_Normal)
|
||||
err := _DefaultActivityBanner.OpCreate(ctx, req)
|
||||
nt := time.Now().Unix()
|
||||
if req.ActivityBanner.GetSt() > nt {
|
||||
req.ActivityBanner.Status = goproto.Int64(consts.ActivityBannerStatus_Waiting)
|
||||
} else {
|
||||
req.ActivityBanner.Status = goproto.Int64(consts.ActivityBannerStatus_Normal)
|
||||
}
|
||||
|
||||
// 优先级修改
|
||||
err := _DefaultActivityBanner.BeforeInsert(ctx, req.ActivityBanner.GetPriority())
|
||||
if err != nil {
|
||||
logger.Error("BeforeInsert fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
err = _DefaultActivityBanner.OpCreate(ctx, req)
|
||||
if err != nil {
|
||||
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityBannerSrvFail
|
||||
|
@ -5593,6 +5652,37 @@ func (s *Service) OpCreateActivityBanner(ctx *gin.Context, req *activity_banner_
|
|||
|
||||
func (s *Service) OpUpdateActivityBanner(ctx *gin.Context, req *activity_banner_proto.OpUpdateReq) (ec errcode.ErrCode) {
|
||||
ec = errcode.ErrCodeActivityBannerSrvOk
|
||||
|
||||
if req.ActivityBanner.GetPriority() != 0 {
|
||||
oldActivityBanner, err := _DefaultActivityBanner.GetById(ctx, req.ActivityBanner.GetId())
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
ec = errcode.ErrCodeActivityBannerNotExist
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityBannerSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
var beforeFunc func() error
|
||||
if oldActivityBanner.GetPriority() != 0 {
|
||||
beforeFunc = func() error {
|
||||
return _DefaultActivityBanner.BeforeUpdate(ctx, oldActivityBanner.GetPriority(), req.ActivityBanner.GetPriority())
|
||||
}
|
||||
} else {
|
||||
beforeFunc = func() error { return _DefaultActivityBanner.BeforeInsert(ctx, req.ActivityBanner.GetPriority()) }
|
||||
}
|
||||
|
||||
// 优先级修改
|
||||
if err = beforeFunc(); err != nil {
|
||||
logger.Error("BeforeUpdate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityBannerSrvFail
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err := _DefaultActivityBanner.OpUpdate(ctx, req)
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
ec = errcode.ErrCodeActivityBannerNotExist
|
||||
|
|
|
@ -7,7 +7,7 @@ type ActivityBanner struct {
|
|||
Hyperlinks []*Hyperlink `json:"hyperlinks" bson:"hyperlinks"` // 跳转链接
|
||||
St *int64 `json:"st" bson:"st"` // 开始时间
|
||||
Et *int64 `json:"et" bson:"et"` // 结束时间
|
||||
DeviceType *int64 `json:"device_type" bson:"device_type"` // 支持的设备类型
|
||||
DeviceType []int64 `json:"device_type" bson:"device_type"` // 支持的设备类型
|
||||
Priority *int64 `json:"priority" bson:"priority"` // 优先级
|
||||
Status *int64 `json:"status" bson:"status"` // 状态 0-已生效,1-已暂停
|
||||
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||
|
@ -15,6 +15,20 @@ type ActivityBanner struct {
|
|||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||
}
|
||||
|
||||
func (p *ActivityBanner) GetId() int64 {
|
||||
if p == nil || p.Id == nil {
|
||||
return -1
|
||||
}
|
||||
return *p.Id
|
||||
}
|
||||
|
||||
func (p *ActivityBanner) GetPriority() int64 {
|
||||
if p == nil || p.Priority == nil {
|
||||
return -1
|
||||
}
|
||||
return *p.Priority
|
||||
}
|
||||
|
||||
func (p *ActivityBanner) GetTitle() string {
|
||||
if p == nil || p.Title == nil {
|
||||
return ""
|
||||
|
|
|
@ -16,6 +16,13 @@ type ActivityHot struct {
|
|||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||
}
|
||||
|
||||
func (p *ActivityHot) GetId() int64 {
|
||||
if p == nil || p.Id == nil {
|
||||
return -1
|
||||
}
|
||||
return *p.Id
|
||||
}
|
||||
|
||||
func (p *ActivityHot) GetMid() int64 {
|
||||
if p == nil || p.Mid == nil {
|
||||
return -1
|
||||
|
@ -57,3 +64,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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue