Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
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.Name, Value: 1}},
|
||||
Options: options.Index().
|
||||
SetName("uniq_video_category_name").
|
||||
SetUnique(true).
|
||||
SetPartialFilterExpression(bson.M{FN.VideoCategory.Name: bson.M{"$type": "string", "$gt": ""}}),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.Status, Value: 1},
|
||||
{Key: FN.VideoCategory.Rank, 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 {
|
||||
if mongo.IsDuplicateKeyError(err) {
|
||||
log.Warn("VideoCategorymod:InsertOneVideoCategory duplicate key", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInputExist, "视频分类已存在")
|
||||
}
|
||||
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
+54
@@ -0,0 +1,54 @@
|
||||
package videocategorymod
|
||||
|
||||
type TagVideoCategory struct {
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
DisplayPosition string
|
||||
IndexNow string
|
||||
Name string
|
||||
Slug string
|
||||
Rank string
|
||||
SortType string
|
||||
Tags string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
TranslationCategoryId string
|
||||
DisplayMode string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCategory TagVideoCategory
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCategory string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCategory.CreatedAt = "createdAt"
|
||||
FN.VideoCategory.Desc = "desc"
|
||||
FN.VideoCategory.Id = "_id"
|
||||
FN.VideoCategory.DisplayPosition = "displayPosition"
|
||||
FN.VideoCategory.IndexNow = "indexNow"
|
||||
FN.VideoCategory.Name = "name"
|
||||
FN.VideoCategory.Slug = "slug"
|
||||
FN.VideoCategory.Rank = "rank"
|
||||
FN.VideoCategory.SortType = "sortType"
|
||||
FN.VideoCategory.Tags = "tags"
|
||||
FN.VideoCategory.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoCategory.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoCategory.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoCategory.Status = "status"
|
||||
FN.VideoCategory.Title = "title"
|
||||
FN.VideoCategory.UpdatedAt = "updatedAt"
|
||||
FN.VideoCategory.TranslationCategoryId = "translationCategoryId"
|
||||
FN.VideoCategory.DisplayMode = "displayMode"
|
||||
TN.VideoCategory = "video_category"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package videocategorymod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// VideoCategory 视频分类集合
|
||||
// @table:video_category
|
||||
type VideoCategory struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
Slug string `json:"slug" bson:"slug"` // slug
|
||||
Title string `json:"title" bson:"title"` // APP显示
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
DisplayPosition pubdef.CategoryDisplayPosition `json:"displayPosition" bson:"displayPosition"` // 显示位置 0=仅TAB 1=仅首页 2=两者都显示
|
||||
SortType pubdef.CategorySortType `json:"sortType" bson:"sortType"` // 排序方式
|
||||
Tags []int64 `json:"tags" bson:"tags"` // 关联视频标签
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
TranslationCategoryId int64 `json:"translationCategoryId" bson:"translationCategoryId"` // 导航分类
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
DisplayMode pubdef.DisplayMode `json:"displayMode" bson:"displayMode"` // 展示方式 0:默认 1:卡片层叠轮播 2:头像列表 3:图文列表 4:大封面列表
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoCategoryList []*VideoCategory
|
||||
Reference in New Issue
Block a user