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:
glz
2026-06-02 17:58:10 +08:00
parent 8ed012bba8
commit 0a32754740
24 changed files with 551 additions and 209 deletions

View File

@ -8,6 +8,7 @@ using QYZH.InteractiveMagazine.Models.Enum;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
[Route("api/[controller]")]
[ApiController]
public class AdminController : BaseController
@ -63,7 +64,7 @@ public class AdminController : BaseController
var userId = GetCurrentUserId();
if (userId == null)
{
return BaseResponse<AdminUserInfoOutput>.Fail("未获取到用户信息", 401);
return BaseResponse<AdminUserInfoOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
}
var result = await _adminAuthService.GetAdminInfoAsync(userId.Value);
@ -104,12 +105,12 @@ public class AdminController : BaseController
catch (BusinessException ex)
{
_logger.LogWarning(ex, "创建管理员业务异常: {Message}", ex.Message);
return BaseResponse<AdminUserOutput>.Fail(ex.Message, ex.Code);
return BaseResponse<AdminUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建管理员系统异常,参数:{Input}", input);
return BaseResponse<AdminUserOutput>.Fail("创建管理员失败,请稍后重试", 500);
return BaseResponse<AdminUserOutput>.Fail("创建管理员失败,请稍后重试");
}
}
@ -130,12 +131,12 @@ public class AdminController : BaseController
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新管理员业务异常: {Message}", ex.Message);
return BaseResponse<AdminUserOutput>.Fail(ex.Message, ex.Code);
return BaseResponse<AdminUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新管理员系统异常ID{Id},参数:{Input}", id, input);
return BaseResponse<AdminUserOutput>.Fail("更新管理员失败,请稍后重试", 500);
return BaseResponse<AdminUserOutput>.Fail("更新管理员失败,请稍后重试");
}
}
@ -155,12 +156,12 @@ public class AdminController : BaseController
catch (BusinessException ex)
{
_logger.LogWarning(ex, "删除管理员业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message, ex.Code);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "删除管理员系统异常ID{Id}", id);
return BaseResponse<object>.Fail("删除管理员失败,请稍后重试", 500);
return BaseResponse<object>.Fail("删除管理员失败,请稍后重试");
}
}
@ -180,12 +181,12 @@ public class AdminController : BaseController
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取管理员业务异常: {Message}", ex.Message);
return BaseResponse<AdminUserOutput>.Fail(ex.Message, ex.Code);
return BaseResponse<AdminUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取管理员系统异常ID{Id}", id);
return BaseResponse<AdminUserOutput>.Fail("获取管理员信息失败,请稍后重试", 500);
return BaseResponse<AdminUserOutput>.Fail("获取管理员信息失败,请稍后重试");
}
}
@ -205,12 +206,12 @@ public class AdminController : BaseController
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询管理员列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<AdminUserOutput>>.Fail(ex.Message, ex.Code);
return BaseResponse<PageListModel<AdminUserOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询管理员列表系统异常,参数:{Input}", input);
return BaseResponse<PageListModel<AdminUserOutput>>.Fail("查询管理员列表失败,请稍后重试", 500);
return BaseResponse<PageListModel<AdminUserOutput>>.Fail("查询管理员列表失败,请稍后重试");
}
}
}