From cf2e10154f0f5dab13621a7922abfd0dcc80cef0 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Thu, 7 Dec 2023 17:17:52 +0800 Subject: [PATCH] 1 --- script/Makefile | 3 +- script/group_room_visit500.go | 117 ++++++++++++++++++++++++++++++++++ script/promotion_data.go | 6 +- 3 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 script/group_room_visit500.go diff --git a/script/Makefile b/script/Makefile index b1ccec3..d48fe4a 100644 --- a/script/Makefile +++ b/script/Makefile @@ -28,4 +28,5 @@ race_ksa_rank: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o race_ksa_rank race_ksa_rank.go promotion_data: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o promotion_data promotion_data.go - +group_room_visit500: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o group_room_visit500 group_room_visit500.go diff --git a/script/group_room_visit500.go b/script/group_room_visit500.go new file mode 100644 index 0000000..4ecd47e --- /dev/null +++ b/script/group_room_visit500.go @@ -0,0 +1,117 @@ +package main + +import ( + "context" + "fmt" + "git.hilo.cn/hilo-common/mylogrus" + "git.hilo.cn/hilo-common/script/mysql" + "github.com/go-redis/redis/v8" + "github.com/spf13/cast" + "github.com/tealeg/xlsx" +) + +var RedisClient *redis.Client + +func init() { + RedisClient = redis.NewClient(&redis.Options{ + Addr: "172.28.16.47:6379", // redis cluster + Password: "", + DB: 0, // use default DB + PoolSize: 20, + MinIdleConns: 20, + }) + pong, err := RedisClient.Ping(context.Background()).Result() + if err != nil { + panic(err) + } else { + mylogrus.MyLog.Info("redis db0 connection success - ", pong) + } +} + +type GroupRoomVisit struct { + GroupId string + GroupCode string + Country string + Visit string + Consume string + Area string +} + +func getGroupCode(groupId string) string { + var code string + if err := mysql.ProdReadOnlyDB.Table("group_info").Where("im_group_id = ?", groupId).Select("code").Scan(&code).Error; err != nil { + panic(err) + } + return code +} + +func getGroupCountry(groupId string) string { + var code string + if err := mysql.ProdReadOnlyDB.Table("group_info").Where("im_group_id = ?", groupId).Select("country").Scan(&code).Error; err != nil { + panic(err) + } + return code +} + +func getArea(country string) string { + code := "非阿语区" + var area int + if err := mysql.ProdReadOnlyDB.Table("res_country").Where("name = ?", country).Select("area").Scan(&code).Error; err != nil { + panic(err) + } + if area == 1 { + code = "阿语区" + } + return code +} + +func getConsume(groupId string) string { + var result int64 + if err := mysql.ProdReadOnlyDB.Table("room_day_consume").Where("group_id = ?", groupId).Select("SUM(diamond)").Scan(&result).Error; err != nil { + panic(err) + } + return cast.ToString(result) +} + +func main() { + var data []GroupRoomVisit + zRes, err := RedisClient.ZRevRangeByScoreWithScores(context.Background(), "room_visit_count_zset", &redis.ZRangeBy{ + Min: fmt.Sprintf("%d", 500), + Max: "+inf", + }).Result() + if err != nil { + panic(err) + } + for _, v := range zRes { + d := GroupRoomVisit{ + GroupId: cast.ToString(v.Member), + GroupCode: "", + Country: "", + Visit: cast.ToString(v.Score), + Consume: "", + } + code := getGroupCode(d.GroupId) + country := getGroupCountry(d.GroupId) + area := getArea(country) + consume := getConsume(d.GroupId) + d.GroupCode = code + d.Country = country + d.Area = area + d.Consume = consume + } + excelFileName := fmt.Sprintf("./房间500热度.xlsx") + xlFile := xlsx.NewFile() + sheet, err := xlFile.AddSheet("room") + if err != nil { + panic(err) + } + row := sheet.AddRow() + c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() + c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = "房间code", "国家", "访客热度", "房间奖杯", "区域" + for _, d := range data { + row := sheet.AddRow() + c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() + c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = d.GroupCode, d.Country, d.Visit, d.Consume, d.Area + } + _ = xlFile.Save(excelFileName) +} diff --git a/script/promotion_data.go b/script/promotion_data.go index 8eab158..bf1fcf5 100644 --- a/script/promotion_data.go +++ b/script/promotion_data.go @@ -34,7 +34,7 @@ type PromotionDataResp struct { } `json:"data"` } -func ats37(a interface{}) string { +func ats38(a interface{}) string { return fmt.Sprintf("%v", a) } @@ -95,8 +95,8 @@ func main() { row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value, c7.Value, c8.Value, c9.Value, c10.Value, c11.Value, c12.Value, c13.Value = - ats37(d.AgentCode), ats37(d.Name), ats37(d.InviteeCode), ats37(d.Platform), ats37(d.PlatformId), ats37(d.Reason), ats37(d.GroupCode), ats37(d.GroupMemberNum), ats37(d.GroupTotalConsume), ats37(d.InviteDate), - ats37(d.MonthPaySum), ats37(d.TwoMonthPaySum), ats37(d.MonthDealPaySum) + ats38(d.AgentCode), ats38(d.Name), ats38(d.InviteeCode), ats38(d.Platform), ats38(d.PlatformId), ats38(d.Reason), ats38(d.GroupCode), ats38(d.GroupMemberNum), ats38(d.GroupTotalConsume), ats38(d.InviteDate), + ats38(d.MonthPaySum), ats38(d.TwoMonthPaySum), ats38(d.MonthDealPaySum) } _ = xlFile.Save(excelFileName) } -- 2.22.0