|
|
|
@ -1,16 +1,161 @@
|
|
|
|
|
package BaseRoleService
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"dsBaseRpc/Const"
|
|
|
|
|
"dsBaseRpc/Const/ErrorConst"
|
|
|
|
|
"dsBaseRpc/RpcService/BaseRole/BaseRoleDao"
|
|
|
|
|
"dsBaseRpc/RpcService/BaseRole/BaseRoleProto"
|
|
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
|
|
"dsBaseRpc/Utils/LogUtil"
|
|
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
|
|
"dsBaseRpc/models"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Rpc struct{} //服务对象
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//获取单条
|
|
|
|
|
rpc GetBaseRole (ModelArg) returns (Reply) {}
|
|
|
|
|
//选择单条
|
|
|
|
|
func (s *Rpc) GetBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (*BaseRoleProto.Reply, error) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//rpc响应
|
|
|
|
|
var reply BaseRoleProto.Reply
|
|
|
|
|
//通用获取单条
|
|
|
|
|
list := SqlKit.QueryByIds([]string{in.RoleId}, "t_base_role")
|
|
|
|
|
//将结果序列化
|
|
|
|
|
reply.Success = true
|
|
|
|
|
reply.Count = 1
|
|
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
|
|
return &reply, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//增加
|
|
|
|
|
rpc AddBaseRole (ModelArg) returns (Reply) {}
|
|
|
|
|
//批量删除
|
|
|
|
|
rpc DeleteBaseRole (DeleteIdsArg) returns (Reply) {}
|
|
|
|
|
func (s *Rpc) AddBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (*BaseRoleProto.Reply, error) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//rpc响应
|
|
|
|
|
var reply BaseRoleProto.Reply
|
|
|
|
|
|
|
|
|
|
//调用dao
|
|
|
|
|
model := new(models.TBaseRole)
|
|
|
|
|
//检查一下RoleCode是不是已存在
|
|
|
|
|
exist, err := BaseRoleDao.ExistRoleCode(in.RoleCode)
|
|
|
|
|
if err != nil {
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = "检查角色代码是否存在时发生严重错误!"
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
if exist {
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = "角色代码已存在!"
|
|
|
|
|
return &reply, nil
|
|
|
|
|
}
|
|
|
|
|
// 通过,则保存
|
|
|
|
|
model.RoleId = CommonUtil.GetUUID()
|
|
|
|
|
model.RoleName = in.RoleName
|
|
|
|
|
model.RoleCode = in.RoleCode
|
|
|
|
|
model.RoleLevel = in.RoleLevel
|
|
|
|
|
model.IdentityId = in.IdentityId
|
|
|
|
|
model.SortId = in.SortId
|
|
|
|
|
model.BUse = 1
|
|
|
|
|
//增加
|
|
|
|
|
_, err = BaseRoleDao.AddBaseRole(*model)
|
|
|
|
|
if err != nil {
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseRole时发生严重错误:"+err.Error())
|
|
|
|
|
} else {
|
|
|
|
|
reply.Success = true
|
|
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
|
|
}
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除
|
|
|
|
|
func (s *Rpc) DeleteBaseRole(ctx context.Context, in *BaseRoleProto.DeleteIdsArg) (*BaseRoleProto.Reply, error) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//rpc响应
|
|
|
|
|
var reply BaseRoleProto.Reply
|
|
|
|
|
|
|
|
|
|
//调用通用删除命令进行删除
|
|
|
|
|
err := SqlKit.DeleteIds("t_base_role", in.Ids)
|
|
|
|
|
//错误处理
|
|
|
|
|
if err != nil {
|
|
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseRole时发生严重错误:"+err.Error())
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
reply.Success = true
|
|
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//修改
|
|
|
|
|
rpc UpdateBaseRole (ModelArg) returns (Reply) {}
|
|
|
|
|
//查询(分页)
|
|
|
|
|
rpc PageBaseRole (QueryArg) returns (Reply) {}
|
|
|
|
|
*/
|
|
|
|
|
func (s *Rpc) UpdateBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (*BaseRoleProto.Reply, error) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//rpc响应
|
|
|
|
|
var reply BaseRoleProto.Reply
|
|
|
|
|
//修改
|
|
|
|
|
model := new(models.TBaseRole)
|
|
|
|
|
model.RoleId = in.RoleId
|
|
|
|
|
model.IdentityId = in.IdentityId
|
|
|
|
|
|
|
|
|
|
model.BUse = in.BUse
|
|
|
|
|
_, err := BaseRoleDao.UpdateBaseRole(*model, in.ForceUpdateFields)
|
|
|
|
|
//错误处理
|
|
|
|
|
if err != nil {
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseRole时发生严重错误:"+err.Error())
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
reply.Success = true
|
|
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
|
|
return &reply, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//分页查询
|
|
|
|
|
func (s *Rpc) PageBaseRole(ctx context.Context, in *BaseRoleProto.QueryArg) (*BaseRoleProto.Reply, error) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//rpc响应
|
|
|
|
|
var reply BaseRoleProto.Reply
|
|
|
|
|
list, count, err := BaseRoleDao.PageBaseRole(in)
|
|
|
|
|
//错误处理
|
|
|
|
|
if err != nil {
|
|
|
|
|
reply.Success = false
|
|
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseRole时发生严重错误:"+err.Error())
|
|
|
|
|
return &reply, err
|
|
|
|
|
}
|
|
|
|
|
reply.Count = count
|
|
|
|
|
reply.Success = true
|
|
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
|
|
return &reply, nil
|
|
|
|
|
}
|
|
|
|
|