This commit is contained in:
liwei1dao 2022-06-21 13:53:10 +08:00
commit f0df016e8b
29 changed files with 251 additions and 223 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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{}) {
log.Printf("rsp [%s.%s] [%v]", msg.MainType, msg.SubType, rsp)
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)
}
}
//方法参数跟踪

View File

@ -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)

View File

@ -19,6 +19,7 @@ const (
const (
Service_Gateway = "gateway"
Service_Worker = "worker"
Service_DB = "dbservice"
)
//ERR

View File

@ -165,6 +165,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
return
}
// 写入日志数据
func (this *DB_Comp) Model_InsertDBByLog(data *comm.Autogenerated) (err error) {
_, err = this.DB.InsertOne(DB_ModelTable, data)
@ -173,3 +174,13 @@ func (this *DB_Comp) Model_InsertDBByLog(data *comm.Autogenerated) (err error) {
}
return err
}
// 查询 当前日志列表还有没有处理完条数
func (this *DB_Comp) Model_TotalCount() int {
_data, err := this.DB.Find("model_log", bson.M{})
if err == nil {
return _data.RemainingBatchLength()
}
return 0
}

View File

@ -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.Get(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
}

View File

@ -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.Get(session.GetUserId(), self)
@ -76,11 +76,11 @@ 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.Change(target.UserId, map[string]interface{}{
"friendIds": target.FriendIds,

View File

@ -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.Get(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
}

View File

@ -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

View File

@ -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.Get(session.GetUserId(), self)

View File

@ -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,
}
}

View File

@ -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}},

View File

@ -43,15 +43,15 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent {
//用户代理
type Agent struct {
gateway IGateway
wsConn *websocket.Conn
sessionId string
uId string
wId string
writeChan chan *pb.UserMessage
closeSignal chan bool
state int32 //状态 0 关闭 1 运行 2 关闭中
wg sync.WaitGroup
gateway IGateway
wsConn *websocket.Conn
sessionId string
uId string
wId string
writeChan chan *pb.UserMessage
closeSignal chan bool
state int32 //状态 0 关闭 1 运行 2 关闭中
wg sync.WaitGroup
}
func (this *Agent) readLoop() {
@ -132,21 +132,23 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
//解码
func decodeUserData(msg *pb.UserMessage) error {
//只有login的时候才需要解码
base64Str := msg.Sec
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
if err != nil {
log.Errorf("base64 decode err %v", err)
return nil
}
now := time.Now().Unix()
jsonRet := gjson.Parse(string(dec))
timestamp := jsonRet.Get("timestamp").Int()
//秘钥30秒失效
if now-time.Unix(timestamp, 0).Unix() > 30 {
return fmt.Errorf("sec key expire")
}
//只有login的时候才需要设置Data
if msg.MainType == "user" && msg.SubType == "login" {
base64Str := msg.Sec
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
if err != nil {
log.Errorf("base64 decode err %v", err)
return nil
}
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
}
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,

View File

@ -35,7 +35,7 @@ func (this *Api_Comp) GetUserMailAttachment(session comm.IUserSession, agrs map[
for _, v := range _data {
_items[int32(v.ItemId)] += int32(v.ItemCount)
}
bRet := this.pack.AddItemsToUserPack(mail.UserId, _items)
bRet := this.pack.AddItemsToUserPack(mail.Uid, _items)
if bRet != nil {
// 修改状态
this.module.db_comp.Mail_UpdateMailAttachmentState(req.ObjID)

View File

@ -43,7 +43,7 @@ func (this *Mail) OnInstallComp() {
func (this *Mail) CreateNewMail(uId string) {
mail := &pb.DB_MailData{
ObjId: primitive.NewObjectID().Hex(),
UserId: uId,
Uid: uId,
Title: "系统邮件",
Contex: "恭喜获得专属礼包一份",
CreateTime: uint64(time.Now().Unix()),

View File

@ -57,7 +57,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( //装备组件
@ -156,3 +156,10 @@ func Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_UserItemData) (err er
module.model_pack_comp.DB.InsertMany(DB_PackTable, data)
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)
}

View File

@ -1,10 +1,13 @@
package user
import (
"errors"
"go_dreamfactory/modules"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go.mongodb.org/mongo-driver/bson"
)
const (
@ -25,3 +28,15 @@ func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core
this.module = module.(*User)
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
_data, err := this.module.modelUser.DB.Find("model_log", bson.M{})
if err == nil {
if _data.RemainingBatchLength() > 0 {
return errors.New("")
}
}
return
}

View File

@ -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

View File

@ -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,
}},

View File

@ -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 {

View File

@ -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 (

View File

@ -81,7 +81,7 @@ type DB_MailData struct {
unknownFields protoimpl.UnknownFields
ObjId string `protobuf:"bytes,1,opt,name=ObjId,proto3" json:"ObjId" bson:"_id"` // ID
UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId"`
Uid string `protobuf:"bytes,2,opt,name=Uid,proto3" json:"Uid"`
Title string `protobuf:"bytes,3,opt,name=Title,proto3" json:"Title"` // 邮件标题
Contex string `protobuf:"bytes,4,opt,name=Contex,proto3" json:"Contex"` // 邮件内容
CreateTime uint64 `protobuf:"varint,5,opt,name=CreateTime,proto3" json:"CreateTime"` // 发送时间
@ -130,9 +130,9 @@ func (x *DB_MailData) GetObjId() string {
return ""
}
func (x *DB_MailData) GetUserId() string {
func (x *DB_MailData) GetUid() string {
if x != nil {
return x.UserId
return x.Uid
}
return ""
}
@ -194,24 +194,24 @@ var file_mail_mail_db_proto_rawDesc = []byte{
0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x1c,
0x0a, 0x09, 0x49, 0x74, 0x65, 0x6d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x09, 0x49, 0x74, 0x65, 0x6d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xf8, 0x01, 0x0a,
0x0d, 0x52, 0x09, 0x49, 0x74, 0x65, 0x6d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xf2, 0x01, 0x0a,
0x0b, 0x44, 0x42, 0x5f, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05,
0x4f, 0x62, 0x6a, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x4f, 0x62, 0x6a,
0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x69,
0x74, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65,
0x12, 0x16, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x43, 0x72,
0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x44, 0x75, 0x65, 0x54,
0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x44, 0x75, 0x65, 0x54, 0x69,
0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x07, 0x20, 0x01, 0x28,
0x08, 0x52, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x52, 0x65, 0x77, 0x61,
0x72, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64,
0x12, 0x25, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x0f, 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74,
0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x03, 0x55, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x43, 0x6f,
0x6e, 0x74, 0x65, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x43, 0x6f, 0x6e, 0x74,
0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65,
0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69,
0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x44, 0x75, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20,
0x01, 0x28, 0x04, 0x52, 0x07, 0x44, 0x75, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05,
0x43, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x43, 0x68, 0x65,
0x63, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x18, 0x08, 0x20, 0x01,
0x28, 0x08, 0x52, 0x06, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x12, 0x25, 0x0a, 0x05, 0x49, 0x74,
0x65, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x4d, 0x61, 0x69, 0x6c,
0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d,
0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (

View File

@ -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
}

View File

@ -13,7 +13,7 @@ message MailAttachment { // 附件
message DB_MailData {
string ObjId = 1; // @go_tags(`bson:"_id"`) ID
string UserId = 2;
string Uid = 2;
string Title = 3; //
string Contex = 4; //
uint64 CreateTime = 5; //

View File

@ -5,20 +5,20 @@ message Cache_UserData {
string uid = 1;
string SessionId = 2;
string GatewayServiceId = 3;
// DB_UserData UserData = 4;
// 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"`)
}

View File

@ -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,

View File

@ -59,7 +59,7 @@ func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceC
this.msgcheck = make(map[string]*msghandle)
this.msghandles = make(map[string]*msghandle)
return err
}
} //
//组件启动时注册rpc服务监听
func (this *SComp_GateRouteComp) Start() (err error) {
@ -76,6 +76,9 @@ func (this *SComp_GateRouteComp) Start() (err error) {
}
}
})
event.RegisterGO(core.Event_FindNewService, func() {
log.Debugf("find new service")
})
return
}

140
sys/cache/init_test.go vendored
View File

@ -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(),
UserId: "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)
}