init: web_hgdjc_server

This commit is contained in:
2026-11-07 10:44:09 +08:00
commit 71a4f4e175
713 changed files with 147749 additions and 0 deletions
@@ -0,0 +1,320 @@
package videoinformationmod
import (
"context"
"videoweb/pub/common/log"
"videoweb/pub/common/srvdef"
"videoweb/pub/mongos"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// 表名
var db *mongos.Collection
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.Shop.Coll(TN.VideoInformation)
// 获取数据库表
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.VideoInformation.AddedTime, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.CategoryIds, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Tags, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.CreatorId, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.CreatedAt, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.CategoryIds, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Video.FileId, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.Sort, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
},
},
{
// /api/app/video/list 按 status 过滤,并按 addedTime/_id 倒序游标分页。
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Id, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.MediaType, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Id, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.CategoryIds, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.CreatorId, Value: 1},
{Key: FN.VideoInformation.Status, Value: 1},
},
},
{
Keys: bson.D{
{Key: "nodes.nodeId", Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Sort, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.CreatorId, Value: 1},
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.Tags, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.Tags, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.Id, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Status, Value: 1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
{Key: FN.VideoInformation.IsTop, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.IsTop, Value: -1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Sort, Value: -1},
{Key: FN.VideoInformation.AddedTime, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.HevcStatus, Value: 1},
{Key: FN.VideoInformation.HevcFailCount, Value: 1},
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.HevcStatus, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.VideoInformation.Slug, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(channelmod:initVideoInformationIndex) Create VideoInformation Index failed! err:%+v:", err))
}
}
// InsertOneVideoInformation 插入一个渠道统计
func InsertOneVideoInformation(ctx context.Context, qa *VideoInformation) *srvdef.SrvErr {
if _, err := db.InsertOne(ctx, qa); err != nil {
// log.Warn("VideoInformationmod:InsertOneVideoInformation db.InsertOne failed", log.E(err))
return srvdef.New(srvdef.ErrDbInsertError, "", "")
}
return nil
}
func InsertManyVideoInformation(ctx context.Context, qa []*VideoInformation) *srvdef.SrvErr {
if _, err := db.InsertMany(ctx, &qa); err != nil {
return srvdef.New(srvdef.ErrDbInsertError, "", "")
}
return nil
}
// DelOneVideoInformation 删除一个渠道统计
func DelOneVideoInformation(ctx context.Context, filter bson.M) (
int64, *srvdef.SrvErr) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("VideoInformationmod:DelOneVideoInformation db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
}
return count, nil
}
// FindOneVideoInformation 查找一个渠道统计
func FindOneVideoInformation(ctx context.Context, filter bson.M) (
*VideoInformation, *srvdef.SrvErr) {
var VideoInformation VideoInformation
if err := db.FindOneEx(ctx, &VideoInformation, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Warn("VideoInformationmod:FindOneVideoInformation db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return nil, srvdef.New(srvdef.ErrNoData, "", "")
}
return &VideoInformation, nil
}
// FindOneVideoInformationWithOptions 按条件查询单条视频信息,支持projection等查询选项。
func FindOneVideoInformationWithOptions(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (
*VideoInformation, *srvdef.SrvErr) {
var VideoInformation VideoInformation
if err := db.FindOneEx(ctx, &VideoInformation, filter, opts...); err != nil {
log.Warn("VideoInformationmod:FindOneVideoInformationWithOptions db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, srvdef.New(srvdef.ErrNoData, "", "")
}
return &VideoInformation, nil
}
func FindManyVideoInformations(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoInformationList, *srvdef.SrvErr) {
data := make(VideoInformationList, 0)
if err := db.Find(ctx, &data, filter, opts...); nil != err {
log.Warn("faq:FindManyVideoInformations", log.E(err), log.Any("filter", filter))
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
}
return data, nil
}
// CountVideoInformations 统计视频数量
func CountVideoInformations(ctx context.Context, filter bson.M, opts ...*options.CountOptions) (
int64, *srvdef.SrvErr) {
count, err := db.Count(ctx, filter, opts...)
if err != nil {
log.Warn("faqmod:CountVideoInformations db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return count, nil
}
// UpdateOneVideoInformation 更新一个渠道统计
func UpdateOneVideoInformation(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("post:UpdateOneVideoInformation db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
}
if result.MatchedCount != 1 {
log.Warn("post:UpdateOneVideoInformation db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return srvdef.New(srvdef.ErrNoData, "", "")
}
return nil
}
// AggregateVideoInformations 聚合查询视频信息
func AggregateVideoInformations(ctx context.Context, bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("videoinformationmod:AggregateVideoInformations failed", log.E(err))
return srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return nil
}
func UpdateManyVideoInformation(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
result, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("post:UpdateManyVideoInformation db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
}
if result.MatchedCount < 1 {
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return srvdef.New(srvdef.ErrNoData, "", "")
}
return nil
}
// BulkWriteVideoInformation 批量写入或更新视频信息
func BulkWriteVideoInformation(ctx context.Context, docs []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, *srvdef.SrvErr) {
result, err := db.BulkWrite(ctx, docs, opts...)
if err != nil {
log.Warn("视频信息批量写入或更新失败", log.E(err))
return nil, srvdef.New(srvdef.ErrDbUpdateError, "", "")
}
return result, nil
}
+136
View File
@@ -0,0 +1,136 @@
package videoinformationmod
type TagVideoInformation struct {
AddedTime string
CategoryIds string
CoverImg string
CreatedAt string
CreatorId string
CreatorName string
Desc string
FirstTag string
Id string
IndexNow string
IsHot string
IsTop string
Keyworld string
MediaType string
Nodes string
Real struct {
Collects string
Comments string
Likes string
MonthWatchs string
ShowTimes string
TodayWatchs string
WatchTimes string
WeekWatchs string
}
Fake struct {
WatchTimes string
}
Remark string
SecondTags string
Slug string
Sort string
Status string
Tags string
Title string
UpdatedAt string
Video struct {
Cover string
FileId string
Height string
PreMp4FileNameFs string
TaskId string
Url string
H265Url string
VideoTime string
Width string
UnencryptedPreMp4 string
}
VideoCount string
UploadUserName string
OptionAccount string
PageUpdatedAt string
UnencryptedImage string
Content string
SecondUpdatedAt string
TopicIds string
SyncId string
HevcStatus string
HevcFailCount string
PreviewVtt string
AudioFile string
SmartCover string
HevcMetaInfo string
}
var FN struct {
VideoInformation TagVideoInformation
}
var TN struct {
VideoInformation string
}
func init() {
FN.VideoInformation.AddedTime = "addedTime"
FN.VideoInformation.CategoryIds = "categoryIds"
FN.VideoInformation.CoverImg = "coverImg"
FN.VideoInformation.CreatedAt = "createdAt"
FN.VideoInformation.CreatorId = "creatorId"
FN.VideoInformation.CreatorName = "creatorName"
FN.VideoInformation.Desc = "desc"
FN.VideoInformation.FirstTag = "firstTag"
FN.VideoInformation.Id = "_id"
FN.VideoInformation.IndexNow = "indexNow"
FN.VideoInformation.IsHot = "isHot"
FN.VideoInformation.IsTop = "isTop"
FN.VideoInformation.Keyworld = "keyworld"
FN.VideoInformation.MediaType = "mediaType"
FN.VideoInformation.Nodes = "nodes"
FN.VideoInformation.Real.Collects = "real.collects"
FN.VideoInformation.Real.Comments = "real.comments"
FN.VideoInformation.Real.Likes = "real.likes"
FN.VideoInformation.Real.MonthWatchs = "real.monthWatchs"
FN.VideoInformation.Real.ShowTimes = "real.showTimes"
FN.VideoInformation.Real.TodayWatchs = "real.todayWatchs"
FN.VideoInformation.Real.WatchTimes = "real.watchTimes"
FN.VideoInformation.Real.WeekWatchs = "real.weekWatchs"
FN.VideoInformation.Fake.WatchTimes = "fake.watchTimes"
FN.VideoInformation.Remark = "remark"
FN.VideoInformation.SecondTags = "secondTags"
FN.VideoInformation.Slug = "slug"
FN.VideoInformation.Sort = "sort"
FN.VideoInformation.Status = "status"
FN.VideoInformation.Tags = "tags"
FN.VideoInformation.Title = "title"
FN.VideoInformation.UpdatedAt = "updatedAt"
FN.VideoInformation.Video.Cover = "video.cover"
FN.VideoInformation.Video.FileId = "video.fileId"
FN.VideoInformation.Video.Height = "video.height"
FN.VideoInformation.Video.PreMp4FileNameFs = "video.preMp4FileNameFs"
FN.VideoInformation.Video.TaskId = "video.taskId"
FN.VideoInformation.Video.Url = "video.url"
FN.VideoInformation.Video.H265Url = "video.h265Url"
FN.VideoInformation.Video.VideoTime = "video.videoTime"
FN.VideoInformation.Video.Width = "video.width"
FN.VideoInformation.Video.UnencryptedPreMp4 = "video.unencryptedPreMp4"
FN.VideoInformation.VideoCount = "videoCount"
FN.VideoInformation.OptionAccount = "optionAccount"
FN.VideoInformation.UploadUserName = "uploadUserName"
FN.VideoInformation.PageUpdatedAt = "pageUpdatedAt"
FN.VideoInformation.UnencryptedImage = "unencryptedImage"
FN.VideoInformation.Content = "content"
FN.VideoInformation.SecondUpdatedAt = "secondUpdatedAt"
FN.VideoInformation.TopicIds = "topicIds"
FN.VideoInformation.SyncId = "syncId"
FN.VideoInformation.HevcStatus = "hevcStatus"
FN.VideoInformation.HevcFailCount = "hevcFailCount"
FN.VideoInformation.PreviewVtt = "previewVtt"
FN.VideoInformation.AudioFile = "audioFile"
FN.VideoInformation.SmartCover = "smartCover"
FN.VideoInformation.HevcMetaInfo = "hevcMetaInfo"
TN.VideoInformation = "video_information"
}
+187
View File
@@ -0,0 +1,187 @@
package videoinformationmod
import (
"time"
"go.mongodb.org/mongo-driver/bson"
)
// @table:video_information
type VideoInformation struct {
Id int64 `json:"id" bson:"_id,omitempty"`
Title string `json:"title" bson:"title"` // 帖子标题
Slug string `json:"slug" bson:"slug"` // slug
MediaType MediaType `json:"mediaType" bson:"mediaType"` // 资源类型
AddedTime time.Time `json:"addedTime" bson:"addedTime"` // 帖子上架时间
CreatorId int64 `json:"creatorId" bson:"creatorId"` // 作者Id
CreatorName string `json:"creatorName" bson:"creatorName"` // 作者名称
Keyworld []string `bson:"keyworld,omitempty" json:"keyworld"` // 关键字
FirstTag string `bson:"firstTag,omitempty" json:"firstTag"` // 一级标签
SecondTags []string `bson:"secondTags,omitempty" json:"secondTags"` // 二级标签标签
CoverImg string `bson:"coverImg,omitempty" json:"coverImg"` // 封面
UnencryptedImage string `bson:"unencryptedImage,omitempty" json:"unencryptedImage"` // 不加密封面
Desc string `bson:"desc,omitempty" json:"desc"` // 详细描述
Remark string `bson:"remark,omitempty" json:"remark"` // 备注
Nodes []Node `json:"nodes" bson:"nodes"` // 节点
Status InformationSatus `json:"status" bson:"status"` // 帖子上架状态
Video VideoInfo `json:"video" bson:"video"` // 视频
CategoryIds []int64 `json:"categoryIds" bson:"categoryIds"` // 分类ID集合,可绑定首页分类配置ID
TopicIds []int64 `json:"topicIds" bson:"topicIds"` // 专题ID(视频用)
Tags []int64 `json:"tags" bson:"tags"` // 标签
IsHot bool `json:"isHot" bson:"isHot"` // 是否热门
Sort int64 `json:"sort" bson:"sort"` // 排序
Real Flow `json:"real" bson:"real"` // 真实流量
Fake FakeFlow `json:"fake" bson:"fake"` // 伪造流量
VideoCount int64 `json:"videoCount" bson:"videoCount"` // 合集视频数量
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
PageUpdatedAt time.Time `json:"pageUpdatedAt" bson:"pageUpdatedAt"` // 页面展示更新时间
IsTop bool `json:"isTop" bson:"isTop"` // 是否置顶
UploadUserName string `bson:"uploadUserName" json:"uploadUserName,omitempty"` // 上传用户名
OptionAccount string `bson:"optionAccount,omitempty" json:"optionAccount"` // 最后操作人
Content string `json:"content" bson:"content"` // 富文本
SyncId string `json:"syncId" bson:"syncId"` // 同步ID
SecondUpdatedAt time.Time `json:"secondUpdatedAt" bson:"secondUpdatedAt"` // 二次修改时间
HevcStatus HevcStatus `json:"hevcStatus" bson:"hevcStatus"` // 主视频 H265 转码状态
HevcFailCount int `json:"hevcFailCount" bson:"hevcFailCount"` // 主视频转码累计失败次数
PreviewVtt string `json:"previewVtt" bson:"previewVtt,omitempty"` // 雪碧图 vtt
AudioFile string `json:"audioFile" bson:"audioFile,omitempty"` // 音频文件路径
SmartCover string `json:"smartCover" bson:"smartCover,omitempty"` // 智能封面
HevcMetaInfo *VideoMetaInfo `json:"hevcMetaInfo" bson:"hevcMetaInfo,omitempty"` // H265 视频元信息
}
// HevcStatus H265 转码状态(主视频 video.url)。
type HevcStatus int
const (
HevcStatusNone HevcStatus = 0 // 未提交转码
HevcStatusPending HevcStatus = 1 // 转码中
HevcStatusSuccess HevcStatus = 2 // 转码成功
HevcStatusFailed HevcStatus = -1 // 转码失败
)
// VideoMetaInfo H265 转码视频元信息(对应老司机 hevc_meta_info)。
type VideoMetaInfo struct {
M3u8URL string `json:"m3u8Url" bson:"m3u8Url,omitempty"`
Codec string `json:"codec" bson:"codec,omitempty"`
Profile string `json:"profile" bson:"profile,omitempty"`
Width int `json:"width" bson:"width,omitempty"`
Height int `json:"height" bson:"height,omitempty"`
Fps float64 `json:"fps" bson:"fps,omitempty"`
VideoBitrate int `json:"videoBitrate" bson:"videoBitrate,omitempty"`
PixFmt string `json:"pixFmt" bson:"pixFmt,omitempty"`
AudioCodec string `json:"audioCodec" bson:"audioCodec,omitempty"`
AudioBitrate int `json:"audioBitrate" bson:"audioBitrate,omitempty"`
AudioSampleRate int `json:"audioSampleRate" bson:"audioSampleRate,omitempty"`
AudioChannels int `json:"audioChannels" bson:"audioChannels,omitempty"`
Bitrate int `json:"bitrate" bson:"bitrate,omitempty"`
Size int64 `json:"size" bson:"size,omitempty"`
Duration float64 `json:"duration" bson:"duration,omitempty"`
}
type VideoInformationList []*VideoInformation
type Node struct {
NodeId string `json:"nodeId" bson:"nodeId"` // 节点ID
Title string `bson:"title" json:"title"` // 节点标题
Videos []VideoInfo `json:"videos" bson:"videos"` // 视频信息列表
Images []string `json:"images" bson:"images"` // 图片
Url string `json:"url" bson:"url"` // 链接
Text string `json:"text" bson:"text"` // 文本
}
type VideoInfo struct {
TaskId string `json:"taskId" bson:"taskId"` // 视频ID(视频才会存在)
FileId string `json:"fileId" bson:"fileId"` // 媒资库ID
Url string `json:"url" bson:"url"` // 视频URl
H265Url string `json:"h265Url" bson:"h265Url,omitempty"` // H265 视频地址
Cover string `json:"cover" bson:"cover"` // 视频封面
Height int64 `json:"height" bson:"height"` // 分辨率高(视频才会存在)
Width int64 `json:"width" bson:"width"` // 分辨率宽(视频才会存在)
VideoTime int32 `bson:"videoTime" json:"videoTime"` // 影片长度
PreMp4FileNameFs string `bson:"preMp4FileNameFs,omitempty" json:"preMp4FileNameFs"` // 预览MP4文件
UnencryptedPreMp4 string `bson:"unencryptedPreMp4,omitempty" json:"unencryptedPreMp4"` // 不加密的预览MP4
}
type InformationSatus int32
const (
InformationSatusWaiting InformationSatus = 0 // 初始化
InformationSatusVerifyOK InformationSatus = 1 // 上架
InformationSatusVerifyCancel InformationSatus = 2 // 下架
)
type Flow struct {
WatchTimes int64 `json:"watchTimes" bson:"watchTimes"` // 观看次数
ShowTimes int64 `json:"showTimes" bson:"showTimes"` // 展示次数
Comments int64 `json:"comments" bson:"comments"` // 评论条数
Likes int64 `json:"likes" bson:"likes"` // 点赞数
Collects int64 `json:"collects" bson:"collects"` // 收藏数
WeekWatchs int64 `json:"weekWatchs" bson:"weekWatchs"` // 本周观看次数
MonthWatchs int64 `json:"monthWatchs" bson:"monthWatchs"` // 本月观看次数
TodayWatchs int64 `json:"todayWatchs" bson:"todayWatchs"` // 当日观看次数
}
type FakeFlow struct {
WatchTimes int64 `json:"watchTimes" bson:"watchTimes"` // 假观看次数
}
type MediaType int64
const (
MediaType_Video MediaType = 0 // 视频(帖子)
MediaType_Collection MediaType = 1 // 合集
MediaType_Advitise MediaType = 2 // 广告
MediaType_VideoV2 MediaType = 3 // 视频
)
type VideoSortItem struct {
Key VideoSortType `json:"key" form:"key"` // 传递值
Value string `json:"value" form:"value"` // 显示名字
}
// VideoSortType 排序条件
type VideoSortType int64
const (
VideoSortType_Recommend VideoSortType = 1 // 最近最佳
VideoSortType_Hot VideoSortType = 2 // 最多观看
VideoSortType_New VideoSortType = 3 // 最新更新
)
var VideoSortTypeName = map[VideoSortType]string{
VideoSortType_Recommend: "最近最佳",
VideoSortType_New: "最新更新",
VideoSortType_Hot: "最多观看",
}
var VideoSortItems = []VideoSortItem{
{Key: VideoSortType_Recommend, Value: "最近最佳"},
{Key: VideoSortType_New, Value: "最新更新"},
{Key: VideoSortType_Hot, Value: "最多观看"},
}
func (s VideoSortType) GetSortItem() VideoSortItem {
switch s {
case VideoSortType_Recommend:
return VideoSortItems[0]
case VideoSortType_Hot:
return VideoSortItems[2]
case VideoSortType_New:
return VideoSortItems[1]
default:
return VideoSortItems[0]
}
}
func (s VideoSortType) GetSortBson() bson.D {
switch s {
case VideoSortType_Recommend:
return bson.D{{FN.VideoInformation.Sort, -1}, {FN.VideoInformation.Real.WeekWatchs, -1}}
case VideoSortType_Hot:
return bson.D{{FN.VideoInformation.Real.WatchTimes, -1}}
case VideoSortType_New:
return bson.D{{FN.VideoInformation.AddedTime, -1}}
default:
return bson.D{{FN.VideoInformation.AddedTime, -1}}
}
}