This commit is contained in:
Leufolium 2024-09-13 14:33:16 +08:00
commit 25e99d791f
4 changed files with 109 additions and 2 deletions

0
file/zonemember.txt Normal file
View File

106
importfunc/zonemember.go Normal file
View File

@ -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...")
}

View File

@ -13,7 +13,8 @@ var url = "mongodb://root:Wishpal2024@dds-bp1da1ddd62bede41.mongodb.rds.aliyuncs
func NewMongoClient() (*qmgo.Client, error) { func NewMongoClient() (*qmgo.Client, error) {
clientCfg := &qmgo.Config{ 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), ConnectTimeoutMS: goproto.Int64(30000),
MaxPoolSize: goproto.Uint64(16), MaxPoolSize: goproto.Uint64(16),
MinPoolSize: goproto.Uint64(0), MinPoolSize: goproto.Uint64(0),

View File

@ -12,7 +12,7 @@ func NewMysqlDB() (*sqlx.DB, error) {
"%s:%s@(%s)/%s?charset=utf8&parseTime=true&timeout=%ds&readTimeout=%ds&writeTimeout=%ds", "%s:%s@(%s)/%s?charset=utf8&parseTime=true&timeout=%ds&readTimeout=%ds&writeTimeout=%ds",
"root", "root",
"Wishpal2024", "Wishpal2024",
"172.31.37.71:3306", "rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com:3306",
"vas", "vas",
3, 3,
5, 5,