refactor: 完成系统基础架构重构与业务逻辑优化
本次提交包含多项核心变更: 1. **用户体系重构**:将管理员用户状态从字符串改为整型枚举,移除微信用户冗余字段Points和GrowthPoints,新增通用基础实体主键配置 2. **代码清理**:删除HealthController、WxUserMedal、WxUserBag等废弃文件,移除WeChatDto中冗余查询字段 3. **响应格式统一**:重构BaseResponse与ResultCode枚举,标准化全局响应格式 4. **权限与验证优化**:添加JWT认证与开发环境免认证逻辑,新增模型验证过滤器,统一控制器认证配置 5. **工具与配置更新**:新增dotnet-tools.json配置EF工具,调整Swagger与压缩中间件配置,优化SqlSugar默认值处理逻辑 6. **业务逻辑简化**:移除AutoMapper映射,改为手动映射DTO以提升性能,修复异常处理与响应返回逻辑
This commit is contained in:
@ -1,55 +1,199 @@
|
||||
using System.ComponentModel;
|
||||
using System.DirectoryServices.Protocols;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 统一响应模型
|
||||
/// 操作响应基类
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据类型</typeparam>
|
||||
public class BaseResponse<T>
|
||||
public class BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态码
|
||||
/// 构造函数,初始化操作响应基类
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 提示信息
|
||||
/// </summary>
|
||||
public string? Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
public T? Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成功响应
|
||||
/// </summary>
|
||||
/// <param name="data">数据</param>
|
||||
/// <param name="message">提示信息</param>
|
||||
/// <returns>统一响应对象</returns>
|
||||
public static BaseResponse<T> Success(T data, string message = "操作成功")
|
||||
public BaseResponse()
|
||||
{
|
||||
return new BaseResponse<T>
|
||||
{
|
||||
Code = 200,
|
||||
Message = message,
|
||||
Data = data
|
||||
};
|
||||
Code = ResultCode.SUCCESS;
|
||||
}
|
||||
|
||||
#region 公共属性
|
||||
|
||||
/// <summary>
|
||||
/// 操作描述
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结果Code
|
||||
/// </summary>
|
||||
public ResultCode Code { get; set; }
|
||||
|
||||
#endregion 公共属性
|
||||
|
||||
#region 公用方法
|
||||
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
public static BaseResponse Success()
|
||||
{
|
||||
return new BaseResponse { Code = ResultCode.SUCCESS, Message = "操作成功。" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败响应
|
||||
/// 成功
|
||||
/// </summary>
|
||||
/// <param name="message">提示信息</param>
|
||||
/// <param name="code">状态码</param>
|
||||
/// <returns>统一响应对象</returns>
|
||||
public static BaseResponse<T> Fail(string message, int code = 500)
|
||||
public static BaseResponse Success(string message = "操作成功。")
|
||||
{
|
||||
return new BaseResponse<T>
|
||||
{
|
||||
Code = code,
|
||||
Message = message,
|
||||
Data = default
|
||||
};
|
||||
return new BaseResponse { Code = ResultCode.SUCCESS, Message = message };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败
|
||||
/// </summary>
|
||||
public static BaseResponse Fail(string message, ResultCode code = ResultCode.FAIL)
|
||||
{
|
||||
return new BaseResponse { Code = code, Message = message };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 权限验证失败
|
||||
/// </summary>
|
||||
public static BaseResponse AuthFail(string message, ResultCode code = ResultCode.FAIL)
|
||||
{
|
||||
return new BaseResponse { Code = code, Message = message };
|
||||
}
|
||||
|
||||
#endregion 公用方法
|
||||
|
||||
/// <summary>
|
||||
/// 操作结果
|
||||
/// </summary>
|
||||
public bool IsSuccess => Code == ResultCode.SUCCESS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应结果类型
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// </typeparam>
|
||||
public class BaseResponse<T> : BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作结果
|
||||
/// </summary>
|
||||
public T? Result { get; set; }
|
||||
|
||||
#region 公用方法
|
||||
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
public static BaseResponse<T> Success(T result)
|
||||
{
|
||||
return new BaseResponse<T> { Code = ResultCode.SUCCESS, Message = "", Result = result };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
public static BaseResponse<T> Success(T result, string message = "操作成功。")
|
||||
{
|
||||
return new BaseResponse<T> { Code = ResultCode.SUCCESS, Message = message, Result = result };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败
|
||||
/// </summary>
|
||||
public static BaseResponse<T> Fail(string message = "fail")
|
||||
{
|
||||
return new BaseResponse<T> { Code = ResultCode.FAIL, Message = message };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败 自定义结果
|
||||
/// </summary>
|
||||
public static BaseResponse<T> Fail(ResultCode code, string message = "fail")
|
||||
{
|
||||
return new BaseResponse<T> { Code = code, Message = message };
|
||||
}
|
||||
|
||||
public static BaseResponse<T> Fail(T result, string message = "操作失败,请稍后再试")
|
||||
{
|
||||
return new BaseResponse<T> { Code = ResultCode.FAIL, Message = message, Result = result };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 权限验证失败
|
||||
/// </summary>
|
||||
public static BaseResponse<T> AuthFail(string message = "Permission authentication failed")
|
||||
{
|
||||
return new BaseResponse<T> { Code = ResultCode.OAUTH_FAIL, Message = message };
|
||||
}
|
||||
|
||||
///// <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>
|
||||
public bool IsSuccess => Code == ResultCode.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
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")]
|
||||
BAD_REQUEST = 400
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user