init: web_hgcg_server 初始化提交
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package playletchaptercollectmod
|
||||
|
||||
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_chapter_collect 集合和常用查询索引
|
||||
func Init(ctx context.Context) {
|
||||
coll = mongos.Shop.Coll(TN.PlayletChapterCollect)
|
||||
initIndex(ctx)
|
||||
}
|
||||
|
||||
func initIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterCollect.UserId, Value: 1},
|
||||
{Key: FN.PlayletChapterCollect.ChapterId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterCollect.ChapterId, Value: 1},
|
||||
{Key: FN.PlayletChapterCollect.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterCollect.PlayletId, Value: 1},
|
||||
{Key: FN.PlayletChapterCollect.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterCollect.UserId, Value: 1},
|
||||
{Key: FN.PlayletChapterCollect.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(playletchaptercollectmod:initIndex) 创建索引失败 err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOnePlayletChapterCollect 插入一条短剧剧集收藏关系
|
||||
func InsertOnePlayletChapterCollect(ctx context.Context, doc *PlayletChapterCollect) (bool, *srvdef.SrvErr) {
|
||||
if doc.Id == 0 {
|
||||
doc.Id = mongos.Lid.PlayletChapterCollect.Get()
|
||||
}
|
||||
now := time.Now()
|
||||
if doc.CreatedAt.IsZero() {
|
||||
doc.CreatedAt = now
|
||||
}
|
||||
doc.UpdatedAt = now
|
||||
if _, err := coll.InsertOne(ctx, doc); err != nil {
|
||||
if mongo.IsDuplicateKeyError(err) {
|
||||
return false, nil
|
||||
}
|
||||
log.Warn("插入短剧剧集收藏关系失败", log.Any("doc", doc), log.E(err))
|
||||
return false, srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DeleteOnePlayletChapterCollect 删除一条短剧剧集收藏关系
|
||||
func DeleteOnePlayletChapterCollect(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
count, err := coll.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("删除短剧剧集收藏关系失败", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// DeleteManyPlayletChapterCollect 按条件批量删除短剧剧集收藏关系
|
||||
func DeleteManyPlayletChapterCollect(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
count, err := coll.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("批量删除短剧剧集收藏关系失败", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindManyPlayletChapterCollect 按条件查询短剧剧集收藏关系
|
||||
func FindManyPlayletChapterCollect(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (PlayletChapterCollectList, *srvdef.SrvErr) {
|
||||
data := make(PlayletChapterCollectList, 0)
|
||||
if err := coll.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("查询短剧剧集收藏关系列表失败", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountPlayletChapterCollect 统计满足条件的短剧剧集收藏关系数量
|
||||
func CountPlayletChapterCollect(ctx context.Context, filter bson.M, opts ...*options.CountOptions) (int64, *srvdef.SrvErr) {
|
||||
count, err := coll.Count(ctx, filter, opts...)
|
||||
if err != nil {
|
||||
log.Warn("统计短剧剧集收藏关系数量失败", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package playletchaptercollectmod
|
||||
|
||||
// TagPlayletChapterCollect 保存 playlet_chapter_collect 集合字段名
|
||||
type TagPlayletChapterCollect struct {
|
||||
Id string
|
||||
UserId string
|
||||
PlayletId string
|
||||
ChapterId string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
PlayletChapterCollect TagPlayletChapterCollect
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
PlayletChapterCollect string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.PlayletChapterCollect.Id = "_id"
|
||||
FN.PlayletChapterCollect.UserId = "userId"
|
||||
FN.PlayletChapterCollect.PlayletId = "playletId"
|
||||
FN.PlayletChapterCollect.ChapterId = "chapterId"
|
||||
FN.PlayletChapterCollect.CreatedAt = "createdAt"
|
||||
FN.PlayletChapterCollect.UpdatedAt = "updatedAt"
|
||||
|
||||
TN.PlayletChapterCollect = "playlet_chapter_collect"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package playletchaptercollectmod
|
||||
|
||||
import "time"
|
||||
|
||||
// PlayletChapterCollect @table: playlet_chapter_collect
|
||||
//
|
||||
// PlayletChapterCollect 短剧剧集收藏关系模型
|
||||
type PlayletChapterCollect struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // 收藏记录ID
|
||||
UserId int64 `json:"userId" bson:"userId"` // 用户ID
|
||||
PlayletId int64 `json:"playletId" bson:"playletId"` // 短剧ID
|
||||
ChapterId int64 `json:"chapterId" bson:"chapterId"` // 短剧剧集ID
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 修改时间
|
||||
}
|
||||
|
||||
// PlayletChapterCollectList 短剧剧集收藏关系列表
|
||||
type PlayletChapterCollectList []*PlayletChapterCollect
|
||||
Reference in New Issue
Block a user