package BaseGlobalService import ( "context" "dsBaseRpc/Const" "dsBaseRpc/Const/ErrorConst" "dsBaseRpc/RpcService/BaseGlobal/BaseGlobalDao" "dsBaseRpc/RpcService/BaseGlobal/BaseGlobalProto" "dsBaseRpc/Utils/CommonUtil" "dsBaseRpc/Utils/LogUtil" "dsBaseRpc/Utils/SqlKit" "dsBaseRpc/models" "fmt" ) type Rpc struct{} //服务对象 //选择单条 func (s *Rpc) GetBaseGlobal(ctx context.Context, in *BaseGlobalProto.ModelArg) (*BaseGlobalProto.Reply, error) { //异常处理 defer func() { if err := recover(); err != nil { fmt.Printf("%s\n", err) } }() //rpc响应 var reply BaseGlobalProto.Reply //通用获取单条 list := SqlKit.QueryByIds([]string{in.GlobalId}, "t_base_global") //将结果序列化 reply.Success = true reply.Count = 1 reply.Message = Const.SuccessDataBaseAction reply.List = CommonUtil.SerializeToString(list) return &reply, nil } //增加 func (s *Rpc) AddBaseGlobal(ctx context.Context, in *BaseGlobalProto.ModelArg) (*BaseGlobalProto.Reply, error) { //异常处理 defer func() { if err := recover(); err != nil { fmt.Printf("%s\n", err) } }() //rpc响应 var reply BaseGlobalProto.Reply //调用dao model := new(models.TBaseGlobal) //实体填充 //全局变量ID model.GlobalId = CommonUtil.GetUUID() //全局变量分类 model.GlobalTypeId = in.GlobalTypeId //全局变量代码 model.GlobalCode = in.GlobalCode //全局变量值 model.GlobalValue = in.GlobalValue //全局变量备注 model.GlobalRemarks = in.GlobalRemarks //排序号 model.SortId = in.SortId //是否启用 0:未启用 1:启用 model.BUse = in.BUse _, err := BaseGlobalDao.AddBaseGlobal(*model) if err != nil { reply.Success = false reply.Message = Const.DataBaseActionError LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseGlobal时发生严重错误:"+err.Error()) } else { reply.Success = true reply.Message = Const.SuccessDataBaseAction } return &reply, err } //删除 func (s *Rpc) DeleteBaseGlobal(ctx context.Context, in *BaseGlobalProto.DeleteIdsArg) (*BaseGlobalProto.Reply, error) { //异常处理 defer func() { if err := recover(); err != nil { fmt.Printf("%s\n", err) } }() //rpc响应 var reply BaseGlobalProto.Reply //调用通用删除命令进行删除 err := SqlKit.DeleteIds("t_base_global", in.Ids) //错误处理 if err != nil { LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseGlobal时发生严重错误:"+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) UpdateBaseGlobal(ctx context.Context, in *BaseGlobalProto.ModelArg) (*BaseGlobalProto.Reply, error) { //异常处理 defer func() { if err := recover(); err != nil { fmt.Printf("%s\n", err) } }() //rpc响应 var reply BaseGlobalProto.Reply //修改 model := new(models.TBaseGlobal) //实体填充 //全局变量ID model.GlobalId = in.GlobalId //全局变量分类 model.GlobalTypeId = in.GlobalTypeId //全局变量代码 model.GlobalCode = in.GlobalCode //全局变量值 model.GlobalValue = in.GlobalValue //全局变量备注 model.GlobalRemarks = in.GlobalRemarks //排序号 model.SortId = in.SortId //是否启用 0:未启用 1:启用 model.BUse = in.BUse _, err := BaseGlobalDao.UpdateBaseGlobal(*model, in.ForceUpdateFields) //错误处理 if err != nil { reply.Success = false reply.Message = Const.DataBaseActionError LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseGlobal时发生严重错误:"+err.Error()) return &reply, err } reply.Success = true reply.Message = Const.SuccessDataBaseAction return &reply, nil } //分页查询 func (s *Rpc) PageBaseGlobal(ctx context.Context, in *BaseGlobalProto.QueryArg) (*BaseGlobalProto.Reply, error) { //异常处理 defer func() { if err := recover(); err != nil { fmt.Printf("%s\n", err) } }() //rpc响应 var reply BaseGlobalProto.Reply list, count, err := BaseGlobalDao.PageBaseGlobal(in) //错误处理 if err != nil { reply.Success = false reply.Message = Const.DataBaseActionError LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseGlobal时发生严重错误:"+err.Error()) return &reply, err } if list != nil { reply.Count = count reply.Success = true reply.Message = Const.SuccessDataBaseAction reply.List = CommonUtil.SerializeToString(list) return &reply, nil } else { reply.Count = 0 reply.Success = false reply.Message = Const.SuccessDataBaseAction reply.List = Const.BlankArrayString return &reply, nil } }