初始化主播账号

This commit is contained in:
Leufolium 2023-12-24 22:22:45 +08:00
parent 7416cdcc8b
commit fb58491c16
18 changed files with 1293 additions and 24 deletions

View File

@ -8,8 +8,12 @@ import (
"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"
)
func main() {
@ -21,31 +25,29 @@ func main() {
return
}
infilePath := "/app/dataprep/file/outfile.txt"
infilePath := "/Users/PC/Desktop/dataprep/dataprep/file/outfile.txt"
infoPath := "/Users/PC/Desktop/dataprep/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)
list := make([]*mongo.UserIdMap, 0)
_map := make(map[int64]int64)
for {
str, err := reader.ReadString('\n')
if err == io.EOF {
err := client.CreateBatch(context.Background(), list)
if err != nil {
fmt.Printf("CreateBatch fail : %v", err)
return
}
if len(list) > 0 {
fmt.Printf("%v\n", list[len(list)-1])
}
break
}
if err != nil {
@ -70,20 +72,89 @@ func main() {
return
}
list = append(list, &mongo.UserIdMap{
Seq: int64(seq),
UserId: int64(userId),
})
_map[int64(seq)] = int64(userId)
}
if len(list) == 10000 {
err := client.CreateBatch(context.Background(), list)
if err != nil {
fmt.Printf("CreateBatch fail : %v", err)
return
}
fmt.Printf("%v\n", list[9999])
list = make([]*mongo.UserIdMap, 0)
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),
}
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++
}
fmt.Println("End importing...")

28
dbstruct/account.go Normal file
View File

@ -0,0 +1,28 @@
package dbstruct
const (
MemRoleBuyer = 1 // 买家
)
// Account 用户结构
type Account struct {
Mid *int64 `json:"mid" bson:"_id"` // 用户表Id
Name *string `json:"name" bson:"name"` // 用户名
UserId *int64 `json:"user_id" bson:"user_id"` // 业务Id
Avatar *MediaComponent `json:"avatar" bson:"avatar"` // 头像
MobilePhone *string `json:"mobile_phone" bson:"mobile_phone" jcrypto:"rsa" bcrypto:"aes_cbc|1|0"` // 手机号,数据库加密,查询不解密
PhoneHash *string `json:"phone_hash" bson:"phone_hash"` // 手机号hash值
RegionCode *string `json:"region_code" bson:"region_code"` // 地区码
Level *int64 `json:"level" bson:"level"` // 等级
Role *int64 `json:"role" bson:"role"` // 角色
CurrentExp *int64 `json:"current_exp" bson:"current_exp"` // 当前经验
CurrentLevelExp *int64 `json:"current_level_exp" bson:"current_level_exp"` // 当前等级总经验
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"` // 钻石数量
Latitude *float64 `bson:"latitude"` // 纬度
Longitude *float64 `bson:"longitude"` // 经度
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记0-否1-是
}

50
dbstruct/idSeq.go Normal file
View File

@ -0,0 +1,50 @@
package dbstruct
type UserIdSeq struct {
Seq int64 //用户业务id序列号
}
type UserIdMap struct {
Seq int64 `json:"seq" bson:"_id"` //用户业务id序列号
UserId int64 `json:"user_id" bson:"user_id"` //映射后用户业务id序列号
}
type AccountIdSeq struct {
Seq int64 //用户Id序列号
}
type MomentIdSeq struct {
Seq int64 //动态Id序列号
}
type StreamerAuthApprovalIdSeq struct {
Seq int64 //女神认证Id序列号
}
type AccountRelationIdSeq struct {
Seq int64 //用户关系Id序列号
}
type StreamerLinkIdSeq struct {
Seq int64 //主播链接Id序列号
}
type UserWxAddCheckIdSeq struct {
Seq int64 //用户微信添加审核Id序列号
}
type RealNameAuthenticationIdSeq struct {
Seq int64 //实名认证ID序列号
}
type ContactCustomerServiceIdSeq struct {
Seq int64 //联系客服ID序列号
}
type ContactCustomerServiceSessionIdSeq struct {
Seq int64 //联系客服对话ID序列号
}
type MediaIdSeq struct {
Seq int64 `json:"seq" bson:"seq"`
}

18
dbstruct/login.go Normal file
View File

@ -0,0 +1,18 @@
package dbstruct
type Login struct {
Id *int64 `json:"id" bson:"_id"` // 登录表id
Mid *int64 `json:"mid" bson:"mid"` // 用户id
Password *string `json:"password" bson:"password"` // 密码
PhoneHash *string `json:"phone_hash" bson:"phone_hash"` // 手机号hash值
RegionCode *string `json:"region_code" bson:"region_code"` // 国家区号
IsLogined *int64 `json:"is_logined" bson:"is_logined"` // 是否登陆0-否1-是
LastLoginTime *int64 `json:"last_login_time" bson:"last_login_time"` // 最后登陆时间
WrongPswdTimes *int64 `json:"wrong_pswd_times" bson:"wrong_pswd_times"` // 密码错误次数
IsEnabled *int64 `json:"is_enabled" bson:"is_enabled"` // 是否启用0-否1-是
IsLocked *int64 `json:"is_locked" bson:"is_locked"` // 是否锁定0-否1-是
IsBanned *int64 `json:"is_banned" bson:"is_banned"` // 是否封禁0-否1-是
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记0-否1-是
}

41
dbstruct/media.go Normal file
View File

@ -0,0 +1,41 @@
package dbstruct
// 图片
type Image struct {
Id int64 `json:"id" bson:"_id"` // 图片id
Ct int64 `json:"ct" bson:"ct"` // 创建时间
Ut int64 `json:"ut" bson:"ut"` // 更新时间
SrcId string `json:"src_id" bson:"src_id"` // 源id
MD5 string `json:"md5" bson:"md5"` // 视频md5
W int64 `json:"w" bson:"w"` // 宽
H int64 `json:"h" bson:"h"` // 高
Fmt string `json:"fmt" bson:"fmt"` // 图片格式
}
type ToCImage struct {
Id int64 `json:"id"` // 图片id
W int64 `json:"w"` // 宽
H int64 `json:"h"` // 高
Fmt string `json:"fmt"` // 图片格式
Urls []string `json:"urls"` // 图片展示地址
}
// 视频
type Video struct {
Id int64 `json:"id" bson:"_id"` // 视频id
Ct int64 `json:"ct" bson:"ct"` // 创建时间
Ut int64 `json:"ut" bson:"ut"` // 更新时间
SrcId string `json:"src_id" bson:"src_id"` // 源id
CoverSrcId string `json:"cover_src_id" bson:"cover_src_id"` // cover srcId
CoverId int64 `json:"cover_id" bson:"cover_id"` // 封面id
MD5 string `json:"md5" bson:"md5"` // 视频md5
Dur int64 `json:"dur" bson:"dur"` // 视频时长
Fmt string `json:"fmt" bson:"fmt"`
}
type ToCVideo struct {
Id int64 `json:"id"` // 视频id
Dur int64 `json:"dur"` // 视频时
CoverUrls []string `json:"cover_urls"` // 视频封面地址
Urls []string `json:"urls"` // 视频地址
}

View File

@ -0,0 +1,44 @@
package dbstruct
type MediaComponent struct {
ImageIds *[]int64 `json:"image_ids" bson:"image_ids"` // 图片ids
VideoIds *[]int64 `json:"video_ids" bson:"video_ids"` // 视频ids
Images []*ToCImage `json:"images"`
Videos []*ToCVideo `json:"videos"`
}
func (p *MediaComponent) GetImageIds() []int64 {
if p != nil && p.ImageIds != nil {
return *p.ImageIds
}
return nil
}
func (p *MediaComponent) GetVideoIds() []int64 {
if p != nil && p.VideoIds != nil {
return *p.VideoIds
}
return nil
}
func (p *MediaComponent) SetImages(images []*ToCImage) {
if p != nil {
p.Images = make([]*ToCImage, 0)
p.Images = append(p.Images, images...)
}
}
func (p *MediaComponent) SetVideos(videos []*ToCVideo) {
if p != nil {
p.Videos = make([]*ToCVideo, 0)
p.Videos = append(p.Videos, videos...)
}
}
// ImageIds和VideoIds不可同时为空
func (p *MediaComponent) IsEmpty() bool {
if p == nil {
return true
}
return len(p.GetImageIds()) == 0 && len(p.GetVideoIds()) == 0
}

149
file/infile.txt Normal file
View File

@ -0,0 +1,149 @@
猪猪女侠 18333522222 9B22AAC69A2269080A17E282B5233D8CB35601A4FE5C81D36BFA1574304B6739 yEJifJ6homcVtb7ytHdP3A==
宋昱欣Hitomi 15618888167 2F2D7C8FD8F55D64F18D133CA5420691D1E8A0E973C3788D2DB28B6B41D49819 lgwih9Z/IwNFc5INWQtHSQ==
詹詹 18305511841 ADFB84D5F728D4D2906BCEF03C820D8A8C22FF66E910F50314171FCB84721770 TY+xfSCJzCiyy+hQX9j6Ew==
静静大人 13370700555 675A494FF948C46D3BE36002377A70457002E663CA945022A86B15064F313D5F DOKbP7yCmLJonJ9PVi8iPA==
sia 15578830624 50DA5F6DBC3A473DB107477532384894CC1863E22056CCEA48F76BB8401DDB29 jPUUST4pCd1MciFXBMZY8w==
咩咩 13550877340 83D4FC716CA6C50E501E98F67F1CF160A0C61F2280BB1EC3B5A77354520A8C5B kdY5AyY+gzYj4clm5QxLLA==
易阳 15652800555 B6338D136BBAF07768402279D68547914FD772125224AB91A14955883FDC6658 b+ixluyMjMeCywoG5LMdNA==
梓琳 13533338552 57310185CB1FA69B33929D582761B1754BC657398EB75614D5822BE1B7BE60F4 IsYwJauAA2tjNVqCMfo/yg==
阿银 18504058389 2F08EDA6F72C783CD8C3039D30994E1BBCDA5CF4BBBDE47AC2F3DCA0E31FF68D 5VrExOupVksOUlAYbgicyg==
银紫 18846080107 413BD5FD78E284B634BF4F87136135457F37D334B9032A1D15DECF502E7A3A05 2NgTSm+guVhLcYfzKwjkXQ==
博乾 18544358556 6FE0CDACCCAAE409FDD0C4F07354FA109E99B0DD398CBFB3C223D32EA154C6AF gApo7fBBklmsb0E8vO67Cg==
恩馨很甜 13656999764 2C58AEBFAAB79BFD43BDF7544D117E0AE16197F1660DEAE7C62D8269919A1207 fs4+ZTL+zZpkZxqO9DStfA==
TATTOO-纹身师桃子 13761849759 D2067807FA22B2A72916BE9FAE443883F7E65C4B07B0893BBA9BCD54BE09823F LTQfCvil4f/L6Q3cOh2lUg==
LoganOne3 13248365521 C2E93C49A6976EF8E95DECDB9E263BAC8609153B93CEF9128549087199251707 wjMSM8vlnuBp0Z8wQ52JzQ==
一妍爱运动 13922491517 46280580B6B26F164983E0F3A25DA7C2557C61D3CCF2964EA26F9AE589317A00 RZlOfbqMV3kQqTOwmcCrDw==
菲majia 13647930416 D8452FF955B2A3D02E1F67B2F1979A3DFC52B1ADC96E877E2D269D60C54D0D31 5YE69WVeSaNbpHBltnLgaA==
Uu酱 17398177261 BF0F70D9177DDB2C5B4B1AC4E5C236CBC86EE6C0CF3E637DB34A9411313CC135 WypOfhwb8k41wTEyVXOgxQ==
小师妹 17611751358 189B57F644B75154F3DB5DCE799EA57AB6AC7438F5BB773FE11A5F3B6893BEAC w10Iabn0XzonfgViWA5Khg==
这里是小树苗苗儿 17371772736 5B15C2B1ACB41A2F8E3EA3E7A56B14B1A1BD42B2B45B5C23B4669827CC6A43A7 my2EcE+JhozYOkxzGVkOKQ==
钱冰Giovanna 13126237836 CD4F7333FBC3597B7351CE2DF0340D2848F201EDE0B39A2C059513D54D2C8A3F aOqBizC0NuCKCuJBqitXSA==
杨姓奇女子 15026042283 9F5E26B1D24C9CAB14F8BFB19501672A9E455D50493EF6C3ECC69196B0C5E6D2 3NzqFexhydgTcb5SEzayQg==
李李好甜 17631312585 F45FCEF17A99D09C2098AB45E564573974DDC924CF9BDD71F4F01C8BBAF89590 q4YP6H2msBYw0Pqw4WZG6w==
MIYA 17604700080 5C25B1E6993A2A49D1185D459236A3C65FAF0683AEFD3BBC6A454DAE7A3982AB tmD30z7rO0XQLjs8Yk77ug==
任智桃 18284974701 73BCDCBA0AEC73FED9E4BBD17334609ADDEEA8D376380CC6CE98ED990E7EC749 DRw5C3vU4N97IMhqWH2bOw==
馨子baby 13160650408 7FAD7913D8267F7C7DAD2BDCB30EF052AB85BFBBD505D28A8D7FA9041B304D14 DHVXas6ZiJnQ8CoV4yB6+Q==
贝蒂蔓蔓 13504460065 8C0C7DC620EEB3CC84549B7D4DE0DCCE1952F1E252820D1236D0DA4507098BA0 bVoEiBISf+ODQsUXxR+f1g==
夏蓝 13520109074 4BC64BD84B39073D0404B66D60CB1C6826BCF0D902BDD71CE6EE95CDD1597B1F Hb4bmrsG1c+L55/WlGhe/Q==
美酱Nami 18916394242 E41F44818F1FBDB85AF10A39F5C0C4D43E506AED98BCA6F9A1C001BDB371DCE7 OhLLjZ8MGbobkkn7fxEFFg==
凌大小姐 17858845077 CE9744086FC66FD118B762641A8FB0E883D5FD018E2A44CBC0CA06AB0CB42A6A G7hvOKoZlLKVcO8XmG7lRw==
小酒伏特加 15873148468 7AD7DC4D6F5B7C6B17C6CB9408E2930DFC8FBF3FA87F2C09985EBE78B8BFA7C2 TDEVKBJ/EluGbR3YztW+vg==
落落酱 15390072655 87801C0644C125829A1D3FBD267B512CB997CFDCDAEEB65DA3F73DDA04843BBD 7b2/s+j1LSVMc5jhUcAsmw==
章鱼小童谣 18843305306 4B2DDB6820EE503FEAC46C743BE416FC7F14305333D1F7F6B831C468E1EBCE77 TBU0M/EgjI3UeqrM1xelzg==
宝宝子 15524263835 49AC3E5A2AF7E922E278CE84DE28410DD10E9FE9C39A89AF55F6E7F7407E7090 IggOMIrNuAZ+DWP8Bg+Y4Q==
性感羊秘 15960236407 7CEC8FD5FBBAB0D6D3B01E0D0B97381ED0B9FF075E4C0754BC930318C57B656F QBbcB4+tt7wcmaRhEJkvrg==
沈真理 18581837673 ADED7BA93FA22F94E262BFEDF4D58B67269814C9C469948764B47197EAECBCBB C7lRfZcKpTqRzRSAjGS5PA==
晴子兔 18070513696 83489B3871E3BD44C35BD3EF388FA5EF41CF98374B312DFC42985D572A0CA148 qeXfusmBvQtjjHQm5dBthw==
密友50009823 15554201129 F4B28D288984BD6E7BEB1EB533E9DCDF8CF4BE9619441FED1924BDE412438726 T83p62Ma2Zq+uV00iD6cDg==
慢慢妹妹 15008200160 3F0B49E92C09EEE83CBF215194A48D89C7FCCB40D7C4E7F9DF925111CFF58D76 2+DSm++VAAHUQXMpReiFtQ==
安琪啦baby 18964988981 34D88073548025733337583E07E9C2942D7395CDD3F3D57F4AD01CCF0D01CB3A QG4xPZbdcnM8te+5GYJ/kQ==
抖音艾柔柔 17375566500 481B9A215A97394595EE95CDEB7C54F64522C4E3C1FF3B979AB4D216848A1471 ZlnaSFqoO+JranqK/VhB6A==
小 13033973566 9DB9FB288AB90F2D09D8DEA6428BBA52B1D91A74C9861F8A6D71C7C1E7D27F51 U5f7Ib7Z3RKN/ieXxLfMgQ==
糖糖老师 18975554617 6455C8CAC59A8395E1A93C5885006676AF1DA54C29638EF7CDD128BC2BE8ECB6 tgDR8NB7ZjuHLu3IP84/0w==
狗剩同学 16621600123 C34C56FBB4481EDE1E66FED73556D522CF50846E58E629D4A2C2321CB600B4A5 rP302NCXXNRg8SPh5vrrCQ==
快乐阿拉蕾 19958936310 F0DDB76292A1EE1D7547E613636BAF81848E710264A082B07BBCDAE541194B00 bPL/kdPSTRNRNbC0VDZxNw==
陈佩奇 15803080996 152EFA574D5E156A7B2F45F41D6424C08CB1345854F837CB85EB581CC6DF5778 0rQ0tgr0JXGL4TSdiaj18Q==
陈佩奇 18075154137 7BEA100932300A3069A3147C8BB4296116B59164A0F1D4430EA2F52FF5B15704 ZDQWFbS7LLwU1mwPXvmibw==
雪霏霏FEI 18874096060 DE98B830E3CD5EDD95C99F58575CB3C864D8501E1293C33D4C2F75F202DC3B11 sLwyz+YgtXp/HL4tJF1kAw==
呆呆娜 18278337228 06ECE4E28784D644FF9D965E7EBF5D2F857C139672535857F3FDA6EF50B2196A LZs9gq34HUxtymymNfDwDA==
小芷儿 15197971283 B53285647181ED9DFFA2D714C8B5962729FA80F961981DBA6FA82B83594A1B9D 4YmziEtyvNR64jjmarLuOA==
芭比洁 19851913533 0B8FC51AF8D3E6A2C2AAEF2F1F5E2C4AE2FED7CB4EE531F0F5B906C485879767 APAiODBpSKQrz3AVZojNmA==
小辣椒呀LAL 18235950181 ADC5E803ED0520700CEAFB7A6A6275C8A823490BBB5B5A3025304D45517B8731 bqqAZosAoXU/Cf5048ZZfQ==
小柔限定 15659593346 A335C4064B710AC18D47D564383A9BCB4F606A990A0900A3FFBEB85CABC056C2 5zTlNjWbuYkHQtgySSrEiA==
密友56456137 15097897375 2F7F7E5544F6DA09200925DC269E1060375BB55034CAA3548DCE30C4D10581AE Gc4tVl0IGzSJ6JftPqOCVg==
抖音Spidery 15270623857 E6E77DB85B1E90448F9B21FBB5351227C53E7D915E9A6AC693B68D375BBE9C07 J+uBa183c9HaMU/d9fBlsw==
是信息 13572152398 627A1D80DBBB41554C1F8B4152B07F9E894C14EA5E163E98F32D7388AFB7F065 uId/dTar40IOaobzHQF1og==
文茜 17823781616 E3FF8801B49B5836BBAA0E09589F4CD29257A1C97B29E6CCFF459843CEFDA676 nOZ8+sghz+7vH8vaHw7cSA==
张鑫Amy 18310357600 433AD4E23BCA82A1627BA19612F5F8D0F9B405194B7CE89B67036E82C587CDE3 qjX6QRVLw3KDlpZ/DUmLoA==
Kellybabybaby 19928396669 3C985EFF49D9025A68CAF6030216817DDE66D722C33222C9A27A418093C2FE83 gMWS7KHeW4GREc1ExfjhLw==
鱼神 17745178103 AEB81D2480B37FDA8F0A57E8B3058C9DEF15D81DAE90AAA7610706FF0A83A543 n4FTbgOcdZNVaOUAMGKHYw==
媛媛酱SAYUKI 15057700920 87ED63275A3E6C9EB566272BDE5AC5CE66478E37EB921493410878DAE86A1E43 DSIBbRe+wSYXI7IhF+J/MA==
相扑猫 13795162131 8F6B7131C4C9704D4D4F154369AAA3C513E9E7F3B9E1E8F1CE3BDFC4D001A02A CvUDl+TxjTACguVwamvICw==
左公子666 18740808897 B84358332DD6395363D04BF63BF7E526F67F62926F9EB3FCF722213CAD468659 IlAGLldJGiwvvVTEZqqObg==
王兔兔啊 13754683334 2C967A47C94CEA2C68C7FE5A5D0DD761C0BECAAB608273270A30622CA63C7D55 h94adpjOEEOZyJQTmC76fA==
果儿Victoria 13840290626 82EA0B5EA9A0CFA6827D7158A26A5E38186A13E712A86495D087DBE5E04B15ED NGSNa1eapOKoBKk3h6tYtg==
Dull-迷人 13120727583 DDDEE43DEDA65E6C00C6EB75984059BB86AD5D1362517043A73E522E2025C68B 6V+hGqFTiKZrz8LG6TvQzA==
杉杉超辣 15091776563 74B8EA1B1205995ECDCD762880CAD80DB18A8029ACAEE29B54B53B266FC288AA c5oeu0o7wfTP6BNr8/+b1Q==
洁己u 17674765681 C08C0099613A0B672115CCFE641FC696B7BDD2B61539CC0DA4723BAF69365EEA eY1LyiSZ2LzHqY5fVyJS5A==
小雅子 18406555123 85CFAF37CC9FB51C2BB82035E060D9B76EBDEC68FB34262B2C416CF5470E3CFD x7Fdl/pq3ojCjMfUYCeoWA==
卡戴星 18664569575 5F9629929C1FBD3EA901679C36FF41C0F66D2FB823C31BC3FD0D1BEB5D3D60F3 2Aw/vmSkWuIz2/jd0mPObA==
瘦宝 13146600300 27B1AFC328A025812749E637049DA85B2BC2251B28BA6A557DE025403BB95D6D y7itHY+YP3v0PKrBFn9NZA==
醇子小姨 18841526979 F0D800DBEC99FD6C62531177FB38A5FAFCA3B975FF5CFE8E8CBEE0A0A847BDBC YSUgRQK/EtiOMeZpyl00FA==
保守的二舅妈 17625188530 4247D3C25D0032E9B052E009C8D93CE1BCD6EFB7E78E7894387218CC191CBA3F JkhpxQMJkI4xe5kz3+t8XQ==
俏妞qiaoniutT 13567630660 1EB101655F5DBEF84E4B5BCD6EBEB097B62169A17929C94B7C012985977C13FD wrXb8gTTfvM8quLFk0dAIw==
嘉油站 13860174604 411693DEE7CF392855D224DA91A8073A1E8F76D32863078EDA35932B9EB28A8D pv9PO3P4HcYwg1GnV83FOw==
不爱笑的赛琳 18214741220 905CD0BA485656D709F68CBE0A7FE3AFD879A1BA06F55138D753BD2BEFE5983A LyuBCPEsO9oI0oemdHz6GQ==
纪念小小V 13224001190 83EE57EB8E62F9C9D6C50C80A5BFDEE288E765B69BB4796CCDE9B8009C97D23C x3JcXPhf9J4cUbFwq56fZA==
葛征GEZHENGO 13661176093 04EC51EECBED86AF48DE2FFA1CE7BB42CEAAB3858A5967C9E6E74663B5ED1E4C Spv2mj4Fj64gXsp6fPqGHg==
u金希儿 15029276666 36862053F226B368F7B3E2E556659011BC5997411DEB9D8882C8BCCB7AB9A970 E0ikA9gHsI1znCZmgEPmkg==
女刺客 18573177773 26052EE71A656AAB00EDFCBACB43FCA6C4DEA76E2FE423DD553F383D2565519A mEJCJRybX+yHa2sliQ3dlQ==
你的荷拉 18046238515 6796D40C31881F53B0F9DB3BB5705C84484D9D7EC71C55550F4F282D25A2CFA9 TVixP7+3MlakkBQ0pUlf0g==
王雨纯 13085087771 AD461715E0E03AF1DA3DBF0523AB53992853BD7AA954D0B3BEAEB5A0B698ED1A OgFQodKjfIm5q/ITD5Bwww==
凌凌七DL 15099711552 97DDDD6D96295CBDE3C08DADF5334E05FAFC8AF3546FAD37EF1A7BA3A5F64AE4 xKtHOe/3DQEy2GVkXP/H1w==
炸蛋boom 18025455071 868CAE8A3AC4F7D5450F5268DF26D2D663932B25BC8B9EE5AF6604CAA79971CA R9n7fSjsgNuD5FHXg3Be5w==
周一萌呀 17721498872 0E98C7A4A8B1B33C169CC4BCF505B0E50996E2834CD157A8C7E74F417E064647 kgoNUbyukz9KM6Oik4qhrw==
金金金live 13819494426 F12FEA5DA9BADB6F6193898071D7BD5622D431A09E51DD6624594615C37FAC06 Gz41G6MXY9NO343zwpqmCg==
奶白鹿神 15868827431 3A20BAC2FF092D582B130D8CC7420806F3F3E044EA9F0BA7C0693F5CD2258CBC 868Qoranm6QzIX2+ujTcAw==
奶油泡芙 13735407280 CF17A4D23A946A8DADBBCD260F69A250A8630854335FA18C90DF3E6437E67770 xSgFUt2UvIUTh2O1UJ9fPw==
多肉大白兔Miko 13555837888 FB070E1E39FDC83AD8364BE2B75BCE75320BF32DAE67508E19A12E7B88EAFA8A EyK8l6PajpVLimNwbJlHfQ==
董一涵_ 19548112455 FB46BF55C51071A51F33ED5BCFC001AC698D727942B2564AAE945A455607FD84 qWPx1OWxa7vGyJl7lOufxA==
炎炎炎cp 17317106653 E0135D3C1CD524A21FB79A95E306FF1567676D6DDD239F17442F4ACDA4564227 ITYpT1CS6sfObvq7OiT7sA==
赵尹君伊 18001215074 CFAAA23EE9AA2CD1C78022B3FCC969A39CBAB6316065FDB8441DE689BE918C2F oZC28T1ybn0NuEqAe0/jaQ==
水蜜桃米米 13608063005 566F00A48ED7A93AE757912EC3890EAC3CF959F5AD2EF6A5DA7649C94B2236C5 7ZzE5p46yGuDRsNP4JA0sg==
聂傲娇 13732978649 1D21CCE3D1B03FCF3916653CF441667B7D9F8495031467AE57ACCF1948277D66 o+yeGFJTZ1disBcEjUKaNA==
是可馨儿 13570016474 811ED234BA9F37C4120AD08389FC7E32D236E56BB7825AB8517C67E824498135 wd9yW5mK7U8Nf3GuxsFuzA==
孟晓艺 13522222563 0E01045217BD32D0DB06D223C282D84C3377A979E734C42CB53EE7E56DB26BA7 WOiW9I5dnOI4zr2MU+bxog==
姐姐LaLion 19350924996 16C2E4083E235091F5DF400D08AE7D5CF148EB80B5DF67A5ACCCBE4F1734EA10 wkSZ4NMuFjE/mu7tS2vfGQ==
安妮_yo 15581013141 0502FDE4A4B5FDC1F7B12C3773008ABE06529B695690211374CC0B664DD90807 7FTm03iRVvxP/G8DW3HFAw==
奶瑶妹妹 13160820157 5A4C340311BD86F05F22A9180C5AF16BFD4F7DAA70F99EB843D64BE731D38C0E 6zm0b4hS/1nNR3wbbUzDag==
PUPIHAN 17260600385 4AF02B1700BBF592274CAF27F96EEB0570927DC319279D90AF52F8E082D1030E 3aHHDXMRTKwJJOVH2vPMTg==
夏天的小雪 17771147722 BA62D954AE2D26FCED9DC26CECD59FFA3D124C4FE5DA3BB58BDE204514A4EBC1 B10y/vhpYEYvsS2XBXe5yQ==
麻辣奶兔 13371765196 E430883FA6DA07E5AE2380E9210940DF0E44232CCB72C92317241C12DFEDDBBA WtbEU8HGu9KMa04i1upeHA==
于芷晴MINI 15210182156 FF40810774426190F8399CA2DE4CCFA3525B0E4998A6803DD22FC70E55959955 EWT7LHDbAfGTJL8XTa9jCA==
王秋宝 13729550791 36B7A7F54CD09E58D0EBDC9944A04A7E309D2D1D23986CBCC7EA21F2B05948A3 TtT+OJqnoDzK2DwnHEDm0w==
铁锤姐姐 15629069055 CA04793AC023546A568ECFED2F8B733CD2F115D9346AF916FA9AC6FC96450FF8 QWNZSjfk2O292yoeW+E0kw==
徐珺大哥 18823709287 D479A309608712196F97AA07830AB0492CD4A8573D96D39276512E72FFB3C9CD dzy9prqyWEwivfrtylXq5g==
徐珺大哥 13590232786 DCEAB2666D99E98E30EF4B27DE0BC8C87D4BA1C84C4DF3533DA25118D1FA38B9 gA53Kj/9k9D2v5jNXTqK5w==
我才是岚岚 15918873890 126E092148336EAF2FD0FB1E7A9D6B7BDC7279C75A1B28198AF1D453427C8DB1 VqAkkBvFzwe3DdMKoYC2eg==
奔跑晶骡子 15773631621 EB4046D0434C8866BF05BA5130F477B28CC881496C1CE9EF5FA7DDCB8D921159 zZlSpqKWVedvBtxnqJy5Gg==
无欲无求的推土君 18898376009 43CD8A1A8D43E66618BA604C154D15E2CEA0A5BA41BC5015F9E624C9D95E20B3 F4lIsMMju+vuXuRyGj5hMA==
yu酱睡不醒 18086743857 362470CBEE81F004074BB5B3A4318CABA0ACA69F79F9D94734D38699F387B7D3 8KEycPAHk8ClQ+Wn3zQBPg==
阿色 15950987513 5321D24628F75A200BA8CA889B733B0FADEDE6A400471A1C4408FDF8294438CD QB2l+WwOopzWbSkddVylOA==
瑜7 18757538780 657DA58DC05F817EFCE109048239E7BEFFF316438D2E1CEF01A95A54E1125E60 pTOincTs92hEWO7cEq/x1g==
麻利亚辣 15013908848 DAF80DE9E44C865BE75181C72B4B8CC4F47EEE3DDB229414644D2B782C958063 IB3NP0w4YXEUU3awKJAiXQ==
甜幼清 17343110192 E043F43708392D539564ED2093498DDBD7F3B211EED8E849C05FC62BA6987B2F 7ICzGWVfTeBfQLPUJ1GPxg==
宝儿茹 18539159545 DFDC29EE2F385E90C645C1FD89E0D30F138520D549DB546F6F804F91F9E403C3 7l2yLHHrg46dJUMlhsBQeQ==
奶宝妹纸 13759964146 59AEE1FF3F0B2E47A7E28A3B0BF330AD6AA19B35BCCA1E6E2C827B89D1B154CD HxY6j4IqqUQQUZtRRiQouw==
小艾根本吃不饱 15778841322 BD090FA45D0A81AF78ECE83554065F1877961F6DC89898FA0686F26E15756AB8 JMKCdeAAdX/GlFMPhcZLNQ==
小玉吃果冻 18672634982 590FA0474CCCDDAB99A9015773B8D76AB3A44C349A74DDB26E7A600BFC4A7945 Cug+d+OEhkTUt4Nsan0+FQ==
桃沢樱 19814718001 2CABB2B7A5DC4F6E8DAE0768FAAA7CF0A140F7C9526EDC6FE68EEE72010080DA j5rJOSrOyzZ1gIAg+uRBSA==
美晓 18604698520 C81273624334FB9CC0FBD5B440B10C3FF3DFAC35408214C9ACDC3A0D7985AA4B CxIZfK+A25dq0e9cRVS2Sw==
Carol周妍希 18888688767 48DFC3BE07AE9779498E21E856407549ADC095AB7038CA09EA22F4BA2C786592 vTA3Oq8arzSm0Oh/ha28+g==
圆溜溜啊圆 17780509276 57C0217C2059DF659017162A4F91C4D4480DD8333F0D122F193582FA358DBEF6 lTWnFlVYt7z/tbLBj3hjBQ==
尤妮丝 18353355273 3A52386635C2D19322F840674C17A12992E08D9B140D2839D20160943B3949A3 cNPNJCXo9MUxCFPH4enKTg==
叫我bobo小姐 13159222275 40ED200A4DB0BF7984CE3E5A29F5A18975733D8AA532A646EE8DF3F237FBDA30 gaZsLypMXCLFRBaLGVW87Q==
悦悦babe 18053598786 589D7C6BF9C8E23EDC8C10B32E5AA1CF8295A1E71A534BDEA7A793541C5F9279 +9VZZh6mYva6GxUBQnCNPQ==
喵小哟 17355698231 A4C41878207E4B32C5E4B1ADD3EDC56DD43B47D3A61F4E1F0B44AF0F1B6072EB KXzZsMYLZfGVexXcSHRriw==
九头蛇 13263566351 879642495708E9A091A1EFFE799191ABCA9E408CF3BA645DF28FD756ADF9113F IX/batLHFVYaG0VwIx3bcg==
拜托了姨妈 13032707441 1A39D383F7C75457602F6D6BB3DC51E6C223F8B458D2AA0EFD8643E9AE5EBBF4 66+UpR1Bq3oA3DdKTC1WLQ==
雯宝儿 18782231050 383E2CFED78B53F36F56E6D5B2FD8FB33B65B879F62D551EA23C1DD0454AE7FA YT128nsLWWAPKRlN+e77Xw==
沈汝凡 15807160396 C99B7060DF38A2E3DA8BD8E6B0EE761C813A5FFE662360DD0E973288D53D1BA0 EoSMlUNnjhdUtA2EcR1Ggw==
五姨太 17789827745 4B52D3D44CDD0BF5A98FDD8BD8589E6FE89C665B2FE6E60365293D00CED84F35 I+l92aK6GKlULCMuz0O5rA==
赵伊彤 15822709315 622381C53409A37608D10700BE794A74718E91D84E474AF479E42F8B73C9E3E0 TTrcC2jtntbYBrE4c+UFew==
徐莉芝booty 18127952634 950E32339A1B2B9EE2F68F7DFD1BCE9A718D09F64EA615E30D47AD5AD5AAE0A8 KR77rXo2y2pfQZH5siDnng==
冲田花老师 15986922434 90965C50BA7E99860FD69B581DF88450EDAC0A3F9021DF7AE6C5CF863D2EAA1A RCcGQ0ev3hDYUzisKFFMFg==
肉肉菲猪 13719581433 039EBB732C9F2406DB5B4563A07DBB52E3686FA69B825308102B5F1C6F3D2FFB bs3n/Kfmx+pWJBEJPcR+dg==
发福的迪丽肉巴 16518352122 075D1CE734FC8E45B807061C91509CF03E2E96C7BCF8928362F2A7606BBDEE0F kZtP+HlqV8Evtv389cqTfA==
美邵女Baby 15265358678 FCBDB25ADE2E5AEE45252EA22D14C34DEFEF0016615E0FEE0FF1415DAA41C864 Ax9RdOWRd6Dhya81BUKYLA==
杨晨晨 18520440107 4619036297BC3B9145B5DBD11787FC270CD4380CBB25CCD66DC2B68C55AA6B2D dtak7Lj4ylq8JpQ21se8ow==
玫玫 15263833572 9A11CC3287FF5DF82749C75583CEE2EA77DD1F3957CC13A3AC381F24BF0F6E53 5tLJC213Q+TPri/4s3v9KA==
绮里嘉ula 15868106668 7868D0E86C343E8EDC35CD6B545895A51048E28C01B3040097F1B3248101EE6F QbpXQXA28E1Jya/HWlA0DA==
陈老师微胖 13133603562 6FDA9CD3443BEAAC708A40DE30CD504D6382F653067D666DF695E2720B89C8DA EuVibod2wSJ6kBLXbllYgA==
羊羊崽 13260558318 6252A4BB8E749EF17F853749CB608FEECB4BF523C5CE612A2D36E47A3A89CFC8 ldBsuDXUlKhuX/e22uBZ0A==
呆萌橘子酱 18624151986 4F5570E31CFE08B1FB881177491A9651F156F73AE281528F6087689DDDA078AA BM1qaAJFNC8c+zCzHpEozQ==
李美兮 13522808945 962838F8C000B3EF69E6D4225140E395B3BFE539ACF0C1D85A353124EC762771 puXY/M/cdbwwd6ao90XtHQ==
仙儿 18572667488 36A4B9CC224273A481EFFCEFD0C6A7433D3D76F2D6C6DEFF412394E8AA5FD902 6qMbJ66l00P1GUOlu45TLA==
玫桃泡芙 15891749566 D03D89807D596412494DDEBCED2696C81D6EA4FC3F1F646CFD1C170830F89605 ZruT12+LeH3p3RhfxdyG+g==
大冰冰超甜 13939644961 1A62B66A0B96AC2DD1FFDA92D301F077A15A58B5AB2ACF4D75F300EB4F10AF61 x3TT9cYvBMn7PJZOcF6wkw==
富贵拿铁 15907719313 71BD2DB1575CDF1F5F74E1F72B7449BECBE810EA023D68CF84C1906BC668FB65 gPE52RXi/oPheC0Q+m1Wyg==
一只小胡狸 17754978681 12359C30073AEBF1BBAC844EBA04AEAFCA54DE4D2F5D97353A12FB39637EADDB spNl3iK/Va4jy/KFCoUnbw==

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.18
require github.com/qiniu/qmgo v1.1.8
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect

2
go.sum
View File

@ -1,3 +1,5 @@
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=

215
idgenerator/genid.go Normal file
View File

@ -0,0 +1,215 @@
package idgenerator
import (
"errors"
"github.com/bwmarrin/snowflake"
)
// With default settings, this snowflake generator should be sufficiently fast enough
// on most systems to generate 4096 unique ID's per millisecond. This is the maximum
// that the snowflake ID format supports. That is, around 243-244 nanoseconds per operation.
// 业务node, node ∈ [0, 1023]
const (
NodeMin = 0 // 最小node 包括
NodeMax = 1023 // 最大node 包括
)
const (
_ = iota
NodeMaterial // node 素材(商品)
NodeCatalog // node 分类
NodeOrder // node 订单
NodeBanner // node banner
NodeLogin // node login
NodeToken // node token
NodeAccount // node account
NodeVeriCode // node vericode
NodeMember // node 用户id
NodeProduct // node 商品
NodeMoment // node 动态
NodeFootPrint // node 足迹
NodeThumbsUp // node 点赞
NodeAccountRelation // node 用户关系
NodeStreamer // node 主播
NodeFeedback // node 意见反馈
NodeCallHistory // node 通话记录
NodeStreamerLink // node 主播链接
NodeUserWxAddCheck // node 用户微信添加审核
NodeRealNameAuthentication // node 实名认证
NodeContactCustomerService // node 联系客服
NodeImageAudit // node 图像审核
NodeCoinOrder // node 金币订单
NodeImageAuditTask // node 图像审核任务
NodeTextAudit // node 文字审核
NodeTextAuditTask // node 文字审核任务
)
func GenIdInt64(node int64) (int64, error) {
if node < NodeMin || node > NodeMax {
return -1, errors.New("node number must include [0, 1023]")
}
n, err := snowflake.NewNode(node)
if err != nil {
return -1, err
}
return n.Generate().Int64(), nil
}
func GenIdString(node int64) (string, error) {
if node < NodeMin || node > NodeMax {
return "", errors.New("node number must include [0, 1023]")
}
n, err := snowflake.NewNode(node)
if err != nil {
return "", err
}
return n.Generate().String(), nil
}
// 商品
func GenProductId() string {
id, _ := GenIdString(NodeProduct)
return id
}
// 订单
func GenOrderId() string {
id, _ := GenIdString(NodeOrder)
return id
}
// 金币订单
func GenCoinOrderId() string {
id, _ := GenIdString(NodeCoinOrder)
return id
}
// banner
func GenBannerId() int64 {
id, _ := GenIdInt64(NodeBanner)
return id
}
// login
func GenLoginId() int64 {
id, _ := GenIdInt64(NodeLogin)
return id
}
// token
func GenTokenId() int64 {
id, _ := GenIdInt64(NodeToken)
return id
}
// account
func GenAccountId() int64 {
id, _ := GenIdInt64(NodeAccount)
return id
}
// vericode
func GenVeriCodeId() int64 {
id, _ := GenIdInt64(NodeVeriCode)
return id
}
// catalog
func GenCatalogId() int64 {
id, _ := GenIdInt64(NodeCatalog)
return id
}
// moment
func GenMomentId() int64 {
id, _ := GenIdInt64(NodeMoment)
return id
}
// footprint
func GenFootPrintId() int64 {
id, _ := GenIdInt64(NodeFootPrint)
return id
}
// thumbs_up
func GenThumbsUpId() int64 {
id, _ := GenIdInt64(NodeThumbsUp)
return id
}
// account_relation
func GenAccountRelationId() int64 {
id, _ := GenIdInt64(NodeAccountRelation)
return id
}
// streamer
func GenStreamerId() int64 {
id, _ := GenIdInt64(NodeStreamer)
return id
}
// feedback
func GenFeedbackId() int64 {
id, _ := GenIdInt64(NodeFeedback)
return id
}
// callhistory
func GenCallHistoryId() int64 {
id, _ := GenIdInt64(NodeCallHistory)
return id
}
// streamerlink
func GenStreamerLinkId() int64 {
id, _ := GenIdInt64(NodeStreamerLink)
return id
}
// userwxaddcheck
func GenUserWxAddCheckId() int64 {
id, _ := GenIdInt64(NodeUserWxAddCheck)
return id
}
// realname_authentication
func GenRealNameAuthenticationId() int64 {
id, _ := GenIdInt64(NodeRealNameAuthentication)
return id
}
// contact_customer_service
func GenContactCustomerServiceId() int64 {
id, _ := GenIdInt64(NodeContactCustomerService)
return id
}
// // imageaudit
// func GenImageAuditId() string {
// id, _ := GenIdString(NodeImageAudit)
// return id
// }
// // imageaudittask
// func GenImageAuditTaskId() string {
// id, _ := GenIdString(NodeImageAuditTask)
// return id
// }
// // textaudit
// func GenTextAuditId() string {
// id, _ := GenIdString(NodeTextAudit)
// return id
// }
// // textaudittask
// func GenTextAuditTaskId() string {
// id, _ := GenIdString(NodeTextAuditTask)
// return id
// }

15
idgenerator/genid_test.go Normal file
View File

@ -0,0 +1,15 @@
package idgenerator
import (
"fmt"
"testing"
"time"
)
func TestGenIdInt64(t *testing.T) {
for i := 0; i < 1024; i++ {
id, err := GenIdInt64(int64(0))
fmt.Println(id, err)
time.Sleep(time.Nanosecond)
}
}

View File

@ -11,7 +11,7 @@ import (
func NewMongoClient() (*qmgo.Client, error) {
clientCfg := &qmgo.Config{
Uri: "mongodb://root:Wishpal2024@dds-bp1628b447c242e41.mongodb.rds.aliyuncs.com:3717,dds-bp1628b447c242e42.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-74245203",
Uri: "mongodb://admin:Wishpal%402023@127.0.0.1:27017",
ConnectTimeoutMS: goproto.Int64(30000),
MaxPoolSize: goproto.Uint64(16),
MinPoolSize: goproto.Uint64(0),

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/Leufolium/test/dbstruct"
"github.com/qiniu/qmgo"
)
@ -30,15 +31,103 @@ func NewMongo() (mongo *Mongo, err error) {
const (
DBUserIdSeq = "user_id_seq"
COLUserIdSeq = "user_id_seq"
COLUserIdMap = "user_id_map"
DBAccountIdSeq = "account_id_seq"
COLAccountIdSeq = "account_id_seq"
DBAccount = "account"
COLAccount = "account"
DBLogin = "login"
COLLogin = "login"
)
func (m *Mongo) getColUserIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdSeq)
}
func (m *Mongo) getColUserIdMap() *qmgo.Collection {
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdMap)
}
// Account表
func (m *Mongo) getColAccount() *qmgo.Collection {
return m.clientMix.Database(DBAccount).Collection(COLAccount)
}
// 登录表
func (m *Mongo) getColLogin() *qmgo.Collection {
return m.clientMix.Database(DBLogin).Collection(COLLogin)
}
// AccountIdSeq序列表
func (m *Mongo) getColAccountIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBAccountIdSeq).Collection(COLAccountIdSeq)
}
func (m *Mongo) CreateBatch(ctx context.Context, userIdSeqs []*UserIdMap) error {
col := m.getColUserIdMap()
_, err := col.InsertMany(ctx, userIdSeqs)
return err
}
// account相关
func (m *Mongo) CreateAccount(ctx context.Context, account *dbstruct.Account) error {
col := m.getColAccount()
_, err := col.InsertOne(ctx, account)
return err
}
func (m *Mongo) CreateLogin(ctx context.Context, login *dbstruct.Login) error {
col := m.getColLogin()
_, err := col.InsertOne(ctx, login)
return err
}
func (m *Mongo) GetAndUpdateAccountIdSeq(ctx context.Context) (accountIdSeq *dbstruct.AccountIdSeq, err error) {
col := m.getColAccountIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
accountIdSeqInstance := dbstruct.AccountIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "account_id_seq_id"}).Apply(change, &accountIdSeqInstance); err != nil {
fmt.Printf("change error : %v", err)
return
}
return &accountIdSeqInstance, err
}
func (m *Mongo) GetAndUpdateUserIdSeq(ctx context.Context) (userIdSeq *dbstruct.UserIdSeq, err error) {
col := m.getColUserIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
userIdSeqInstance := dbstruct.UserIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "user_id_seq_id"}).Apply(change, &userIdSeqInstance); err != nil {
fmt.Printf("change error : %v", err)
return
}
return &userIdSeqInstance, err
}
func (m *Mongo) GetMappedUserId(ctx context.Context, userIdSeq int64) (*dbstruct.UserIdMap, error) {
userIdMap := &dbstruct.UserIdMap{}
col := m.getColUserIdMap()
query := qmgo.M{
"_id": userIdSeq,
}
err := col.Find(ctx, query).One(&userIdMap)
return userIdMap, err
}

12
vendor/github.com/bwmarrin/snowflake/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,12 @@
language: go
go:
- 1.11.x
- 1.12.x
install:
- go get -v .
- go get -v golang.org/x/lint/golint
script:
- diff <(gofmt -d .) <(echo -n)
- go vet -x ./...
- golint -set_exit_status ./...
- go test -v -race ./...

23
vendor/github.com/bwmarrin/snowflake/LICENSE generated vendored Normal file
View File

@ -0,0 +1,23 @@
Copyright (c) 2016, Bruce
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

143
vendor/github.com/bwmarrin/snowflake/README.md generated vendored Normal file
View File

@ -0,0 +1,143 @@
snowflake
====
[![GoDoc](https://godoc.org/github.com/bwmarrin/snowflake?status.svg)](https://godoc.org/github.com/bwmarrin/snowflake) [![Go report](http://goreportcard.com/badge/bwmarrin/snowflake)](http://goreportcard.com/report/bwmarrin/snowflake) [![Coverage](http://gocover.io/_badge/github.com/bwmarrin/snowflake)](https://gocover.io/github.com/bwmarrin/snowflake) [![Build Status](https://travis-ci.org/bwmarrin/snowflake.svg?branch=master)](https://travis-ci.org/bwmarrin/snowflake) [![Discord Gophers](https://img.shields.io/badge/Discord%20Gophers-%23info-blue.svg)](https://discord.gg/0f1SbxBZjYq9jLBk)
snowflake is a [Go](https://golang.org/) package that provides
* A very simple Twitter snowflake generator.
* Methods to parse existing snowflake IDs.
* Methods to convert a snowflake ID into several other data types and back.
* JSON Marshal/Unmarshal functions to easily use snowflake IDs within a JSON API.
* Monotonic Clock calculations protect from clock drift.
**For help with this package or general Go discussion, please join the [Discord
Gophers](https://discord.gg/0f1SbxBZjYq9jLBk) chat server.**
## Status
This package should be considered stable and completed. Any additions in the
future will strongly avoid API changes to existing functions.
### ID Format
By default, the ID format follows the original Twitter snowflake format.
* The ID as a whole is a 63 bit integer stored in an int64
* 41 bits are used to store a timestamp with millisecond precision, using a custom epoch.
* 10 bits are used to store a node id - a range from 0 through 1023.
* 12 bits are used to store a sequence number - a range from 0 through 4095.
### Custom Format
You can alter the number of bits used for the node id and step number (sequence)
by setting the snowflake.NodeBits and snowflake.StepBits values. Remember that
There is a maximum of 22 bits available that can be shared between these two
values. You do not have to use all 22 bits.
### Custom Epoch
By default this package uses the Twitter Epoch of 1288834974657 or Nov 04 2010 01:42:54.
You can set your own epoch value by setting snowflake.Epoch to a time in milliseconds
to use as the epoch.
### Custom Notes
When setting custom epoch or bit values you need to set them prior to calling
any functions on the snowflake package, including NewNode(). Otherwise the
custom values you set will not be applied correctly.
### How it Works.
Each time you generate an ID, it works, like this.
* A timestamp with millisecond precision is stored using 41 bits of the ID.
* Then the NodeID is added in subsequent bits.
* Then the Sequence Number is added, starting at 0 and incrementing for each ID generated in the same millisecond. If you generate enough IDs in the same millisecond that the sequence would roll over or overfill then the generate function will pause until the next millisecond.
The default Twitter format shown below.
```
+--------------------------------------------------------------------------+
| 1 Bit Unused | 41 Bit Timestamp | 10 Bit NodeID | 12 Bit Sequence ID |
+--------------------------------------------------------------------------+
```
Using the default settings, this allows for 4096 unique IDs to be generated every millisecond, per Node ID.
## Getting Started
### Installing
This assumes you already have a working Go environment, if not please see
[this page](https://golang.org/doc/install) first.
```sh
go get github.com/bwmarrin/snowflake
```
### Usage
Import the package into your project then construct a new snowflake Node using a
unique node number. The default settings permit a node number range from 0 to 1023.
If you have set a custom NodeBits value, you will need to calculate what your
node number range will be. With the node object call the Generate() method to
generate and return a unique snowflake ID.
Keep in mind that each node you create must have a unique node number, even
across multiple servers. If you do not keep node numbers unique the generator
cannot guarantee unique IDs across all nodes.
**Example Program:**
```go
package main
import (
"fmt"
"github.com/bwmarrin/snowflake"
)
func main() {
// Create a new Node with a Node number of 1
node, err := snowflake.NewNode(1)
if err != nil {
fmt.Println(err)
return
}
// Generate a snowflake ID.
id := node.Generate()
// Print out the ID in a few different ways.
fmt.Printf("Int64 ID: %d\n", id)
fmt.Printf("String ID: %s\n", id)
fmt.Printf("Base2 ID: %s\n", id.Base2())
fmt.Printf("Base64 ID: %s\n", id.Base64())
// Print out the ID's timestamp
fmt.Printf("ID Time : %d\n", id.Time())
// Print out the ID's node number
fmt.Printf("ID Node : %d\n", id.Node())
// Print out the ID's sequence number
fmt.Printf("ID Step : %d\n", id.Step())
// Generate and print, all in one.
fmt.Printf("ID : %d\n", node.Generate().Int64())
}
```
### Performance
With default settings, this snowflake generator should be sufficiently fast
enough on most systems to generate 4096 unique ID's per millisecond. This is
the maximum that the snowflake ID format supports. That is, around 243-244
nanoseconds per operation.
Since the snowflake generator is single threaded the primary limitation will be
the maximum speed of a single processor on your system.
To benchmark the generator on your system run the following command inside the
snowflake package directory.
```sh
go test -run=^$ -bench=.
```
If your curious, check out this commit that shows benchmarks that compare a few
different ways of implementing a snowflake generator in Go.
* https://github.com/bwmarrin/snowflake/tree/9befef8908df13f4102ed21f42b083dd862b5036

365
vendor/github.com/bwmarrin/snowflake/snowflake.go generated vendored Normal file
View File

@ -0,0 +1,365 @@
// Package snowflake provides a very simple Twitter snowflake generator and parser.
package snowflake
import (
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
"strconv"
"sync"
"time"
)
var (
// Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds
// You may customize this to set a different epoch for your application.
Epoch int64 = 1288834974657
// NodeBits holds the number of bits to use for Node
// Remember, you have a total 22 bits to share between Node/Step
NodeBits uint8 = 10
// StepBits holds the number of bits to use for Step
// Remember, you have a total 22 bits to share between Node/Step
StepBits uint8 = 12
// DEPRECATED: the below four variables will be removed in a future release.
mu sync.Mutex
nodeMax int64 = -1 ^ (-1 << NodeBits)
nodeMask = nodeMax << StepBits
stepMask int64 = -1 ^ (-1 << StepBits)
timeShift = NodeBits + StepBits
nodeShift = StepBits
)
const encodeBase32Map = "ybndrfg8ejkmcpqxot1uwisza345h769"
var decodeBase32Map [256]byte
const encodeBase58Map = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
var decodeBase58Map [256]byte
// A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
type JSONSyntaxError struct{ original []byte }
func (j JSONSyntaxError) Error() string {
return fmt.Sprintf("invalid snowflake ID %q", string(j.original))
}
// ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
// ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase32 = errors.New("invalid base32")
// Create maps for decoding Base58/Base32.
// This speeds up the process tremendously.
func init() {
for i := 0; i < len(encodeBase58Map); i++ {
decodeBase58Map[i] = 0xFF
}
for i := 0; i < len(encodeBase58Map); i++ {
decodeBase58Map[encodeBase58Map[i]] = byte(i)
}
for i := 0; i < len(encodeBase32Map); i++ {
decodeBase32Map[i] = 0xFF
}
for i := 0; i < len(encodeBase32Map); i++ {
decodeBase32Map[encodeBase32Map[i]] = byte(i)
}
}
// A Node struct holds the basic information needed for a snowflake generator
// node
type Node struct {
mu sync.Mutex
epoch time.Time
time int64
node int64
step int64
nodeMax int64
nodeMask int64
stepMask int64
timeShift uint8
nodeShift uint8
}
// An ID is a custom type used for a snowflake ID. This is used so we can
// attach methods onto the ID.
type ID int64
// NewNode returns a new snowflake node that can be used to generate snowflake
// IDs
func NewNode(node int64) (*Node, error) {
// re-calc in case custom NodeBits or StepBits were set
// DEPRECATED: the below block will be removed in a future release.
mu.Lock()
nodeMax = -1 ^ (-1 << NodeBits)
nodeMask = nodeMax << StepBits
stepMask = -1 ^ (-1 << StepBits)
timeShift = NodeBits + StepBits
nodeShift = StepBits
mu.Unlock()
n := Node{}
n.node = node
n.nodeMax = -1 ^ (-1 << NodeBits)
n.nodeMask = n.nodeMax << StepBits
n.stepMask = -1 ^ (-1 << StepBits)
n.timeShift = NodeBits + StepBits
n.nodeShift = StepBits
if n.node < 0 || n.node > n.nodeMax {
return nil, errors.New("Node number must be between 0 and " + strconv.FormatInt(n.nodeMax, 10))
}
var curTime = time.Now()
// add time.Duration to curTime to make sure we use the monotonic clock if available
n.epoch = curTime.Add(time.Unix(Epoch/1000, (Epoch%1000)*1000000).Sub(curTime))
return &n, nil
}
// Generate creates and returns a unique snowflake ID
// To help guarantee uniqueness
// - Make sure your system is keeping accurate system time
// - Make sure you never have multiple nodes running with the same node ID
func (n *Node) Generate() ID {
n.mu.Lock()
now := time.Since(n.epoch).Nanoseconds() / 1000000
if now == n.time {
n.step = (n.step + 1) & n.stepMask
if n.step == 0 {
for now <= n.time {
now = time.Since(n.epoch).Nanoseconds() / 1000000
}
}
} else {
n.step = 0
}
n.time = now
r := ID((now)<<n.timeShift |
(n.node << n.nodeShift) |
(n.step),
)
n.mu.Unlock()
return r
}
// Int64 returns an int64 of the snowflake ID
func (f ID) Int64() int64 {
return int64(f)
}
// ParseInt64 converts an int64 into a snowflake ID
func ParseInt64(id int64) ID {
return ID(id)
}
// String returns a string of the snowflake ID
func (f ID) String() string {
return strconv.FormatInt(int64(f), 10)
}
// ParseString converts a string into a snowflake ID
func ParseString(id string) (ID, error) {
i, err := strconv.ParseInt(id, 10, 64)
return ID(i), err
}
// Base2 returns a string base2 of the snowflake ID
func (f ID) Base2() string {
return strconv.FormatInt(int64(f), 2)
}
// ParseBase2 converts a Base2 string into a snowflake ID
func ParseBase2(id string) (ID, error) {
i, err := strconv.ParseInt(id, 2, 64)
return ID(i), err
}
// Base32 uses the z-base-32 character set but encodes and decodes similar
// to base58, allowing it to create an even smaller result string.
// NOTE: There are many different base32 implementations so becareful when
// doing any interoperation.
func (f ID) Base32() string {
if f < 32 {
return string(encodeBase32Map[f])
}
b := make([]byte, 0, 12)
for f >= 32 {
b = append(b, encodeBase32Map[f%32])
f /= 32
}
b = append(b, encodeBase32Map[f])
for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 {
b[x], b[y] = b[y], b[x]
}
return string(b)
}
// ParseBase32 parses a base32 []byte into a snowflake ID
// NOTE: There are many different base32 implementations so becareful when
// doing any interoperation.
func ParseBase32(b []byte) (ID, error) {
var id int64
for i := range b {
if decodeBase32Map[b[i]] == 0xFF {
return -1, ErrInvalidBase32
}
id = id*32 + int64(decodeBase32Map[b[i]])
}
return ID(id), nil
}
// Base36 returns a base36 string of the snowflake ID
func (f ID) Base36() string {
return strconv.FormatInt(int64(f), 36)
}
// ParseBase36 converts a Base36 string into a snowflake ID
func ParseBase36(id string) (ID, error) {
i, err := strconv.ParseInt(id, 36, 64)
return ID(i), err
}
// Base58 returns a base58 string of the snowflake ID
func (f ID) Base58() string {
if f < 58 {
return string(encodeBase58Map[f])
}
b := make([]byte, 0, 11)
for f >= 58 {
b = append(b, encodeBase58Map[f%58])
f /= 58
}
b = append(b, encodeBase58Map[f])
for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 {
b[x], b[y] = b[y], b[x]
}
return string(b)
}
// ParseBase58 parses a base58 []byte into a snowflake ID
func ParseBase58(b []byte) (ID, error) {
var id int64
for i := range b {
if decodeBase58Map[b[i]] == 0xFF {
return -1, ErrInvalidBase58
}
id = id*58 + int64(decodeBase58Map[b[i]])
}
return ID(id), nil
}
// Base64 returns a base64 string of the snowflake ID
func (f ID) Base64() string {
return base64.StdEncoding.EncodeToString(f.Bytes())
}
// ParseBase64 converts a base64 string into a snowflake ID
func ParseBase64(id string) (ID, error) {
b, err := base64.StdEncoding.DecodeString(id)
if err != nil {
return -1, err
}
return ParseBytes(b)
}
// Bytes returns a byte slice of the snowflake ID
func (f ID) Bytes() []byte {
return []byte(f.String())
}
// ParseBytes converts a byte slice into a snowflake ID
func ParseBytes(id []byte) (ID, error) {
i, err := strconv.ParseInt(string(id), 10, 64)
return ID(i), err
}
// IntBytes returns an array of bytes of the snowflake ID, encoded as a
// big endian integer.
func (f ID) IntBytes() [8]byte {
var b [8]byte
binary.BigEndian.PutUint64(b[:], uint64(f))
return b
}
// ParseIntBytes converts an array of bytes encoded as big endian integer as
// a snowflake ID
func ParseIntBytes(id [8]byte) ID {
return ID(int64(binary.BigEndian.Uint64(id[:])))
}
// Time returns an int64 unix timestamp in milliseconds of the snowflake ID time
// DEPRECATED: the below function will be removed in a future release.
func (f ID) Time() int64 {
return (int64(f) >> timeShift) + Epoch
}
// Node returns an int64 of the snowflake ID node number
// DEPRECATED: the below function will be removed in a future release.
func (f ID) Node() int64 {
return int64(f) & nodeMask >> nodeShift
}
// Step returns an int64 of the snowflake step (or sequence) number
// DEPRECATED: the below function will be removed in a future release.
func (f ID) Step() int64 {
return int64(f) & stepMask
}
// MarshalJSON returns a json byte array string of the snowflake ID.
func (f ID) MarshalJSON() ([]byte, error) {
buff := make([]byte, 0, 22)
buff = append(buff, '"')
buff = strconv.AppendInt(buff, int64(f), 10)
buff = append(buff, '"')
return buff, nil
}
// UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.
func (f *ID) UnmarshalJSON(b []byte) error {
if len(b) < 3 || b[0] != '"' || b[len(b)-1] != '"' {
return JSONSyntaxError{b}
}
i, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 64)
if err != nil {
return err
}
*f = ID(i)
return nil
}

3
vendor/modules.txt vendored
View File

@ -1,3 +1,6 @@
# github.com/bwmarrin/snowflake v0.3.0
## explicit
github.com/bwmarrin/snowflake
# github.com/go-playground/locales v0.13.0
## explicit; go 1.13
github.com/go-playground/locales