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:
@ -37,11 +37,9 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
NickName = input.NickName,
|
||||
AvatarUrl = input.AvatarUrl,
|
||||
Phone = input.Phone,
|
||||
Points = input.Points,
|
||||
Type = input.Type,
|
||||
Status = input.Status,
|
||||
Pwd = input.Pwd ?? string.Empty,
|
||||
GrowthPoints = input.GrowthPoints,
|
||||
CreatedBy = "System",
|
||||
UpdatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
@ -58,7 +56,21 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
|
||||
_logger.LogInformation("微信用户创建成功,OpenId: {OpenId}, ID: {Id}", input.OpenId, wxUser.Id);
|
||||
|
||||
return MapToOutput(wxUser);
|
||||
return new WxUserOutput
|
||||
{
|
||||
Id = wxUser.Id,
|
||||
OpenId = wxUser.OpenId,
|
||||
UnionId = wxUser.UnionId,
|
||||
NickName = wxUser.NickName,
|
||||
AvatarUrl = wxUser.AvatarUrl,
|
||||
Phone = wxUser.Phone,
|
||||
Type = wxUser.Type,
|
||||
Status = wxUser.Status,
|
||||
CreatedBy = wxUser.CreatedBy,
|
||||
CreatedAt = wxUser.CreatedAt,
|
||||
UpdatedBy = wxUser.UpdatedBy,
|
||||
UpdatedAt = wxUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<WxUserOutput> UpdateAsync(long id, WxUserInput input)
|
||||
@ -88,11 +100,9 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
wxUser.NickName = input.NickName ?? wxUser.NickName;
|
||||
wxUser.AvatarUrl = input.AvatarUrl ?? wxUser.AvatarUrl;
|
||||
wxUser.Phone = input.Phone ?? wxUser.Phone;
|
||||
wxUser.Points = input.Points;
|
||||
wxUser.Type = input.Type ?? wxUser.Type;
|
||||
wxUser.Status = input.Status ?? wxUser.Status;
|
||||
wxUser.Pwd = input.Pwd ?? wxUser.Pwd;
|
||||
wxUser.GrowthPoints = input.GrowthPoints;
|
||||
|
||||
wxUser.UpdatedBy = "System";
|
||||
wxUser.UpdatedAt = DateTime.Now;
|
||||
@ -106,7 +116,21 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
|
||||
_logger.LogInformation("微信用户更新成功,ID: {Id}", id);
|
||||
|
||||
return MapToOutput(wxUser);
|
||||
return new WxUserOutput
|
||||
{
|
||||
Id = wxUser.Id,
|
||||
OpenId = wxUser.OpenId,
|
||||
UnionId = wxUser.UnionId,
|
||||
NickName = wxUser.NickName,
|
||||
AvatarUrl = wxUser.AvatarUrl,
|
||||
Phone = wxUser.Phone,
|
||||
Type = wxUser.Type,
|
||||
Status = wxUser.Status,
|
||||
CreatedBy = wxUser.CreatedBy,
|
||||
CreatedAt = wxUser.CreatedAt,
|
||||
UpdatedBy = wxUser.UpdatedBy,
|
||||
UpdatedAt = wxUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(long id)
|
||||
@ -132,21 +156,32 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
|
||||
public async Task<WxUserOutput> GetByIdAsync(long id)
|
||||
{
|
||||
_logger.LogInformation("正在获取微信用户信息,ID: {Id}", id);
|
||||
|
||||
var wxUser = await wxUserRepository.GetByIdAsync(id);
|
||||
if (wxUser == null)
|
||||
{
|
||||
_logger.LogWarning("未找到微信用户,ID: {Id}", id);
|
||||
|
||||
throw new BusinessException("微信用户不存在", 404);
|
||||
}
|
||||
|
||||
return MapToOutput(wxUser);
|
||||
return new WxUserOutput
|
||||
{
|
||||
Id = wxUser.Id,
|
||||
OpenId = wxUser.OpenId,
|
||||
UnionId = wxUser.UnionId,
|
||||
NickName = wxUser.NickName,
|
||||
AvatarUrl = wxUser.AvatarUrl,
|
||||
Phone = wxUser.Phone,
|
||||
Type = wxUser.Type,
|
||||
Status = wxUser.Status,
|
||||
CreatedBy = wxUser.CreatedBy,
|
||||
CreatedAt = wxUser.CreatedAt,
|
||||
UpdatedBy = wxUser.UpdatedBy,
|
||||
UpdatedAt = wxUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<PageListModel<WxUserOutput>> GetListAsync(WxUserQueryInput input)
|
||||
{
|
||||
_logger.LogInformation("正在查询微信用户列表,页码: {PageIndex}, 每页条数: {PageSize}", input.PageIndex, input.PageSize);
|
||||
|
||||
if (input.PageIndex <= 0)
|
||||
{
|
||||
@ -162,30 +197,25 @@ public class WxUserService(BaseRepository<WxUser> wxUserRepository, ILogger<WxUs
|
||||
var pageResult = await wxUserRepository.Queryable()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.NickName), a => a.NickName == input.NickName)
|
||||
.OrderByDescending(a => a.CreatedAt)
|
||||
.Select(a => MapToOutput(a), true)
|
||||
.Select(wxUser => new WxUserOutput
|
||||
{
|
||||
Id = wxUser.Id,
|
||||
OpenId = wxUser.OpenId,
|
||||
UnionId = wxUser.UnionId,
|
||||
NickName = wxUser.NickName,
|
||||
AvatarUrl = wxUser.AvatarUrl,
|
||||
Phone = wxUser.Phone,
|
||||
Type = wxUser.Type,
|
||||
Status = wxUser.Status,
|
||||
CreatedBy = wxUser.CreatedBy,
|
||||
CreatedAt = wxUser.CreatedAt,
|
||||
UpdatedBy = wxUser.UpdatedBy,
|
||||
UpdatedAt = wxUser.UpdatedAt
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||
|
||||
return new PageListModel<WxUserOutput>(pageResult, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
private static WxUserOutput MapToOutput(WxUser wxUser)
|
||||
{
|
||||
return new WxUserOutput
|
||||
{
|
||||
Id = wxUser.Id,
|
||||
OpenId = wxUser.OpenId,
|
||||
UnionId = wxUser.UnionId,
|
||||
NickName = wxUser.NickName,
|
||||
AvatarUrl = wxUser.AvatarUrl,
|
||||
Phone = wxUser.Phone,
|
||||
Points = wxUser.Points,
|
||||
Type = wxUser.Type,
|
||||
Status = wxUser.Status,
|
||||
GrowthPoints = wxUser.GrowthPoints,
|
||||
CreatedBy = wxUser.CreatedBy,
|
||||
CreatedAt = wxUser.CreatedAt,
|
||||
UpdatedBy = wxUser.UpdatedBy,
|
||||
UpdatedAt = wxUser.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user