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:
@ -64,7 +64,7 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
|
||||
logger.LogInformation("管理员创建成功,用户名: {UserName}, ID: {Id}", input.UserName, adminUser.Id);
|
||||
|
||||
return MapToOutput(adminUser);
|
||||
return new AdminUserOutput { Id = adminUser.Id, UserName = adminUser.UserName, Type = adminUser.Type, Status = adminUser.Status, CreatedBy = adminUser.CreatedBy, CreatedAt = adminUser.CreatedAt, UpdatedBy = adminUser.UpdatedBy, UpdatedAt = adminUser.UpdatedAt };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -105,10 +105,6 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
adminUser.Type = input.Type;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(input.Status))
|
||||
{
|
||||
adminUser.Status = input.Status;
|
||||
}
|
||||
|
||||
adminUser.UpdatedBy = "System";
|
||||
adminUser.UpdatedAt = DateTime.Now;
|
||||
@ -122,7 +118,7 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
|
||||
logger.LogInformation("管理员更新成功,ID: {Id}", id);
|
||||
|
||||
return MapToOutput(adminUser);
|
||||
return new AdminUserOutput { Id = adminUser.Id, UserName = adminUser.UserName, Type = adminUser.Type, Status = adminUser.Status, CreatedBy = adminUser.CreatedBy, CreatedAt = adminUser.CreatedAt, UpdatedBy = adminUser.UpdatedBy, UpdatedAt = adminUser.UpdatedAt };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -162,8 +158,17 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
logger.LogWarning("未找到管理员,ID: {Id}", id);
|
||||
throw new BusinessException("管理员不存在", 404);
|
||||
}
|
||||
|
||||
return MapToOutput(adminUser);
|
||||
return new AdminUserOutput
|
||||
{
|
||||
Id = adminUser.Id,
|
||||
UserName = adminUser.UserName,
|
||||
Type = adminUser.Type,
|
||||
Status = adminUser.Status,
|
||||
CreatedBy = adminUser.CreatedBy,
|
||||
CreatedAt = adminUser.CreatedAt,
|
||||
UpdatedBy = adminUser.UpdatedBy,
|
||||
UpdatedAt = adminUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -186,26 +191,18 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
var pageResult = await adminUserRepository.Queryable()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), a => a.UserName == input.UserName)
|
||||
.OrderByDescending(a => a.CreatedAt)
|
||||
.Select(a => MapToOutput(a), true)
|
||||
.Select(a => new AdminUserOutput
|
||||
{
|
||||
Id = a.Id,
|
||||
UserName = a.UserName,
|
||||
Type = a.Type,
|
||||
Status = a.Status,
|
||||
CreatedBy = a.CreatedBy,
|
||||
CreatedAt = a.CreatedAt,
|
||||
UpdatedBy = a.UpdatedBy,
|
||||
UpdatedAt = a.UpdatedAt
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||
return new PageListModel<AdminUserOutput>(pageResult, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将实体映射为输出DTO
|
||||
/// </summary>
|
||||
private static AdminUserOutput MapToOutput(AdminUser adminUser)
|
||||
{
|
||||
return new AdminUserOutput
|
||||
{
|
||||
Id = adminUser.Id,
|
||||
UserName = adminUser.UserName,
|
||||
Type = adminUser.Type,
|
||||
Status = adminUser.Status,
|
||||
CreatedBy = adminUser.CreatedBy,
|
||||
CreatedAt = adminUser.CreatedAt,
|
||||
UpdatedBy = adminUser.UpdatedBy,
|
||||
UpdatedAt = adminUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user