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