Initial commit

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-23 11:07:42 +08:00
co-authored by Claude Opus 5.5
commit 7974a42301
633 changed files with 120248 additions and 0 deletions
+126
View File
@@ -0,0 +1,126 @@
package playletcategorymod
import (
"context"
"fmt"
"time"
"videoweb/pub/common/log"
"videoweb/pub/common/srvdef"
"videoweb/pub/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var coll *mongos.Collection
// Init 初始化 playlet_category 集合和后台常用查询索引。
func Init(ctx context.Context) {
coll = mongos.Shop.Coll(TN.PlayletCategory)
initIndex(ctx)
}
func initIndex(ctx context.Context) {
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.PlayletCategory.Status, Value: 1},
{Key: FN.PlayletCategory.Rank, Value: -1},
{Key: FN.PlayletCategory.Id, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.PlayletCategory.Name, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.PlayletCategory.Slug, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.PlayletCategory.CreatedAt, Value: -1},
{Key: FN.PlayletCategory.Id, Value: -1},
},
},
}
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(playletcategorymod:initIndex) Create Index failed! err:%+v:", err))
}
}
// InsertOnePlayletCategory 插入一条短剧分类数据。
func InsertOnePlayletCategory(ctx context.Context, doc *PlayletCategory) *srvdef.SrvErr {
if doc.Id == 0 {
doc.Id = mongos.Lid.PlayletCategory.Get()
}
now := time.Now()
if doc.CreatedAt.IsZero() {
doc.CreatedAt = now
}
doc.UpdatedAt = now
if _, err := coll.InsertOne(ctx, doc); err != nil {
log.Warn("playletcategorymod:InsertOnePlayletCategory failed", log.Any("doc", doc), log.E(err))
return srvdef.New(srvdef.ErrDbInsertError, "", "")
}
return nil
}
// DelOnePlayletCategory 删除一条短剧分类数据。
func DelOnePlayletCategory(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
count, err := coll.DeleteOne(ctx, filter)
if err != nil {
log.Warn("playletcategorymod:DelOnePlayletCategory failed", log.E(err), log.Any("filter", filter))
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
}
return count, nil
}
// FindOnePlayletCategory 查询一条短剧分类数据。
func FindOnePlayletCategory(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (*PlayletCategory, *srvdef.SrvErr) {
var doc PlayletCategory
if err := coll.FindOneEx(ctx, &doc, filter, opts...); err != nil {
if err != mongo.ErrNoDocuments {
log.Warn("playletcategorymod:FindOnePlayletCategory failed", log.E(err), log.Any("filter", filter))
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return nil, srvdef.New(srvdef.ErrNoData, "", "")
}
return &doc, nil
}
// FindManyPlayletCategory 按条件查询多条短剧分类数据。
func FindManyPlayletCategory(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (PlayletCategoryList, *srvdef.SrvErr) {
data := make(PlayletCategoryList, 0)
if err := coll.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("playletcategorymod:FindManyPlayletCategory failed", log.E(err), log.Any("filter", filter))
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return data, nil
}
// CountPlayletCategory 统计满足条件的短剧分类数量。
func CountPlayletCategory(ctx context.Context, filter bson.M, opts ...*options.CountOptions) (int64, *srvdef.SrvErr) {
count, err := coll.Count(ctx, filter, opts...)
if err != nil {
log.Warn("playletcategorymod:CountPlayletCategory failed", log.E(err), log.Any("filter", filter))
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return count, nil
}
// UpdateOnePlayletCategory 更新一条短剧分类数据。
func UpdateOnePlayletCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
result, err := coll.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("playletcategorymod:UpdateOnePlayletCategory failed", log.E(err), log.Any("filter", filter))
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
}
if result.MatchedCount != 1 {
return srvdef.New(srvdef.ErrNoData, "", "")
}
return nil
}
+46
View File
@@ -0,0 +1,46 @@
package playletcategorymod
// TagPlayletCategory 保存 playlet_category 集合字段名。
type TagPlayletCategory struct {
Id string
Name string
Slug string
Desc string
Icon string
Status string
Rank string
Remark string
SeoInfo struct {
Description string
Keyworld string
Title string
}
CreatedAt string
UpdatedAt string
}
var FN struct {
PlayletCategory TagPlayletCategory
}
var TN struct {
PlayletCategory string
}
func init() {
FN.PlayletCategory.Id = "_id"
FN.PlayletCategory.Name = "name"
FN.PlayletCategory.Slug = "slug"
FN.PlayletCategory.Desc = "desc"
FN.PlayletCategory.Icon = "icon"
FN.PlayletCategory.Status = "status"
FN.PlayletCategory.Rank = "rank"
FN.PlayletCategory.Remark = "remark"
FN.PlayletCategory.SeoInfo.Description = "seoInfo.webDescription"
FN.PlayletCategory.SeoInfo.Keyworld = "seoInfo.webKeyworld"
FN.PlayletCategory.SeoInfo.Title = "seoInfo.webTitle"
FN.PlayletCategory.CreatedAt = "createdAt"
FN.PlayletCategory.UpdatedAt = "updatedAt"
TN.PlayletCategory = "playlet_category"
}
+26
View File
@@ -0,0 +1,26 @@
package playletcategorymod
import (
"time"
"videoweb/pub/pubdef"
)
// PlayletCategory @table: playlet_category
//
// PlayletCategory 短剧分类集合模型
type PlayletCategory struct {
Id int64 `json:"id" bson:"_id,omitempty"`
Name string `json:"name" bson:"name"` // 分类名称
Slug string `json:"slug" bson:"slug"` // slug
Desc string `json:"desc" bson:"desc"` // 描述
Icon string `json:"icon" bson:"icon"` // 分类图标
Status bool `json:"status" bson:"status"` // 启用状态
Rank int64 `json:"rank" bson:"rank"` // 排序,越大越靠前
Remark string `json:"remark" bson:"remark"` // 备注
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 修改时间
}
// PlayletCategoryList 短剧分类列表
type PlayletCategoryList []*PlayletCategory