init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package srv_search
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/esmanager"
|
||||
"videoweb/pub/models/esmod"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func getVideoEsData(ctx context.Context, minTime, endTime *time.Time, esIndex string) (esmanager.M, *srvdef.SrvErr) {
|
||||
data, serr := getVideoData(ctx, minTime, endTime)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
return videoToEsData(data), nil
|
||||
}
|
||||
func getVideoData(ctx context.Context, minTime, endTime *time.Time) ([]*videoinformationmod.VideoInformation, *srvdef.SrvErr) {
|
||||
pageNumber := 1
|
||||
pageSize := 1000
|
||||
rsl := make([]*videoinformationmod.VideoInformation, 0)
|
||||
filter := bson.M{
|
||||
videoinformationmod.FN.VideoInformation.MediaType: bson.M{
|
||||
"$in": []interface{}{
|
||||
videoinformationmod.MediaType_Video,
|
||||
videoinformationmod.MediaType_VideoV2,
|
||||
},
|
||||
},
|
||||
}
|
||||
if minTime != nil && endTime != nil {
|
||||
filter[videoinformationmod.FN.VideoInformation.UpdatedAt] = bson.M{
|
||||
"$gte": minTime,
|
||||
"$lte": endTime,
|
||||
}
|
||||
}
|
||||
for {
|
||||
opts := &options.FindOptions{}
|
||||
opts.SetSort(bson.M{videoinformationmod.FN.VideoInformation.UpdatedAt: -1})
|
||||
opts.SetSkip(int64(pageSize * (pageNumber - 1)))
|
||||
opts.SetLimit(int64(pageSize))
|
||||
data, serr := videoinformationmod.FindManyVideoInformations(ctx, filter, opts)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
rsl = append(rsl, data...)
|
||||
if len(data) < pageSize {
|
||||
break
|
||||
}
|
||||
pageNumber++
|
||||
}
|
||||
return rsl, nil
|
||||
}
|
||||
func videoToEsData(data []*videoinformationmod.VideoInformation) esmanager.M {
|
||||
rsl := make(map[string]interface{}, len(data))
|
||||
for _, v := range data {
|
||||
esInfo := esmod.ESVideo{
|
||||
Id: v.Id,
|
||||
Title: v.Title,
|
||||
Slug: v.Slug,
|
||||
MediaType: v.MediaType,
|
||||
AddedTime: v.AddedTime,
|
||||
CreatorName: v.CreatorName,
|
||||
Keyworlds: "",
|
||||
Desc: v.Desc,
|
||||
Remark: v.Remark,
|
||||
Status: v.Status,
|
||||
IsHot: v.IsHot,
|
||||
Sort: v.Sort,
|
||||
WatchTimes: v.Real.WatchTimes,
|
||||
ShowTimes: v.Real.ShowTimes,
|
||||
Comments: v.Real.Comments,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Keyworld: v.Keyworld,
|
||||
CreatorId: v.CreatorId,
|
||||
FirstTag: v.FirstTag,
|
||||
SecondTags: v.SecondTags,
|
||||
CoverImg: v.CoverImg,
|
||||
Nodes: v.Nodes,
|
||||
Video: v.Video,
|
||||
CategoryIds: v.CategoryIds,
|
||||
Tags: v.Tags,
|
||||
Real: v.Real,
|
||||
VideoCount: v.VideoCount,
|
||||
}
|
||||
if v.Keyworld != nil && len(v.Keyworld) > 0 {
|
||||
esInfo.Keyworlds = strings.Join(v.Keyworld, " ")
|
||||
}
|
||||
rsl[strconv.FormatInt(v.Id, 10)] = esInfo
|
||||
}
|
||||
return rsl
|
||||
}
|
||||
Reference in New Issue
Block a user