From 900910e10185a23efe1b0dcc371c9ad64a065354 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 7 Sep 2022 20:07:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=97=8F=E4=B9=A6=E9=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 +++ modules/library/api_getlist.go | 31 +++++++++++++++++++++ modules/library/model_hunting.go | 44 ++++++++++++++++++++++++++++++ modules/library/module.go | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 modules/library/api_getlist.go create mode 100644 modules/library/model_hunting.go create mode 100644 modules/library/module.go diff --git a/comm/const.go b/comm/const.go index a7b507791..b8d9a4989 100644 --- a/comm/const.go +++ b/comm/const.go @@ -60,6 +60,7 @@ const ( ModuleHunting core.M_Modules = "hunting" //狩猎 ModuleLinestory core.M_Modules = "linestory" //支线剧情 ModuleBattle core.M_Modules = "battle" //战斗 + ModuleLibrary core.M_Modules = "library" // ) //数据表名定义处 @@ -133,6 +134,8 @@ const ( // 支线剧情任务 TableLinestory = "linestory" + + TableLibrary = "library" ) //RPC服务接口定义处 diff --git a/modules/library/api_getlist.go b/modules/library/api_getlist.go new file mode 100644 index 000000000..5ec155b04 --- /dev/null +++ b/modules/library/api_getlist.go @@ -0,0 +1,31 @@ +package library + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.DBHero) (code pb.ErrorCode) { + + return +} + +func (this *apiComp) GetList(session comm.IUserSession, req *pb.DBHero) (code pb.ErrorCode, data proto.Message) { + + code = this.GetListCheck(session, req) + if code != pb.ErrorCode_Success { + return // 参数校验失败直接返回 + } + + // list, err := this.module.modelLibrary.getLibraryList(session.GetUserId()) + // if err != nil { + // code = pb.ErrorCode_DBError + // return + // } + + //session.SendMsg(string(this.module.GetType()), LibraryGetListResp, &pb.LibraryGetListResp{Data: list}) + return +} diff --git a/modules/library/model_hunting.go b/modules/library/model_hunting.go new file mode 100644 index 000000000..be267a399 --- /dev/null +++ b/modules/library/model_hunting.go @@ -0,0 +1,44 @@ +package library + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +type modelLibrary struct { + modules.MCompModel + module *Library +} + +func (this *modelLibrary) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.TableName = string(comm.TableLibrary) + err = this.MCompModel.Init(service, module, comp, options) + this.module = module.(*Library) + // uid 创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} + +func (this *modelLibrary) modifyLibraryDataByObjId(uid string, data map[string]interface{}) error { + return this.Change(uid, data) +} + +// 获取列表信息 +func (this *modelLibrary) getLibraryList(uid string) (result *pb.DBHero, err error) { + result = &pb.DBHero{} + if err = this.Get(uid, result); err != nil && mgo.MongodbNil != err { + + return + } + + err = nil + return result, err +} diff --git a/modules/library/module.go b/modules/library/module.go new file mode 100644 index 000000000..4666c2039 --- /dev/null +++ b/modules/library/module.go @@ -0,0 +1,46 @@ +package library + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" +) + +type Library struct { + modules.ModuleBase + modelLibrary *modelLibrary + api *apiComp + configure *configureComp +} + +func NewModule() core.IModule { + return &Library{} +} + +func (this *Library) GetType() core.M_Modules { + return comm.ModuleLibrary +} + +func (this *Library) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + + return +} + +func (this *Library) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.modelLibrary = this.RegisterComp(new(modelLibrary)).(*modelLibrary) + + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) +} + +// 接口信息 +func (this *Library) ModifyLibraryData(uid string, data map[string]interface{}) (code pb.ErrorCode) { + err := this.modelLibrary.modifyLibraryDataByObjId(uid, data) + if err != nil { + code = pb.ErrorCode_DBError + } + return +}