forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package dailystatadvertise
|
||||
|
||||
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.DailyStatAdvertise)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.DailyStatAdvertise.SumDate, Value: 1},
|
||||
{Key: FN.DailyStatAdvertise.AppId, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(DailyStatAdvertise:initDailyStatAdvertiseIndex) Create DailyStatAdvertise Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
//InsertOneDailyStatAdvertise 插入一个VIP购买记录
|
||||
func InsertOneDailyStatAdvertise(ctx context.Context, DailyStatAdvertise *DailyStatAdvertise) error {
|
||||
if _, err := db.InsertOne(ctx, DailyStatAdvertise); err != nil {
|
||||
log.Warn("DailyStatAdvertise:InsertOneDailyStatAdvertise db.InsertOne failed", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindOneDailyStatAdvertise 查找一个VIP购买记录
|
||||
func FindOneDailyStatAdvertise(ctx context.Context, filter bson.M) (
|
||||
*DailyStatAdvertise, error) {
|
||||
var DailyStatAdvertise DailyStatAdvertise
|
||||
if err := db.FindOne(ctx, &DailyStatAdvertise, filter); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DailyStatAdvertise, nil
|
||||
}
|
||||
|
||||
//DelOneDailyStatAdvertise 删除一个VIP购买记录
|
||||
func DelOneDailyStatAdvertise(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("DailyStatAdvertise:DelOneDailyStatAdvertise db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateOneDailyStatAdvertise 更新一个VIP购买记录
|
||||
func UpdateOneDailyStatAdvertise(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateOneDailyStatAdvertise db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//CountDailyStatAdvertises 统计VIP购买记录数量
|
||||
func CountDailyStatAdvertises(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("DailyStatAdvertise:CountDailyStatAdvertises db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateManyDailyStatAdvertise 更新满足条件的VIP购买记录
|
||||
func UpdateManyDailyStatAdvertise(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateManyDailyStatAdvertise db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindManyDailyStatAdvertise 查找一批VIP购买记录数据
|
||||
func FindManyDailyStatAdvertise(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (DailyStatAdvertiseList, error) {
|
||||
data := make(DailyStatAdvertiseList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("DailyStatAdvertise:FindManyDailyStatAdvertise db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//FindManyDailyStatAdvertiseWithBind 用自己定义结构查找一批VIP购买记录数据
|
||||
func FindManyDailyStatAdvertiseWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) error {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("DailyStatAdvertise:FindManyDailyStatAdvertiseWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//AggregateDailyStatAdvertises 聚合查找一批VIP购买记录信息
|
||||
func AggregateDailyStatAdvertises(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) error {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateDailyStatAdvertises db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
package dailystatadvertise
|
||||
|
||||
type TagDailyStatAdvertise struct {
|
||||
AppId string
|
||||
AppName string
|
||||
Day1RetainRate string
|
||||
Day3RetainRate string
|
||||
Day7RetainRate string
|
||||
DirectVisitCount string
|
||||
ID string
|
||||
NewDirectCount string
|
||||
SumDate string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
DailyStatAdvertise TagDailyStatAdvertise
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
DailyStatAdvertise string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.DailyStatAdvertise.AppId = "appId"
|
||||
FN.DailyStatAdvertise.AppName = "appName"
|
||||
FN.DailyStatAdvertise.Day1RetainRate = "day1RetainRate"
|
||||
FN.DailyStatAdvertise.Day3RetainRate = "day3RetainRate"
|
||||
FN.DailyStatAdvertise.Day7RetainRate = "day7RetainRate"
|
||||
FN.DailyStatAdvertise.DirectVisitCount = "directVisitCount"
|
||||
FN.DailyStatAdvertise.ID = "_id"
|
||||
FN.DailyStatAdvertise.NewDirectCount = "newDirectCount"
|
||||
FN.DailyStatAdvertise.SumDate = "sumDate"
|
||||
TN.DailyStatAdvertise = "dailystat_advertise"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dailystatadvertise
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 帖子模型,数据库中的
|
||||
// @table:dailystat_advertise
|
||||
type DailyStatAdvertise struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"` // ID
|
||||
SumDate time.Time `bson:"sumDate" json:"sumDate"` // 记录时间 按天对齐
|
||||
AppId int32 `bson:"appId,omitempty" json:"appId"` // appId
|
||||
AppName string `bson:"appName,omitempty" json:"appName"` // app名称
|
||||
NewDirectCount int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
|
||||
DirectVisitCount int64 `bson:"directVisitCount,omitempty" json:"directVisitCount"` // 直推访问数
|
||||
Day1RetainRate string `bson:"day1RetainRate,omitempty" json:"day1RetainRate"` // 次日留存率
|
||||
Day3RetainRate string `bson:"day3RetainRate,omitempty" json:"day3RetainRate"` // 3日留存率
|
||||
Day7RetainRate string `bson:"day7RetainRate,omitempty" json:"day7RetainRate"` // 7日留存率
|
||||
}
|
||||
type DailyStatAdvertiseList []*DailyStatAdvertise
|
||||
Reference in New Issue
Block a user