上传接口代码优化

This commit is contained in:
liwei1dao 2023-02-27 10:21:11 +08:00
parent dea631420b
commit 21677da329
11 changed files with 283 additions and 40 deletions

View File

@ -200,15 +200,20 @@ func (this *Chat) SendUnionChat(msg *pb.DBChat) (code pb.ErrorCode) {
//向个人发送聊天消息
func (this *Chat) SendUserChat(msg *pb.DBChat) (code pb.ErrorCode) {
var (
err error
err error
session comm.IUserSession
ok bool
)
if session, ok := this.GetUserSession(msg.Ruid); ok {
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(msg.Ruid); ok {
session.SendMsg(string(this.GetType()), "message", &pb.ChatMessagePush{Chat: msg})
if err = session.Push(); err != nil {
this.Errorf("err:%v", err)
code = pb.ErrorCode_SystemError
return
}
return
} else {
if err = this.modelChat.saveUserMsg(msg); err != nil {
code = pb.ErrorCode_DBError
@ -318,12 +323,19 @@ func (this *Chat) pushChatToUnion(msg *pb.DBChat) (err error) {
//推送私聊消息
func (this *Chat) pushChatToPrivate(msg *pb.DBChat) (err error) {
if session, ok := this.GetUserSession(msg.Ruid); ok {
var (
session comm.IUserSession
ok bool
)
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(msg.Ruid); ok {
session.SendMsg(string(this.GetType()), "message", &pb.ChatMessagePush{Chat: msg})
if err = session.Push(); err != nil {
this.Errorf("err:%v", err)
}
return
} else {
err = this.modelChat.saveUserMsg(msg)
}

View File

@ -470,10 +470,19 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
func (this *GM) Rpc_ModuleGMCreateCmd(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleGMCreateCmd", log.Field{Key: "args", Value: args.String()})
if args.Param1 == "" || args.Param2 == "" {
err = errors.New("请求参数错误")
return
}
if session, ok := this.GetUserSession(args.Param1); !ok {
var (
session comm.IUserSession
ok bool
)
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(args.Param1); !ok {
err = fmt.Errorf("目标用户:%s 不在线", args.Param1)
return
} else {

View File

@ -247,10 +247,17 @@ func (this *Library) Rpc_ModuleFetter(ctx context.Context, args *pb.RPCGeneralRe
this.Debug("Rpc_ModuleFetter", log.Field{Key: "args", Value: args.String()})
if args.Param1 == "" || args.Param2 == "" {
err = errors.New("请求参数错误")
}
if session, ok := this.GetUserSession(args.Param1); !ok {
err = fmt.Errorf("目标用户:%s 不在线", args.Param1)
return
}
var (
session comm.IUserSession
ok bool
)
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(args.Param1); !ok {
err = fmt.Errorf("目标用户:%s 不在线", args.Param1)
} else {
this.AddHeroFetterData(session.GetUserId(), args.Param2)
session.Push()

View File

@ -127,19 +127,24 @@ func (this *Mail) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red
func (this *Mail) Rpc_Mail(ctx context.Context, args *pb.DBMailData) (err error) {
this.Debug("Rpc_Mail", log.Field{Key: "args", Value: args.String()})
var (
conn *db.DBConn
session comm.IUserSession
online bool
)
tag, _, b := utils.UIdSplit(args.Uid)
if b {
if conn, err := db.ServerDBConn(tag); err == nil {
if conn, err = db.ServerDBConn(tag); err == nil {
dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn)
_, err = dbModel.DB.InsertOne(comm.TableMail, args)
if err != nil {
this.Error("Create Rpc_Mail failed", log.Field{Key: "uid", Value: args.Uid}, log.Field{Key: "err", Value: err.Error()})
return
}
}
}
defer func() {
this.PutUserSession(session)
}()
if session, online = this.GetUserSession(args.Uid); online {
session.SendMsg(string(this.GetType()), "getnewmail", &pb.MailGetNewMailPush{Mail: args})
}

View File

@ -101,10 +101,14 @@ func (this *Moonfantasy) Trigger(session comm.IUserSession, source *pb.BattleRep
if int32(n.Int64()) < triggerData.DreamlandPro {
if this.IsCross() {
go func(uid string) {
ss, _ := this.GetUserSession(uid)
this.modelDream.trigger(ss)
if err = ss.Push(); err != nil {
this.Errorln(err)
if ss, ok := this.GetUserSession(uid); ok {
this.modelDream.trigger(ss)
if err = ss.Push(); err != nil {
this.Errorln(err)
}
this.PutUserSession(ss)
} else {
this.PutUserSession(ss)
}
}(session.GetUserId())
@ -130,7 +134,14 @@ func (this *Moonfantasy) Rpc_ModuleMoonfantasyTrigger(ctx context.Context, args
err = errors.New("参数异常!")
return
}
if session, ok := this.GetUserSession(args.Param1); !ok {
var (
session comm.IUserSession
ok bool
)
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(args.Param1); !ok {
err = fmt.Errorf("未查询到用户:%s在线信息!", args.Param1)
return
} else {
@ -146,6 +157,9 @@ func (this *Moonfantasy) Rpc_ModuleMoonfantasyTriggerMF(ctx context.Context, arg
session comm.IUserSession
ok bool
)
defer func() {
this.PutUserSession(session)
}()
if session, ok = this.GetUserSession(args.Uid); !ok {
err = fmt.Errorf("no found user%s", args.Uid)
this.Errorln(err)
@ -180,10 +194,14 @@ func (this *Moonfantasy) EventOpenCond(uid string, funcIds []string) {
for _, v := range funcIds {
if v == "Mystery" { //月子秘境
if this.IsCross() {
ss, _ := this.GetUserSession(uid)
this.modelDream.trigger(ss)
if err := ss.Push(); err != nil {
this.Errorln(err)
if ss, ok := this.GetUserSession(uid); ok {
this.modelDream.trigger(ss)
if err := ss.Push(); err != nil {
this.Errorln(err)
}
this.PutUserSession(ss)
} else {
this.PutUserSession(ss)
}
} else {
if _, err := this.service.AcrossClusterRpcGo(context.Background(),

View File

@ -94,14 +94,15 @@ func (this *Pay) Rpc_ModulePayDelivery(ctx context.Context, args *pb.PayDelivery
res = conf.DiamondNumDouble
}
info.Record[args.Productid]++
defer func() {
this.PutUserSession(session)
}()
if session, online = this.GetUserSession(args.Uid); online {
if reply.Code = this.DispenseRes(session, res, true); reply.Code != pb.ErrorCode_Success {
return
}
} else {
session = comm.NewUserSessionByPools(this.service)
session.SetSession("", "", "", "", args.Uid)
if reply.Code = this.DispenseRes(session, res, false); reply.Code != pb.ErrorCode_Success {
return
}
@ -142,7 +143,7 @@ func (this *Pay) Rpc_ModulePayDelivery(ctx context.Context, args *pb.PayDelivery
return
}
}
go this.ModuleHero.RechargeMoney(session.GetUserId(), conf.Amount)
go this.ModuleHero.RechargeMoney(args.Uid, conf.Amount)
return
}

View File

@ -0,0 +1,21 @@
package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) EnrolledCheck(session comm.IUserSession, req *pb.PracticeEnrolledReq) (code pb.ErrorCode) {
return
}
///练功请求
func (this *apiComp) Enrolled(session comm.IUserSession, req *pb.PracticeEnrolledReq) (code pb.ErrorCode, data proto.Message) {
session.SendMsg(string(this.module.GetType()), "info", &pb.PracticeEnrolledResp{})
return
}

View File

@ -152,7 +152,9 @@ func (this *apiComp) Expulsion(session comm.IUserSession, req *pb.PracticeExpuls
}
}
}
defer func() {
this.module.PutUserSession(_session)
}()
if _session, ok = this.module.GetUserSession(pillar.Uid); ok {
if _, code = this.module.ModuleHero.AddHeroExp(_session, pillar.Hero, exp); code != pb.ErrorCode_Success {
return
@ -161,7 +163,29 @@ func (this *apiComp) Expulsion(session comm.IUserSession, req *pb.PracticeExpuls
return
}
} else {
if _, code = this.module.ModuleHero.AddHeroExp(_session, pillar.Hero, exp); code != pb.ErrorCode_Success {
return
}
res := make([]*pb.UserAssets, 0)
for _, v := range ants1 {
res = append(res, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
for _, v := range ants2 {
res = append(res, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
this.module.mail.SendNewMail(&pb.DBMailData{
Cid: "Drivethemail",
CreateTime: uint64(configure.Now().Unix()),
Items: res,
}, pillar.Uid)
}
room.Knapsack[pillar.Teacher] = 0

View File

@ -20,6 +20,7 @@ func NewModule() core.IModule {
type Practice struct {
modules.ModuleBase
service base.IRPCXService
mail comm.Imail
api *apiComp
configure *configureComp
modelPandata *modelPandata
@ -38,7 +39,11 @@ func (this *Practice) Init(service core.IService, module core.IModule, options c
}
func (this *Practice) Start() (err error) {
err = this.ModuleBase.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleMail); err != nil {
return
}
this.mail = module.(comm.Imail)
return
}

View File

@ -334,8 +334,6 @@ const (
ErrorCode_SmithyNoActivateAtlas ErrorCode = 4113 // 没有图鉴更新数据
ErrorCode_SmithyLvToolsFailed ErrorCode = 4114 //
ErrorCode_SmithyLvToolsPre ErrorCode = 4115 // 前置条件不足
// dispatch
ErrorCode_DispatchHeroNoReached ErrorCode = 4201 //英雄条件未达标
)
// Enum value maps for ErrorCode.
@ -620,7 +618,6 @@ var (
4113: "SmithyNoActivateAtlas",
4114: "SmithyLvToolsFailed",
4115: "SmithyLvToolsPre",
4201: "DispatchHeroNoReached",
}
ErrorCode_value = map[string]int32{
"Success": 0,
@ -902,7 +899,6 @@ var (
"SmithyNoActivateAtlas": 4113,
"SmithyLvToolsFailed": 4114,
"SmithyLvToolsPre": 4115,
"DispatchHeroNoReached": 4201,
}
)
@ -937,7 +933,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0xff, 0x32, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x6f, 0x2a, 0xe3, 0x32, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
@ -1343,10 +1339,8 @@ var file_errorcode_proto_rawDesc = []byte{
0x6c, 0x61, 0x73, 0x10, 0x91, 0x20, 0x12, 0x18, 0x0a, 0x13, 0x53, 0x6d, 0x69, 0x74, 0x68, 0x79,
0x4c, 0x76, 0x54, 0x6f, 0x6f, 0x6c, 0x73, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x92, 0x20,
0x12, 0x15, 0x0a, 0x10, 0x53, 0x6d, 0x69, 0x74, 0x68, 0x79, 0x4c, 0x76, 0x54, 0x6f, 0x6f, 0x6c,
0x73, 0x50, 0x72, 0x65, 0x10, 0x93, 0x20, 0x12, 0x1a, 0x0a, 0x15, 0x44, 0x69, 0x73, 0x70, 0x61,
0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64,
0x10, 0xe9, 0x20, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x73, 0x50, 0x72, 0x65, 0x10, 0x93, 0x20, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -763,6 +763,118 @@ func (*PracticeReceiveResp) Descriptor() ([]byte, []int) {
return file_practice_practice_msg_proto_rawDescGZIP(), []int{13}
}
///登记满级英雄
type PracticeEnrolledReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Group int32 `protobuf:"varint,1,opt,name=group,proto3" json:"group"`
Hero string `protobuf:"bytes,2,opt,name=hero,proto3" json:"hero"`
}
func (x *PracticeEnrolledReq) Reset() {
*x = PracticeEnrolledReq{}
if protoimpl.UnsafeEnabled {
mi := &file_practice_practice_msg_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PracticeEnrolledReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PracticeEnrolledReq) ProtoMessage() {}
func (x *PracticeEnrolledReq) ProtoReflect() protoreflect.Message {
mi := &file_practice_practice_msg_proto_msgTypes[14]
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 PracticeEnrolledReq.ProtoReflect.Descriptor instead.
func (*PracticeEnrolledReq) Descriptor() ([]byte, []int) {
return file_practice_practice_msg_proto_rawDescGZIP(), []int{14}
}
func (x *PracticeEnrolledReq) GetGroup() int32 {
if x != nil {
return x.Group
}
return 0
}
func (x *PracticeEnrolledReq) GetHero() string {
if x != nil {
return x.Hero
}
return ""
}
///登记满级英雄 回应
type PracticeEnrolledResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Group int32 `protobuf:"varint,1,opt,name=group,proto3" json:"group"`
Hero string `protobuf:"bytes,2,opt,name=hero,proto3" json:"hero"`
}
func (x *PracticeEnrolledResp) Reset() {
*x = PracticeEnrolledResp{}
if protoimpl.UnsafeEnabled {
mi := &file_practice_practice_msg_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PracticeEnrolledResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PracticeEnrolledResp) ProtoMessage() {}
func (x *PracticeEnrolledResp) ProtoReflect() protoreflect.Message {
mi := &file_practice_practice_msg_proto_msgTypes[15]
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 PracticeEnrolledResp.ProtoReflect.Descriptor instead.
func (*PracticeEnrolledResp) Descriptor() ([]byte, []int) {
return file_practice_practice_msg_proto_rawDescGZIP(), []int{15}
}
func (x *PracticeEnrolledResp) GetGroup() int32 {
if x != nil {
return x.Group
}
return 0
}
func (x *PracticeEnrolledResp) GetHero() string {
if x != nil {
return x.Hero
}
return ""
}
var File_practice_practice_msg_proto protoreflect.FileDescriptor
var file_practice_practice_msg_proto_rawDesc = []byte{
@ -824,7 +936,16 @@ var file_practice_practice_msg_proto_rawDesc = []byte{
0x78, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x06, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x22, 0x15, 0x0a, 0x13, 0x50, 0x72, 0x61,
0x63, 0x74, 0x69, 0x63, 0x65, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70,
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x22, 0x3f, 0x0a, 0x13, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x45, 0x6e, 0x72, 0x6f,
0x6c, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x12, 0x0a,
0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x65, 0x72,
0x6f, 0x22, 0x40, 0x0a, 0x14, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x45, 0x6e, 0x72,
0x6f, 0x6c, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f,
0x75, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12,
0x12, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68,
0x65, 0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
@ -839,7 +960,7 @@ func file_practice_practice_msg_proto_rawDescGZIP() []byte {
return file_practice_practice_msg_proto_rawDescData
}
var file_practice_practice_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_practice_practice_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
var file_practice_practice_msg_proto_goTypes = []interface{}{
(*PracticeInfoReq)(nil), // 0: PracticeInfoReq
(*PracticeInfoResp)(nil), // 1: PracticeInfoResp
@ -855,11 +976,13 @@ var file_practice_practice_msg_proto_goTypes = []interface{}{
(*PracticeExpulsionResp)(nil), // 11: PracticeExpulsionResp
(*PracticeReceiveReq)(nil), // 12: PracticeReceiveReq
(*PracticeReceiveResp)(nil), // 13: PracticeReceiveResp
(*DBPracticeRoom)(nil), // 14: DBPracticeRoom
(*PracticeEnrolledReq)(nil), // 14: PracticeEnrolledReq
(*PracticeEnrolledResp)(nil), // 15: PracticeEnrolledResp
(*DBPracticeRoom)(nil), // 16: DBPracticeRoom
}
var file_practice_practice_msg_proto_depIdxs = []int32{
14, // 0: PracticeInfoResp.info:type_name -> DBPracticeRoom
14, // 1: PracticeFriendRommResp.info:type_name -> DBPracticeRoom
16, // 0: PracticeInfoResp.info:type_name -> DBPracticeRoom
16, // 1: PracticeFriendRommResp.info:type_name -> DBPracticeRoom
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
@ -1042,6 +1165,30 @@ func file_practice_practice_msg_proto_init() {
return nil
}
}
file_practice_practice_msg_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PracticeEnrolledReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_practice_practice_msg_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PracticeEnrolledResp); 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{
@ -1049,7 +1196,7 @@ func file_practice_practice_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_practice_practice_msg_proto_rawDesc,
NumEnums: 0,
NumMessages: 14,
NumMessages: 16,
NumExtensions: 0,
NumServices: 0,
},