refactor: 拆分微信API到独立项目并迁移相关代码
1. 新增WeChatApi独立项目,将原WebApi中的微信相关控制器迁移至新项目 2. 新增后台权限管理相关实体、服务接口和基础控制器 3. 完善管理员用户服务,增加角色关联查询和赋值逻辑 4. 修复WebApi Swagger文档过滤微信API版本的问题 5. 更新解决方案文件,添加新的微信API项目引用 6. 新增微信API基础配置文件和项目属性配置
This commit is contained in:
@ -15,7 +15,10 @@ namespace QYZH.InteractiveMagazine.Service;
|
||||
/// <summary>
|
||||
/// 管理员用户服务实现
|
||||
/// </summary>
|
||||
public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILogger<AdminUserService> logger) : BaseRepository<AdminUser>, IAdminUserService
|
||||
public class AdminUserService(
|
||||
BaseRepository<AdminUser> adminUserRepository,
|
||||
IAdminPermissionService adminPermissionService,
|
||||
ILogger<AdminUserService> logger) : BaseRepository<AdminUser>, IAdminUserService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@ -63,9 +66,14 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
throw new BusinessException("创建管理员失败", ResultCode.GLOBAL_ERROR);
|
||||
}
|
||||
|
||||
if (input.RoleIds != null)
|
||||
{
|
||||
await adminPermissionService.AssignAdminUserRolesAsync(adminUser.Id, new AssignAdminUserRolesInput { RoleIds = input.RoleIds });
|
||||
}
|
||||
|
||||
logger.LogInformation("管理员创建成功,用户名: {UserName}, ID: {Id}", input.UserName, adminUser.Id);
|
||||
|
||||
return new AdminUserOutput { Id = adminUser.Id, UserName = adminUser.UserName, Type = adminUser.Type.ToString(), Status = adminUser.Status, CreatedBy = adminUser.CreatedBy, CreatedAt = adminUser.CreatedAt, UpdatedBy = adminUser.UpdatedBy, UpdatedAt = adminUser.UpdatedAt };
|
||||
return await ToAdminUserOutputAsync(adminUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -114,9 +122,14 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
throw new BusinessException("更新管理员失败", ResultCode.GLOBAL_ERROR);
|
||||
}
|
||||
|
||||
if (input.RoleIds != null)
|
||||
{
|
||||
await adminPermissionService.AssignAdminUserRolesAsync(adminUser.Id, new AssignAdminUserRolesInput { RoleIds = input.RoleIds });
|
||||
}
|
||||
|
||||
logger.LogInformation("管理员更新成功,ID: {Id}", id);
|
||||
|
||||
return new AdminUserOutput { Id = adminUser.Id, UserName = adminUser.UserName, Type = adminUser.Type.ToString(), Status = adminUser.Status, CreatedBy = adminUser.CreatedBy, CreatedAt = adminUser.CreatedAt, UpdatedBy = adminUser.UpdatedBy, UpdatedAt = adminUser.UpdatedAt };
|
||||
return await ToAdminUserOutputAsync(adminUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -156,17 +169,7 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
logger.LogWarning("未找到管理员,ID: {Id}", id);
|
||||
throw new BusinessException("管理员不存在", ResultCode.NOT_FOUND);
|
||||
}
|
||||
return new AdminUserOutput
|
||||
{
|
||||
Id = adminUser.Id,
|
||||
UserName = adminUser.UserName,
|
||||
Type = adminUser.Type.ToString(),
|
||||
Status = adminUser.Status,
|
||||
CreatedBy = adminUser.CreatedBy,
|
||||
CreatedAt = adminUser.CreatedAt,
|
||||
UpdatedBy = adminUser.UpdatedBy,
|
||||
UpdatedAt = adminUser.UpdatedAt
|
||||
};
|
||||
return await ToAdminUserOutputAsync(adminUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -201,6 +204,12 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
UpdatedAt = a.UpdatedAt
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||
foreach (var item in pageResult)
|
||||
{
|
||||
item.Roles = await adminPermissionService.GetAdminUserRolesAsync(item.Id);
|
||||
item.RoleIds = item.Roles.Select(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
return new PageListModel<AdminUserOutput>(pageResult, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
@ -231,4 +240,22 @@ public class AdminUserService(BaseRepository<AdminUser> adminUserRepository, ILo
|
||||
|
||||
logger.LogInformation("管理员状态更新成功,ID: {Id}", id);
|
||||
}
|
||||
|
||||
private async Task<AdminUserOutput> ToAdminUserOutputAsync(AdminUser adminUser)
|
||||
{
|
||||
var roles = await adminPermissionService.GetAdminUserRolesAsync(adminUser.Id);
|
||||
return new AdminUserOutput
|
||||
{
|
||||
Id = adminUser.Id,
|
||||
UserName = adminUser.UserName,
|
||||
Type = adminUser.Type.ToString(),
|
||||
Status = adminUser.Status,
|
||||
CreatedBy = adminUser.CreatedBy,
|
||||
CreatedAt = adminUser.CreatedAt,
|
||||
UpdatedBy = adminUser.UpdatedBy,
|
||||
UpdatedAt = adminUser.UpdatedAt,
|
||||
RoleIds = roles.Select(x => x.Id).ToList(),
|
||||
Roles = roles
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user