2026-06-02 17:58:10 +08:00
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.DirectoryServices.Protocols;
|
|
|
|
|
|
2026-06-01 13:42:40 +08:00
|
|
|
namespace QYZH.InteractiveMagazine.Models.Dto;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 操作响应基类
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
public class BaseResponse
|
2026-06-01 13:42:40 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 构造函数,初始化操作响应基类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BaseResponse()
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
code = ResultCode.SUCCESS;
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 公共属性
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作描述
|
|
|
|
|
/// </summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
public string message { get; set; }
|
2026-06-02 17:58:10 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 结果Code
|
|
|
|
|
/// </summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
public ResultCode code { get; set; }
|
2026-06-02 17:58:10 +08:00
|
|
|
|
|
|
|
|
#endregion 公共属性
|
|
|
|
|
|
|
|
|
|
#region 公用方法
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 成功
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse Success()
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse { code = ResultCode.SUCCESS, message = "操作成功。" };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 成功
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
public static BaseResponse Success(string message = "操作成功。")
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse { code = ResultCode.SUCCESS, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 失败
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse Fail(string message, ResultCode code = ResultCode.FAIL)
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse { code = code, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 权限验证失败
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse AuthFail(string message, ResultCode code = ResultCode.FAIL)
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse { code = code, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion 公用方法
|
2026-06-01 13:42:40 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 操作结果
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
public bool isSuccess => code == ResultCode.SUCCESS;
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
2026-06-01 13:42:40 +08:00
|
|
|
|
2026-06-02 17:58:10 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 响应结果类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">
|
|
|
|
|
/// </typeparam>
|
|
|
|
|
public class BaseResponse<T> : BaseResponse
|
|
|
|
|
{
|
2026-06-01 13:42:40 +08:00
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 操作结果
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
public T? result { get; set; }
|
2026-06-02 17:58:10 +08:00
|
|
|
|
|
|
|
|
#region 公用方法
|
2026-06-01 13:42:40 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 成功
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
public static BaseResponse<T> Success(T result)
|
2026-06-01 13:42:40 +08:00
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = ResultCode.SUCCESS, message = "", result = result };
|
2026-06-01 13:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
/// 成功
|
2026-06-01 13:42:40 +08:00
|
|
|
/// </summary>
|
2026-06-02 17:58:10 +08:00
|
|
|
public static BaseResponse<T> Success(T result, string message = "操作成功。")
|
2026-06-01 13:42:40 +08:00
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = ResultCode.SUCCESS, message = message, result = result };
|
2026-06-01 13:42:40 +08:00
|
|
|
}
|
2026-06-02 17:58:10 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 失败
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse<T> Fail(string message = "fail")
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = ResultCode.FAIL, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 失败 自定义结果
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse<T> Fail(ResultCode code, string message = "fail")
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = code, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BaseResponse<T> Fail(T result, string message = "操作失败,请稍后再试")
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = ResultCode.FAIL, message = message, result = result };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 权限验证失败
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static BaseResponse<T> AuthFail(string message = "Permission authentication failed")
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
return new BaseResponse<T> { code = ResultCode.OAUTH_FAIL, message = message };
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 成功
|
|
|
|
|
///// </summary>
|
|
|
|
|
//public static BaseResponse<T> Assert(T result, string message = "")
|
|
|
|
|
//{
|
|
|
|
|
// if (result is bool b)
|
|
|
|
|
// return b ? BaseResponse<T>.Success(result) : BaseResponse<T>.Fail(message);
|
|
|
|
|
// if (result is object o)
|
|
|
|
|
// return (data == null || data.IsNull() == true) ? BaseResponse<T>.Success(result) : BaseResponse<T>.Fail(message);
|
|
|
|
|
// return new BaseResponse<T> { Code = ResultCode.SUCCESS, Message = message, Result = result };
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion 公用方法
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作结果
|
|
|
|
|
/// </summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
public bool isSuccess => code == ResultCode.SUCCESS;
|
2026-06-02 17:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum ResultCode
|
|
|
|
|
{
|
|
|
|
|
[Description("success")]
|
|
|
|
|
SUCCESS = 200,
|
|
|
|
|
|
|
|
|
|
[Description("没有更多数据")]
|
|
|
|
|
NO_DATA = 210,
|
|
|
|
|
|
|
|
|
|
[Description("参数错误")]
|
|
|
|
|
PARAM_ERROR = 101,
|
|
|
|
|
|
|
|
|
|
[Description("验证码错误")]
|
|
|
|
|
CAPTCHA_ERROR = 103,
|
|
|
|
|
|
|
|
|
|
[Description("登录错误")]
|
|
|
|
|
LOGIN_ERROR = 105,
|
|
|
|
|
|
|
|
|
|
[Description("操作失败")]
|
|
|
|
|
FAIL = 1,
|
|
|
|
|
|
|
|
|
|
[Description("服务端出错啦")]
|
|
|
|
|
GLOBAL_ERROR = 500,
|
|
|
|
|
|
|
|
|
|
[Description("自定义异常")]
|
|
|
|
|
CUSTOM_ERROR = 110,
|
|
|
|
|
|
|
|
|
|
[Description("非法请求")]
|
|
|
|
|
INVALID_REQUEST = 116,
|
|
|
|
|
|
|
|
|
|
[Description("授权失败")]
|
|
|
|
|
OAUTH_FAIL = 201,
|
|
|
|
|
|
|
|
|
|
[Description("请先绑定手机号")]
|
|
|
|
|
PHONE_BIND = 202,
|
|
|
|
|
|
|
|
|
|
[Description("未授权")]
|
|
|
|
|
DENY = 401,
|
|
|
|
|
|
|
|
|
|
[Description("授权访问失败")]
|
|
|
|
|
FORBIDDEN = 403,
|
|
|
|
|
|
|
|
|
|
[Description("Bad Request")]
|
2026-06-29 16:34:26 +08:00
|
|
|
BAD_REQUEST = 400,
|
|
|
|
|
|
|
|
|
|
[Description("资源不存在")]
|
|
|
|
|
NOT_FOUND = 404,
|
|
|
|
|
|
|
|
|
|
[Description("冲突/重复提交")]
|
|
|
|
|
CONFLICT = 409,
|
|
|
|
|
|
|
|
|
|
[Description("业务规则校验失败")]
|
|
|
|
|
UNPROCESSABLE_ENTITY = 422,
|
|
|
|
|
|
|
|
|
|
[Description("请求过于频繁")]
|
|
|
|
|
TOO_MANY_REQUESTS = 429,
|
|
|
|
|
|
|
|
|
|
[Description("第三方服务异常")]
|
|
|
|
|
BAD_GATEWAY = 502,
|
|
|
|
|
|
|
|
|
|
[Description("服务不可用")]
|
|
|
|
|
SERVICE_UNAVAILABLE = 503
|
2026-06-01 13:42:40 +08:00
|
|
|
}
|