|
@@ -2,6 +2,7 @@ package v1
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "designs/app/common/request"
|
|
|
"designs/config"
|
|
"designs/config"
|
|
|
"designs/crons"
|
|
"designs/crons"
|
|
|
"designs/global"
|
|
"designs/global"
|
|
@@ -234,6 +235,9 @@ func WriteDBDataToFile(c *gin.Context) {
|
|
|
// 对打点数据进行汇算
|
|
// 对打点数据进行汇算
|
|
|
func ActionDataSummary(c *gin.Context) {
|
|
func ActionDataSummary(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
+ service.SeeAdsSummary("20250706")
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
now := time.Now()
|
|
now := time.Now()
|
|
|
for i := 1; i <= 30; i++ {
|
|
for i := 1; i <= 30; i++ {
|
|
|
lastDay := now.AddDate(0, 0, -i).Format("20060102")
|
|
lastDay := now.AddDate(0, 0, -i).Format("20060102")
|
|
@@ -246,6 +250,51 @@ func ActionDataSummary(c *gin.Context) {
|
|
|
response.Success(c, gin.H{})
|
|
response.Success(c, gin.H{})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func CopyGameConfig(c *gin.Context) {
|
|
|
|
|
+ form := request.Check(c, &struct {
|
|
|
|
|
+ Gid string `json:"gid" binding:""`
|
|
|
|
|
+ }{})
|
|
|
|
|
+
|
|
|
|
|
+ form.Gid = "snake"
|
|
|
|
|
+
|
|
|
|
|
+ ////查询出所有的Key
|
|
|
|
|
+ //redisKey := "config_game:snake:" + "*"
|
|
|
|
|
+ //
|
|
|
|
|
+ //fmt.Println(redisKey)
|
|
|
|
|
+ //val, err := global.App.Redis.Keys(context.Background(), redisKey).Result()
|
|
|
|
|
+ //if err != nil {
|
|
|
|
|
+ // response.Fail(c, 1001, err.Error())
|
|
|
|
|
+ // return
|
|
|
|
|
+ //}
|
|
|
|
|
+ //
|
|
|
|
|
+ //for _, key := range val {
|
|
|
|
|
+ // data, _ := global.App.Redis.Get(context.Background(), key).Result()
|
|
|
|
|
+ //
|
|
|
|
|
+ // global.App.DB.Table("snake").Create(&map[string]interface{}{
|
|
|
|
|
+ // "key": key,
|
|
|
|
|
+ // "data": data,
|
|
|
|
|
+ // })
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ type aaa struct {
|
|
|
|
|
+ Key string `json:"key"`
|
|
|
|
|
+ Data string `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var data []aaa
|
|
|
|
|
+ global.App.DB.Table("snake").Scan(&data)
|
|
|
|
|
+
|
|
|
|
|
+ for _, v := range data {
|
|
|
|
|
+ err := global.App.Redis.Set(context.Background(), v.Key, v.Data, 0).Err()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ response.Success(c, gin.H{"data": data})
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func BehaviorTimeSummary(c *gin.Context) {
|
|
func BehaviorTimeSummary(c *gin.Context) {
|
|
|
//先查出所有gid
|
|
//先查出所有gid
|
|
|
ActiveGid := service.GetActiveGid()
|
|
ActiveGid := service.GetActiveGid()
|
|
@@ -267,8 +316,8 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
//先查出所有gid
|
|
//先查出所有gid
|
|
|
ActiveGid := service.GetActiveGid()
|
|
ActiveGid := service.GetActiveGid()
|
|
|
|
|
|
|
|
- now := time.Now().AddDate(0, 0, -1)
|
|
|
|
|
- start := now.AddDate(0, 0, -45)
|
|
|
|
|
|
|
+ //now := time.Now().AddDate(0, 0, -1)
|
|
|
|
|
+ //start := now.AddDate(0, 0, -45)
|
|
|
|
|
|
|
|
pf := "wx"
|
|
pf := "wx"
|
|
|
//循环一下,查出userId 跟相关的在线数据
|
|
//循环一下,查出userId 跟相关的在线数据
|
|
@@ -277,13 +326,13 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
start1 := time.Now()
|
|
start1 := time.Now()
|
|
|
fmt.Println("处理数据开始,gid :", gid)
|
|
fmt.Println("处理数据开始,gid :", gid)
|
|
|
|
|
|
|
|
- //查询 30天内的在线数据
|
|
|
|
|
-
|
|
|
|
|
- SummaryData, err := service.UserOnlineSummary(gid, pf, "", start.Format("2006-01-02 15:04:05"), now.Format("2006-01-02 15:04:05"))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- response.Fail(c, 1001, err.Error())
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ////查询 30天内的在线数据
|
|
|
|
|
+ //
|
|
|
|
|
+ //SummaryData, err := service.UserOnlineSummary(gid, pf, "", start.Format("2006-01-02 15:04:05"), now.Format("2006-01-02 15:04:05"))
|
|
|
|
|
+ //if err != nil {
|
|
|
|
|
+ // response.Fail(c, 1001, err.Error())
|
|
|
|
|
+ // return
|
|
|
|
|
+ //}
|
|
|
|
|
|
|
|
//aaa, _ := json.Marshal(SummaryData)
|
|
//aaa, _ := json.Marshal(SummaryData)
|
|
|
//global.App.Log.Error(string(aaa))
|
|
//global.App.Log.Error(string(aaa))
|
|
@@ -298,7 +347,7 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
}
|
|
}
|
|
|
loginDataMap := make(map[int]int)
|
|
loginDataMap := make(map[int]int)
|
|
|
|
|
|
|
|
- err = global.App.DB.Table("user_login").
|
|
|
|
|
|
|
+ err := global.App.DB.Table("user_login").
|
|
|
Where("gid", gid).
|
|
Where("gid", gid).
|
|
|
Where("pf", pf).
|
|
Where("pf", pf).
|
|
|
Group("userId").
|
|
Group("userId").
|
|
@@ -357,8 +406,8 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
userBehavior := make(map[int]model.UserBehavior)
|
|
userBehavior := make(map[int]model.UserBehavior)
|
|
|
for _, users := range userIdList {
|
|
for _, users := range userIdList {
|
|
|
userBehavior[users.UserId] = model.UserBehavior{
|
|
userBehavior[users.UserId] = model.UserBehavior{
|
|
|
- ID: users.ID,
|
|
|
|
|
- Duration: int(SummaryData[users.UserId]),
|
|
|
|
|
|
|
+ ID: users.ID,
|
|
|
|
|
+ //Duration: int(SummaryData[users.UserId]),
|
|
|
StartNum: loginDataMap[users.UserId],
|
|
StartNum: loginDataMap[users.UserId],
|
|
|
AdCount: seeAdsDataMap[users.UserId],
|
|
AdCount: seeAdsDataMap[users.UserId],
|
|
|
AdExpCount: seeAdsDataMap2[users.UserId],
|
|
AdExpCount: seeAdsDataMap2[users.UserId],
|
|
@@ -371,8 +420,8 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err = global.App.DB.Table("user_behavior").Clauses(clause.OnConflict{
|
|
err = global.App.DB.Table("user_behavior").Clauses(clause.OnConflict{
|
|
|
- Columns: []clause.Column{{Name: "id"}}, // 冲突列(主键)
|
|
|
|
|
- DoUpdates: clause.AssignmentColumns([]string{"duration", "startNum", "adCount", "adExpCount"}), // 需要更新的列
|
|
|
|
|
|
|
+ Columns: []clause.Column{{Name: "id"}}, // 冲突列(主键)
|
|
|
|
|
+ DoUpdates: clause.AssignmentColumns([]string{"startNum", "adCount", "adExpCount"}), // 需要更新的列
|
|
|
}).CreateInBatches(&userBehaviorList, 1000).Error
|
|
}).CreateInBatches(&userBehaviorList, 1000).Error
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
//global.App.Log.Error(userBehavior)
|
|
//global.App.Log.Error(userBehavior)
|
|
@@ -388,10 +437,71 @@ func BehaviorSummary(c *gin.Context) {
|
|
|
|
|
|
|
|
func TestClickHouse(c *gin.Context) {
|
|
func TestClickHouse(c *gin.Context) {
|
|
|
|
|
|
|
|
- sql := "CREATE TABLE user_see_ads\n(\n `pf` LowCardinality(String) COMMENT '登录路径',\n `gid` LowCardinality(String) COMMENT '游戏ID',\n `userId` UInt32 COMMENT '用户ID',\n `date` Date COMMENT '日期',\n `createdAt` DateTime DEFAULT now() COMMENT '时间',\n `adsId` Nullable(String) COMMENT '广告ID',\n \n -- 修复字段声明顺序:Nullable 应包裹 LowCardinality\n `adsType` LowCardinality(Nullable(String)) COMMENT '类型',\n `adsScene` LowCardinality(Nullable(String)) COMMENT '广告场景',\n \n `adsState` Nullable(Int8) COMMENT '广告状态: 0失败 1成功 2完整观看',\n `startTime` Nullable(DateTime) COMMENT '广告开始时间',\n `cost` UInt32 DEFAULT 0 COMMENT '广告收益'\n)\nENGINE = MergeTree()\nPARTITION BY (toYear(date), toMonth(date))\nORDER BY (date, pf, gid, userId)\nPRIMARY KEY (date, pf, gid)\nSETTINGS \n index_granularity = 8192,\n index_granularity_bytes = 10485760;\n"
|
|
|
|
|
- err := global.App.Clickhouse.Exec(sql).Error
|
|
|
|
|
|
|
+ //sql := "CREATE TABLE IF NOT EXISTS example_table (pf FixedString(10), gid FixedString(20), userId Int64) ENGINE = MergeTree() ORDER BY (pf, gid, userId);"
|
|
|
|
|
+ //err := global.App.Clickhouse.Exec(sql).Error
|
|
|
|
|
+
|
|
|
|
|
+ now := time.Now()
|
|
|
|
|
+ //for i := 100; i >= 0; i-- {
|
|
|
|
|
+ // global.App.Clickhouse.Table("example_table").Create(map[string]interface{}{
|
|
|
|
|
+ // "gid": "aaa",
|
|
|
|
|
+ // "pf": "wx",
|
|
|
|
|
+ // "userId": 1001,
|
|
|
|
|
+ // })
|
|
|
|
|
+ //
|
|
|
|
|
+ // fmt.Println(time.Since(now))
|
|
|
|
|
+ //
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ type ssss struct {
|
|
|
|
|
+ UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
|
|
+ Gid string `json:"gid" gorm:"not null;column:gid;"`
|
|
|
|
|
+ Pf string `json:"pf" gorm:"not null;column:pf;"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var insert []ssss
|
|
|
|
|
+ for i := 100; i >= 0; i-- {
|
|
|
|
|
+ insert = append(insert, ssss{
|
|
|
|
|
+ UserId: 1001,
|
|
|
|
|
+ Gid: "aaa",
|
|
|
|
|
+ Pf: "wx",
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ global.App.Clickhouse.Table("example_table").CreateInBatches(&insert, 1000)
|
|
|
|
|
+ fmt.Println(time.Since(now))
|
|
|
|
|
+
|
|
|
|
|
+ //var res []struct {
|
|
|
|
|
+ // UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
|
|
+ // Gid string `json:"gid" gorm:"not null;column:gid;"`
|
|
|
|
|
+ // Pf string `json:"pf" gorm:"not null;column:pf;"`
|
|
|
|
|
+ //}
|
|
|
|
|
+ //global.App.Clickhouse.Table("example_table").Scan(&res)
|
|
|
|
|
+ //
|
|
|
|
|
+ //response.Success(c, gin.H{
|
|
|
|
|
+ // "res": res,
|
|
|
|
|
+ //})
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TestLevel(c *gin.Context) {
|
|
|
|
|
+ //block := [][]string{
|
|
|
|
|
+ // {
|
|
|
|
|
+ // "*0", "*0",
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // "e0", "e0", "f0", "f0",
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // "*0", "*0",
|
|
|
|
|
+ // },
|
|
|
|
|
+ //}
|
|
|
|
|
+ ////随机移动
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func move() {
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func check() {
|
|
|
|
|
|
|
|
- response.Success(c, gin.H{
|
|
|
|
|
- "res": err,
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|