forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package minutestatmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// 初始化model
|
||||
func Init() {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, CollMinuteStat)
|
||||
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "sumDate", Value: 1}, {Key: "updatedAt", Value: 1}},
|
||||
}, {
|
||||
Keys: bson.D{{Key: "sumDate", Value: 1}, {Key: "appId", Value: 1}},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollMinuteStat, err))
|
||||
}
|
||||
}
|
||||
|
||||
func UpsertMinuteStatEx(ctx context.Context,
|
||||
filter bson.M, update bson.M) error {
|
||||
if _, err := db.UpsertOneEx(ctx, filter, update); err != nil {
|
||||
log.Info("minutestatmod:UpsertMinuteStatEx db.InsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpsertMinuteDocStat(ctx context.Context, sumDate time.Time, appId int32, update *MinuteStatDoc) error {
|
||||
now := time.Now()
|
||||
update.UpdatedAt = &now
|
||||
|
||||
filter := bson.M{
|
||||
"appId": appId,
|
||||
"sumDate": sumDate,
|
||||
}
|
||||
|
||||
upsertDoc := bson.M{
|
||||
"$set": update,
|
||||
"$setOnInsert": filter,
|
||||
}
|
||||
|
||||
if _, err := db.UpsertOneEx(ctx, filter, upsertDoc); err != nil {
|
||||
log.Info("minutestatmod:UpsertMinuteStatEx db.InsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertDailyStat 更新或插入一条统计记录
|
||||
func UpsertMinuteStat(ctx context.Context, sumDate time.Time, appId int32, doc MinuteStatDoc) (err error) {
|
||||
var filter = bson.M{
|
||||
"sumDate": sumDate,
|
||||
"appId": appId,
|
||||
}
|
||||
var update = mongos.ToBsonM(doc)
|
||||
|
||||
exists, err := db.Exists(ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if exists {
|
||||
_, err = db.UpdateOne(ctx, filter, bson.M{"$set": update})
|
||||
} else {
|
||||
insertDoc := update
|
||||
insertDoc["sumDate"] = sumDate
|
||||
insertDoc["appId"] = appId
|
||||
|
||||
_, err = db.InsertOne(ctx, insertDoc)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetMinuteStatList(ctx context.Context, start, end time.Time, appId int32) (data []MinuteStatMod, err error) {
|
||||
filter := bson.M{"sumDate": bson.M{"$gte": start, "$lt": end}, "appId": appId}
|
||||
|
||||
sort := bson.D{{Key: "sumDate", Value: 1}}
|
||||
|
||||
opts := options.Find().SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("minuteStat GetMinuteStatList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package minutestatmod
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollMinuteStat = "minute_stat"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
// MinuteStatMod 实时统计(5分钟数据)
|
||||
type MinuteStatMod struct {
|
||||
SumDate time.Time `bson:"sumDate"` // 记录时间
|
||||
AppId int32 `bson:"appId"` // appId
|
||||
// 新增
|
||||
NewCount int64 `bson:"newCount"` // 新增总量
|
||||
DirectAddCount int64 `bson:"directAddCount"` // 直推新增
|
||||
FissionAddCount int64 `bson:"fissionAddCount"` // 裂变新增
|
||||
WebAddCount int64 `bson:"webAddCount"` // 官网新增
|
||||
DistrictAddCount int64 `bson:"districtAddCount"` // 渠道新增
|
||||
NormalAddCount int64 `bson:"normalAddCount"` // 自来新增
|
||||
AndroidAddCount int64 `bson:"androidAddCount"` // android新增
|
||||
IosAddCount int64 `bson:"iosAddCount"` // ios新增
|
||||
H5AddCount int64 `bson:"h5AddCount"` // H5新增
|
||||
H5FormalAddCount int64 `bson:"h5FormalAddCount"` // H5注册新增
|
||||
LightGuestAddCount int64 `bson:"lightGuestAddCount"` // 轻量安装新增
|
||||
LightFormalAddCount int64 `bson:"lightFormalAddCount"` // 轻量注册新增
|
||||
// 充值
|
||||
RechargetCount int64 `bson:"rechageCount"` // 充值订单
|
||||
RechargetMoney int64 `bson:"rechageMoney"` // 充值金额
|
||||
DirectAmount int64 `bson:"directAmount"` // 直推充值金额
|
||||
FissionAmount int64 `bson:"fissionAmount"` // 裂变充值金额
|
||||
DistrictRecharge int64 `bson:"districtRecharge"` // 渠道充值新增
|
||||
WebRecharge int64 `bson:"webRecharge"` // 官网充值新增
|
||||
NormalRecharge int64 `bson:"normalRecharge"` // 自来量充值新增
|
||||
AndroidRecharge int64 `bson:"androidRecharge"` // android充值
|
||||
IosRecharge int64 `bson:"iosRecharge"` // Ios充值
|
||||
LightRecharge int64 `bson:"lightRecharge"` // 轻量充值
|
||||
H5Recharge int64 `bson:"h5Recharge"` // H5充值
|
||||
// 访问
|
||||
AccessCount int64 `bson:"accessCount"` // 访问量
|
||||
AndroidAccessCount int64 `bson:"androidAccessCount"` // android访问量
|
||||
IosAccessCount int64 `bson:"iosAccessCount"` // ios访问量
|
||||
H5AccessCount int64 `bson:"h5AccessCount"` // H5
|
||||
LightAccessCount int64 `bson:"lightAccessCount"` // Light访问量
|
||||
DirectAccessCount int64 `bson:"directAccessCount"` // 直推访问数
|
||||
FissionAccessCount int64 `bson:"fissionAccessCount"` // 裂变访问数
|
||||
NaturalAccessCount int64 `bson:"naturalAccessCount"` // 自然访问数
|
||||
DistrictAccessCount int64 `bson:"districtAccessCount"` // 渠道访问量
|
||||
WebAccessCount int64 `bson:"webAccessCount"` // 官网访问量
|
||||
NormalAccessCount int64 `bson:"normalAccessCount"` // 自来访问量
|
||||
// 落地页
|
||||
LandpageAndroidClick int64 `bson:"landpageAndroidClick"` // 落地页android访问次数
|
||||
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick"` // 落地页iOS商店包访问次数
|
||||
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick"` // 落地页iOS其他包访问次数
|
||||
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
type MinuteStatDoc struct {
|
||||
// 新增
|
||||
NewCount *int64 `bson:"newCount,omitempty"` // 新增总量
|
||||
DirectAddCount *int64 `bson:"directAddCount,omitempty"` // 直推新增
|
||||
FissionAddCount *int64 `bson:"fissionAddCount,omitempty"` // 裂变新增
|
||||
WebAddCount *int64 `bson:"webAddCount,omitempty"` // 官网新增
|
||||
DistrictAddCount *int64 `bson:"districtAddCount,omitempty"` // 渠道新增
|
||||
NormalAddCount *int64 `bson:"normalAddCount,omitempty"` // 自来新增
|
||||
AndroidAddCount *int64 `bson:"androidAddCount,omitempty"` // android新增
|
||||
IosAddCount *int64 `bson:"iosAddCount,omitempty"` // ios新增
|
||||
H5AddCount *int64 `bson:"h5AddCount,omitempty"` // H5新增
|
||||
H5FormalAddCount *int64 `bson:"h5FormalAddCount,omitempty"` // H5注册新增
|
||||
LightGuestAddCount *int64 `bson:"lightGuestAddCount,omitempty"` // 轻量安装新增
|
||||
LightFormalAddCount *int64 `bson:"lightFormalAddCount,omitempty"` // 轻量注册新增
|
||||
// 充值
|
||||
RechargetCount *int64 `bson:"rechageCount,omitempty"` // 充值订单
|
||||
RechargetMoney *int64 `bson:"rechageMoney,omitempty"` // 充值金额
|
||||
DirectAmount *int64 `bson:"directAmount,omitempty"` // 直推充值金额
|
||||
FissionAmount *int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
|
||||
DistrictRecharge *int64 `bson:"districtRecharge,omitempty"` // 渠道充值新增
|
||||
WebRecharge *int64 `bson:"webRecharge,omitempty"` // 官网充值新增
|
||||
NormalRecharge *int64 `bson:"normalRecharge,omitempty"` // 自来量充值新增
|
||||
AndroidRecharge *int64 `bson:"androidRecharge,omitempty"` // android充值
|
||||
IosRecharge *int64 `bson:"iosRecharge,omitempty"` // Ios充值
|
||||
LightRecharge *int64 `bson:"lightRecharge,omitempty"` // 轻量充值
|
||||
H5Recharge *int64 `bson:"h5Recharge,omitempty"` // H5充值
|
||||
// 访问
|
||||
AccessCount *int64 `bson:"accessCount,omitempty"` // 访问量
|
||||
AndroidAccessCount *int64 `bson:"androidAccessCount,omitempty"` // android访问量
|
||||
IosAccessCount *int64 `bson:"iosAccessCount,omitempty"` // ios访问量
|
||||
H5AccessCount *int64 `bson:"h5AccessCount,omitempty"` // H5
|
||||
LightAccessCount *int64 `bson:"lightAccessCount,omitempty"` // Light访问量
|
||||
DirectAccessCount *int64 `bson:"directAccessCount,omitempty"` // 直推访问数
|
||||
FissionAccessCount *int64 `bson:"fissionAccessCount,omitempty"` // 裂变访问数
|
||||
NaturalAccessCount *int64 `bson:"naturalAccessCount,omitempty"` // 自然访问数
|
||||
DistrictAccessCount *int64 `bson:"districtAccessCount,omitempty"` // 渠道访问量
|
||||
WebAccessCount *int64 `bson:"webAccessCount,omitempty"` // 官网访问量
|
||||
NormalAccessCount *int64 `bson:"normalAccessCount,omitempty"` // 自来访问量
|
||||
// 落地页
|
||||
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
|
||||
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
|
||||
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
|
||||
LandpageIosH5Click *int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
|
||||
// 时间
|
||||
UpdatedAt *time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
Reference in New Issue
Block a user