来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
133 lines
4.0 KiB
Go
133 lines
4.0 KiB
Go
package videocreatermod
|
|
|
|
import (
|
|
"context"
|
|
"hkdj-web-server/pub/common/log"
|
|
"hkdj-web-server/pub/common/srvdef"
|
|
"hkdj-web-server/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.VideoCreaterInfo)
|
|
// 获取数据库表
|
|
indexes := []mongo.IndexModel{
|
|
{
|
|
Keys: bson.D{
|
|
{Key: FN.VideoCreaterInfo.Status, Value: 1},
|
|
},
|
|
},
|
|
{
|
|
Keys: bson.D{
|
|
{Key: FN.VideoCreaterInfo.CreatedAt, Value: -1},
|
|
},
|
|
},
|
|
{
|
|
Keys: bson.D{
|
|
{Key: FN.VideoCreaterInfo.Slug, Value: 1},
|
|
},
|
|
},
|
|
}
|
|
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
|
panic(fmt.Sprintf("(channelmod:initVideoCreaterInfoIndex) Create VideoCreaterInfo Index failed! err:%+v:", err))
|
|
}
|
|
|
|
}
|
|
|
|
// InsertOneVideoCreaterInfo 插入一个渠道统计
|
|
func InsertOneVideoCreaterInfo(ctx context.Context, qa *VideoCreaterInfo) *srvdef.SrvErr {
|
|
if _, err := db.InsertOne(ctx, qa); err != nil {
|
|
log.Warn("VideoCreaterInfomod:InsertOneVideoCreaterInfo db.InsertOne failed", log.E(err))
|
|
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DelOneVideoCreaterInfo 删除一个渠道统计
|
|
func DelOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
|
int64, *srvdef.SrvErr) {
|
|
count, err := db.DeleteOne(ctx, filter)
|
|
if err != nil {
|
|
log.Warn("VideoCreaterInfomod:DelOneVideoCreaterInfo db.DeleteOne failed",
|
|
log.E(err), log.Any("filter", filter))
|
|
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
|
}
|
|
return count, nil
|
|
}
|
|
|
|
// FindOneVideoCreaterInfo 查找一个渠道统计
|
|
func FindOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
|
*VideoCreaterInfo, *srvdef.SrvErr) {
|
|
var VideoCreaterInfo VideoCreaterInfo
|
|
if err := db.FindOneEx(ctx, &VideoCreaterInfo, filter); err != nil {
|
|
if err != mongo.ErrNoDocuments {
|
|
log.Warn("VideoCreaterInfomod:FindOneVideoCreaterInfo db.FindOne failed",
|
|
log.E(err), log.Any("filter", filter))
|
|
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
|
}
|
|
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
|
}
|
|
return &VideoCreaterInfo, nil
|
|
}
|
|
|
|
func FindManyVideoCreaterInfos(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCreaterInfoList, *srvdef.SrvErr) {
|
|
data := make(VideoCreaterInfoList, 0)
|
|
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
|
log.Warn("faq:FindManyVideoCreaterInfos", log.E(err), log.Any("filter", filter))
|
|
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
// CountVideoCreaterInfos 统计渠道统计数量
|
|
func CountVideoCreaterInfos(ctx context.Context, filter bson.M) (
|
|
int64, *srvdef.SrvErr) {
|
|
count, err := db.Count(ctx, filter)
|
|
if err != nil {
|
|
log.Warn("faqmod:CountVideoCreaterInfos db.Count failed",
|
|
log.E(err), log.Any("filter", filter))
|
|
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
|
}
|
|
return count, nil
|
|
}
|
|
|
|
// UpdateOneVideoCreaterInfo 更新一个渠道统计
|
|
func UpdateOneVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
|
result, err := db.UpdateOne(ctx, filter, update)
|
|
if err != nil {
|
|
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
|
log.E(err), log.Any("filter", filter))
|
|
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
|
}
|
|
if result.MatchedCount != 1 {
|
|
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
|
log.E(err), log.Any("filter", filter))
|
|
return srvdef.New(srvdef.ErrNoData, "", "")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func UpdateManyVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
|
result, err := db.UpdateMany(ctx, filter, update)
|
|
if err != nil {
|
|
log.Warn("post:UpdateManyVideoCreaterInfo 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
|
|
}
|