test
This commit is contained in:
parent
076ff8cfd4
commit
fc6f81c29f
146
cmd/main.go
146
cmd/main.go
|
@ -1,17 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Leufolium/test/dbstruct"
|
||||
"github.com/Leufolium/test/idgenerator"
|
||||
"github.com/Leufolium/test/mongo"
|
||||
goproto "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
@ -25,139 +17,11 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
infilePath := "/app/dataprep/file/outfile.txt"
|
||||
infoPath := "/app/dataprep/file/infile.txt"
|
||||
|
||||
infile, err := os.Open(infilePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Open File Err : %v", err)
|
||||
}
|
||||
|
||||
infofile, err1 := os.Open(infoPath)
|
||||
if err1 != nil {
|
||||
fmt.Printf("Open File Err : %v", err)
|
||||
}
|
||||
|
||||
defer infile.Close()
|
||||
|
||||
reader := bufio.NewReader(infile)
|
||||
inforeader := bufio.NewReader(infofile)
|
||||
|
||||
_map := make(map[int64]int64)
|
||||
|
||||
for {
|
||||
str, err := reader.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("ReadString fail : %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
strs := strings.Split(str, ":")
|
||||
seqStr := strs[0]
|
||||
userIdStr := strs[1]
|
||||
userIdStr = strings.ReplaceAll(userIdStr, "\n", "")
|
||||
userIdStr = strings.ReplaceAll(userIdStr, "\r", "")
|
||||
|
||||
seq, err := strconv.Atoi(seqStr)
|
||||
if err != nil {
|
||||
fmt.Printf("atoi fail : %v", err)
|
||||
return
|
||||
}
|
||||
userId, err := strconv.Atoi(userIdStr)
|
||||
if err != nil {
|
||||
fmt.Printf("atoi fail : %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
_map[int64(seq)] = int64(userId)
|
||||
}
|
||||
|
||||
imageIds := []int64{1}
|
||||
offset := 0
|
||||
for {
|
||||
|
||||
str, err := inforeader.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("ReadString fail : %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
strs := strings.Split(str, " ")
|
||||
name := strs[0]
|
||||
//mobilephone := strs[1]
|
||||
phonehash := strs[2]
|
||||
aes := strs[3]
|
||||
aes = strings.ReplaceAll(aes, "\n", "")
|
||||
aes = strings.ReplaceAll(aes, "\r", "")
|
||||
|
||||
accountSeqId, err := client.GetAndUpdateAccountIdSeq(context.Background())
|
||||
if err != nil {
|
||||
fmt.Printf("GetAndUpdateAccountIdSeq err : %v", err)
|
||||
}
|
||||
userSeqId, err := client.GetAndUpdateUserIdSeq(context.Background())
|
||||
if err != nil {
|
||||
fmt.Printf("GetAndUpdateUserIdSeq err : %v", err)
|
||||
}
|
||||
|
||||
account := &dbstruct.Account{
|
||||
Mid: goproto.Int64(int64(accountSeqId.Seq)),
|
||||
Name: goproto.String(name),
|
||||
UserId: goproto.Int64(_map[userSeqId.Seq]),
|
||||
Avatar: &dbstruct.MediaComponent{
|
||||
ImageIds: &imageIds,
|
||||
},
|
||||
MobilePhone: goproto.String(aes),
|
||||
PhoneHash: goproto.String(phonehash),
|
||||
RegionCode: goproto.String("86"),
|
||||
Level: goproto.Int64(1),
|
||||
Role: goproto.Int64(0),
|
||||
CurrentExp: goproto.Int64(0),
|
||||
CurrentLevelExp: goproto.Int64(100),
|
||||
IsDndModeEnabled: goproto.Int64(0),
|
||||
GoldNum: goproto.Int64(0),
|
||||
DiamondNum: goproto.Int64(0),
|
||||
Ct: goproto.Int64(time.Now().Unix()),
|
||||
Ut: goproto.Int64(time.Now().Unix()),
|
||||
DelFlag: goproto.Int64(0),
|
||||
}
|
||||
if strings.HasPrefix(name, "运营") {
|
||||
account.Role = goproto.Int64(2)
|
||||
}
|
||||
|
||||
err = client.CreateAccount(context.Background(), account)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateAccount err : %v", err)
|
||||
}
|
||||
|
||||
login := &dbstruct.Login{
|
||||
Id: goproto.Int64(idgenerator.GenLoginId() + int64(offset)),
|
||||
Mid: account.Mid,
|
||||
Password: goproto.String("472642e65f4132e33a4b916f82165e1a"),
|
||||
PhoneHash: goproto.String(phonehash),
|
||||
RegionCode: goproto.String("86"),
|
||||
IsLogined: goproto.Int64(0),
|
||||
LastLoginTime: goproto.Int64(0),
|
||||
WrongPswdTimes: goproto.Int64(0),
|
||||
IsEnabled: goproto.Int64(1),
|
||||
IsLocked: goproto.Int64(0),
|
||||
IsBanned: goproto.Int64(0),
|
||||
Ct: goproto.Int64(time.Now().Unix()),
|
||||
Ut: goproto.Int64(time.Now().Unix()),
|
||||
DelFlag: goproto.Int64(0),
|
||||
}
|
||||
|
||||
err = client.CreateLogin(context.Background(), login)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateLogin err : %v", err)
|
||||
}
|
||||
|
||||
offset++
|
||||
ctx := context.Background()
|
||||
account, _ := client.GetAccountListByMid(ctx, 2)
|
||||
if account != nil {
|
||||
account.UserIdString = goproto.String(fmt.Sprint(*account.UserId))
|
||||
client.UpdateAccount(ctx, account)
|
||||
}
|
||||
|
||||
fmt.Println("End importing...")
|
||||
|
|
|
@ -20,8 +20,13 @@ type Account struct {
|
|||
IsDndModeEnabled *int64 `json:"is_dnd_mode_enabled" bson:"is_dnd_mode_enabled"` // 是否开启勿扰模式
|
||||
GoldNum *int64 `json:"gold_num" bson:"gold_num"` // 金币数量
|
||||
DiamondNum *int64 `json:"diamond_num" bson:"diamond_num"` // 钻石数量
|
||||
Inviter *int64 `json:"inviter" bson:"inviter"` // 邀请人user_id
|
||||
IsAMember *int64 `json:"is_a_member" bson:"is_a_member"` // 是否是会员,0-否,1-是
|
||||
Status *int64 `json:"status" bson:"status"` // 账户状态,0-正常,1-账户注销中,2-账户已注销
|
||||
DevType *int32 `bson:"dev_type"` // 注册来源
|
||||
Latitude *float64 `bson:"latitude"` // 纬度
|
||||
Longitude *float64 `bson:"longitude"` // 经度
|
||||
UserIdString *string `bson:"user_id_string"` // string型user_id,为模糊匹配设置
|
||||
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记,0-否,1-是
|
||||
|
|
|
@ -3,6 +3,7 @@ package mongo
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Leufolium/test/dbstruct"
|
||||
"github.com/qiniu/qmgo"
|
||||
|
@ -131,3 +132,35 @@ func (m *Mongo) GetMappedUserId(ctx context.Context, userIdSeq int64) (*dbstruct
|
|||
err := col.Find(ctx, query).One(&userIdMap)
|
||||
return userIdMap, err
|
||||
}
|
||||
|
||||
func (m *Mongo) GetAccountListByMid(ctx context.Context, mid int64) (*dbstruct.Account, error) {
|
||||
col := m.getColAccount()
|
||||
account := &dbstruct.Account{}
|
||||
|
||||
query := qmgo.M{
|
||||
"_id": mid,
|
||||
}
|
||||
|
||||
err := col.Find(ctx, query).One(account)
|
||||
if err == qmgo.ErrNoSuchDocuments {
|
||||
err = nil
|
||||
return nil, err
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return account, err
|
||||
}
|
||||
|
||||
func (m *Mongo) UpdateAccount(ctx context.Context, account *dbstruct.Account) error {
|
||||
col := m.getColAccount()
|
||||
set := qmgo.M{
|
||||
"user_id_string": *account.UserIdString,
|
||||
}
|
||||
set["ut"] = time.Now().Unix()
|
||||
up := qmgo.M{
|
||||
"$set": set,
|
||||
}
|
||||
err := col.UpdateId(ctx, *account.Mid, up)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue