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