From f1aba67e55d19e1e2428e40262f44d8d616335cc Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 2 Sep 2024 18:37:31 +0800 Subject: [PATCH 1/7] 1 --- mongo/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mongo/client.go b/mongo/client.go index a283f7e..60867a5 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -13,7 +13,8 @@ var url = "mongodb://root:Wishpal2024@dds-bp1da1ddd62bede41.mongodb.rds.aliyuncs func NewMongoClient() (*qmgo.Client, error) { clientCfg := &qmgo.Config{ - Uri: "mongodb://admin:Wishpal%402023@172.31.37.71:27017", + //Uri: "mongodb://admin:Wishpal%402023@172.31.37.71:27017", + Uri: url, ConnectTimeoutMS: goproto.Int64(30000), MaxPoolSize: goproto.Uint64(16), MinPoolSize: goproto.Uint64(0), From 1baaf495c5ea956136b41bf841e369301f266527 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 00:50:43 +0800 Subject: [PATCH 2/7] 1 --- file/zonemember.txt | 0 importfunc/zonemember.go | 105 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 file/zonemember.txt create mode 100644 importfunc/zonemember.go diff --git a/file/zonemember.txt b/file/zonemember.txt new file mode 100644 index 0000000..e69de29 diff --git a/importfunc/zonemember.go b/importfunc/zonemember.go new file mode 100644 index 0000000..b88a759 --- /dev/null +++ b/importfunc/zonemember.go @@ -0,0 +1,105 @@ +package importfunc + +import ( + "context" + "fmt" + + mycrypto "github.com/Leufolium/test/crypto" + "github.com/Leufolium/test/dbstruct" + "github.com/Leufolium/test/mongo" + "github.com/Leufolium/test/mysql" + "github.com/Leufolium/test/util" +) + +func ImportZoneMemberInfo() { + fmt.Println("Start importing...") + + mcli, err := mongo.NewMongo() + if err != nil { + fmt.Printf("mongo client init fail : %v", err) + return + } + + mysqlcli, err := mysql.NewMysql() + if err != nil { + fmt.Printf("mysql client init fail : %v", err) + return + } + + ctx := context.Background() + + limit := 1000 + offset := 0 + + streamers, err := mcli.GetStreamerList(ctx, offset, limit) + if err != nil { + fmt.Printf("GetStreamerListfail : %v", err) + return + } + mids := make([]int64, 0) + for _, streamer := range streamers { + mids = append(mids, streamer.GetMid()) + } + accounts, _ := mcli.GetAccountListByMids(ctx, mids) + acctMp := make(map[int64]*dbstruct.Account) + for _, acct := range accounts { + acctMp[acct.GetMid()] = acct + } + zones, _ := mcli.GetZoneListByMids(ctx, mids) + zoneMp := make(map[int64]*dbstruct.Zone) + for _, zone := range zones { + zoneMp[zone.GetMid()] = zone + } + + zids := make([]int64, 0) + fmt.Printf("zid: [") + for _, zone := range zones { + zids = append(zids, zone.GetId()) + fmt.Printf("%v ", zone.GetId()) + } + fmt.Printf("]") + + zmlist, err := mysqlcli.GetZoneMemberCountGroupByZid(ctx, nil, zids) + if err != nil { + fmt.Printf("GetZoneMemberCountGroupByZid : %v", err) + return + } + zmMp := make(map[int64]*dbstruct.ZoneMemberCount) + for _, zm := range zmlist { + zmMp[zm.GetZid()] = zm + } + + fmt.Printf("user_id\t昵称\t手机号\t空间动态数\t空间人数") + + for _, streamer := range streamers { + + acct, ok := acctMp[streamer.GetMid()] + if !ok { + continue + } + + userId := acct.GetUserId() + name := acct.GetName() + mobilephonestr := util.DerefString(acct.MobilePhone) + dcrb, err := mycrypto.CryptoServiceInstance().DecryptByAES([]byte(mobilephonestr)) + if err != nil { + fmt.Printf("DecryptByAES : %v", err) + return + } + mobilephone := string(dcrb) + zmmtcount := int64(0) + zmbcount := int64(0) + zone, ok := zoneMp[streamer.GetMid()] + if ok { + zmmtcount = zone.GetZoneMomentCount() + zmb, ok := zmMp[zone.GetId()] + if ok { + zmbcount = zmb.GetNum() + } + } + + fmt.Printf("%d\t%s\t%s\t%d\t%d", userId, name, mobilephone, zmmtcount, zmbcount) + } + + fmt.Println("End importing...") +} From 74d285b9d35970655607ae011ee1b8b2cb998d01 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 00:54:07 +0800 Subject: [PATCH 3/7] 1 --- cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 23cdedc..032ee5f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,5 +3,5 @@ package main import "github.com/Leufolium/test/importfunc" func main() { - importfunc.ImportStreamerIntoEs() + importfunc.ImportZoneMemberInfo() } From 6d8a0c3b3ab4a978544c0b5e999ac35084665c34 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 00:56:06 +0800 Subject: [PATCH 4/7] 1 --- mysql/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql/client.go b/mysql/client.go index 03c37bd..07f4d24 100644 --- a/mysql/client.go +++ b/mysql/client.go @@ -12,7 +12,7 @@ func NewMysqlDB() (*sqlx.DB, error) { "%s:%s@(%s)/%s?charset=utf8&parseTime=true&timeout=%ds&readTimeout=%ds&writeTimeout=%ds", "root", "Wishpal2024", - "172.31.37.71:3306", + "rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com:3306", "vas", 3, 5, From c5924a117dd19c3b5396b88433d79df43ff381cf Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 00:58:36 +0800 Subject: [PATCH 5/7] 1 --- importfunc/zonemember.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/importfunc/zonemember.go b/importfunc/zonemember.go index b88a759..5586d7b 100644 --- a/importfunc/zonemember.go +++ b/importfunc/zonemember.go @@ -52,12 +52,10 @@ func ImportZoneMemberInfo() { } zids := make([]int64, 0) - fmt.Printf("zid: [") for _, zone := range zones { zids = append(zids, zone.GetId()) fmt.Printf("%v ", zone.GetId()) } - fmt.Printf("]") zmlist, err := mysqlcli.GetZoneMemberCountGroupByZid(ctx, nil, zids) if err != nil { @@ -69,7 +67,9 @@ func ImportZoneMemberInfo() { zmMp[zm.GetZid()] = zm } - fmt.Printf("user_id\t昵称\t手机号\t空间动态数\t空间人数") + mycrypto.CryptoServiceInstance().Init() + + fmt.Printf("user_id\t昵称\t手机号\t空间动态数\t空间人数\n") for _, streamer := range streamers { @@ -98,7 +98,7 @@ func ImportZoneMemberInfo() { } } - fmt.Printf("%d\t%s\t%s\t%d\t%d", userId, name, mobilephone, zmmtcount, zmbcount) + fmt.Printf("%d\t%s\t%s\t%d\t%d\n", userId, name, mobilephone, zmmtcount, zmbcount) } fmt.Println("End importing...") From a2529e96c8cd10bf4e30077a1a20fe3dee628620 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 01:09:05 +0800 Subject: [PATCH 6/7] 1 --- importfunc/zonemember.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/importfunc/zonemember.go b/importfunc/zonemember.go index 5586d7b..2e4838f 100644 --- a/importfunc/zonemember.go +++ b/importfunc/zonemember.go @@ -54,7 +54,6 @@ func ImportZoneMemberInfo() { zids := make([]int64, 0) for _, zone := range zones { zids = append(zids, zone.GetId()) - fmt.Printf("%v ", zone.GetId()) } zmlist, err := mysqlcli.GetZoneMemberCountGroupByZid(ctx, nil, zids) @@ -83,7 +82,7 @@ func ImportZoneMemberInfo() { mobilephonestr := util.DerefString(acct.MobilePhone) dcrb, err := mycrypto.CryptoServiceInstance().DecryptByAES([]byte(mobilephonestr)) if err != nil { - fmt.Printf("DecryptByAES : %v", err) + fmt.Printf("DecryptByAES : %v, mobielphonestr : %v", err, mobilephonestr) return } mobilephone := string(dcrb) From 57a4fcc05ef6163ad5f04f6009a0a2431c3dff63 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 4 Sep 2024 01:12:48 +0800 Subject: [PATCH 7/7] 1 --- importfunc/zonemember.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/importfunc/zonemember.go b/importfunc/zonemember.go index 2e4838f..be3c42f 100644 --- a/importfunc/zonemember.go +++ b/importfunc/zonemember.go @@ -2,6 +2,7 @@ package importfunc import ( "context" + "encoding/base64" "fmt" mycrypto "github.com/Leufolium/test/crypto" @@ -80,7 +81,8 @@ func ImportZoneMemberInfo() { userId := acct.GetUserId() name := acct.GetName() mobilephonestr := util.DerefString(acct.MobilePhone) - dcrb, err := mycrypto.CryptoServiceInstance().DecryptByAES([]byte(mobilephonestr)) + base64DecryptedBytes, _ := base64.StdEncoding.DecodeString(mobilephonestr) + dcrb, err := mycrypto.CryptoServiceInstance().DecryptByAES(base64DecryptedBytes) if err != nil { fmt.Printf("DecryptByAES : %v, mobielphonestr : %v", err, mobilephonestr) return