94 lines
1.7 KiB
Go
94 lines
1.7 KiB
Go
package statvidmod
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/common/pageopt"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type Matcher = pageopt.Matcher
|
|
|
|
// SumDateMatch
|
|
type SumDateMatch struct {
|
|
SumDate *time.Time
|
|
}
|
|
|
|
func (s *SumDateMatch) New() Matcher {
|
|
return pageopt.NewAssignMatch("sumDate", s.SumDate)
|
|
}
|
|
|
|
// SumDateGTEAndLTMatch
|
|
type SumDateGTEAndLTMatch struct {
|
|
GTE *time.Time
|
|
LT *time.Time
|
|
}
|
|
|
|
func (s *SumDateGTEAndLTMatch) New() Matcher {
|
|
return pageopt.NewGTEAndLTMatch("sumDate", s.GTE, s.LT)
|
|
}
|
|
|
|
// PublisherIDMatch
|
|
type PublisherIDMatch struct {
|
|
UID *uint64
|
|
}
|
|
|
|
func (p *PublisherIDMatch) New() Matcher {
|
|
return pageopt.NewAssignMatch("publisherID", p.UID)
|
|
}
|
|
|
|
// PayCountGTMatch
|
|
type PayCountGTMatch struct {
|
|
GT *int64
|
|
}
|
|
|
|
func (p *PayCountGTMatch) New() Matcher {
|
|
return pageopt.NewGTMatch("payCount", p.GT)
|
|
}
|
|
|
|
// PlayCountGTMatch
|
|
type PlayCountGTMatch struct {
|
|
GT *int64
|
|
}
|
|
|
|
func (p *PlayCountGTMatch) New() Matcher {
|
|
return pageopt.NewGTMatch("playCount", p.GT)
|
|
}
|
|
|
|
// VidMatch
|
|
type VidMatch struct {
|
|
Vid *ObjectID
|
|
}
|
|
|
|
func (p *VidMatch) New() Matcher {
|
|
return pageopt.NewAssignMatch("vid", p.Vid)
|
|
}
|
|
|
|
// VidInMatch
|
|
type VidInMatch struct {
|
|
Vids []ObjectID
|
|
}
|
|
|
|
func (p *VidInMatch) New() Matcher {
|
|
return pageopt.NewInMatch("vid", p.Vids)
|
|
}
|
|
|
|
func List(sort bson.D, skip, limit int64, matchs ...Matcher) ([]Stat, error) {
|
|
opt := &options.FindOptions{}
|
|
if len(sort) != 0 {
|
|
opt.SetSort(sort)
|
|
}
|
|
opt.SetSkip(skip)
|
|
opt.SetLimit(limit)
|
|
filter := pageopt.MergeM(matchs)
|
|
list := make([]Stat, 0, limit)
|
|
return list, coll(nil).Find(&list, filter, opt)
|
|
}
|
|
|
|
func Count(matchs ...Matcher) (int64, error) {
|
|
filter := pageopt.MergeM(matchs)
|
|
return coll(nil).Count(filter)
|
|
}
|