This commit is contained in:
Leufolium 2024-09-04 00:50:43 +08:00
parent f1aba67e55
commit 1baaf495c5
2 changed files with 105 additions and 0 deletions

0
file/zonemember.txt Normal file
View File

105
importfunc/zonemember.go Normal file
View File

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