From a26068eea7817d0783b69b52edecbaab49faadd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E6=AC=A3?= <83699462@qq.com>
Date: Tue, 16 Jan 2024 16:58:30 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=BF=94=E5=9B=9E=E5=80=BC?=
=?UTF-8?q?=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DS.Module.Core/Enum/ResultCode.cs | 12 ++++
.../Ds.WMS.WebCore/ActionResultHelper.cs | 55 +++++++++++++++++++
.../Ds.WMS.WebCore/DsAppActionFilter.cs | 18 +++---
3 files changed, 78 insertions(+), 7 deletions(-)
create mode 100644 ds-wms-service/Ds.WMS.WebCore/ActionResultHelper.cs
diff --git a/ds-wms-service/DS.Module.Core/Enum/ResultCode.cs b/ds-wms-service/DS.Module.Core/Enum/ResultCode.cs
index 121d4928..3d1c691d 100644
--- a/ds-wms-service/DS.Module.Core/Enum/ResultCode.cs
+++ b/ds-wms-service/DS.Module.Core/Enum/ResultCode.cs
@@ -36,5 +36,17 @@ namespace DS.Module.Core
///
[Description("其他")]
Other = -3,
+
+ ///
+ /// 其他
+ ///
+ [Description("没权限")]
+ NoPermission = 401,
+
+ ///
+ ///
+ ///
+ [Description("没数据")]
+ NoDatavailable = 201
}
}
\ No newline at end of file
diff --git a/ds-wms-service/Ds.WMS.WebCore/ActionResultHelper.cs b/ds-wms-service/Ds.WMS.WebCore/ActionResultHelper.cs
new file mode 100644
index 00000000..725fd195
--- /dev/null
+++ b/ds-wms-service/Ds.WMS.WebCore/ActionResultHelper.cs
@@ -0,0 +1,55 @@
+using DS.Module.Core;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+
+namespace Ds.WMS.WebCore
+{
+ public static class ActionResultHelper
+ {
+ ///
+ /// 统一返回数据结果
+ ///
+ ///
+ public static ActionExecutedContext ActionForResult(ActionExecutedContext context)
+ {
+ var response = new DataResult
+ {
+ Data = (context.Result as ObjectResult)?.Value,
+ Code = ResultCode.Success,
+ Message = "操作成功"
+ };
+
+ if (context.Result is ForbidResult)
+ {
+ response = new DataResult
+ {
+ Data = (context.Result as ObjectResult)?.Value,
+ Code = ResultCode.NoPermission,
+ Message = "没有权限"
+ };
+ }
+ else if (context.Result is NotFoundResult)
+ {
+ response = new DataResult
+ {
+ Data = (context.Result as ObjectResult)?.Value,
+ Code = ResultCode.NoDatavailable,
+ Message = "没有数据"
+ };
+ }
+ else if (context.Result is BadRequestResult)
+ {
+ response = new DataResult
+ {
+ Data = (context.Result as ObjectResult)?.Value,
+ Code = ResultCode.Fail,
+ Message = "操作失败"
+ };
+ }
+
+ context.Result = new ObjectResult(response);
+
+ return context;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ds-wms-service/Ds.WMS.WebCore/DsAppActionFilter.cs b/ds-wms-service/Ds.WMS.WebCore/DsAppActionFilter.cs
index eef8e32a..1ac89b27 100644
--- a/ds-wms-service/Ds.WMS.WebCore/DsAppActionFilter.cs
+++ b/ds-wms-service/Ds.WMS.WebCore/DsAppActionFilter.cs
@@ -2,24 +2,28 @@
namespace Ds.WMS.WebCore
{
- public class DsAppActionFilter : IActionFilter
+ public class DsAppActionFilter : ActionFilterAttribute
{
///
- /// 执行后
+ /// 执行前
///
///
- public void OnActionExecuted(ActionExecutedContext context)
+ public void OnActionExecuting(ActionExecutingContext context)
{
-
}
///
- /// 执行前
+ /// 执行后
///
///
- public void OnActionExecuting(ActionExecutingContext context)
+ public override void OnActionExecuted(ActionExecutedContext context)
{
+ //统一返回值内容
+ //记录返回信息
+
+ context = ActionResultHelper.ActionForResult(context);
+ base.OnActionExecuted(context);
}
}
-}
+}
\ No newline at end of file