Initial commit: web_hghl_server

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 16:28:14 +08:00
co-authored by Claude Opus 4.7
commit 65fca60622
653 changed files with 135901 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
package playletlikemod
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_like 集合和常用查询索引
func Init(ctx context.Context) {
coll = mongos.Shop.Coll(TN.PlayletLike)
initIndex(ctx)
}
func initIndex(ctx context.Context) {
indexes := []mongo.IndexModel{
{Keys: bson.D{{Key: FN.PlayletLike.UserID, Value: 1}, {Key: FN.PlayletLike.PlayletID, Value: 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{{Key: FN.PlayletLike.PlayletID, Value: 1}}},
{Keys: bson.D{{Key: FN.PlayletLike.CreatedAt, Value: -1}, {Key: FN.PlayletLike.PlayletID, Value: 1}}},
{Keys: bson.D{{Key: FN.PlayletLike.UserID, Value: 1}, {Key: FN.PlayletLike.CreatedAt, Value: -1}, {Key: FN.PlayletLike.Id, Value: -1}}},
}
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(playletlikemod:initIndex) Create Index failed! err:%+v:", err))
}
}
// UpsertOnePlayletLike 按用户ID和短剧ID写入点赞关系,返回是否新增点赞
func UpsertOnePlayletLike(ctx context.Context, userId, playletId int64, now time.Time) (bool, *srvdef.SrvErr) {
filter := bson.M{FN.PlayletLike.UserID: userId, FN.PlayletLike.PlayletID: playletId}
update := bson.M{
"$set": bson.M{FN.PlayletLike.UpdatedAt: now},
"$setOnInsert": bson.M{
FN.PlayletLike.Id: mongos.Lid.PlayletLike.Get(),
FN.PlayletLike.UserID: userId,
FN.PlayletLike.PlayletID: playletId,
FN.PlayletLike.CreatedAt: now,
},
}
result, err := coll.UpdateOne(ctx, filter, update, options.Update().SetUpsert(true))
if err != nil {
log.Warn("playletlikemod:UpsertOnePlayletLike db.UpdateOne failed", log.Any("filter", filter), log.E(err))
return false, srvdef.New(srvdef.ErrDbUpdateError, "", "")
}
return result.UpsertedCount > 0, nil
}
// DeleteOnePlayletLike 删除一条短剧点赞关系,返回是否实际删除
func DeleteOnePlayletLike(ctx context.Context, filter bson.M) (bool, *srvdef.SrvErr) {
result, err := coll.DeleteOne(ctx, filter)
if err != nil {
log.Warn("playletlikemod:DeleteOnePlayletLike db.DeleteOne failed", log.Any("filter", filter), log.E(err))
return false, srvdef.New(srvdef.ErrDbDeleteError, "", "")
}
return result > 0, nil
}
// CountPlayletLike 统计短剧点赞关系数量
func CountPlayletLike(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
count, err := coll.Count(ctx, filter)
if err != nil {
log.Warn("playletlikemod:CountPlayletLike db.Count failed", log.Any("filter", filter), log.E(err))
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return count, nil
}
// AggregatePlayletLike 聚合查询短剧点赞关系
func AggregatePlayletLike(ctx context.Context, bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
if err := coll.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("playletlikemod:AggregatePlayletLike db.Aggregate failed", log.Any("pipeline", pipeline), log.E(err))
return srvdef.New(srvdef.ErrDbQueryError, "", "")
}
return nil
}
+28
View File
@@ -0,0 +1,28 @@
package playletlikemod
// TagPlayletLike 保存 playlet_like 集合字段名
type TagPlayletLike struct {
Id string
UserID string
PlayletID string
CreatedAt string
UpdatedAt string
}
var FN struct {
PlayletLike TagPlayletLike
}
var TN struct {
PlayletLike string
}
func init() {
FN.PlayletLike.Id = "_id"
FN.PlayletLike.UserID = "userId"
FN.PlayletLike.PlayletID = "playletId"
FN.PlayletLike.CreatedAt = "createdAt"
FN.PlayletLike.UpdatedAt = "updatedAt"
TN.PlayletLike = "playlet_like"
}
+15
View File
@@ -0,0 +1,15 @@
package playletlikemod
import "time"
// PlayletLike 短剧点赞关系
type PlayletLike struct {
Id int64 `json:"id" bson:"_id,omitempty"`
UserID int64 `json:"userId" bson:"userId"` // 用户ID
PlayletID int64 `json:"playletId" bson:"playletId"` // 短剧ID
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}
// PlayletLikeList 短剧点赞列表
type PlayletLikeList []*PlayletLike