dtp/importfunc/streamer_into_es.go

130 lines
3.6 KiB
Go
Raw Normal View History

2024-08-15 05:10:02 +08:00
package importfunc
2024-08-15 04:56:58 +08:00
import (
"context"
"fmt"
"strings"
"time"
"github.com/Leufolium/test/dbstruct"
"github.com/Leufolium/test/es"
"github.com/Leufolium/test/mongo"
"github.com/Leufolium/test/util"
"github.com/mozillazg/go-pinyin"
)
func ImportStreamerIntoEs() {
fmt.Println("Start importing...")
mcli, err := mongo.NewMongo()
if err != nil {
fmt.Printf("mongo client init fail : %v", err)
return
}
escli, err := es.NewElasticSearch()
if err != nil {
fmt.Printf("elastic search 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
}
2024-08-20 18:08:35 +08:00
userInfos, _ := mcli.GetUserVasInfoByMids(ctx, mids)
userInfoMp := make(map[int64]*dbstruct.UserVasInfo)
for _, userInfo := range userInfos {
userInfoMp[userInfo.Mid] = userInfo
}
zids := make([]int64, 0)
2024-08-20 18:28:00 +08:00
fmt.Printf("zid: [")
2024-08-20 18:08:35 +08:00
for _, zone := range zones {
zids = append(zids, zone.GetId())
2024-08-20 18:28:00 +08:00
fmt.Printf("%v ", zone.GetId())
2024-08-20 18:08:35 +08:00
}
2024-08-20 18:28:00 +08:00
fmt.Printf("]")
2024-08-20 18:08:35 +08:00
zoneVases, _ := mcli.GetZoneVasByIds(ctx, zids)
zoneVasMp := make(map[int64]*dbstruct.ZoneVas)
for _, zoneVas := range zoneVases {
zoneVasMp[zoneVas.Zid] = zoneVas
}
2024-08-15 04:56:58 +08:00
streameraccts := make([]*dbstruct.EsStreamerAcct, 0)
2024-08-20 18:28:44 +08:00
fmt.Printf("price: [")
2024-08-15 04:56:58 +08:00
for _, streamer := range streamers {
zone, ok := zoneMp[streamer.GetMid()]
lastZoneMomentCreateDay := int64(0)
2024-08-20 18:49:06 +08:00
zoneadmissionprice := int64(-999999)
2024-08-15 04:56:58 +08:00
if ok && zone.GetLastZoneMomentCt() != 0 {
lastZoneMomentCreateDay = util.GetDayStartTimeStamp(time.Unix(zone.GetLastZoneMomentCt(), 0))
2024-08-20 18:08:35 +08:00
zoneVas, ok1 := zoneVasMp[zone.GetId()]
if ok1 {
zoneadmissionprice = zoneVas.AdmissionPrice
2024-08-20 18:28:44 +08:00
fmt.Printf("%v ", zoneadmissionprice)
2024-08-20 18:08:35 +08:00
}
2024-08-15 04:56:58 +08:00
}
name := ""
py := ""
userIdString := ""
acct, ok := acctMp[streamer.GetMid()]
if ok {
name = acct.GetName()
py = strings.Join(pinyin.LazyConvert(acct.GetName(), nil), "")
userIdString = util.DerefString(acct.UserIdString)
}
2024-08-20 18:08:35 +08:00
wechatcoinprice := int64(0)
userInfo, ok := userInfoMp[streamer.GetMid()]
if ok {
wechatcoinprice = userInfo.WechatCoinPrice
}
2024-08-15 04:56:58 +08:00
streameraccts = append(streameraccts, &dbstruct.EsStreamerAcct{
Mid: streamer.GetMid(),
Name: name,
UserIdString: userIdString,
PinYin: py,
Age: util.DerefInt64(streamer.Age),
Height: util.DerefInt64(streamer.Height),
Weight: util.DerefInt64(streamer.Weight),
City: util.DerefString(streamer.City),
Constellation: util.DerefString(streamer.Constellation),
LastZoneMomentCreateDayStart: lastZoneMomentCreateDay,
2024-08-20 18:08:35 +08:00
WechatCoinPrice: wechatcoinprice,
ZoneAdmissionPrice: zoneadmissionprice,
2024-08-15 04:56:58 +08:00
Ct: time.Now().Unix(),
Ut: time.Now().Unix(),
DelFlag: 0,
})
}
2024-08-20 18:28:44 +08:00
fmt.Printf("]")
2024-08-15 04:56:58 +08:00
err = escli.CreateStreamerAcct(ctx, streameraccts)
if err != nil {
fmt.Printf("CreateStreamerAcct : %v", err)
return
}
fmt.Println("End importing...")
}