package main import ( "encoding/json" "git.hilo.cn/hilo-common/script/mysql" ) // cat 146.json | grep 'gameId\\"\:17' | wc -l // 如果mysql navicate中导出json,可以用上面的命令,是准确的。 type RpcLog struct { Type int Msg string } type Msg struct { GameType int `json:"gameType"` GameId int `json:"gameId"` } var GameTypeMap = map[int]string{ //0: "slot", //5: "幸运盒子", //6: "水果机", 17: "赛车", } func main() { var rpcLogs []RpcLog if err := mysql.ProdReadOnlyDB.Table("rpc_log_202308").Where("`type` = 146"). Where("created_time >= ?", "2023-08-22 15:57:49").Find(&rpcLogs).Error; err != nil { panic(err) } var data = make(map[int]int) for _, log := range rpcLogs { msg := new(Msg) if err := json.Unmarshal([]byte(log.Msg), msg); err != nil { panic(err) } data[msg.GameId]++ } for gameId, count := range data { println(GameTypeMap[gameId], count) } }