by Robin at 20240913
This commit is contained in:
parent
e563f5ee4e
commit
1cf1a7ca75
|
@ -0,0 +1,5 @@
|
|||
package cmd
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
|
@ -1,13 +1,9 @@
|
|||
package importfunc
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"math/rand"
|
||||
|
||||
"data_prep/dbstruct"
|
||||
"data_prep/mongo"
|
||||
|
@ -22,56 +18,39 @@ func ImportUserIdMap() {
|
|||
}
|
||||
ctx := context.Background()
|
||||
|
||||
infilePath := "/app/dataprep/file/user_id_map.txt"
|
||||
|
||||
infile, err := os.Open(infilePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Open File Err : %v", err)
|
||||
}
|
||||
|
||||
defer infile.Close()
|
||||
|
||||
reader := bufio.NewReader(infile)
|
||||
|
||||
userIdMaps := make([]*dbstruct.UserIdMap, 0)
|
||||
|
||||
for {
|
||||
str, err := reader.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("ReadString fail : %v", err)
|
||||
return
|
||||
// 打乱
|
||||
list := make([]int64, 0)
|
||||
for i := int64(1000000); i < 100000000; i++ {
|
||||
list = append(list, i)
|
||||
}
|
||||
rand.Shuffle(99000000, func(i, j int) {
|
||||
list[i], list[j] = list[j], list[i]
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
for i := range list {
|
||||
seq := int64(1000000) + int64(i)
|
||||
userId := list[i]
|
||||
userIdMaps = append(userIdMaps, &dbstruct.UserIdMap{
|
||||
Seq: int64(seq),
|
||||
UserId: int64(userId),
|
||||
})
|
||||
if len(userIdMaps) == 10000 {
|
||||
mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateMappedUserIds err :%v", err)
|
||||
}
|
||||
userIdMaps = make([]*dbstruct.UserIdMap, 0)
|
||||
}
|
||||
}
|
||||
|
||||
if len(userIdMaps) > 0 {
|
||||
mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateMappedUserIds err :%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Import into test success")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue