Initial commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
谢宇宁
2026-10-22 14:47:17 +07:00
co-authored by Claude Opus 5.5
commit 3639d2184a
574 changed files with 61690 additions and 0 deletions
@@ -0,0 +1,248 @@
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},
},
},
{
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.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},
},
},
}
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
}
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) (
int64, *srvdef.SrvErr) {
count, err := db.Count(ctx, filter)
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
}
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
}
+100
View File
@@ -0,0 +1,100 @@
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 {
Comments string
MonthWatchs string
ShowTimes string
TodayWatchs string
WatchTimes string
WeekWatchs string
}
Remark string
SecondTags string
Sort string
Status string
Tags string
Title string
UpdatedAt string
PageUpdatedAt string
Video struct {
Cover string
FileId string
Height string
PreMp4FileNameFs string
TaskId string
Url string
VideoTime string
Width string
UnencryptedPreMp4 string
}
VideoCount string
UnencryptedImage 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.Comments = "real.comments"
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.Remark = "remark"
FN.VideoInformation.SecondTags = "secondTags"
FN.VideoInformation.Sort = "sort"
FN.VideoInformation.Status = "status"
FN.VideoInformation.Tags = "tags"
FN.VideoInformation.Title = "title"
FN.VideoInformation.UpdatedAt = "updatedAt"
FN.VideoInformation.PageUpdatedAt = "pageUpdatedAt"
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.VideoTime = "video.videoTime"
FN.VideoInformation.Video.Width = "video.width"
FN.VideoInformation.Video.UnencryptedPreMp4 = "video.unencryptedPreMp4"
FN.VideoInformation.VideoCount = "videoCount"
FN.VideoInformation.UnencryptedImage = "unencryptedImage"
TN.VideoInformation = "video_information"
}
+85
View File
@@ -0,0 +1,85 @@
package videoinformationmod
import (
"time"
)
// @table:video_information
type VideoInformation struct {
Id int64 `json:"id" bson:"_id,omitempty"`
Title string `json:"title" bson:"title"` // 帖子标题
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
Tags []int64 `json:"tags" bson:"tags"` // 标签
IsHot bool `json:"isHot" bson:"isHot"` // 是否热门
Sort int64 `json:"sort" bson:"sort"` // 排序
Real Flow `json:"real" bson:"real"` // 真实流量
VideoCount int64 `json:"videoCount" bson:"videoCount"` // 合集视频数量
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
PageUpdatedAt time.Time `json:"pageUpdatedAt" bson:"pageUpdatedAt"` // 页面展示更新时间
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
IsTop bool `json:"isTop" bson:"isTop"` // 是否置顶
}
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
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
VttFile string `bson:"vttFile" json:"vttFile"` // 雪碧图
TotalFrames int64 `bson:"totalFrames,omitempty" json:"totalFrames"` // 总帧数
}
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"` // 评论条数
WeekWatchs int64 `json:"weekWatchs" bson:"weekWatchs"` // 本周观看次数
MonthWatchs int64 `json:"monthWatchs" bson:"monthWatchs"` // 本月观看次数
TodayWatchs int64 `json:"todayWatchs" bson:"todayWatchs"` // 当日观看次数
}
type MediaType int64
const (
MediaType_Video MediaType = 0 // 视频
MediaType_Collection MediaType = 1 // 合集
MediaType_Advitise MediaType = 2 // 广告
)