Initial commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package landpageImg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, TN.LandpageImg)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.LandpageImg.Name, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(LandpageImg:initLandpageImgIndex) Create LandpageImg Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
//InsertOneLandpageImg 插入一个落地页资源配置
|
||||
func InsertOneLandpageImg(ctx context.Context, LandpageImg *LandpageImg) error {
|
||||
if _, err := db.InsertOne(ctx, LandpageImg); err != nil {
|
||||
log.Warn("LandpageImg:InsertOneLandpageImg db.InsertOne failed", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindOneLandpageImg 查找一个落地页资源配置
|
||||
func FindOneLandpageImg(ctx context.Context, filter bson.M) (
|
||||
*LandpageImg, error) {
|
||||
var LandpageImg LandpageImg
|
||||
if err := db.FindOne(ctx, &LandpageImg, filter); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LandpageImg, nil
|
||||
}
|
||||
|
||||
//DelOneLandpageImg 删除一个落地页资源配置
|
||||
func DelOneLandpageImg(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("LandpageImg:DelOneLandpageImg db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateOneLandpageImg 更新一个落地页资源配置
|
||||
func UpdateOneLandpageImg(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateOneLandpageImg db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//CountLandpageImgs 统计落地页资源配置数量
|
||||
func CountLandpageImgs(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("LandpageImg:CountLandpageImgs db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateManyLandpageImg 更新满足条件的落地页资源配置
|
||||
func UpdateManyLandpageImg(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateManyLandpageImg db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindManyLandpageImg 查找一批落地页资源配置数据
|
||||
func FindManyLandpageImg(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (LandpageImgList, error) {
|
||||
data := make(LandpageImgList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("LandpageImg:FindManyLandpageImg db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//FindManyLandpageImgWithBind 用自己定义结构查找一批落地页资源配置数据
|
||||
func FindManyLandpageImgWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) error {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("LandpageImg:FindManyLandpageImgWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//AggregateLandpageImgs 聚合查找一批落地页资源配置信息
|
||||
func AggregateLandpageImgs(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) error {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateLandpageImgs db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
package landpageImg
|
||||
|
||||
type TagLandpageImg struct {
|
||||
CreatedAt string
|
||||
ID string
|
||||
MobileAvatar string
|
||||
MobileBackgroud string
|
||||
MobileTiltle string
|
||||
Music string
|
||||
Name string
|
||||
PcAvatar string
|
||||
PcBackgroud string
|
||||
PcTitle string
|
||||
Rank string
|
||||
Status string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
LandpageImg TagLandpageImg
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
LandpageImg string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.LandpageImg.CreatedAt = "createdAt"
|
||||
FN.LandpageImg.ID = "_id"
|
||||
FN.LandpageImg.MobileAvatar = "mobileAvatar"
|
||||
FN.LandpageImg.MobileBackgroud = "mobileBackgroud"
|
||||
FN.LandpageImg.MobileTiltle = "mobileTiltle"
|
||||
FN.LandpageImg.Music = "music"
|
||||
FN.LandpageImg.Name = "name"
|
||||
FN.LandpageImg.PcAvatar = "pcAvatar"
|
||||
FN.LandpageImg.PcBackgroud = "pcBackgroud"
|
||||
FN.LandpageImg.PcTitle = "pcTitle"
|
||||
FN.LandpageImg.Rank = "rank"
|
||||
FN.LandpageImg.Status = "status"
|
||||
FN.LandpageImg.UpdatedAt = "updatedAt"
|
||||
TN.LandpageImg = "landpage_img"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package landpageImg
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 帖子模型,数据库中的
|
||||
// @table:landpage_img
|
||||
type LandpageImg struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
|
||||
Name string `json:"name" bson:"name"` // 图片名称
|
||||
PcAvatar string `json:"pcAvatar" bson:"pcAvatar"` // PC端图片
|
||||
MobileAvatar string `json:"mobileAvatar" bson:"mobileAvatar"` // 移动端图片
|
||||
PcBackgroud string `json:"pcBackgroud" bson:"pcBackgroud"` // PC端背景图
|
||||
MobileBackgroud string `json:"mobileBackgroud" bson:"mobileBackgroud"` // 移动端背景图
|
||||
PcTitle string `json:"pcTitle" bson:"pcTitle"` // PC端标语
|
||||
MobileTiltle string `json:"mobileTiltle" bson:"mobileTiltle"` // 移动端标语
|
||||
Music string `json:"music" bson:"music"` // 音频文件
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
Status bool `json:"status" bson:"status"` // 是否启用
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type LandpageImgList []*LandpageImg
|
||||
Reference in New Issue
Block a user