118 lines
2.8 KiB
Go
118 lines
2.8 KiB
Go
package vidhotsearcher
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/app/service/searcher"
|
|
"91porn-server/common/log"
|
|
"91porn-server/models/s/statvidmod"
|
|
"91porn-server/models/v/vidmod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type ObjectID = primitive.ObjectID
|
|
|
|
// VidHotSearcher VidHotSearcher
|
|
type VidHotSearcher struct {
|
|
uid uint64
|
|
typ ResultType
|
|
}
|
|
|
|
// NewVidHotSearcher NewVidHotSearcher
|
|
func NewVidHotSearcher(uid uint64) searcher.Searcher {
|
|
return &VidHotSearcher{
|
|
uid: uid,
|
|
typ: Video,
|
|
}
|
|
}
|
|
|
|
// NewRichVidHotSearcher NewRichVidHotSearcher
|
|
func NewRichVidHotSearcher(uid uint64) searcher.Searcher {
|
|
return &VidHotSearcher{
|
|
uid: uid,
|
|
typ: RichVido,
|
|
}
|
|
}
|
|
|
|
// Search Search
|
|
func (v *VidHotSearcher) Search(unuse searcher.KeyWorder, opt searcher.Opter) (result searcher.Resulter, err error) {
|
|
var (
|
|
vidList []ObjectID
|
|
countMap map[ObjectID]int64
|
|
)
|
|
limitEx := opt.Limit() + 1
|
|
if isEarlyMorning1AM(time.Now()) {
|
|
vidList, err = vidmod.VIDListByCreatedAt(opt.Skip(), limitEx)
|
|
} else {
|
|
vidList, countMap, err = statvidmod.GetDailyPlayCountGroup(opt.Skip(), limitEx)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(vidList) == 0 {
|
|
return &Result{
|
|
dat: []VideoRes{},
|
|
richDat: []RichVidRes{},
|
|
typ: v.typ,
|
|
hasNext: false,
|
|
}, nil
|
|
}
|
|
hasNext := false
|
|
if len(vidList) > int(opt.Limit()) {
|
|
vidList = vidList[:opt.Limit()]
|
|
hasNext = true
|
|
}
|
|
if v.typ == Video {
|
|
videoResList, err := searcher.GetVideoResList(v.uid, vidList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
setVideoResListPayCount(videoResList, countMap)
|
|
return &Result{
|
|
dat: videoResList,
|
|
typ: v.typ,
|
|
hasNext: hasNext,
|
|
}, nil
|
|
} else {
|
|
richVideoResList, err := searcher.GetRichVideoResList(v.uid, vidList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
setRichVideoResListPayCount(richVideoResList, countMap)
|
|
return &Result{
|
|
richDat: richVideoResList,
|
|
typ: v.typ,
|
|
hasNext: hasNext,
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
func setVideoResListPayCount(list []VideoRes, countMap map[ObjectID]int64) {
|
|
for i := 0; i < len(list); i++ {
|
|
video := list[i]
|
|
vid := *video.VideoInfo.ID
|
|
playCount := int(countMap[vid])
|
|
video.PlayCount = &playCount
|
|
list[i] = video
|
|
}
|
|
}
|
|
|
|
func setRichVideoResListPayCount(list []RichVidRes, countMap map[ObjectID]int64) {
|
|
for i := 0; i < len(list); i++ {
|
|
video := list[i]
|
|
vid := *video.VideoInfo.ID
|
|
playCount := int(countMap[vid])
|
|
video.PlayCount = &playCount
|
|
list[i] = video
|
|
}
|
|
}
|
|
|
|
//1:00 - 1:10
|
|
func isEarlyMorning1AM(cur time.Time) bool {
|
|
start := time.Date(cur.Year(), cur.Month(), cur.Day(), 1, 0, 0, 0, cur.Location())
|
|
end := time.Date(cur.Year(), cur.Month(), cur.Day(), 1, 10, 0, 0, cur.Location())
|
|
log.Info("vidhotsearcher isEarlyMorning1AM", log.Any("start", start.String()), log.Any("end", end.String()), log.Any("cur", cur.String()))
|
|
return cur.After(start) && cur.Before(end)
|
|
}
|