去除底层互相引用方式该由上层按需执行保存引用对象
This commit is contained in:
parent
11a63977c3
commit
4931d310e2
@ -1,7 +1,6 @@
|
|||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/base"
|
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/redis"
|
"go_dreamfactory/lego/sys/redis"
|
||||||
@ -13,16 +12,12 @@ import (
|
|||||||
*/
|
*/
|
||||||
type MComp_CacheComp struct {
|
type MComp_CacheComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
S base.IRPCXService //rpc服务对象
|
|
||||||
M IModule //当前业务模块
|
|
||||||
Redis redis.ISys
|
Redis redis.ISys
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *MComp_CacheComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *MComp_CacheComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.S = service.(base.IRPCXService)
|
|
||||||
this.M = module.(IModule)
|
|
||||||
this.Redis = cache.Redis()
|
this.Redis = cache.Redis()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/base"
|
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
@ -17,9 +16,6 @@ import (
|
|||||||
*/
|
*/
|
||||||
type MComp_DBComp struct {
|
type MComp_DBComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
S base.IRPCXService //rpc服务对象
|
|
||||||
M IModule //当前业务模块
|
|
||||||
|
|
||||||
DB mgo.ISys
|
DB mgo.ISys
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,8 +24,6 @@ const ()
|
|||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *MComp_DBComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *MComp_DBComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.S = service.(base.IRPCXService)
|
|
||||||
this.M = module.(IModule)
|
|
||||||
this.DB = db.Mgo()
|
this.DB = db.Mgo()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,17 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
|
|||||||
*/
|
*/
|
||||||
type MComp_GateComp struct {
|
type MComp_GateComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
S base.IRPCXService //rpc服务对象
|
service base.IRPCXService //rpc服务对象
|
||||||
M IModule //当前业务模块
|
module core.IModule //当前业务模块
|
||||||
comp core.IModuleComp //网关组件自己
|
comp core.IModuleComp //网关组件自己
|
||||||
scomp comm.ISC_GateRouteComp
|
scomp comm.ISC_GateRouteComp
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.S = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
this.M = module.(IModule)
|
this.module = module
|
||||||
this.comp = comp
|
this.comp = comp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ func (this *MComp_GateComp) Start() (err error) {
|
|||||||
}
|
}
|
||||||
var comp core.IServiceComp
|
var comp core.IServiceComp
|
||||||
//注册远程路由
|
//注册远程路由
|
||||||
if comp, err = this.S.GetComp(comm.SC_ServiceGateRouteComp); err != nil {
|
if comp, err = this.service.GetComp(comm.SC_ServiceGateRouteComp); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.scomp = comp.(comm.ISC_GateRouteComp)
|
this.scomp = comp.(comm.ISC_GateRouteComp)
|
||||||
@ -96,7 +96,7 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) bool {
|
|||||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.M.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
|
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSess
|
|||||||
code = pb.ErrorCode_NoLogin
|
code = pb.ErrorCode_NoLogin
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bRet := this.M.DB().(*DB_Comp).Mail_DelUserMail(req.ObjID)
|
bRet := this.module.db_comp.Mail_DelUserMail(req.ObjID)
|
||||||
if !bRet {
|
if !bRet {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if mailinfo, err = this.M.DB().(*DB_Comp).Mail_QueryUserMail(session.GetUserId()); err != nil {
|
if mailinfo, err = this.module.db_comp.Mail_QueryUserMail(session.GetUserId()); err != nil {
|
||||||
log.Errorf("QueryUserMailResp err:%v", err)
|
log.Errorf("QueryUserMailResp err:%v", err)
|
||||||
code = pb.ErrorCode_CacheReadError
|
code = pb.ErrorCode_CacheReadError
|
||||||
return
|
return
|
||||||
|
@ -20,12 +20,12 @@ func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm
|
|||||||
code = pb.ErrorCode_NoLogin
|
code = pb.ErrorCode_NoLogin
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_bGet := this.M.DB().(*DB_Comp).Mail_GetMailAttachmentState(req.ObjID)
|
_bGet := this.module.db_comp.Mail_GetMailAttachmentState(req.ObjID)
|
||||||
if !_bGet {
|
if !_bGet {
|
||||||
code = pb.ErrorCode_StateInvalid
|
code = pb.ErrorCode_StateInvalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_data, err := this.M.DB().(*DB_Comp).Mail_GetMailAttachment(req.ObjID)
|
_data, err := this.module.db_comp.Mail_GetMailAttachment(req.ObjID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(_data) > 0 {
|
if len(_data) > 0 {
|
||||||
// todo 领取附件
|
// todo 领取附件
|
||||||
@ -36,7 +36,7 @@ func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm
|
|||||||
bRet := this.pack.AddItemsToUserPack(mail.UserId, _items)
|
bRet := this.pack.AddItemsToUserPack(mail.UserId, _items)
|
||||||
if bRet != nil {
|
if bRet != nil {
|
||||||
// 修改状态
|
// 修改状态
|
||||||
this.M.DB().(*DB_Comp).Mail_UpdateMailAttachmentState(req.ObjID)
|
this.module.db_comp.Mail_UpdateMailAttachmentState(req.ObjID)
|
||||||
mail.Reward = true
|
mail.Reward = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSe
|
|||||||
code = pb.ErrorCode_NoLogin
|
code = pb.ErrorCode_NoLogin
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if mailinfo, err = this.M.DB().(*DB_Comp).Mail_QueryUserMail(session.GetUserId()); err != nil {
|
if mailinfo, err = this.module.db_comp.Mail_QueryUserMail(session.GetUserId()); err != nil {
|
||||||
log.Errorf("QueryUserMailResp err:%v", err)
|
log.Errorf("QueryUserMailResp err:%v", err)
|
||||||
code = pb.ErrorCode_CacheReadError
|
code = pb.ErrorCode_CacheReadError
|
||||||
return
|
return
|
||||||
|
@ -20,7 +20,7 @@ func (this *Api_Comp) ReadUserMailReq(ctx context.Context, session comm.IUserSes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mail, err = this.M.DB().(*DB_Comp).Mail_ReadOneMail(req.ObjID)
|
mail, err = this.module.db_comp.Mail_ReadOneMail(req.ObjID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_ReqParameterError
|
code = pb.ErrorCode_ReqParameterError
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ func NewModule() core.IModule {
|
|||||||
type Mail struct {
|
type Mail struct {
|
||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
api_comp *Api_Comp
|
api_comp *Api_Comp
|
||||||
|
db_comp *DB_Comp
|
||||||
configure_comp *Configure_Comp
|
configure_comp *Configure_Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ func (this *Mail) GetType() core.M_Modules {
|
|||||||
func (this *Mail) OnInstallComp() {
|
func (this *Mail) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||||
|
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
||||||
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ func (this *Mail) CreateNewMail(uId string) {
|
|||||||
Check: false,
|
Check: false,
|
||||||
Reward: false,
|
Reward: false,
|
||||||
}
|
}
|
||||||
err := this.DB().(*DB_Comp).Mail_InsertUserMail(mail)
|
err := this.db_comp.Mail_InsertUserMail(mail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("create mail failed")
|
log.Error("create mail failed")
|
||||||
}
|
}
|
||||||
|
@ -20,25 +20,7 @@ import (
|
|||||||
*/
|
*/
|
||||||
type ModuleBase struct {
|
type ModuleBase struct {
|
||||||
cbase.ModuleBase
|
cbase.ModuleBase
|
||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
Api_Comp IAPI_Comp
|
|
||||||
Cache_Comp ICache_Comp
|
|
||||||
Db_Comp IDB_Comp
|
|
||||||
Configure_Comp IConfigure_Comp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ModuleBase) API() IAPI_Comp {
|
|
||||||
return this.Api_Comp
|
|
||||||
}
|
|
||||||
func (this *ModuleBase) Cache() ICache_Comp {
|
|
||||||
return this.Cache_Comp
|
|
||||||
}
|
|
||||||
func (this *ModuleBase) DB() IDB_Comp {
|
|
||||||
return this.Db_Comp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ModuleBase) Configure() IConfigure_Comp {
|
|
||||||
return this.Configure_Comp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块初始化接口
|
//模块初始化接口
|
||||||
|
@ -17,10 +17,12 @@ const ( //消息回复的头名称
|
|||||||
*/
|
*/
|
||||||
type Api_Comp struct {
|
type Api_Comp struct {
|
||||||
modules.MComp_GateComp
|
modules.MComp_GateComp
|
||||||
|
module *Pack
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
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.MComp_GateComp.Init(service, module, comp, options)
|
||||||
|
this.module = module.(*Pack)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -29,23 +29,23 @@ func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, re
|
|||||||
dels []string
|
dels []string
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.M.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
|
session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
|
||||||
if code == pb.ErrorCode_Success {
|
if code == pb.ErrorCode_Success {
|
||||||
go func() { //异步处理修改数据
|
go func() { //异步处理修改数据
|
||||||
this.M.Cache().(*Cache_Comp).Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
this.module.cache_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
||||||
this.M.Cache().(*Cache_Comp).Pack_DeleteUserPack(session.GetUserId(), dels...)
|
this.module.cache_comp.Pack_DeleteUserPack(session.GetUserId(), dels...)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if code = this.Getlist_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
if code = this.Getlist_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if items, err = this.M.Cache().(*Cache_Comp).Pack_QueryUserPack(session.GetUserId()); err != nil {
|
if items, err = this.module.cache_comp.Pack_QueryUserPack(session.GetUserId()); err != nil {
|
||||||
log.Errorf("QueryUserPackReq err:%v", err)
|
log.Errorf("QueryUserPackReq err:%v", err)
|
||||||
code = pb.ErrorCode_CacheReadError
|
code = pb.ErrorCode_CacheReadError
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
tempgrids = this.M.Configure().(*Configure_Comp).GetPackItemByType(items, req.IType)
|
tempgrids = this.module.configure_comp.GetPackItemByType(items, req.IType)
|
||||||
modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids))
|
modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids))
|
||||||
dels = make([]string, 0, len(tempgrids))
|
dels = make([]string, 0, len(tempgrids))
|
||||||
grids = make([]*pb.DB_UserItemData, 0, len(grids))
|
grids = make([]*pb.DB_UserItemData, 0, len(grids))
|
||||||
|
@ -21,7 +21,7 @@ func (this *Api_Comp) SellItem(ctx context.Context, session comm.IUserSession, r
|
|||||||
code pb.ErrorCode
|
code pb.ErrorCode
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.M.GetType()), SellItemResp, code, &pb.SellItemResp{})
|
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
|
||||||
}()
|
}()
|
||||||
if code = this.SellItem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
if code = this.SellItem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
|
@ -21,7 +21,7 @@ func (this *Api_Comp) Useitem(ctx context.Context, session comm.IUserSession, re
|
|||||||
code pb.ErrorCode
|
code pb.ErrorCode
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.M.GetType()), UseItemResp, code, &pb.UseItemResp{})
|
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
|
||||||
}()
|
}()
|
||||||
if code = this.Useitem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
if code = this.Useitem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
|
@ -15,11 +15,13 @@ import (
|
|||||||
///背包缓存数据管理组件
|
///背包缓存数据管理组件
|
||||||
type Cache_Comp struct {
|
type Cache_Comp struct {
|
||||||
modules.MComp_CacheComp
|
modules.MComp_CacheComp
|
||||||
|
module *Pack
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *Cache_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *Cache_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
|
this.module = module.(*Pack)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ func (this *Cache_Comp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemD
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if err == redis.RedisNil {
|
} else if err == redis.RedisNil {
|
||||||
if itmes, err = this.M.DB().(*DB_Comp).Pack_QueryUserPack(uId); err == nil {
|
if itmes, err = this.module.db_comp.Pack_QueryUserPack(uId); err == nil {
|
||||||
temp = make(map[string]interface{})
|
temp = make(map[string]interface{})
|
||||||
for _, v := range itmes {
|
for _, v := range itmes {
|
||||||
temp[v.GridId] = v
|
temp[v.GridId] = v
|
||||||
@ -59,7 +61,7 @@ func (this *Cache_Comp) Pack_QueryUserPackByGridId(uId string, grid string) (itm
|
|||||||
if err = this.Redis.HGet(fmt.Sprintf(Redis_PackCache, uId), grid, itme); err == nil {
|
if err = this.Redis.HGet(fmt.Sprintf(Redis_PackCache, uId), grid, itme); err == nil {
|
||||||
return
|
return
|
||||||
} else if err == redis.RedisNil {
|
} else if err == redis.RedisNil {
|
||||||
if itmes, err = this.M.DB().(*DB_Comp).Pack_QueryUserPack(uId); err == nil {
|
if itmes, err = this.module.db_comp.Pack_QueryUserPack(uId); err == nil {
|
||||||
temp = make(map[string]interface{})
|
temp = make(map[string]interface{})
|
||||||
for _, v := range itmes {
|
for _, v := range itmes {
|
||||||
temp[v.GridId] = v
|
temp[v.GridId] = v
|
||||||
@ -86,7 +88,7 @@ func (this *Cache_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItem
|
|||||||
temp[v.GridId] = v
|
temp[v.GridId] = v
|
||||||
}
|
}
|
||||||
if err = this.Redis.HMSet(fmt.Sprintf(Redis_PackCache, uId), temp); err != nil {
|
if err = this.Redis.HMSet(fmt.Sprintf(Redis_PackCache, uId), temp); err != nil {
|
||||||
this.M.DB().(*DB_Comp).Pack_UpdateGridToUserPack(uId, itmes...)
|
this.module.db_comp.Pack_UpdateGridToUserPack(uId, itmes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -95,7 +97,7 @@ func (this *Cache_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItem
|
|||||||
//更新用户的背包信息
|
//更新用户的背包信息
|
||||||
func (this *Cache_Comp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) {
|
func (this *Cache_Comp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) {
|
||||||
if err = this.Redis.HDel(fmt.Sprintf(Redis_PackCache, uId), gridIds...); err != nil {
|
if err = this.Redis.HDel(fmt.Sprintf(Redis_PackCache, uId), gridIds...); err != nil {
|
||||||
err = this.M.DB().(*DB_Comp).Pack_DeleteGridToUserPack(uId, gridIds...)
|
err = this.module.db_comp.Pack_DeleteGridToUserPack(uId, gridIds...)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ func NewModule() core.IModule {
|
|||||||
|
|
||||||
type Pack struct {
|
type Pack struct {
|
||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
|
api_comp *Api_Comp
|
||||||
|
cache_comp *Cache_Comp
|
||||||
|
db_comp *DB_Comp
|
||||||
|
configure_comp *Configure_Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块名称
|
//模块名称
|
||||||
@ -36,24 +40,24 @@ func (this *Pack) Init(service core.IService, module core.IModule, options core.
|
|||||||
//装备组件
|
//装备组件
|
||||||
func (this *Pack) OnInstallComp() {
|
func (this *Pack) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.Api_Comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||||
this.Cache_Comp = this.RegisterComp(new(Cache_Comp)).(*Cache_Comp)
|
this.cache_comp = this.RegisterComp(new(Cache_Comp)).(*Cache_Comp)
|
||||||
this.Db_Comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
||||||
this.Configure_Comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//IPack-------------------------------------------------------------------------------------------------------------------------------
|
//IPack-------------------------------------------------------------------------------------------------------------------------------
|
||||||
///查询用户背包物品数量
|
///查询用户背包物品数量
|
||||||
func (this *Pack) QueryUserPackItemAmount(uId string, itemid int32) (amount uint32) {
|
func (this *Pack) QueryUserPackItemAmount(uId string, itemid int32) (amount uint32) {
|
||||||
defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount)
|
defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount)
|
||||||
amount = this.Cache_Comp.(*Cache_Comp).Pack_QueryUserPackItemAmount(uId, itemid)
|
amount = this.cache_comp.Pack_QueryUserPackItemAmount(uId, itemid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
///添加单个物品到背包 (可以加物品和减物品)
|
///添加单个物品到背包 (可以加物品和减物品)
|
||||||
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) {
|
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) {
|
||||||
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil)
|
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil)
|
||||||
if err = this.Cache_Comp.(*Cache_Comp).Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
|
if err = this.cache_comp.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
|
||||||
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
|
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -62,7 +66,7 @@ func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error
|
|||||||
///添加多个物品到背包 (可以加物品和减物品)
|
///添加多个物品到背包 (可以加物品和减物品)
|
||||||
func (this *Pack) AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
func (this *Pack) AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
||||||
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil)
|
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil)
|
||||||
if err = this.Cache_Comp.(*Cache_Comp).Pack_AddItemsToUserPack(uId, items); err != nil {
|
if err = this.cache_comp.Pack_AddItemsToUserPack(uId, items); err != nil {
|
||||||
log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
|
log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
27
modules/pack/pack_test.go
Normal file
27
modules/pack/pack_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package pack_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/sys/cache"
|
||||||
|
"go_dreamfactory/sys/configure"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
//测试环境下初始化db和cache 系统
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
if err := db.OnInit(nil, db.Set_MongodbUrl("mongodb://admin:123456@10.0.0.9:27018"), db.Set_MongodbDatabase("dreamfactory")); err != nil {
|
||||||
|
fmt.Printf("err:%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := cache.OnInit(nil, cache.Set_Redis_Addr([]string{"10.0.0.9:9001", "10.0.0.9:9002", "10.0.0.9:9003", "10.0.1.45:9004", "10.0.1.45:9005", "10.0.1.45:9006"}), cache.Set_Redis_Password("")); err != nil {
|
||||||
|
fmt.Printf("err:%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := configure.OnInit(nil); err != nil {
|
||||||
|
fmt.Printf("err:%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Exit(m.Run())
|
||||||
|
}
|
@ -11,6 +11,8 @@ import (
|
|||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go_dreamfactory/lego/base"
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/event"
|
"go_dreamfactory/lego/sys/event"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
@ -20,6 +22,13 @@ import (
|
|||||||
|
|
||||||
type LoginComp struct {
|
type LoginComp struct {
|
||||||
modules.MComp_GateComp
|
modules.MComp_GateComp
|
||||||
|
service base.IRPCXService
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *LoginComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
|
this.MComp_GateComp.Init(service, module, comp, options)
|
||||||
|
this.service = service.(base.IRPCXService)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//解码
|
//解码
|
||||||
@ -81,9 +90,9 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
log.Errorf("User_CreateUser err %v", err)
|
log.Errorf("User_CreateUser err %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.Bind(user.Uid, this.S.GetId())
|
session.Bind(user.Uid, this.service.GetId())
|
||||||
} else {
|
} else {
|
||||||
session.Bind(db_user.Uid, this.S.GetId())
|
session.Bind(db_user.Uid, this.service.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_user := &pb.Cache_UserData{
|
cache_user := &pb.Cache_UserData{
|
||||||
|
Loading…
Reference in New Issue
Block a user