diff --git a/Infrastructure/Controllers/BaseController.cs b/Infrastructure/Controllers/BaseController.cs
index 0332d49..d3dcb8b 100644
--- a/Infrastructure/Controllers/BaseController.cs
+++ b/Infrastructure/Controllers/BaseController.cs
@@ -12,6 +12,9 @@ using System.Web;
namespace Infrastructure.Controllers
{
+ ///
+ /// web层通用数据处理
+ ///
public class BaseController : ControllerBase
{
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
diff --git a/Infrastructure/Model/ApiResult.cs b/Infrastructure/Model/ApiResult.cs
index cc72c73..c0388d3 100644
--- a/Infrastructure/Model/ApiResult.cs
+++ b/Infrastructure/Model/ApiResult.cs
@@ -1,10 +1,19 @@
using Infrastructure.Constant;
using Newtonsoft.Json;
+using System.Collections.Generic;
namespace Infrastructure.Model
{
- public class ApiResult
+ public class ApiResult : Dictionary
{
+ /** 状态码 */
+ public static readonly string CODE_TAG = "code";
+
+ /** 返回内容 */
+ public static readonly string MSG_TAG = "msg";
+
+ /** 数据对象 */
+ public static readonly string DATA_TAG = "data";
public int Code { get; set; }
public string Msg { get; set; }
///
@@ -27,8 +36,8 @@ namespace Infrastructure.Model
///
public ApiResult(int code, string msg)
{
- Code = code;
- Msg = msg;
+ Add(CODE_TAG, code);
+ Add(MSG_TAG, msg);
}
///
@@ -36,33 +45,28 @@ namespace Infrastructure.Model
///
///
///
+ ///
public ApiResult(int code, string msg, object data)
{
- Code = code;
- Msg = msg;
+ Add(CODE_TAG, code);
+ Add(MSG_TAG, msg);
if (data != null)
{
- Data = data;
- }
+ Add(DATA_TAG, data);
+ }
}
+ ///
+ /// 返回成功消息
+ ///
+ /// < returns > 成功消息 returns >
+ public static ApiResult Success() { return new ApiResult(HttpStatus.SUCCESS, "success"); }
///
/// 返回成功消息
///
- ///
- public ApiResult Success()
- {
- Code = (int)ResultCode.SUCCESS;
- Msg = "success";
- return this;
- }
-
- /////
- ///// 返回成功消息
- /////
- ///// 数据对象 param >
- ///// < returns > 成功消息 returns >
- //public static ApiResult Success(object data) { return new ApiResult(HttpStatus.SUCCESS, "success", data); }
+ ///
+ /// 成功消息
+ public static ApiResult Success(object data) { return new ApiResult(HttpStatus.SUCCESS, "success", data); }
///
/// 返回成功消息
@@ -79,21 +83,9 @@ namespace Infrastructure.Model
/// 成功消息
public static ApiResult Success(string msg, object data) { return new ApiResult(HttpStatus.SUCCESS, msg, data); }
- ///
- /// 访问被拒
- ///
- ///
- public ApiResult On401()
+ public static ApiResult Error(ResultCode code, string msg = "")
{
- Code = (int)ResultCode.DENY;
- Msg = "access denyed";
- return this;
- }
- public ApiResult Error(ResultCode resultCode, string msg = "")
- {
- Code = (int)resultCode;
- Msg = msg;
- return this;
+ return Error((int)code, msg);
}
///
diff --git a/ZR.ServiceCore/Filters/ActionPermissionFilter.cs b/ZR.ServiceCore/Filters/ActionPermissionFilter.cs
index 96d17ac..cff36f6 100644
--- a/ZR.ServiceCore/Filters/ActionPermissionFilter.cs
+++ b/ZR.ServiceCore/Filters/ActionPermissionFilter.cs
@@ -82,12 +82,7 @@ namespace ZR.ServiceCore.Middleware
if (!HasPermi && !Permission.Equals("common"))
{
logger.Info($"用户{info.UserName}没有权限访问{url},当前权限[{Permission}]");
- JsonResult result = new(new ApiResult()
- {
- Code = (int)ResultCode.FORBIDDEN,
- Msg = $"你当前没有权限[{Permission}]访问,请联系管理员",
- Data = url
- })
+ JsonResult result = new(new ApiResult((int)ResultCode.FORBIDDEN, $"你当前没有权限[{Permission}]访问,请联系管理员", url))
{
ContentType = "application/json",
};
diff --git a/ZR.ServiceCore/Filters/GlobalActionMonitor.cs b/ZR.ServiceCore/Filters/GlobalActionMonitor.cs
index 77699a1..a94ba2f 100644
--- a/ZR.ServiceCore/Filters/GlobalActionMonitor.cs
+++ b/ZR.ServiceCore/Filters/GlobalActionMonitor.cs
@@ -46,11 +46,8 @@ namespace ZR.ServiceCore.Middleware
if (!string.IsNullOrEmpty(msg))
{
logger.Info($"请求参数错误,{msg}");
- ApiResult response = new()
- {
- Code = (int)ResultCode.PARAM_ERROR,
- Msg = msg
- };
+ ApiResult response = new((int)ResultCode.PARAM_ERROR, msg);
+
context.Result = new JsonResult(response);
}
return base.OnActionExecutionAsync(context, next);
diff --git a/ZR.ServiceCore/Filters/VerifyAttribute.cs b/ZR.ServiceCore/Filters/VerifyAttribute.cs
index ec4d1ac..b9c44d8 100644
--- a/ZR.ServiceCore/Filters/VerifyAttribute.cs
+++ b/ZR.ServiceCore/Filters/VerifyAttribute.cs
@@ -63,8 +63,9 @@ namespace ZR.Admin.WebApi.Filters
{
string msg = $"请求访问[{url}]失败,无法访问系统资源";
//logger.Info(msg);
-
- context.Result = new JsonResult(new ApiResult((int)ResultCode.DENY, msg));
+ var r = new ApiResult((int)ResultCode.DENY, msg);
+
+ context.Result = new JsonResult(r);
}
}
}