Initial commit
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
package landPageConfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
)
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, TN.LandPageConfig)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.LandPageConfig.Id, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(LandPageConfig:initLandPageConfigIndex) Create LandPageConfig Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
//InsertOneLandPageConfig 插入一个视频标签
|
||||
func InsertOneLandPageConfig(ctx context.Context, LandPageConfig *LandPageConfig) error {
|
||||
if _, err := db.InsertOne(ctx, LandPageConfig); err != nil {
|
||||
log.Warn("LandPageConfig:InsertOneLandPageConfig db.InsertOne failed", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindOneLandPageConfig 查找一个视频标签
|
||||
func FindOneLandPageConfig(ctx context.Context, filter bson.M) (
|
||||
*LandPageConfig, error) {
|
||||
var LandPageConfig LandPageConfig
|
||||
if err := db.FindOne(ctx, &LandPageConfig, filter); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LandPageConfig, nil
|
||||
}
|
||||
|
||||
//DelOneLandPageConfig 删除一个视频标签
|
||||
func DelOneLandPageConfig(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("LandPageConfig:DelOneLandPageConfig db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateOneLandPageConfig 更新一个视频标签
|
||||
func UpdateOneLandPageConfig(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateOneLandPageConfig db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//CountLandPageConfigs 统计视频标签数量
|
||||
func CountLandPageConfigs(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("LandPageConfig:CountLandPageConfigs db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateManyLandPageConfig 更新满足条件的视频标签
|
||||
func UpdateManyLandPageConfig(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateManyLandPageConfig db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindManyLandPageConfig 查找一批视频标签数据
|
||||
func FindManyLandPageConfig(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (LandPageConfigList, error) {
|
||||
data := make(LandPageConfigList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("LandPageConfig:FindManyLandPageConfig db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//FindManyLandPageConfigWithBind 用自己定义结构查找一批视频标签数据
|
||||
func FindManyLandPageConfigWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) error {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("LandPageConfig:FindManyLandPageConfigWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//AggregateLandPageConfigs 聚合查找一批视频标签信息
|
||||
func AggregateLandPageConfigs(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) error {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateLandPageConfigs db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
package landPageConfig
|
||||
|
||||
type TagLandPageConfig struct {
|
||||
Actor string
|
||||
AddedTime string
|
||||
AppId string
|
||||
Bango string
|
||||
CreateAt string
|
||||
Desc string
|
||||
Id string
|
||||
LandPageType string
|
||||
Media string
|
||||
Picture string
|
||||
Rank string
|
||||
Status string
|
||||
Title string
|
||||
UpdateAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
LandPageConfig TagLandPageConfig
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
LandPageConfig string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.LandPageConfig.Actor = "actor"
|
||||
FN.LandPageConfig.AddedTime = "addedTime"
|
||||
FN.LandPageConfig.AppId = "appId"
|
||||
FN.LandPageConfig.Bango = "bango"
|
||||
FN.LandPageConfig.CreateAt = "createAt"
|
||||
FN.LandPageConfig.Desc = "desc"
|
||||
FN.LandPageConfig.Id = "_id"
|
||||
FN.LandPageConfig.LandPageType = "landPageType"
|
||||
FN.LandPageConfig.Media = "media"
|
||||
FN.LandPageConfig.Picture = "picture"
|
||||
FN.LandPageConfig.Rank = "rank"
|
||||
FN.LandPageConfig.Status = "status"
|
||||
FN.LandPageConfig.Title = "title"
|
||||
FN.LandPageConfig.UpdateAt = "updateAt"
|
||||
TN.LandPageConfig = "landPageConfig"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package landPageConfig
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 落地页配置
|
||||
// @table:landPageConfig
|
||||
type LandPageConfig struct {
|
||||
Id int64 `json:"id" bson:"_id"`
|
||||
AppId int32 `json:"appId" bson:"appId"` //appId
|
||||
LandPageType int8 `json:"landPageType" bson:"landPageType"` //类型,1PC端,2移动端
|
||||
Title string `json:"title" bson:"title"` //主题
|
||||
Desc string `json:"desc" bson:"desc"` //描述
|
||||
Actor string `json:"actor" bson:"actor"` //演员
|
||||
Bango string `json:"bango" bson:"bango"` //番号,唯一
|
||||
AddedTime time.Time `json:"addedTime" bson:"addedTime"` //上架时间(审核通过时间)
|
||||
Picture string `json:"picture" bson:"picture"` //图片
|
||||
Media string `json:"media" bson:"media"` //视频
|
||||
Rank int64 `json:"rank" bson:"rank"` //排序
|
||||
Status bool `json:"status" bson:"status"` //状态
|
||||
CreateAt time.Time `json:"createAt" bson:"createAt"` //创建时间
|
||||
UpdateAt time.Time `json:"updateAt" bson:"updateAt"` //更新时间
|
||||
}
|
||||
|
||||
type LandPageConfigList []*LandPageConfig
|
||||
Reference in New Issue
Block a user