diff --git a/dsAutoCode/Controller/ProtoController/Template/RpcServiceFramework.template b/dsAutoCode/Controller/ProtoController/Template/RpcServiceFramework.template index 414b7bab..9f3f3f89 100644 --- a/dsAutoCode/Controller/ProtoController/Template/RpcServiceFramework.template +++ b/dsAutoCode/Controller/ProtoController/Template/RpcServiceFramework.template @@ -1,111 +1,141 @@ -package {{.tableName}}Service - -import ( - "context" - "dsBaseRpc/Const" - "dsBaseRpc/Const/ErrorConst" - "dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonDao" - "dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonProto" - "dsBaseRpc/Utils/CommonUtil" - "dsBaseRpc/Utils/LogUtil" - "dsBaseRpc/Utils/SqlKit" - "dsBaseRpc/models" -) - -type Rpc struct{} //服务对象 - -//选择单条 -func (s *Rpc) Get{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { - //rpc响应 - var reply {{.tableName}}Proto.Reply - //通用获取单条 - list := SqlKit.QueryIds([]string{{.s1}}, "{{.realTableName}}") - - //将结果序列化 - reply.Success = true - reply.Count = 1 - reply.Message = Const.SuccessDataBaseAction - reply.List = CommonUtil.SerializeToString(list) - return &reply, nil -} - -//增加 -func (s *Rpc) Add{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { - //rpc响应 - var reply {{.tableName}}Proto.Reply - //调用dao - model := new(models.T{{.tableName}}) - //实体填充 - {{.modelFill}} - _, err := {{.tableName}}Dao.Add{{.tableName}}(*model) - if err != nil { - reply.Success = false - reply.Message = Const.DataBaseActionError - LogUtil.Error(ErrorConst.SqlUpdateError, "执行Add{{.tableName}}时发生严重错误:"+err.Error()) - } else { - reply.Success = true - reply.Message = Const.SuccessDataBaseAction - } - return &reply, err -} - -//删除 -func (s *Rpc) Delete{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.DeleteIdsArg) (*{{.tableName}}Proto.Reply, error) { - //rpc响应 - var reply {{.tableName}}Proto.Reply - - //调用通用删除命令进行删除 - err := SqlKit.DeleteIds("{{.realTableName}}",in.Ids) - - //错误处理 - if err != nil { - LogUtil.Error(ErrorConst.SqlUpdateError, "执行Delete{{.tableName}}时发生严重错误:"+err.Error()) - reply.Success = false - reply.Message = Const.DataBaseActionError - return &reply, err - } - reply.Success = true - reply.Message = Const.SuccessDataBaseAction - return &reply, err -} - -//修改 -func (s *Rpc) Update{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { - //rpc响应 - var reply {{.tableName}}Proto.Reply - //3、修改 - model := new(models.T{{.tableName}}) - //实体填充 - {{.modelFill}} - _, err := {{.tableName}}Dao.Update{{.tableName}}(*model, in.ForceUpdateFields) - //错误处理 - if err != nil { - reply.Success = false - reply.Message = Const.DataBaseActionError - LogUtil.Error(ErrorConst.SqlUpdateError, "执行Update{{.tableName}}时发生严重错误:"+err.Error()) - return &reply, err - } - reply.Success = true - reply.Message = Const.SuccessDataBaseAction - return &reply, nil -} - -//分页查询 -func (s *Rpc) Page{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.QueryArg) (*{{.tableName}}Proto.Reply, error) { - //rpc响应 - var reply {{.tableName}}Proto.Reply - - list, count, err := {{.tableName}}Dao.Page{{.tableName}}(in) - //错误处理 - if err != nil { - reply.Success = false - reply.Message = Const.DataBaseActionError - LogUtil.Error(ErrorConst.SqlQueryError, "执行Page{{.tableName}}时发生严重错误:"+err.Error()) - return &reply, err - } - reply.Count = count - reply.Success = true - reply.Message = Const.SuccessDataBaseAction - reply.List = CommonUtil.SerializeToString(list) - return &reply, nil -} +package {{.tableName}}Service + +import ( + "context" + "dsBaseRpc/Const" + "dsBaseRpc/Const/ErrorConst" + "dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonDao" + "dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonProto" + "dsBaseRpc/Utils/CommonUtil" + "dsBaseRpc/Utils/LogUtil" + "dsBaseRpc/Utils/SqlKit" + "dsBaseRpc/models" +) + +type Rpc struct{} //服务对象 + +//选择单条 +func (s *Rpc) Get{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + //rpc响应 + var reply {{.tableName}}Proto.Reply + //通用获取单条 + list := SqlKit.QueryIds([]string{{.s1}}, "{{.realTableName}}") + + //将结果序列化 + reply.Success = true + reply.Count = 1 + reply.Message = Const.SuccessDataBaseAction + reply.List = CommonUtil.SerializeToString(list) + return &reply, nil +} + +//增加 +func (s *Rpc) Add{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + //rpc响应 + var reply {{.tableName}}Proto.Reply + //调用dao + model := new(models.T{{.tableName}}) + //实体填充 + {{.modelFill}} + _, err := {{.tableName}}Dao.Add{{.tableName}}(*model) + if err != nil { + reply.Success = false + reply.Message = Const.DataBaseActionError + LogUtil.Error(ErrorConst.SqlUpdateError, "执行Add{{.tableName}}时发生严重错误:"+err.Error()) + } else { + reply.Success = true + reply.Message = Const.SuccessDataBaseAction + } + return &reply, err +} + +//删除 +func (s *Rpc) Delete{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.DeleteIdsArg) (*{{.tableName}}Proto.Reply, error) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + //rpc响应 + var reply {{.tableName}}Proto.Reply + + //调用通用删除命令进行删除 + err := SqlKit.DeleteIds("{{.realTableName}}",in.Ids) + + //错误处理 + if err != nil { + LogUtil.Error(ErrorConst.SqlUpdateError, "执行Delete{{.tableName}}时发生严重错误:"+err.Error()) + reply.Success = false + reply.Message = Const.DataBaseActionError + return &reply, err + } + reply.Success = true + reply.Message = Const.SuccessDataBaseAction + return &reply, err +} + +//修改 +func (s *Rpc) Update{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.ModelArg) (*{{.tableName}}Proto.Reply, error) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + //rpc响应 + var reply {{.tableName}}Proto.Reply + //3、修改 + model := new(models.T{{.tableName}}) + //实体填充 + {{.modelFill}} + _, err := {{.tableName}}Dao.Update{{.tableName}}(*model, in.ForceUpdateFields) + //错误处理 + if err != nil { + reply.Success = false + reply.Message = Const.DataBaseActionError + LogUtil.Error(ErrorConst.SqlUpdateError, "执行Update{{.tableName}}时发生严重错误:"+err.Error()) + return &reply, err + } + reply.Success = true + reply.Message = Const.SuccessDataBaseAction + return &reply, nil +} + +//分页查询 +func (s *Rpc) Page{{.tableName}}(ctx context.Context, in *{{.tableName}}Proto.QueryArg) (*{{.tableName}}Proto.Reply, error) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + //rpc响应 + var reply {{.tableName}}Proto.Reply + + list, count, err := {{.tableName}}Dao.Page{{.tableName}}(in) + //错误处理 + if err != nil { + reply.Success = false + reply.Message = Const.DataBaseActionError + LogUtil.Error(ErrorConst.SqlQueryError, "执行Page{{.tableName}}时发生严重错误:"+err.Error()) + return &reply, err + } + reply.Count = count + reply.Success = true + reply.Message = Const.SuccessDataBaseAction + reply.List = CommonUtil.SerializeToString(list) + return &reply, nil +}