增加ImageCache微信 图片缓存
This commit is contained in:
1 parent
d6cb5b966b
commit
d0f9f00b76
15 files changed
+518
-30
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using MAX.Framework.Commons;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MAX.Framework.Dtos
|
||||
{
|
||||
@@ -29,10 +29,10 @@ namespace MAX.Framework.Dtos
|
||||
public abstract class ApiResultBase
|
||||
{
|
||||
/// <summary>业务状态码</summary>
|
||||
public int Code { get; set; } = ResultCode.Success;
|
||||
public int Code { get; init; } = ResultCode.Success;
|
||||
|
||||
/// <summary>提示信息</summary>
|
||||
public string? Msg { get; set; }
|
||||
public string? Msg { get; init; }
|
||||
|
||||
/// <summary>请求是否成功</summary>
|
||||
public bool Success => Code == ResultCode.Success;
|
||||
@@ -44,13 +44,25 @@ namespace MAX.Framework.Dtos
|
||||
/// </summary>
|
||||
public class ApiResult<T> : ApiResultBase
|
||||
{
|
||||
public T? Data { get; set; }
|
||||
/// <summary>响应数据;失败时不应依赖该值,值类型默认值并非 null。</summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public T? Data { get; init; }
|
||||
|
||||
/// <summary>将无数据响应转换为当前数据类型,保留状态码和提示信息。</summary>
|
||||
public static implicit operator ApiResult<T>(ApiResult result)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(result);
|
||||
return new ApiResult<T> { Code = result.Code, Msg = result.Msg, Data = default };
|
||||
}
|
||||
|
||||
public static ApiResult<T> Ok(T data, string msg = "操作成功")
|
||||
=> new ApiResult<T> { Code = ResultCode.Success, Data = data, Msg = msg };
|
||||
|
||||
public static ApiResult<T> Fail(string msg = "操作失败", int code = ResultCode.Fail, T? data = default)
|
||||
=> new ApiResult<T> { Code = code, Msg = msg, Data = data };
|
||||
{
|
||||
ApiResult.ValidateFailureCode(code);
|
||||
return new ApiResult<T> { Code = code, Msg = msg, Data = data };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,11 +70,32 @@ namespace MAX.Framework.Dtos
|
||||
/// </summary>
|
||||
public class ApiResult : ApiResultBase
|
||||
{
|
||||
public static ApiResult Ok(string msg = "操作成功")
|
||||
=> new ApiResult { Code = ResultCode.Success, Msg = msg };
|
||||
/// <summary>无数据响应仍输出 data: null,保持统一的响应字段。</summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public object? Data => null;
|
||||
|
||||
/// <summary>创建带数据的成功响应,自动推断数据类型。</summary>
|
||||
public static ApiResult<T> Ok<T>(T data, string msg = "操作成功")
|
||||
=> ApiResult<T>.Ok(data, msg);
|
||||
|
||||
/// <summary>创建带数据的失败响应,自动推断数据类型。</summary>
|
||||
public static ApiResult<T> Fail<T>(string msg, T data, int code = ResultCode.Fail)
|
||||
=> ApiResult<T>.Fail(msg, code, data);
|
||||
|
||||
public static ApiResult Ok()
|
||||
=> new ApiResult { Code = ResultCode.Success, Msg = "操作成功" };
|
||||
|
||||
public static ApiResult Fail(string msg = "操作失败", int code = ResultCode.Fail)
|
||||
=> new ApiResult { Code = code, Msg = msg };
|
||||
{
|
||||
ValidateFailureCode(code);
|
||||
return new ApiResult { Code = code, Msg = msg };
|
||||
}
|
||||
|
||||
internal static void ValidateFailureCode(int code)
|
||||
{
|
||||
if (code == ResultCode.Success)
|
||||
throw new ArgumentOutOfRangeException(nameof(code), code, "失败响应不能使用成功状态码。");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user