init: import web_huangguo2 server project
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package playletchapterlikemod
|
||||
|
||||
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_like 集合和常用查询索引
|
||||
func Init(ctx context.Context) {
|
||||
coll = mongos.Shop.Coll(TN.PlayletChapterLike)
|
||||
initIndex(ctx)
|
||||
}
|
||||
|
||||
func initIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterLike.UserId, Value: 1},
|
||||
{Key: FN.PlayletChapterLike.ChapterId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterLike.ChapterId, Value: 1},
|
||||
{Key: FN.PlayletChapterLike.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterLike.PlayletId, Value: 1},
|
||||
{Key: FN.PlayletChapterLike.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.PlayletChapterLike.UserId, Value: 1},
|
||||
{Key: FN.PlayletChapterLike.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(playletchapterlikemod:initIndex) 创建索引失败 err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOnePlayletChapterLike 插入一条短剧剧集点赞关系
|
||||
func InsertOnePlayletChapterLike(ctx context.Context, doc *PlayletChapterLike) (bool, *srvdef.SrvErr) {
|
||||
if doc.Id == 0 {
|
||||
doc.Id = mongos.Lid.PlayletChapterLike.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
|
||||
}
|
||||
|
||||
// DeleteOnePlayletChapterLike 删除一条短剧剧集点赞关系
|
||||
func DeleteOnePlayletChapterLike(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
|
||||
}
|
||||
|
||||
// DeleteManyPlayletChapterLike 按条件批量删除短剧剧集点赞关系
|
||||
func DeleteManyPlayletChapterLike(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
|
||||
}
|
||||
|
||||
// FindManyPlayletChapterLike 按条件查询短剧剧集点赞关系
|
||||
func FindManyPlayletChapterLike(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (PlayletChapterLikeList, *srvdef.SrvErr) {
|
||||
data := make(PlayletChapterLikeList, 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
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package playletchapterlikemod
|
||||
|
||||
// TagPlayletChapterLike 保存 playlet_chapter_like 集合字段名
|
||||
type TagPlayletChapterLike struct {
|
||||
Id string
|
||||
UserId string
|
||||
PlayletId string
|
||||
ChapterId string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
PlayletChapterLike TagPlayletChapterLike
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
PlayletChapterLike string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.PlayletChapterLike.Id = "_id"
|
||||
FN.PlayletChapterLike.UserId = "userId"
|
||||
FN.PlayletChapterLike.PlayletId = "playletId"
|
||||
FN.PlayletChapterLike.ChapterId = "chapterId"
|
||||
FN.PlayletChapterLike.CreatedAt = "createdAt"
|
||||
FN.PlayletChapterLike.UpdatedAt = "updatedAt"
|
||||
|
||||
TN.PlayletChapterLike = "playlet_chapter_like"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package playletchapterlikemod
|
||||
|
||||
import "time"
|
||||
|
||||
// PlayletChapterLike @table: playlet_chapter_like
|
||||
//
|
||||
// PlayletChapterLike 短剧剧集点赞关系模型
|
||||
type PlayletChapterLike 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"` // 修改时间
|
||||
}
|
||||
|
||||
// PlayletChapterLikeList 短剧剧集点赞关系列表
|
||||
type PlayletChapterLikeList []*PlayletChapterLike
|
||||
Reference in New Issue
Block a user