You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB
Go

package pusher
import (
"context"
"joybuywork/internal/consts/ckey"
"joybuywork/internal/service/provider/cachecurd"
"joybuywork/internal/utils/verify"
"time"
)
const (
groupSec = 300
)
type pushGroup struct {
one, two, three *cachecurd.HMap
oneBt, twoBt, threeBt [2]int64
}
func (s *pushGroup) insideOne(doneAt int64) bool {
return verify.Inside[int64](doneAt, s.oneBt[0], s.oneBt[1])
}
func (s *pushGroup) insideTwo(doneAt int64) bool {
return verify.Inside[int64](doneAt, s.twoBt[0], s.twoBt[1])
}
func (s *pushGroup) insideThree(doneAt int64) bool {
return verify.Inside[int64](doneAt, s.threeBt[0], s.threeBt[1])
}
func newPushGroup(ctx context.Context, t time.Time, cpnId int64, mark string) *pushGroup {
var base = t.Minute() / 5
one, two, three := base+1, base+2, base+3
if two > 12 {
two -= 12
}
if three > 12 {
three -= 12
}
pg := &pushGroup{}
pg.one, _ = cachecurd.NewHMap(ctx, ckey.FissionPushUserGroup(cpnId, mark, one), cachecurd.SetHMapExp(16*time.Minute))
pg.two, _ = cachecurd.NewHMap(ctx, ckey.FissionPushUserGroup(cpnId, mark, two), cachecurd.SetHMapExp(16*time.Minute))
pg.three, _ = cachecurd.NewHMap(ctx, ckey.FissionPushUserGroup(cpnId, mark, three), cachecurd.SetHMapExp(16*time.Minute))
pg.oneBt = [2]int64{t.Unix() - 3*groupSec, t.Unix() - 2*groupSec}
pg.twoBt = [2]int64{t.Unix() - 2*groupSec, t.Unix() - groupSec}
pg.threeBt = [2]int64{t.Unix() - groupSec, t.Unix()}
return pg
}