From 5e0724c795083b07a059525eddde6d3cef1998ab Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 6 Jun 2022 15:58:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- modules/login/module.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index daf1be6cd..d3a36b9cb 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/liwei1dao/lego v0.0.0-20220531091126-a21bb3766fbc github.com/spf13/cobra v1.2.1 + github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.1 go.mongodb.org/mongo-driver v1.5.1 google.golang.org/protobuf v1.28.0 @@ -95,7 +96,6 @@ require ( github.com/smallnest/quick v0.0.0-20220103065406-780def6371e6 // indirect github.com/smallnest/rpcx v1.7.4 // indirect github.com/soheilhy/cmux v0.1.5 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect github.com/tinylib/msgp v1.1.6 // indirect diff --git a/modules/login/module.go b/modules/login/module.go index 282d94a0f..e7bd37df7 100644 --- a/modules/login/module.go +++ b/modules/login/module.go @@ -3,8 +3,11 @@ package login import ( "go_dreamfactory/comm" "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" "github.com/liwei1dao/lego/core" + "github.com/liwei1dao/lego/sys/log" ) func NewModule() core.IModule { @@ -25,3 +28,22 @@ func (this *Login) OnInstallComp() { this.ModuleBase.OnInstallComp() this.user_comp = this.RegisterComp(new(LoginComp)).(*LoginComp) } + +func (this *Login) Start() (err error) { + + if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil { + return + } + + if data, ret := configure.GetConfigure("tbitem.json"); ret == nil { + _data := data.(*cfg.TbItem).GetDataMap() + for _, v := range _data { + if v.Id > 0 { + break + } + log.Debugf(v.Name) + } + } + + return nil +} From ec3b62d3700a7806157fcabd3ea162815ebb99ff Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 6 Jun 2022 18:38:03 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 1 + modules/gate_comp.go | 1 + modules/login/login_comp.go | 12 +- modules/mail/api_comp.go | 23 +++ modules/mail/configure_comp.go | 16 ++ modules/mail/module.go | 34 ++++ pb/mail.pb.go | 339 +++++++++++++++++++++++++++++++++ pb/pack_db.pb.go | 2 +- pb/proto/mail.proto | 22 +++ pb/user_db.pb.go | 2 +- pb_2.7.py | 3 +- services/worker/main.go | 2 + sys/db/mail.go | 14 ++ 13 files changed, 467 insertions(+), 4 deletions(-) create mode 100644 modules/mail/api_comp.go create mode 100644 modules/mail/configure_comp.go create mode 100644 modules/mail/module.go create mode 100644 pb/mail.pb.go create mode 100644 pb/proto/mail.proto diff --git a/comm/core.go b/comm/core.go index a5eada943..b26e11c5c 100644 --- a/comm/core.go +++ b/comm/core.go @@ -18,6 +18,7 @@ const ( SM_WebModule core.M_Modules = "web" //web模块 SM_LoginModule core.M_Modules = "login" //web模块 SM_PackModule core.M_Modules = "pack" //背包模块 + SM_MailModule core.M_Modules = "mail" //邮件模块 ) const ( //Rpc diff --git a/modules/gate_comp.go b/modules/gate_comp.go index a8de11d18..be6e14e4f 100644 --- a/modules/gate_comp.go +++ b/modules/gate_comp.go @@ -33,6 +33,7 @@ func (this *MComp_GateComp) Init(service core.IService, module core.IModule, com this.service = service.(base.IRPCXService) this.module = module this.comp = comp + return } diff --git a/modules/login/login_comp.go b/modules/login/login_comp.go index b7eee99cd..8822b342e 100644 --- a/modules/login/login_comp.go +++ b/modules/login/login_comp.go @@ -6,6 +6,8 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/cache" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "github.com/liwei1dao/lego/sys/log" @@ -36,7 +38,15 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req } session.Build(db_user.UserId) - + if data, ret := configure.GetConfigure("tbitem.json"); ret == nil { + _data := data.(*cfg.TbItem).GetDataMap() + for _, v := range _data { + if v.Id > 0 { + break + } + log.Debugf(v.Name) + } + } cache_user := &pb.Cache_UserData{ SessionId: session.GetSessionId(), GatewayServiceId: session.GetGatewayServiceId(), diff --git a/modules/mail/api_comp.go b/modules/mail/api_comp.go new file mode 100644 index 000000000..4c938fc40 --- /dev/null +++ b/modules/mail/api_comp.go @@ -0,0 +1,23 @@ +package mail + +import ( + "go_dreamfactory/modules" + + "github.com/liwei1dao/lego/core" +) + +const ( + QueryUserMailReq = "mail.queryusermailreq" + QueryUserMailResp = "mail.queryusermailresp" +) + +type Api_Comp struct { + modules.MComp_GateComp + module *Mail +} + +func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MComp_GateComp.Init(service, module, comp, options) + this.module = module.(*Mail) + return +} diff --git a/modules/mail/configure_comp.go b/modules/mail/configure_comp.go new file mode 100644 index 000000000..5ba11ce3b --- /dev/null +++ b/modules/mail/configure_comp.go @@ -0,0 +1,16 @@ +package mail + +import ( + "github.com/liwei1dao/lego/core" + "github.com/liwei1dao/lego/core/cbase" +) + +// 邮件配置管理组件 +type Configure_Comp struct { + cbase.ModuleCompBase +} + +func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.ModuleCompBase.Init(service, module, comp, options) + return +} diff --git a/modules/mail/module.go b/modules/mail/module.go new file mode 100644 index 000000000..8ec9fa452 --- /dev/null +++ b/modules/mail/module.go @@ -0,0 +1,34 @@ +package mail + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/modules" + + "github.com/liwei1dao/lego/core" +) + +/* +模块名:Mail +描述:邮件系统模块 +开发:梅雄风 +*/ +func NewModule() core.IModule { + m := new(Mail) + return m +} + +type Mail struct { + modules.ModuleBase + api_comp *Api_Comp + configure_comp *Configure_Comp +} + +func (this *Mail) GetType() core.M_Modules { + return comm.SM_MailModule +} + +func (this *Mail) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) + this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) +} diff --git a/pb/mail.pb.go b/pb/mail.pb.go new file mode 100644 index 000000000..103198ff3 --- /dev/null +++ b/pb/mail.pb.go @@ -0,0 +1,339 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: mail.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MailAttachment struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Itemid uint32 `protobuf:"varint,1,opt,name=Itemid,proto3" json:"Itemid,omitempty"` // 道具iD + ItemCount uint32 `protobuf:"varint,2,opt,name=ItemCount,proto3" json:"ItemCount,omitempty"` // 数量 +} + +func (x *MailAttachment) Reset() { + *x = MailAttachment{} + if protoimpl.UnsafeEnabled { + mi := &file_mail_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MailAttachment) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MailAttachment) ProtoMessage() {} + +func (x *MailAttachment) ProtoReflect() protoreflect.Message { + mi := &file_mail_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MailAttachment.ProtoReflect.Descriptor instead. +func (*MailAttachment) Descriptor() ([]byte, []int) { + return file_mail_proto_rawDescGZIP(), []int{0} +} + +func (x *MailAttachment) GetItemid() uint32 { + if x != nil { + return x.Itemid + } + return 0 +} + +func (x *MailAttachment) GetItemCount() uint32 { + if x != nil { + return x.ItemCount + } + return 0 +} + +//背包格子 +type MailData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Title string `protobuf:"bytes,1,opt,name=Title,proto3" json:"Title,omitempty"` // 邮件标题 + Contex string `protobuf:"bytes,2,opt,name=Contex,proto3" json:"Contex,omitempty"` // 邮件内容 + CreateTime uint64 `protobuf:"varint,3,opt,name=CreateTime,proto3" json:"CreateTime,omitempty"` // 发送时间 + DueTime uint64 `protobuf:"varint,4,opt,name=DueTime,proto3" json:"DueTime,omitempty"` // 过期时间 + Check bool `protobuf:"varint,5,opt,name=Check,proto3" json:"Check,omitempty"` // 是否查看 + Items []*MailAttachment `protobuf:"bytes,6,rep,name=Items,proto3" json:"Items,omitempty"` // 附件 +} + +func (x *MailData) Reset() { + *x = MailData{} + if protoimpl.UnsafeEnabled { + mi := &file_mail_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MailData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MailData) ProtoMessage() {} + +func (x *MailData) ProtoReflect() protoreflect.Message { + mi := &file_mail_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MailData.ProtoReflect.Descriptor instead. +func (*MailData) Descriptor() ([]byte, []int) { + return file_mail_proto_rawDescGZIP(), []int{1} +} + +func (x *MailData) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *MailData) GetContex() string { + if x != nil { + return x.Contex + } + return "" +} + +func (x *MailData) GetCreateTime() uint64 { + if x != nil { + return x.CreateTime + } + return 0 +} + +func (x *MailData) GetDueTime() uint64 { + if x != nil { + return x.DueTime + } + return 0 +} + +func (x *MailData) GetCheck() bool { + if x != nil { + return x.Check + } + return false +} + +func (x *MailData) GetItems() []*MailAttachment { + if x != nil { + return x.Items + } + return nil +} + +//用户背包 +type DB_UserMailData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId uint32 `bson:"_id" json:"UserId,omitempty" protobuf:"varint,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id + Mails []*MailData `protobuf:"bytes,2,rep,name=mails,proto3" json:"mails,omitempty"` // 邮件列表 +} + +func (x *DB_UserMailData) Reset() { + *x = DB_UserMailData{} + if protoimpl.UnsafeEnabled { + mi := &file_mail_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DB_UserMailData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DB_UserMailData) ProtoMessage() {} + +func (x *DB_UserMailData) ProtoReflect() protoreflect.Message { + mi := &file_mail_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DB_UserMailData.ProtoReflect.Descriptor instead. +func (*DB_UserMailData) Descriptor() ([]byte, []int) { + return file_mail_proto_rawDescGZIP(), []int{2} +} + +func (x *DB_UserMailData) GetUserId() uint32 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *DB_UserMailData) GetMails() []*MailData { + if x != nil { + return x.Mails + } + return nil +} + +var File_mail_proto protoreflect.FileDescriptor + +var file_mail_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x46, 0x0a, 0x0e, + 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x16, + 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, + 0x49, 0x74, 0x65, 0x6d, 0x69, 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, 0xaf, 0x01, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x74, 0x65, + 0x78, 0x18, 0x02, 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, 0x03, 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, 0x04, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x07, 0x44, 0x75, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, + 0x25, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x06, 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, 0x22, 0x4a, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, + 0x72, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x6d, 0x61, 0x69, + 0x6c, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_mail_proto_rawDescOnce sync.Once + file_mail_proto_rawDescData = file_mail_proto_rawDesc +) + +func file_mail_proto_rawDescGZIP() []byte { + file_mail_proto_rawDescOnce.Do(func() { + file_mail_proto_rawDescData = protoimpl.X.CompressGZIP(file_mail_proto_rawDescData) + }) + return file_mail_proto_rawDescData +} + +var file_mail_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_mail_proto_goTypes = []interface{}{ + (*MailAttachment)(nil), // 0: MailAttachment + (*MailData)(nil), // 1: MailData + (*DB_UserMailData)(nil), // 2: DB_UserMailData +} +var file_mail_proto_depIdxs = []int32{ + 0, // 0: MailData.Items:type_name -> MailAttachment + 1, // 1: DB_UserMailData.mails:type_name -> MailData + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_mail_proto_init() } +func file_mail_proto_init() { + if File_mail_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_mail_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MailAttachment); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_mail_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MailData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_mail_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DB_UserMailData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_mail_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_mail_proto_goTypes, + DependencyIndexes: file_mail_proto_depIdxs, + MessageInfos: file_mail_proto_msgTypes, + }.Build() + File_mail_proto = out.File + file_mail_proto_rawDesc = nil + file_mail_proto_goTypes = nil + file_mail_proto_depIdxs = nil +} diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go index b9aa2f991..16187b266 100644 --- a/pb/pack_db.pb.go +++ b/pb/pack_db.pb.go @@ -147,7 +147,7 @@ type DB_UserPackData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id + UserId uint32 `bson:"_id" json:"UserId,omitempty" protobuf:"varint,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id Pack []*GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 } diff --git a/pb/proto/mail.proto b/pb/proto/mail.proto new file mode 100644 index 000000000..ebdf9ed65 --- /dev/null +++ b/pb/proto/mail.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +option go_package = ".;pb"; + +message MailAttachment { // 附件 + uint32 Itemid = 1; // 道具iD + uint32 ItemCount = 2; // 数量 +} +//背包格子 +message MailData { + string Title = 1; // 邮件标题 + string Contex = 2; // 邮件内容 + uint64 CreateTime = 3; // 发送时间 + uint64 DueTime = 4; // 过期时间 + bool Check = 5; // 是否查看 + repeated MailAttachment Items = 6; // 附件 +} + +//用户背包 +message DB_UserMailData { + uint32 UserId = 1; //tags:{bson:"_id"}用户Id + repeated MailData mails = 2; // 邮件列表 +} \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 136214325..9f5b30372 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -88,7 +88,7 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id + UserId uint32 `bson:"_id" json:"UserId,omitempty" protobuf:"varint,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}动态Id Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"` Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"` diff --git a/pb_2.7.py b/pb_2.7.py index e20ff5832..e5e9d74fb 100644 --- a/pb_2.7.py +++ b/pb_2.7.py @@ -30,4 +30,5 @@ buildProto('./pb/proto','./pb','errorcode') buildProto('./pb/proto','./pb','user_db') buildProto('./pb/proto','./pb','user_msg') buildProto('./pb/proto','./pb','pack_db') -buildProto('./pb/proto','./pb','pack_msg') \ No newline at end of file +buildProto('./pb/proto','./pb','pack_msg') +buildProto('./pb/proto','./pb','mail') \ No newline at end of file diff --git a/services/worker/main.go b/services/worker/main.go index fda63a1c1..bcbdf7682 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "go_dreamfactory/modules/login" + "go_dreamfactory/modules/mail" "go_dreamfactory/modules/pack" "go_dreamfactory/services" "go_dreamfactory/sys/cache" @@ -32,6 +33,7 @@ func main() { // web.NewModule(), login.NewModule(), pack.NewModule(), + mail.NewModule(), ) } diff --git a/sys/db/mail.go b/sys/db/mail.go index a8e5d8532..fa06af9f5 100644 --- a/sys/db/mail.go +++ b/sys/db/mail.go @@ -1,4 +1,18 @@ package db +import ( + "go_dreamfactory/pb" + + "github.com/liwei1dao/lego/core" +) + type IMail interface { } + +const ( //Redis + DB_MailTable core.SqlTable = "mail" +) + +type IMain interface { + QueryUserMail(uId uint32) (pack *pb.DB_UserPackData, err error) +} From 1caf66f7290e0f247de49bf25e657d02ae621719 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Jun 2022 10:19:31 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E3=80=82=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/module.go | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/modules/user/module.go b/modules/user/module.go index 9e192d124..47afe980f 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -3,11 +3,8 @@ package user import ( "go_dreamfactory/comm" "go_dreamfactory/modules" - "go_dreamfactory/sys/configure" - cfg "go_dreamfactory/sys/configure/structs" "github.com/liwei1dao/lego/core" - "github.com/liwei1dao/lego/sys/log" ) func NewModule() core.IModule { @@ -28,22 +25,3 @@ func (this *User) OnInstallComp() { this.ModuleBase.OnInstallComp() this.login_comp = this.RegisterComp(new(LoginComp)).(*LoginComp) } - -func (this *Login) Start() (err error) { - - if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil { - return - } - - if data, ret := configure.GetConfigure("tbitem.json"); ret == nil { - _data := data.(*cfg.TbItem).GetDataMap() - for _, v := range _data { - if v.Id > 0 { - break - } - log.Debugf(v.Name) - } - } - - return nil -} From 951e89248785ff8b12c7f74b53205ae1947118e4 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Jun 2022 11:33:26 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pb/mail.pb.go | 12 +++++------- pb/pack_db.pb.go | 2 +- pb/proto/mail.proto | 5 ++--- pb/user_db.pb.go | 2 +- sys/cache/core.go | 1 + sys/cache/mail.go | 34 +++++++++++++++++++++++++++++++--- sys/db/mail.go | 14 +++++++++----- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/pb/mail.pb.go b/pb/mail.pb.go index 103198ff3..e5e2522b9 100644 --- a/pb/mail.pb.go +++ b/pb/mail.pb.go @@ -75,7 +75,6 @@ func (x *MailAttachment) GetItemCount() uint32 { return 0 } -//背包格子 type MailData struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -163,14 +162,13 @@ func (x *MailData) GetItems() []*MailAttachment { return nil } -//用户背包 type DB_UserMailData struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId uint32 `bson:"_id" json:"UserId,omitempty" protobuf:"varint,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id - Mails []*MailData `protobuf:"bytes,2,rep,name=mails,proto3" json:"mails,omitempty"` // 邮件列表 + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id + Mails []*MailData `protobuf:"bytes,2,rep,name=mails,proto3" json:"mails,omitempty"` // 邮件列表 } func (x *DB_UserMailData) Reset() { @@ -205,11 +203,11 @@ func (*DB_UserMailData) Descriptor() ([]byte, []int) { return file_mail_proto_rawDescGZIP(), []int{2} } -func (x *DB_UserMailData) GetUserId() uint32 { +func (x *DB_UserMailData) GetUserId() string { if x != nil { return x.UserId } - return 0 + return "" } func (x *DB_UserMailData) GetMails() []*MailData { @@ -240,7 +238,7 @@ var file_mail_proto_rawDesc = []byte{ 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x4a, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go index 6dd9577bf..0dc1074bd 100644 --- a/pb/pack_db.pb.go +++ b/pb/pack_db.pb.go @@ -139,7 +139,7 @@ type DB_UserPackData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id Pack []*GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 } diff --git a/pb/proto/mail.proto b/pb/proto/mail.proto index ebdf9ed65..6c3c4f54c 100644 --- a/pb/proto/mail.proto +++ b/pb/proto/mail.proto @@ -5,7 +5,7 @@ message MailAttachment { // 附件 uint32 Itemid = 1; // 道具iD uint32 ItemCount = 2; // 数量 } -//背包格子 + message MailData { string Title = 1; // 邮件标题 string Contex = 2; // 邮件内容 @@ -15,8 +15,7 @@ message MailData { repeated MailAttachment Items = 6; // 附件 } -//用户背包 message DB_UserMailData { - uint32 UserId = 1; //tags:{bson:"_id"}用户Id + string UserId = 1; //tags:{bson:"_id"}用户Id repeated MailData mails = 2; // 邮件列表 } \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 2ce469232..2c4b65c99 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -88,7 +88,7 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}动态Id Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"` Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"` diff --git a/sys/cache/core.go b/sys/cache/core.go index e8eecaed8..ddda681f7 100644 --- a/sys/cache/core.go +++ b/sys/cache/core.go @@ -4,6 +4,7 @@ type ( ISys interface { IUser IPack + IMail } ) diff --git a/sys/cache/mail.go b/sys/cache/mail.go index fca759d23..d42970c83 100644 --- a/sys/cache/mail.go +++ b/sys/cache/mail.go @@ -1,7 +1,35 @@ package cache -const ( //Redis - Redis_mailCache string = "mail:%d" +import ( + "fmt" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" + + "github.com/liwei1dao/lego/sys/mgo" + "github.com/liwei1dao/lego/sys/redis" ) -type IMail interface{} +const ( //Redis + Redis_MailCache string = "mail:%s" +) + +type IMail interface { + QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) +} + +// 查询玩家邮件数据 +func (this *Cache) QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) { + mail = &pb.DB_UserMailData{ + UserId: uId, + } + if err = this.redis.Get(fmt.Sprintf(Redis_MailCache, uId), mail); err == nil { + return + } else if err == redis.RedisNil { + if mail, err = db.Defsys.QueryUserMail(uId); err == nil { + this.redis.Set(fmt.Sprintf(Redis_MailCache, uId), mail, -1) + } else if err == mgo.MongodbNil { + err = nil + } + } + return +} diff --git a/sys/db/mail.go b/sys/db/mail.go index fa06af9f5..5772e2e42 100644 --- a/sys/db/mail.go +++ b/sys/db/mail.go @@ -4,15 +4,19 @@ import ( "go_dreamfactory/pb" "github.com/liwei1dao/lego/core" + "go.mongodb.org/mongo-driver/bson" ) -type IMail interface { -} - const ( //Redis DB_MailTable core.SqlTable = "mail" ) -type IMain interface { - QueryUserMail(uId uint32) (pack *pb.DB_UserPackData, err error) +type IMail interface { + QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) +} + +func (this *DB) QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) { + mail = &pb.DB_UserMailData{} + err = this.mgo.FindOne(DB_MailTable, bson.M{"_id": uId}).Decode(mail) + return } From ea9b9a394c07d697d0961549bfb97aee9b1c01d0 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 7 Jun 2022 11:57:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 1 + comm/usersession.go | 4 ++++ pb/proto/user_db.proto | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/comm/core.go b/comm/core.go index 88a10e89e..bf0f70ce8 100644 --- a/comm/core.go +++ b/comm/core.go @@ -41,6 +41,7 @@ type IUserSession interface { GetUserId() string GetIP() string GetGatewayServiceId() string + IsLogin() bool Build(uid string) (err error) UnBuild(ServiceMethod string, msg proto.Message) (err error) SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error) diff --git a/comm/usersession.go b/comm/usersession.go index 44a961e51..f8ecb4d27 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -42,6 +42,10 @@ func (this *UserSession) GetGatewayServiceId() string { return this.GatewayServiceId } +func (this *UserSession) IsLogin() bool { + return this.UserId != "" +} + func (this *UserSession) Build(uid string) (err error) { reply := &pb.RPCMessageReply{} if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentBuild), context.Background(), &pb.AgentBuildReq{ diff --git a/pb/proto/user_db.proto b/pb/proto/user_db.proto index 7a239c802..8c042169e 100644 --- a/pb/proto/user_db.proto +++ b/pb/proto/user_db.proto @@ -9,7 +9,7 @@ message Cache_UserData { message DB_UserData { string UserId = 1; //tags:{bson:"_id"}动态Id - string account = 2; + string Account = 2; string NiceName = 3; string Email = 4; string Password = 5;