dtp/importfunc/zonemember.go

107 lines
2.4 KiB
Go

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