@@ -0,0 +1,132 @@
|
||||
package videocategorymod
|
||||
|
||||
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.VideoCategory)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.ContentType, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCategoryIndex) Create VideoCategory Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCategory 插入一个渠道统计
|
||||
func InsertOneVideoCategory(ctx context.Context, qa *VideoCategory) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoCategorymod:InsertOneVideoCategory db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCategory 删除一个渠道统计
|
||||
func DelOneVideoCategory(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCategorymod:DelOneVideoCategory db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCategory 查找一个渠道统计
|
||||
func FindOneVideoCategory(ctx context.Context, filter bson.M) (
|
||||
*VideoCategory, *srvdef.SrvErr) {
|
||||
var VideoCategory VideoCategory
|
||||
if err := db.FindOneEx(ctx, &VideoCategory, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCategorymod:FindOneVideoCategory db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCategory, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCategorys(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCategoryList, *srvdef.SrvErr) {
|
||||
data := make(VideoCategoryList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCategorys", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCategorys 统计渠道统计数量
|
||||
func CountVideoCategorys(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCategorys db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCategory 更新一个渠道统计
|
||||
func UpdateOneVideoCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoCategory 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
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
package videocategorymod
|
||||
|
||||
type TagVideoCategory struct {
|
||||
ContentType string
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
IndexNow string
|
||||
Name string
|
||||
Rank string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
SortType string
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCategory TagVideoCategory
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCategory string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCategory.ContentType = "contentType"
|
||||
FN.VideoCategory.CreatedAt = "createdAt"
|
||||
FN.VideoCategory.Desc = "desc"
|
||||
FN.VideoCategory.Id = "_id"
|
||||
FN.VideoCategory.IndexNow = "indexNow"
|
||||
FN.VideoCategory.Name = "name"
|
||||
FN.VideoCategory.Rank = "rank"
|
||||
FN.VideoCategory.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoCategory.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoCategory.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoCategory.SortType = "sortType"
|
||||
FN.VideoCategory.Status = "status"
|
||||
FN.VideoCategory.Title = "title"
|
||||
FN.VideoCategory.UpdatedAt = "updatedAt"
|
||||
TN.VideoCategory = "video_category"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package videocategorymod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_category
|
||||
type VideoCategory struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
Title string `json:"title" bson:"title"` // APP显示
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
ContentType int64 `json:"contentType" bson:"contentType"` // 内容:0: 默认 1:首页 2:今日 3:合集
|
||||
SortType int64 `json:"sortType" bson:"sortType"` // 排序方式 0:上线时间 1:观看次数 2排序
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoCategoryList []*VideoCategory
|
||||
type VideoSortType int32
|
||||
|
||||
const (
|
||||
VideoSortTypeAddTime VideoSortType = 0 // 上线时间
|
||||
VideoSortTypeWatchs VideoSortType = 1 // 观看次数
|
||||
VideoSortTypeRank VideoSortType = 2 // 视频排序
|
||||
)
|
||||
Reference in New Issue
Block a user