forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package downloadCpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 初始化model
|
||||
func Init() {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, CollLandingPageCPC)
|
||||
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "appId", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "appId", Value: 1},
|
||||
{Key: "createdAt", Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollLandingPageCPC, err))
|
||||
}
|
||||
}
|
||||
|
||||
// 插入InsertDownloadInfo 商区记录
|
||||
func InsertDownloadInfo(ctx context.Context, model *DownloadCpc) (err error) {
|
||||
_, err = db.InsertOne(ctx, model)
|
||||
return
|
||||
}
|
||||
|
||||
// 插入InsertDownloadInfoMany 商区记录
|
||||
func InsertDownloadInfoMany(ctx context.Context, docs []interface{}) (err error) {
|
||||
_, err = db.GetCollection().InsertMany(ctx, docs)
|
||||
return
|
||||
}
|
||||
|
||||
// FindManyDownloadCpc 查找一批
|
||||
func FindManyDownloadCpc(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (DownloadCpcList, error) {
|
||||
data := make(DownloadCpcList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("FindManyDownloadCpc db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// 根据appId 获取appInfo
|
||||
func GetAccessCountByTime(ctx context.Context, appid int32, start, end time.Time) ([]DownloadCpc, error) {
|
||||
filter := bson.M{"appId": appid, "createdAt": bson.M{"$gte": start, "$lt": end}}
|
||||
results := make([]DownloadCpc, 0)
|
||||
if err := db.Find(ctx, &results, filter); err != nil {
|
||||
log.Error("GetAccessUserByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package downloadCpc
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollLandingPageCPC = "landingpage_cpc"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
type DownloadCpc struct {
|
||||
AppId int32 `json:"appId" bson:"appId"` // appId
|
||||
PC string `json:"pc" bson:"pc"` //推广码
|
||||
DC string `json:"dc" bson:"dc"` //商区序列
|
||||
CH string `json:"ch" bson:"ch"` //渠道
|
||||
IP string `json:"ip" bson:"ip"` //用户IP
|
||||
DevType string `json:"devType" bson:"devType"` //设备类型
|
||||
SysType string `json:"sysType" bson:"sysType"` //系统类型
|
||||
PeerIP string `json:"peerIP" bson:"peerIP"` // 网站IP
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
type DownloadCpcList []*DownloadCpc
|
||||
Reference in New Issue
Block a user