Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into meixiongfeng
This commit is contained in:
commit
f54b2985ac
@ -9,6 +9,8 @@ import (
|
||||
|
||||
func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
||||
switch msg.SubType {
|
||||
case friend.Friend_SubType_List:
|
||||
r.handleFriendList(msg)
|
||||
case friend.Friend_SubType_Apply:
|
||||
r.handleFriendApply(msg)
|
||||
case friend.Friend_SubType_ApplyList:
|
||||
@ -32,7 +34,7 @@ func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendList() {
|
||||
req := &pb.Friend_List_Req{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_List}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -53,7 +55,7 @@ func (r *Robot) FriendSearch(nickName string) {
|
||||
NickName: nickName,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Search}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -74,7 +76,7 @@ func (r *Robot) FriendApply(friendId string) {
|
||||
FriendId: friendId,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -93,7 +95,7 @@ func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendApplyList() {
|
||||
req := &pb.Friend_ApplyList_Req{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_ApplyList}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -114,7 +116,7 @@ func (r *Robot) FriendAgree(friendIds []string) {
|
||||
FriendIds: friendIds,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Agree}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -135,7 +137,7 @@ func (r *Robot) FriendRefuse(friendIds []string) {
|
||||
FriendIds: friendIds,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Refuse}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -154,7 +156,7 @@ func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendBlacklist() {
|
||||
req := &pb.Friend_BlackList_Req{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Blacklist}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -170,10 +172,10 @@ func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
|
||||
}
|
||||
|
||||
//添加黑名单
|
||||
func (r *Robot) FriendAddBlack() {
|
||||
req := &pb.Friend_BlackAdd_Req{}
|
||||
func (r *Robot) FriendAddBlack(friendId string) {
|
||||
req := &pb.Friend_BlackAdd_Req{FriendId: friendId}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_AddBlack}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -194,7 +196,7 @@ func (r *Robot) FriendDelBlack(friendId string) {
|
||||
FriendId: friendId,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_DelBlack}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -17,7 +17,7 @@ func (r *Robot) handlePackMsg(msg *pb.UserMessage) {
|
||||
func (r *Robot) QueryUserPack() {
|
||||
req := &pb.Pack_Getlist_Req{IType: 1}
|
||||
head := &pb.UserMessage{MainType: "pack", SubType: "queryuserpackreq"}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -85,7 +85,7 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
||||
//在这里添加玩家成功登录以后的测试方法
|
||||
func (r *Robot) onUserLoaded() {
|
||||
//user
|
||||
r.CreateUser("乐谷6171")
|
||||
// r.CreateUser("乐谷6171")
|
||||
|
||||
//friend
|
||||
// r.FriendApply("1_62aa8f30d25fb8c1a7d90b50")
|
||||
@ -94,8 +94,8 @@ func (r *Robot) onUserLoaded() {
|
||||
// r.FriendApplyList()
|
||||
// r.FriendList()
|
||||
// r.FriendBlacklist()
|
||||
// r.FriendAddBlack()
|
||||
// r.FriendDelBlack("")
|
||||
// r.FriendAddBlack("0_62b01623e4c60c3db8bfe6da")
|
||||
// r.FriendDelBlack("0_62b01623e4c60c3db8bfe6da")
|
||||
// r.FriendSearch("乐谷5")
|
||||
|
||||
//pack
|
||||
@ -104,6 +104,7 @@ func (r *Robot) onUserLoaded() {
|
||||
}
|
||||
|
||||
func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
|
||||
//模拟客户端 每次请求都会生成新的秘钥
|
||||
msg.Sec = r.BuildSecStr()
|
||||
if comm.ProtoMarshal(rsp, msg) {
|
||||
data, _ := proto.Marshal(msg)
|
||||
@ -160,7 +161,11 @@ func (r *Robot) AccountRegister(account string, sid int32) {
|
||||
|
||||
//打印响应
|
||||
func printReply(msg *pb.UserMessage, rsp interface{}) {
|
||||
if m, ok := rsp.(*pb.ErrorNotify); ok {
|
||||
log.Printf("rsp [%s.%s] [%v:%v]", msg.MainType, msg.SubType, int32(m.Code), m.Data)
|
||||
} else {
|
||||
log.Printf("rsp [%s.%s] [%v]", msg.MainType, msg.SubType, rsp)
|
||||
}
|
||||
}
|
||||
|
||||
//方法参数跟踪
|
||||
|
@ -45,7 +45,7 @@ func (r *Robot) CreateUser(NickName string) {
|
||||
SubType: user.User_SubType_Create,
|
||||
}
|
||||
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUId(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -12,8 +12,8 @@ func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_Bl
|
||||
err error
|
||||
blackNumMax = 50 //TODO 从配置中读取
|
||||
)
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
target := &pb.DB_FriendData{UserId: req.FriendId}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
target := &pb.DB_FriendData{UId: req.FriendId}
|
||||
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
@ -29,12 +29,18 @@ func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_Bl
|
||||
|
||||
//判断目标是否在好友列表里面
|
||||
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendYet}
|
||||
return
|
||||
}
|
||||
|
||||
//判断目标是否已经在黑名单中
|
||||
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfBlackYet}
|
||||
return
|
||||
}
|
||||
|
||||
// 判断自己是否在对方的黑名单中
|
||||
if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
|
||||
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
|
||||
return
|
||||
}
|
||||
@ -72,7 +78,7 @@ func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interfac
|
||||
self.BlackIds = append(self.BlackIds, req.FriendId)
|
||||
|
||||
//更新黑名单
|
||||
err := this.module.model_friend.SetObj(self.UserId, self)
|
||||
err := this.module.model_friend.SetObj(self.UId, self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.Friend_Agree_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
|
||||
//获取玩家自己好友数据
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
@ -76,13 +76,13 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
|
||||
}
|
||||
if _, ok := utils.Find(target.FriendIds, self.UserId); !ok {
|
||||
if _, ok := utils.Find(target.FriendIds, self.UId); !ok {
|
||||
if target.FriendIds == nil {
|
||||
target.FriendIds = []string{}
|
||||
}
|
||||
target.FriendIds = append(target.FriendIds, self.UserId)
|
||||
target.FriendIds = append(target.FriendIds, self.UId)
|
||||
}
|
||||
err = this.module.model_friend.SetObj(target.UserId, target)
|
||||
err = this.module.model_friend.SetObj(target.UId, target)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
}
|
||||
@ -93,7 +93,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
|
||||
}
|
||||
|
||||
//更新
|
||||
err := this.module.model_friend.SetObj(self.UserId, self)
|
||||
err := this.module.model_friend.SetObj(self.UId, self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
target := &pb.DB_FriendData{UserId: req.FriendId}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
target := &pb.DB_FriendData{UId: req.FriendId}
|
||||
|
||||
//获取玩家自己好友数据
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
@ -56,7 +56,7 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply
|
||||
}
|
||||
|
||||
//判断自己是否在目标用户的申请列表中
|
||||
if _, ok := utils.Find(target.ApplyIds, self.UserId); ok {
|
||||
if _, ok := utils.Find(target.ApplyIds, self.UId); ok {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendApplyYet}
|
||||
return
|
||||
}
|
||||
@ -68,7 +68,7 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply
|
||||
}
|
||||
|
||||
//判断是否在对方的黑名单中
|
||||
if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
|
||||
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
|
||||
return
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.Friend_ApplyList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
err := this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.Friend_BlackList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
err := this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.Friend_DelBlack_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
err := this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
|
||||
@ -31,7 +31,7 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac
|
||||
UserId: session.GetUserId(),
|
||||
}
|
||||
}
|
||||
err := session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, rsp)
|
||||
err := session.SendMsg(string(this.module.GetType()), Friend_SubType_DelBlack, rsp)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
@ -43,7 +43,7 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac
|
||||
//从黑名单列表中删除目标
|
||||
self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId)
|
||||
//更新黑名单
|
||||
err := this.module.model_friend.SetObj(self.UserId, self)
|
||||
err := this.module.model_friend.SetObj(self.UId, self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.Friend_List_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
err := this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.Friend_Refuse_Req) (chk map[string]interface{}, code comm.ErrorCode) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
||||
self := &pb.DB_FriendData{UId: session.GetUserId()}
|
||||
|
||||
//获取玩家自己好友数据
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
@ -66,7 +66,7 @@ func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{
|
||||
}
|
||||
//更新
|
||||
if optNum > 0 {
|
||||
err := this.module.model_friend.SetObj(self.UserId, self)
|
||||
err := this.module.model_friend.SetObj(self.UId, self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -31,7 +31,7 @@ func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{
|
||||
user := this.module.model_friend.Frined_FindCond(req.NickName)
|
||||
if user != nil {
|
||||
friend = &pb.FriendBase{
|
||||
UserId: user.Uid,
|
||||
UserId: user.UId,
|
||||
NickName: user.Name,
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,10 @@ func (this *ModelFriend) Init(service core.IService, module core.IModule, comp c
|
||||
}
|
||||
|
||||
//好友
|
||||
// Deprecated
|
||||
func (this *ModelFriend) Friend_SaveOrUpdate(data *pb.DB_FriendData) (err error) {
|
||||
err = this.DB.FindOneAndUpdate(DB_FriendTable,
|
||||
bson.M{"_id": data.UserId},
|
||||
bson.M{"_id": data.UId},
|
||||
bson.M{"$set": bson.M{
|
||||
"friendids": data.FriendIds,
|
||||
"applyids": data.ApplyIds}},
|
||||
|
@ -132,8 +132,6 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
|
||||
|
||||
//解码
|
||||
func decodeUserData(msg *pb.UserMessage) error {
|
||||
//只有login的时候才需要解码
|
||||
if msg.MainType == "user" && msg.SubType == "login" {
|
||||
base64Str := msg.Sec
|
||||
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
|
||||
if err != nil {
|
||||
@ -142,11 +140,15 @@ func decodeUserData(msg *pb.UserMessage) error {
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
jsonRet := gjson.Parse(string(dec))
|
||||
serverId := jsonRet.Get("serverId").Int()
|
||||
timestamp := jsonRet.Get("timestamp").Int()
|
||||
if now-time.Unix(timestamp, 0).Unix() > 100 {
|
||||
return nil
|
||||
//秘钥30秒失效
|
||||
if now-time.Unix(timestamp, 0).Unix() > 30 {
|
||||
return fmt.Errorf("sec key expire")
|
||||
}
|
||||
|
||||
//只有login的时候才需要设置Data
|
||||
if msg.MainType == "user" && msg.SubType == "login" {
|
||||
serverId := jsonRet.Get("serverId").Int()
|
||||
account := jsonRet.Get("account").String()
|
||||
req := &pb.UserLoginReq{
|
||||
Account: account,
|
||||
@ -158,7 +160,6 @@ func decodeUserData(msg *pb.UserMessage) error {
|
||||
}
|
||||
msg.Data = ad
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -218,7 +219,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
|
||||
return err
|
||||
}
|
||||
if reply.Code != pb.ErrorCode_Success {
|
||||
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: reply.Code})
|
||||
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())})
|
||||
err := this.WriteMsg(&pb.UserMessage{
|
||||
MainType: comm.MainType_Notify,
|
||||
SubType: comm.SubType_ErrorNotify,
|
||||
|
@ -60,7 +60,7 @@ var module = new(Pack)
|
||||
//测试环境下初始化db和cache 系统
|
||||
func TestMain(m *testing.M) {
|
||||
service = newService(
|
||||
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
||||
rpcx.SetConfPath("../../bin/conf/worker_2.yaml"),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
)
|
||||
service.OnInstallComp( //装备组件
|
||||
@ -151,3 +151,10 @@ func Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_UserItemData) (err er
|
||||
module.model_pack_comp.DB.BulkWrite(DB_PackTable, models, options.BulkWrite().SetOrdered(false))
|
||||
return
|
||||
}
|
||||
|
||||
func TestGetHM(t *testing.T) {
|
||||
d := make(map[string]interface{})
|
||||
d["amount"] = 10
|
||||
d["itemid"] = 1004
|
||||
module.cache_comp.SetHM("pack:0_62a9afd994fe03b7aaee6773", d)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
event.TriggerEvent(comm.Event_UserLogin, user.Uid)
|
||||
event.TriggerEvent(comm.Event_UserLogin, user.UId)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -57,7 +57,7 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
|
||||
}
|
||||
|
||||
//bind user
|
||||
err = session.Bind(user.Uid, this.service.GetId())
|
||||
err = session.Bind(user.UId, this.service.GetId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_BindUser
|
||||
return
|
||||
@ -69,8 +69,8 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
|
||||
user.Createip = session.GetIP()
|
||||
|
||||
//缓存user session
|
||||
err = this.module.modelSession.SetObj(user.Uid, &pb.Cache_UserData{
|
||||
Uid: user.Uid,
|
||||
err = this.module.modelSession.SetObj(user.UId, &pb.Cache_UserData{
|
||||
Uid: user.UId,
|
||||
SessionId: session.GetSessionId(),
|
||||
GatewayServiceId: session.GetGatewayServiceId(),
|
||||
},
|
||||
@ -82,7 +82,7 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
|
||||
}
|
||||
|
||||
//缓存user
|
||||
err = this.module.modelUser.SetObj(user.Uid, user)
|
||||
err = this.module.modelUser.SetObj(user.UId, user)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -51,7 +51,7 @@ func (this *ModelUser) User_FindById(id string) (*pb.DB_UserData, error) {
|
||||
func (this *ModelUser) User_Create(user *pb.DB_UserData) (err error) {
|
||||
_id := primitive.NewObjectID().Hex()
|
||||
user.Id = _id
|
||||
user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id)
|
||||
user.UId = fmt.Sprintf("%d_%s", user.Sid, _id)
|
||||
user.Uuid = uuid.NewV4().String()
|
||||
user.Ctime = time.Now().Unix()
|
||||
_, err = this.DB.InsertOne(DB_UserTable, user)
|
||||
@ -62,7 +62,7 @@ func (this *ModelUser) User_Create(user *pb.DB_UserData) (err error) {
|
||||
func (this *ModelUser) User_Update(data *pb.DB_UserData) (err error) {
|
||||
err = this.DB.FindOneAndUpdate(
|
||||
DB_UserTable,
|
||||
bson.M{"uid": data.Uid},
|
||||
bson.M{"uid": data.UId},
|
||||
bson.M{"$set": bson.M{
|
||||
"name": data.Name,
|
||||
}},
|
||||
|
@ -38,7 +38,7 @@ func (this *Api_Comp) Register(c *engine.Context) {
|
||||
err := c.BindJSON(&req)
|
||||
if err == nil {
|
||||
err := this.module.modelUser.User_Create(&pb.DB_UserData{
|
||||
Binduid: req.Account,
|
||||
BinduId: req.Account,
|
||||
Sid: req.Sid,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -25,10 +25,10 @@ type DB_FriendData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId" bson:"_id"` // ID
|
||||
FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds"` //好友ID
|
||||
ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds"` //申请用户ID
|
||||
BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds"` //黑名单ID
|
||||
UId string `protobuf:"bytes,1,opt,name=uId,proto3" json:"uId" bson:"uId"` //用户ID
|
||||
FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds" bson:"friendIds"` //好友ID
|
||||
ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds" bson:"applyIds"` //申请用户ID
|
||||
BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds" bson:"blackIds"` //黑名单ID
|
||||
}
|
||||
|
||||
func (x *DB_FriendData) Reset() {
|
||||
@ -63,9 +63,9 @@ func (*DB_FriendData) Descriptor() ([]byte, []int) {
|
||||
return file_friend_friend_db_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *DB_FriendData) GetUserId() string {
|
||||
func (x *DB_FriendData) GetUId() string {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
return x.UId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@ -95,16 +95,16 @@ var File_friend_friend_db_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_friend_friend_db_proto_rawDesc = []byte{
|
||||
0x0a, 0x16, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f,
|
||||
0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x0d, 0x44, 0x42, 0x5f, 0x46,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65,
|
||||
0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49,
|
||||
0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x18, 0x02,
|
||||
0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28,
|
||||
0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x62,
|
||||
0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x62,
|
||||
0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x77, 0x0a, 0x0d, 0x44, 0x42, 0x5f, 0x46,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09,
|
||||
0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70,
|
||||
0x6c, 0x79, 0x49, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x70, 0x70,
|
||||
0x6c, 0x79, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64,
|
||||
0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64,
|
||||
0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -1,11 +1,9 @@
|
||||
syntax = "proto3";
|
||||
option go_package = ".;pb";
|
||||
|
||||
|
||||
message DB_FriendData {
|
||||
string userId = 1;// @go_tags(`bson:"_id"`) ID
|
||||
repeated string friendIds = 2; //好友ID
|
||||
repeated string applyIds = 3;//申请用户ID
|
||||
repeated string blackIds = 4;//黑名单ID
|
||||
|
||||
string uId = 1; //@go_tags(`bson:"uId"`) 用户ID
|
||||
repeated string friendIds = 2; //@go_tags(`bson:"friendIds"`) 好友ID
|
||||
repeated string applyIds = 3; //@go_tags(`bson:"applyIds"`) 申请用户ID
|
||||
repeated string blackIds = 4; //@go_tags(`bson:"blackIds"`) 黑名单ID
|
||||
}
|
@ -5,20 +5,20 @@ message Cache_UserData {
|
||||
string uid = 1;
|
||||
string SessionId = 2;
|
||||
string GatewayServiceId = 3;
|
||||
DB_UserData UserData = 4;// @go_tags(`json:",inline"`) ID
|
||||
// DB_UserData UserData = 4; //@go_tags(`json:",inline"`)
|
||||
}
|
||||
|
||||
message DB_UserData {
|
||||
string id = 1; // @go_tags(`bson:"_id"`) ID
|
||||
string uid = 2;
|
||||
string uuid = 3; //玩家唯一uuid
|
||||
string binduid = 4; //玩家账号
|
||||
string name = 5; //玩家名
|
||||
int32 sid = 6; //区服id
|
||||
string createip = 7; //创建账号时的ip
|
||||
string lastloginip = 8; //最后一次登录时的ip
|
||||
int64 ctime = 9; //玩家创号时间戳
|
||||
int64 logintime = 10; //最后一次登录时间
|
||||
int32 FriendPoint = 11; //友情点
|
||||
int32 avatar = 12; //头像
|
||||
string id = 1; //@go_tags(`bson:"_id"`) ID
|
||||
string uId = 2; //@go_tags(`bson:"uId"`) 用户ID
|
||||
string uuid = 3; //@go_tags(`bson:"uuid"`) 玩家唯一uuid
|
||||
string binduId = 4; //@go_tags(`bson:"binduId"`) 玩家账号
|
||||
string name = 5; //@go_tags(`bson:"name"`) 玩家名
|
||||
int32 sid = 6; //@go_tags(`bson:"sid"`) 区服id
|
||||
string createip = 7; //@go_tags(`bson:"createip"`) 创建账号时的ip
|
||||
string lastloginip = 8; //@go_tags(`bson:"lastloginip"`) 最后一次登录时的ip
|
||||
int64 ctime = 9; //@go_tags(`bson:"ctime"`) 玩家创号时间戳
|
||||
int64 logintime = 10; //@go_tags(`bson:"logintime"`) 最后一次登录时间
|
||||
int32 friendPoint = 11; //@go_tags(`bson:"friendPoint"`) 友情点
|
||||
int32 avatar = 12; //@go_tags(`bson:"avatar"`) 头像
|
||||
}
|
@ -27,7 +27,7 @@ type Cache_UserData struct {
|
||||
|
||||
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"`
|
||||
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId"`
|
||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` // DB_UserData UserData = 4;
|
||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:",inline"` // DB_UserData UserData = 4; //
|
||||
}
|
||||
|
||||
func (x *Cache_UserData) Reset() {
|
||||
@ -88,18 +88,18 @@ type DB_UserData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` // ID
|
||||
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"`
|
||||
Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid"` //玩家唯一uuid
|
||||
Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid"` //玩家账号
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name"` //玩家名
|
||||
Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid"` //区服id
|
||||
Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip"` //创建账号时的ip
|
||||
Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip"` //最后一次登录时的ip
|
||||
Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime"` //玩家创号时间戳
|
||||
Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime"` //最后一次登录时间
|
||||
FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint"` //友情点
|
||||
Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar"` //头像
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
|
||||
UId string `protobuf:"bytes,2,opt,name=uId,proto3" json:"uId" bson:"uId"` //用户ID
|
||||
Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid" bson:"uuid"` //玩家唯一uuid
|
||||
BinduId string `protobuf:"bytes,4,opt,name=binduId,proto3" json:"binduId" bson:"binduId"` //玩家账号
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name" bson:"name"` //玩家名
|
||||
Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid" bson:"sid"` //区服id
|
||||
Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip" bson:"createip"` //创建账号时的ip
|
||||
Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip" bson:"lastloginip"` //最后一次登录时的ip
|
||||
Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime" bson:"ctime"` //玩家创号时间戳
|
||||
Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime" bson:"logintime"` //最后一次登录时间
|
||||
FriendPoint int32 `protobuf:"varint,11,opt,name=friendPoint,proto3" json:"friendPoint" bson:"friendPoint"` //友情点
|
||||
Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar" bson:"avatar"` //头像
|
||||
}
|
||||
|
||||
func (x *DB_UserData) Reset() {
|
||||
@ -141,9 +141,9 @@ func (x *DB_UserData) GetId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DB_UserData) GetUid() string {
|
||||
func (x *DB_UserData) GetUId() string {
|
||||
if x != nil {
|
||||
return x.Uid
|
||||
return x.UId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@ -155,9 +155,9 @@ func (x *DB_UserData) GetUuid() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DB_UserData) GetBinduid() string {
|
||||
func (x *DB_UserData) GetBinduId() string {
|
||||
if x != nil {
|
||||
return x.Binduid
|
||||
return x.BinduId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@ -231,11 +231,11 @@ var file_user_user_db_proto_rawDesc = []byte{
|
||||
0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x49, 0x64, 0x22, 0xaf, 0x02, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61,
|
||||
0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02,
|
||||
0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01,
|
||||
0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x03, 0x75, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64,
|
||||
0x75, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75,
|
||||
0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
|
||||
0x75, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75,
|
||||
0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61,
|
||||
0x74, 0x65, 0x69, 0x70, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61,
|
||||
@ -244,9 +244,9 @@ var file_user_user_db_proto_rawDesc = []byte{
|
||||
0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18,
|
||||
0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09,
|
||||
0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||
0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72,
|
||||
0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x66, 0x72,
|
||||
0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x0b, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76,
|
||||
0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
|
140
sys/cache/init_test.go
vendored
140
sys/cache/init_test.go
vendored
@ -2,19 +2,11 @@ package cache_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
//测试环境下初始化db和cache 系统
|
||||
@ -27,72 +19,72 @@ func TestMain(m *testing.M) {
|
||||
fmt.Printf("err:%v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < 50000; i++ {
|
||||
//go func() {
|
||||
_mail := &pb.DB_MailData{
|
||||
ObjId: primitive.NewObjectID().Hex(),
|
||||
Uid: "uid123",
|
||||
Title: "系统邮件",
|
||||
// _mail := &pb.DB_MailData{
|
||||
// ObjId: primitive.NewObjectID().Hex(),
|
||||
// Uid: "uid123",
|
||||
// Title: "系统邮件",
|
||||
// Contex: "恭喜获得专属礼包一份",
|
||||
// CreateTime: uint64(time.Now().Unix()),
|
||||
// DueTime: uint64(time.Now().Unix()) + 30*24*3600,
|
||||
// Check: false,
|
||||
// Reward: false,
|
||||
// }
|
||||
// //db.InsertModelLogs("mail", "uid123", _mail)
|
||||
// db.Defsys.Mgo().InsertOne("mail", _mail)
|
||||
// data := &comm.Autogenerated{
|
||||
// ID: primitive.NewObjectID().Hex(),
|
||||
// UID: "uid123",
|
||||
// Act: string(comm.LogHandleType_Insert),
|
||||
// }
|
||||
// data.D = append(data.D, "mail") // D[0]
|
||||
// data.D = append(data.D, _mail) // D[1]
|
||||
|
||||
Contex: "恭喜获得专属礼包一份",
|
||||
CreateTime: uint64(time.Now().Unix()),
|
||||
DueTime: uint64(time.Now().Unix()) + 30*24*3600,
|
||||
Check: false,
|
||||
Reward: false,
|
||||
}
|
||||
//db.InsertModelLogs("mail", "uid123", _mail)
|
||||
db.Defsys.Mgo().InsertOne("mail", _mail)
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: "uid123",
|
||||
Act: string(comm.LogHandleType_Insert),
|
||||
}
|
||||
data.D = append(data.D, "mail") // D[0]
|
||||
data.D = append(data.D, _mail) // D[1]
|
||||
// _, err1 := db.Defsys.Mgo().InsertOne("model_log", data)
|
||||
// if err1 != nil {
|
||||
// log.Errorf("insert model db err %v", err1)
|
||||
// }
|
||||
// //}()
|
||||
|
||||
_, err1 := db.Defsys.Mgo().InsertOne("model_log", data)
|
||||
if err1 != nil {
|
||||
log.Errorf("insert model db err %v", err1)
|
||||
}
|
||||
//}()
|
||||
// ///////////////////////////////////////
|
||||
// filter := bson.M{
|
||||
// "userid": "uid123",
|
||||
// "title": "系统邮件",
|
||||
// }
|
||||
// var nd *pb.DB_MailData
|
||||
// err := db.Defsys.Mgo().FindOne("mail", filter).Decode(&nd)
|
||||
// if err == nil {
|
||||
// nd.Check = true
|
||||
// nd.Reward = true
|
||||
|
||||
///////////////////////////////////////
|
||||
filter := bson.M{
|
||||
"userid": "uid123",
|
||||
"title": "系统邮件",
|
||||
}
|
||||
var nd *pb.DB_MailData
|
||||
err := db.Defsys.Mgo().FindOne("mail", filter).Decode(&nd)
|
||||
if err == nil {
|
||||
nd.Check = true
|
||||
nd.Reward = true
|
||||
// data1 := &comm.Autogenerated{
|
||||
// ID: primitive.NewObjectID().Hex(),
|
||||
// UID: "uid123",
|
||||
// Act: string(comm.LogHandleType_Update),
|
||||
// }
|
||||
// filter1 := bson.M{
|
||||
// "userid": "uid123",
|
||||
// "title": "系统邮件",
|
||||
// }
|
||||
// var ndmodify = &bson.M{
|
||||
// "title": "xxxxx",
|
||||
// "check": true,
|
||||
// }
|
||||
|
||||
data1 := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: "uid123",
|
||||
Act: string(comm.LogHandleType_Update),
|
||||
}
|
||||
filter1 := bson.M{
|
||||
"userid": "uid123",
|
||||
"title": "系统邮件",
|
||||
}
|
||||
var ndmodify = &bson.M{
|
||||
"title": "xxxxx",
|
||||
"check": true,
|
||||
}
|
||||
// data1.D = make([]interface{}, 0)
|
||||
// data1.D = append(data1.D, "mail") // D[0]
|
||||
// data1.D = append(data1.D, &filter1) // D[1]
|
||||
// data1.D = append(data1.D, ndmodify) // D[2]
|
||||
// nd.Title = "read"
|
||||
// //db.Defsys.Mgo().UpdateMany("mail", filter1, bson.M{"$set": nd})
|
||||
// _, err = db.Defsys.Mgo().InsertOne("model_log", data1)
|
||||
// if err != nil {
|
||||
// log.Errorf("insert model db err %v", err)
|
||||
// }
|
||||
|
||||
data1.D = make([]interface{}, 0)
|
||||
data1.D = append(data1.D, "mail") // D[0]
|
||||
data1.D = append(data1.D, &filter1) // D[1]
|
||||
data1.D = append(data1.D, ndmodify) // D[2]
|
||||
nd.Title = "read"
|
||||
//db.Defsys.Mgo().UpdateMany("mail", filter1, bson.M{"$set": nd})
|
||||
_, err = db.Defsys.Mgo().InsertOne("model_log", data1)
|
||||
if err != nil {
|
||||
log.Errorf("insert model db err %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
@ -101,19 +93,5 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
friendDb := &pb.DB_FriendData{
|
||||
UserId: "111",
|
||||
FriendIds: []string{"222"},
|
||||
ApplyIds: []string{"333"},
|
||||
BlackIds: []string{"444"},
|
||||
}
|
||||
data := utils.Pb2Map(friendDb)
|
||||
// data2 := map[string]interface{}{
|
||||
// "userId": friendDb.UserId,
|
||||
// "friendIds": friendDb.FriendIds,
|
||||
// "applyIds": friendDb.ApplyIds,
|
||||
// "blackIds": friendDb.BlackIds,
|
||||
// }
|
||||
|
||||
cache.Redis().HMSet("friend:222", data)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user