From e0331a0f59ba79ef394c2b27e7e037a5d5262425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E4=BD=A0=E4=B8=AA=E6=97=BA=E5=91=80?= Date: Fri, 17 Jan 2025 19:06:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=F0=9F=98=80=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Utils/AdminResultProvider.cs | 64 +++++++------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Utils/AdminResultProvider.cs b/Admin.NET/Admin.NET.Core/Utils/AdminResultProvider.cs index a9e1d959..7b3c0f48 100644 --- a/Admin.NET/Admin.NET.Core/Utils/AdminResultProvider.cs +++ b/Admin.NET/Admin.NET.Core/Utils/AdminResultProvider.cs @@ -97,11 +97,32 @@ public class AdminResultProvider : IUnifyResultProvider App.GetOptions()?.JsonSerializerOptions); } break; - - default: break; } } + /// + /// 返回成功结果集 + /// + /// + /// + /// + public static AdminResult Ok(string message, object data = default) + { + return RESTfulResult(StatusCodes.Status200OK, true, data, message); + } + + /// + /// 返回失败结果集 + /// + /// + /// + /// + /// + public static AdminResult Error(string message, int code = StatusCodes.Status400BadRequest, object data = default) + { + return RESTfulResult(code, false, data, message); + } + /// /// 返回 RESTful 风格结果集 /// @@ -132,45 +153,6 @@ public class AdminResultProvider : IUnifyResultProvider Time = DateTime.Now }; } - - /// - /// 返回成功结果集 - /// - /// - /// - /// - public static AdminResult Ok(string message, object data = default) - { - return new AdminResult - { - Code = StatusCodes.Status200OK, - Message = message, - Result = data, - Type = "success", - Extras = UnifyContext.Take(), - Time = DateTime.Now - }; - } - - /// - /// 返回失败结果集 - /// - /// - /// - /// - /// - public static AdminResult Error(string message, int code = StatusCodes.Status400BadRequest, object data = default) - { - return new AdminResult - { - Code = code, - Message = message, - Result = data, - Type = "error", - Extras = UnifyContext.Take(), - Time = DateTime.Now - }; - } } /// From 5fa1d6ca8b39e90ff49c71707a8a1f680137aeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E4=BD=A0=E4=B8=AA=E6=97=BA=E5=91=80?= Date: Fri, 17 Jan 2025 19:14:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=F0=9F=98=80=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.NET/Admin.NET.Core/Utils/ExcelHelper.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Utils/ExcelHelper.cs b/Admin.NET/Admin.NET.Core/Utils/ExcelHelper.cs index fc67d8e1..1e6cc805 100644 --- a/Admin.NET/Admin.NET.Core/Utils/ExcelHelper.cs +++ b/Admin.NET/Admin.NET.Core/Utils/ExcelHelper.cs @@ -51,15 +51,7 @@ public class ExcelHelper catch (Exception ex) { App.HttpContext.Response.Headers.ContentType = "application/json; charset=utf-8"; - throw Oops.Oh(new AdminResult - { - Code = 500, - Message = ex.Message, - Result = null, - Type = "error", - Extras = UnifyContext.Take(), - Time = DateTime.Now - }.ToJson()); + throw Oops.Oh(AdminResultProvider.Error(ex.Message, 500).ToJson()); } }