Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
type TagVideoCollectionMediaModel struct {
|
||||
ID string
|
||||
CollectionID string
|
||||
VideoId string
|
||||
Status string
|
||||
Rank string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCollectionMediaModel TagVideoCollectionMediaModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCollectionMediaModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCollectionMediaModel.ID = "_id"
|
||||
FN.VideoCollectionMediaModel.CollectionID = "collectionId"
|
||||
FN.VideoCollectionMediaModel.VideoId = "videoId"
|
||||
FN.VideoCollectionMediaModel.Status = "status"
|
||||
FN.VideoCollectionMediaModel.Rank = "rank"
|
||||
FN.VideoCollectionMediaModel.CreatedAt = "createdAt"
|
||||
FN.VideoCollectionMediaModel.UpdatedAt = "updatedAt"
|
||||
TN.VideoCollectionMediaModel = "video_collection_media"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// VideoCollectionMediaModel 视频合集资源
|
||||
// @table:video_collection_media
|
||||
type VideoCollectionMediaModel struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 唯一ID
|
||||
CollectionID int64 `json:"collectionId" bson:"collectionId"` // 合集ID
|
||||
VideoId int64 `json:"videoId" bson:"videoId"` // 视频ID
|
||||
Status pubdef.InformationStatus `json:"status" bson:"status"` // 状态
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 刷新时间
|
||||
|
||||
}
|
||||
type VideoCollectionMediaModelList []*VideoCollectionMediaModel
|
||||
@@ -0,0 +1,154 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
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.VideoCollectionMediaModel)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
{Key: FN.VideoCollectionMediaModel.Rank, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
{Key: FN.VideoCollectionMediaModel.VideoId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.VideoId, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCollectionMediaModelIndex) Create VideoCollectionMediaModel Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCollectionMediaModel 插入一个渠道统计
|
||||
func InsertOneVideoCollectionMediaModel(ctx context.Context, qa *VideoCollectionMediaModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoCollectionMediaModelmod:InsertOneVideoCollectionMediaModel db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCollectionMediaModel 删除一个渠道统计
|
||||
func DelOneVideoCollectionMediaModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCollectionMediaModelmod:DelOneVideoCollectionMediaModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
func DelManyVideoCollectionMediaModel(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCollectionMediaModelmod:DelManyVideoCollectionMediaModel db.DeleteMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCollectionMediaModel 查找一个渠道统计
|
||||
func FindOneVideoCollectionMediaModel(ctx context.Context, filter bson.M) (
|
||||
*VideoCollectionMediaModel, *srvdef.SrvErr) {
|
||||
var VideoCollectionMediaModel VideoCollectionMediaModel
|
||||
if err := db.FindOneEx(ctx, &VideoCollectionMediaModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCollectionMediaModelmod:FindOneVideoCollectionMediaModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCollectionMediaModel, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCollectionMediaModels(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCollectionMediaModelList, *srvdef.SrvErr) {
|
||||
data := make(VideoCollectionMediaModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCollectionMediaModels", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCollectionMediaModels 统计渠道统计数量
|
||||
func CountVideoCollectionMediaModels(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCollectionMediaModels db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCollectionMediaModel 更新一个渠道统计
|
||||
func UpdateOneVideoCollectionMediaModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCollectionMediaModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCollectionMediaModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertManyVideoCollectionMedia(ctx context.Context, list []*VideoCollectionMediaModel) *srvdef.SrvErr {
|
||||
_, err := db.InsertMany(ctx, &list)
|
||||
if err != nil {
|
||||
log.Warn("post:InsertManyVideoCollectionMediaModel db.InsertMany failed",
|
||||
log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user