fix(quota): update time handling in quota logic and correct subscriber ID query
This commit is contained in:
parent
9b0e1b1e0f
commit
cf4792cdc8
@ -42,12 +42,12 @@ func (l *CreateQuotaTaskLogic) CreateQuotaTask(req *types.CreateQuotaTaskRequest
|
|||||||
query = query.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished
|
query = query.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished
|
||||||
}
|
}
|
||||||
if req.StartTime != 0 {
|
if req.StartTime != 0 {
|
||||||
start := time.UnixMilli(req.StartTime)
|
start := time.Unix(req.StartTime, 0)
|
||||||
query = query.Where("`start_time` >= ?", start)
|
query = query.Where("`start_time` >= ?", start)
|
||||||
}
|
}
|
||||||
if req.EndTime != 0 {
|
if req.EndTime != 0 {
|
||||||
end := time.UnixMilli(req.EndTime)
|
end := time.UnixMilli(req.EndTime)
|
||||||
query = query.Where("`start_time` <= ?", end)
|
query = query.Where("`expire_time` <= ?", end)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := query.Find(&subs).Error; err != nil {
|
if err := query.Find(&subs).Error; err != nil {
|
||||||
@ -67,6 +67,7 @@ func (l *CreateQuotaTaskLogic) CreateQuotaTask(req *types.CreateQuotaTaskRequest
|
|||||||
IsActive: req.IsActive,
|
IsActive: req.IsActive,
|
||||||
StartTime: req.StartTime,
|
StartTime: req.StartTime,
|
||||||
EndTime: req.EndTime,
|
EndTime: req.EndTime,
|
||||||
|
Objects: subIds,
|
||||||
}
|
}
|
||||||
scopeBytes, _ := scopeInfo.Marshal()
|
scopeBytes, _ := scopeInfo.Marshal()
|
||||||
contentInfo := task.QuotaContent{
|
contentInfo := task.QuotaContent{
|
||||||
|
|||||||
@ -37,12 +37,12 @@ func (l *QueryQuotaTaskPreCountLogic) QueryQuotaTaskPreCount(req *types.QueryQuo
|
|||||||
tx = tx.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished
|
tx = tx.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished
|
||||||
}
|
}
|
||||||
if req.StartTime != 0 {
|
if req.StartTime != 0 {
|
||||||
start := time.UnixMilli(req.StartTime)
|
start := time.Unix(req.StartTime, 0)
|
||||||
tx = tx.Where("`start_time` >= ?", start)
|
tx = tx.Where("`start_time` >= ?", start)
|
||||||
}
|
}
|
||||||
if req.EndTime != 0 {
|
if req.EndTime != 0 {
|
||||||
end := time.UnixMilli(req.EndTime)
|
end := time.UnixMilli(req.EndTime)
|
||||||
tx = tx.Where("`start_time` <= ?", end)
|
tx = tx.Where("`expire_time` <= ?", end)
|
||||||
}
|
}
|
||||||
if err = tx.Count(&count).Error; err != nil {
|
if err = tx.Count(&count).Error; err != nil {
|
||||||
l.Errorf("[QueryQuotaTaskPreCount] count error: %v", err.Error())
|
l.Errorf("[QueryQuotaTaskPreCount] count error: %v", err.Error())
|
||||||
|
|||||||
@ -68,7 +68,7 @@ func (l *QuotaTaskLogic) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribes, err := l.getSubscribes(ctx, scope.Subscribers)
|
subscribes, err := l.getSubscribes(ctx, scope.Objects)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func (l *QuotaTaskLogic) parseTaskData(ctx context.Context, taskInfo *task.Task)
|
|||||||
|
|
||||||
func (l *QuotaTaskLogic) getSubscribes(ctx context.Context, subscriberIDs []int64) ([]*user.Subscribe, error) {
|
func (l *QuotaTaskLogic) getSubscribes(ctx context.Context, subscriberIDs []int64) ([]*user.Subscribe, error) {
|
||||||
var subscribes []*user.Subscribe
|
var subscribes []*user.Subscribe
|
||||||
if err := l.svcCtx.DB.WithContext(ctx).Model(&user.Subscribe{}).Where("subscribe_id IN ?", subscriberIDs).Find(&subscribes).Error; err != nil {
|
if err := l.svcCtx.DB.WithContext(ctx).Model(&user.Subscribe{}).Where("id IN ?", subscriberIDs).Find(&subscribes).Error; err != nil {
|
||||||
logger.WithContext(ctx).Error("[QuotaTaskLogic.getSubscribes] find subscribes error",
|
logger.WithContext(ctx).Error("[QuotaTaskLogic.getSubscribes] find subscribes error",
|
||||||
logger.Field("error", err.Error()),
|
logger.Field("error", err.Error()),
|
||||||
logger.Field("subscribers", subscriberIDs),
|
logger.Field("subscribers", subscriberIDs),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user