Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
package richtextcontentmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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 db *mongos.Collection
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.Shop.Coll(TN.RichTextContentModel)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.RichTextContentModel.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.RichTextContentModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(RichTextContentModelModel:initRichTextContentModelModelIndex) Create RichTextContentModelModel Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneRichTextContentModelModel 插入定时任务
|
||||
func InsertOneRichTextContentModelModel(ctx context.Context, RichTextContentModelModel *RichTextContentModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, RichTextContentModelModel); err != nil {
|
||||
log.Warn("RichTextContentModelModel:InsertOneRichTextContentModelModel db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOneRichTextContentModelModel 插入定时任务
|
||||
func FindOneRichTextContentModelModel(ctx context.Context, filter bson.M) (
|
||||
*RichTextContentModel, *srvdef.SrvErr) {
|
||||
var RichTextContentModelModel RichTextContentModel
|
||||
if err := db.FindOneEx(ctx, &RichTextContentModelModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("RichTextContentModelModel:FindOneRichTextContentModelModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &RichTextContentModelModel, nil
|
||||
}
|
||||
|
||||
// DelOneRichTextContentModelModel 插入定时任务
|
||||
func DelOneRichTextContentModelModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:DelOneRichTextContentModelModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneRichTextContentModelModel 插入定时任务
|
||||
func UpdateOneRichTextContentModelModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:UpdateOneRichTextContentModelModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertOneRichTextContentModelModel 更新插入一个记录
|
||||
func UpsertOneRichTextContentModelModel(ctx context.Context, filter bson.M, upsertDoc bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpsertOne(ctx, filter, upsertDoc)
|
||||
if err != nil {
|
||||
log.Info("RichTextContentModelModel:UpsertOneRichTextContentModelModel db.UpsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountRichTextContentModelModels 统计用户数量
|
||||
func CountRichTextContentModelModels(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:CountRichTextContentModelModels db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateManyRichTextContentModelModel 更新满足条件的用户
|
||||
func UpdateManyRichTextContentModelModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:UpdateManyRichTextContentModelModel db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyRichTextContentModelModel 查找一批用户数据
|
||||
func FindManyRichTextContentModelModel(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (RichTextContentModelList, *srvdef.SrvErr) {
|
||||
data := make(RichTextContentModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("RichTextContentModelModel:FindManyRichTextContentModelModel db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindManyRichTextContentModelModelWithBind 用自己定义结构查找一批用户数据
|
||||
func FindManyRichTextContentModelModelWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) *srvdef.SrvErr {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("RichTextContentModelModel:FindManyRichTextContentModelModelWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateRichTextContentModelModels 聚合查找一批用户信息
|
||||
func AggregateRichTextContentModelModels(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateRichTextContentModelModels db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
package richtextcontentmod
|
||||
|
||||
type TagRichTextContentModel struct {
|
||||
Content string
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Sort string
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
RichTextContentModel TagRichTextContentModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
RichTextContentModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.RichTextContentModel.Content = "content"
|
||||
FN.RichTextContentModel.CreatedAt = "createdAt"
|
||||
FN.RichTextContentModel.Desc = "desc"
|
||||
FN.RichTextContentModel.Id = "_id"
|
||||
FN.RichTextContentModel.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.RichTextContentModel.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.RichTextContentModel.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.RichTextContentModel.Sort = "sort"
|
||||
FN.RichTextContentModel.Status = "status"
|
||||
FN.RichTextContentModel.Title = "title"
|
||||
FN.RichTextContentModel.UpdatedAt = "updatedAt"
|
||||
TN.RichTextContentModel = "rich_text_content"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package richtextcontentmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// RichTextContentModel 富文本内容
|
||||
// @table:rich_text_content
|
||||
type RichTextContentModel struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 标题(内部)
|
||||
Content string `json:"content" bson:"content"` // 内容
|
||||
Status bool `json:"status" bson:"status"` // 是否启用
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序值
|
||||
Desc string `json:"desc" bson:"desc"` // 标题(app)
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt" ` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" ` // 更新时间
|
||||
}
|
||||
|
||||
type RichTextContentModelList []*RichTextContentModel
|
||||
Reference in New Issue
Block a user