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..be3c42f --- /dev/null +++ b/importfunc/zonemember.go @@ -0,0 +1,106 @@ +package importfunc + +import ( + "context" + "encoding/base64" + "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) + for _, zone := range zones { + zids = append(zids, zone.GetId()) + } + + 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 + } + + mycrypto.CryptoServiceInstance().Init() + + fmt.Printf("user_id\t昵称\t手机号\t空间动态数\t空间人数\n") + + for _, streamer := range streamers { + + acct, ok := acctMp[streamer.GetMid()] + if !ok { + continue + } + + userId := acct.GetUserId() + name := acct.GetName() + mobilephonestr := util.DerefString(acct.MobilePhone) + base64DecryptedBytes, _ := base64.StdEncoding.DecodeString(mobilephonestr) + dcrb, err := mycrypto.CryptoServiceInstance().DecryptByAES(base64DecryptedBytes) + if err != nil { + fmt.Printf("DecryptByAES : %v, mobielphonestr : %v", err, mobilephonestr) + 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\n", userId, name, mobilephone, zmmtcount, zmbcount) + } + + fmt.Println("End importing...") +} 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), 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,