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:
@ -25,7 +25,7 @@ public class AdminUserInput
|
||||
/// <summary>
|
||||
/// 状态: Active, Inactive
|
||||
/// </summary>
|
||||
public string Status { get; set; } = "Active";
|
||||
public int Status { get; set; } = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -51,7 +51,7 @@ public class AdminUserOutput
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public string Status { get; set; } = string.Empty;
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
|
||||
@ -36,5 +36,5 @@ public class AdminUserInfoOutput
|
||||
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
public int Status { get; set; }
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -175,24 +175,5 @@ public class WxUserQueryInput : PageQueryModel
|
||||
/// </summary>
|
||||
public string? Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户类型
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public string? Status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信手机号获取输出
|
||||
/// </summary>
|
||||
public class WeChatPhoneNumberOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 手机号
|
||||
/// </summary>
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@ -34,11 +34,5 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// </summary>
|
||||
public string Type {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:状态: Active, Inactive
|
||||
/// Default:Active
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Status {get;set;}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, ColumnName = "Id")]
|
||||
public long Id { get; set; } = YitIdHelper.NextId();
|
||||
/// <summary>
|
||||
/// Desc:状态 0禁用 1启用
|
||||
@ -18,7 +19,7 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "Status")]
|
||||
public string Status { get; set; }
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:是否删除
|
||||
@ -49,7 +50,7 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "updatedBy", IsOnlyIgnoreInsert = true)]
|
||||
[SugarColumn(ColumnName = "UpdatedBy")]
|
||||
public string UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -57,7 +58,7 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "UpdatedAt", IsOnlyIgnoreInsert = true)]
|
||||
[SugarColumn(ColumnName = "UpdatedAt")]
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
58
QYZH.InteractiveMagazine.Models/Entity/User .cs
Normal file
58
QYZH.InteractiveMagazine.Models/Entity/User .cs
Normal file
@ -0,0 +1,58 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
{
|
||||
///<summary>
|
||||
///用户表
|
||||
///</summary>
|
||||
[SugarTable("User")]
|
||||
public partial class User : SqlSugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Desc:微信用户ID
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string WxUserId { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:昵称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:当前成长值
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int GrowthPoints { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:头像地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string AvatarUrl { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:积分余额
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int Points { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:用户类型: Normal, VIP
|
||||
/// Default:Normal
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:状态: Active, Disabled
|
||||
/// Default:Active
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Status { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,10 +5,10 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
///<summary>
|
||||
///用户背包表
|
||||
///</summary>
|
||||
[SugarTable("WxUserBag")]
|
||||
public partial class WxUserBag : SqlSugarBaseEntity
|
||||
[SugarTable("UserBag")]
|
||||
public partial class UserBag : SqlSugarBaseEntity
|
||||
{
|
||||
public WxUserBag(){
|
||||
public UserBag(){
|
||||
|
||||
|
||||
}
|
||||
@ -5,10 +5,10 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
///<summary>
|
||||
///用户勋章表
|
||||
///</summary>
|
||||
[SugarTable("WxUserMedal")]
|
||||
public partial class WxUserMedal : SqlSugarBaseEntity
|
||||
[SugarTable("UserMedal")]
|
||||
public partial class UserMedal : SqlSugarBaseEntity
|
||||
{
|
||||
public WxUserMedal(){
|
||||
public UserMedal(){
|
||||
|
||||
|
||||
}
|
||||
@ -43,12 +43,6 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// </summary>
|
||||
public string Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:积分余额
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int Points { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:用户类型: Normal, VIP
|
||||
@ -70,11 +64,5 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string Pwd { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:当前成长值
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int GrowthPoints { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user