Merge branch 'feat-IRONFANS-250-Robin' into conf-250
This commit is contained in:
commit
248969082d
|
@ -382,10 +382,14 @@ const (
|
|||
const (
|
||||
ActivityHotStatus_Normal = 0 // 已生效
|
||||
ActivityHotStatus_Paused = 1 // 已暂停
|
||||
ActivityHotStatus_Expired = 2 // 已失效(外层封装逻辑)
|
||||
ActivityHotStatus_Waiting = 3 // 待开始(外层封装逻辑)
|
||||
)
|
||||
|
||||
// 活动Banner状态
|
||||
const (
|
||||
ActivityBannerStatus_Normal = 0 // 已生效
|
||||
ActivityBannerStatus_Paused = 1 // 已暂停
|
||||
ActivityBannerStatus_Expired = 2 // 已失效(外层封装逻辑)
|
||||
ActivityBannerStatus_Waiting = 3 // 待开始(外层封装逻辑)
|
||||
)
|
||||
|
|
|
@ -52,7 +52,6 @@ type OpListReq struct {
|
|||
base.BaseRequest
|
||||
DeviceType *int64 `json:"device_type"`
|
||||
Status *int64 `json:"status"`
|
||||
IsValid bool `json:"is_valid"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
type ActivityHotApiVO struct {
|
||||
Mid int64 `json:"mid" bson:"mid"` // 主播mid
|
||||
UserId int64 `json:"user_id" bson:"user_id"` // 主播user_id
|
||||
Image *dbstruct.MediaComponent `json:"image" bson:"image"` // 主图
|
||||
Title string `json:"title" bson:"title"` // 标题
|
||||
Text string `json:"text" bson:"text"` // 文字内容
|
||||
|
|
|
@ -52,7 +52,6 @@ type OpListReq struct {
|
|||
base.BaseRequest
|
||||
Uid *int64 `json:"mid"`
|
||||
Status *int64 `json:"status"`
|
||||
IsValid bool `json:"is_valid"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package proto
|
||||
|
||||
import (
|
||||
"service/api/consts"
|
||||
"service/dbstruct"
|
||||
|
||||
goproto "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ActivityHotOpVO struct {
|
||||
*dbstruct.ActivityHot
|
||||
UserId int64 `json:"user_id" bson:"user_id"` // 主播user_id
|
||||
}
|
||||
|
||||
func NewActivityHotOpVO() *ActivityHotOpVO {
|
||||
return &ActivityHotOpVO{}
|
||||
}
|
||||
|
||||
func (vo *ActivityHotOpVO) CopyActivityHot(activityHot *dbstruct.ActivityHot) *ActivityHotOpVO {
|
||||
if activityHot == nil {
|
||||
return vo
|
||||
}
|
||||
vo.ActivityHot = activityHot
|
||||
return vo
|
||||
}
|
||||
|
||||
func (vo *ActivityHotOpVO) CopyAccount(account *dbstruct.Account) *ActivityHotOpVO {
|
||||
if account == nil {
|
||||
return vo
|
||||
}
|
||||
vo.UserId = account.GetUserId()
|
||||
return vo
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
func (vo *ActivityHotOpVO) SetStatus(nt int64) *ActivityHotOpVO {
|
||||
if vo.ActivityHot.GetSt() > nt { // 开始时间晚于当前时间,则为未开始
|
||||
vo.ActivityHot.Status = goproto.Int64(consts.ActivityHotStatus_Waiting)
|
||||
} else if vo.ActivityHot.GetEt() < nt { // 结束时间早于当前时间,则为已过期
|
||||
vo.ActivityHot.Status = goproto.Int64(consts.ActivityHotStatus_Expired)
|
||||
}
|
||||
return vo
|
||||
}
|
|
@ -7238,22 +7238,34 @@ func (m *Mongo) GetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpL
|
|||
"del_flag": 0,
|
||||
}
|
||||
|
||||
nt := time.Now().Unix()
|
||||
|
||||
if req.Uid != nil {
|
||||
query["mid"] = util.DerefInt64(req.Uid)
|
||||
}
|
||||
|
||||
if req.Status != nil {
|
||||
switch util.DerefInt64(req.Status) {
|
||||
// 正常或暂停
|
||||
case consts.ActivityHotStatus_Normal, consts.ActivityHotStatus_Paused:
|
||||
query["status"] = util.DerefInt64(req.Status)
|
||||
}
|
||||
|
||||
if req.IsValid {
|
||||
nt := time.Now().Unix()
|
||||
query["st"] = qmgo.M{
|
||||
"$lte": nt,
|
||||
}
|
||||
query["et"] = qmgo.M{
|
||||
"$gte": nt,
|
||||
}
|
||||
// 未开始,开始时间必须大于现在的时间(即晚于)
|
||||
case consts.ActivityHotStatus_Waiting:
|
||||
query["st"] = qmgo.M{
|
||||
"$gt": nt,
|
||||
}
|
||||
// 已失效,结束时间必须小于现在的时间(即早于)
|
||||
case consts.ActivityHotStatus_Expired:
|
||||
query["et"] = qmgo.M{
|
||||
"$lt": nt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := col.Find(ctx, query).Sort("-priority").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list)
|
||||
|
@ -7332,21 +7344,33 @@ func (m *Mongo) GetActivityBannerList(ctx *gin.Context, req *activity_banner_pro
|
|||
"del_flag": 0,
|
||||
}
|
||||
|
||||
if req.Status != nil {
|
||||
query["status"] = util.DerefInt64(req.Status)
|
||||
}
|
||||
|
||||
if req.IsValid {
|
||||
nt := time.Now().Unix()
|
||||
|
||||
if req.Status != nil {
|
||||
switch util.DerefInt64(req.Status) {
|
||||
// 正常或暂停
|
||||
case consts.ActivityBannerStatus_Normal, consts.ActivityBannerStatus_Paused:
|
||||
query["status"] = util.DerefInt64(req.Status)
|
||||
query["st"] = qmgo.M{
|
||||
"$lte": nt,
|
||||
}
|
||||
query["et"] = qmgo.M{
|
||||
"$gte": nt,
|
||||
}
|
||||
// 未开始,开始时间必须大于现在的时间(即晚于)
|
||||
case consts.ActivityBannerStatus_Waiting:
|
||||
query["st"] = qmgo.M{
|
||||
"$gt": nt,
|
||||
}
|
||||
// 已失效,结束时间必须小于现在的时间(即早于)
|
||||
case consts.ActivityBannerStatus_Expired:
|
||||
query["et"] = qmgo.M{
|
||||
"$lt": nt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list)
|
||||
err := col.Find(ctx, query).Sort("-priority").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list)
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
err = nil
|
||||
return list, err
|
||||
|
|
|
@ -4888,7 +4888,7 @@ func (s *Service) ApiGetActivityHotList(ctx *gin.Context, req *activity_hot_prot
|
|||
|
||||
// 填充信息
|
||||
if len(list) > 0 {
|
||||
vl, err := s.utilFillActivityHotVO(ctx, activityHotMp, mids)
|
||||
vl, err := s.utilFillActivityHotApiVO(ctx, activityHotMp, mids)
|
||||
if err != nil {
|
||||
logger.Error("utilFillActivityHotVO fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
|
|
|
@ -5554,14 +5554,25 @@ func (s *Service) OpDeleteActivityHot(ctx *gin.Context, id int64) (ec errcode.Er
|
|||
return
|
||||
}
|
||||
|
||||
func (s *Service) OpGetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpListReq) (list []*dbstruct.ActivityHot, ec errcode.ErrCode) {
|
||||
func (s *Service) OpGetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpListReq) (volist []*activity_hot_proto.ActivityHotOpVO, ec errcode.ErrCode) {
|
||||
ec = errcode.ErrCodeActivityHotSrvOk
|
||||
|
||||
volist = make([]*activity_hot_proto.ActivityHotOpVO, 0)
|
||||
|
||||
list, err := _DefaultActivityHot.OpList(ctx, req)
|
||||
if err != nil {
|
||||
logger.Error("OpGetActivityHotList fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
volist, err = s.utilFillActivityHotOpVO(ctx, list)
|
||||
if err != nil {
|
||||
logger.Error("utilFillActivityHotOpVO fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeActivityHotSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -5615,5 +5626,16 @@ func (s *Service) OpGetActivityBannerList(ctx *gin.Context, req *activity_banner
|
|||
ec = errcode.ErrCodeActivityBannerSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
// 当前时间
|
||||
nt := time.Now().Unix()
|
||||
|
||||
for _, v := range list {
|
||||
if v.GetSt() > nt { // 开始时间晚于当前时间,则为未开始
|
||||
v.Status = goproto.Int64(consts.ActivityHotStatus_Waiting)
|
||||
} else if v.GetEt() < nt { // 结束时间早于当前时间,则为已过期
|
||||
v.Status = goproto.Int64(consts.ActivityHotStatus_Expired)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2423,7 +2423,7 @@ func (s *Service) utilGetRecentReceiveNotif(ctx *gin.Context, mid, nType int64)
|
|||
return notif, nil
|
||||
}
|
||||
|
||||
func (s *Service) utilFillActivityHotVO(ctx *gin.Context, activityHotMp map[int64]*dbstruct.ActivityHot, mids []int64) ([]*activity_hot_proto.ActivityHotApiVO, error) {
|
||||
func (s *Service) utilFillActivityHotApiVO(ctx *gin.Context, activityHotMp map[int64]*dbstruct.ActivityHot, mids []int64) ([]*activity_hot_proto.ActivityHotApiVO, error) {
|
||||
volist := make([]*activity_hot_proto.ActivityHotApiVO, 0)
|
||||
|
||||
acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids)
|
||||
|
@ -2463,6 +2463,35 @@ func (s *Service) utilFillActivityHotVO(ctx *gin.Context, activityHotMp map[int6
|
|||
return volist, nil
|
||||
}
|
||||
|
||||
func (s *Service) utilFillActivityHotOpVO(ctx *gin.Context, list []*dbstruct.ActivityHot) ([]*activity_hot_proto.ActivityHotOpVO, error) {
|
||||
volist := make([]*activity_hot_proto.ActivityHotOpVO, 0)
|
||||
|
||||
mids := make([]int64, 0)
|
||||
midMp := make(map[int64]*dbstruct.Account)
|
||||
for _, v := range list {
|
||||
if midMp[v.GetMid()] == nil {
|
||||
midMp[v.GetMid()] = &dbstruct.Account{}
|
||||
mids = append(mids, v.GetMid())
|
||||
}
|
||||
}
|
||||
|
||||
// 补足account表信息
|
||||
acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids)
|
||||
if err != nil {
|
||||
logger.Error("GetAccountMapByMids failed, err: %v", err)
|
||||
return make([]*activity_hot_proto.ActivityHotOpVO, 0), err
|
||||
}
|
||||
|
||||
// 当前时间
|
||||
nt := time.Now().Unix()
|
||||
|
||||
for _, v := range list {
|
||||
vo := activity_hot_proto.NewActivityHotOpVO().CopyActivityHot(v).CopyAccount(acctMp[v.GetMid()]).SetStatus(nt)
|
||||
volist = append(volist, vo)
|
||||
}
|
||||
return volist, nil
|
||||
}
|
||||
|
||||
func (s *Service) utilCompleteActivityHotList(ctx *gin.Context, existedMp map[int64]*dbstruct.ActivityHot, remLength int) ([]*activity_hot_proto.ActivityHotApiVO, error) {
|
||||
|
||||
volist := make([]*activity_hot_proto.ActivityHotApiVO, 0)
|
||||
|
|
|
@ -8,6 +8,7 @@ type ActivityBanner struct {
|
|||
St *int64 `json:"st" bson:"st"` // 开始时间
|
||||
Et *int64 `json:"et" bson:"et"` // 结束时间
|
||||
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"` // 创建时间
|
||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||
|
|
|
@ -50,3 +50,10 @@ func (p *ActivityHot) GetEt() int64 {
|
|||
}
|
||||
return *p.Et
|
||||
}
|
||||
|
||||
func (p *ActivityHot) GetStatus() int64 {
|
||||
if p == nil || p.Status == nil {
|
||||
return -1
|
||||
}
|
||||
return *p.Status
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue