主要更新: 1. 后端核心底座完成 (M1-M6): - 健康检查、指标监控、分布式锁 - 事件总线、队列系统、事务管理 - 安全守卫、多租户隔离、存储适配器 - 审计日志、配置管理、多语言支持 2. 前端迁移到 Ant Design Vue: - 从 Element Plus 迁移到 Ant Design Vue - 完善 system 模块 (role/menu/dept) - 修复依赖和配置问题 3. 文档完善: - AI 开发工作流文档 - 架构约束和开发规范 - 项目进度跟踪 4. 其他改进: - 修复编译错误和类型问题 - 完善测试用例 - 优化项目结构
154 lines
4.6 KiB
TypeScript
154 lines
4.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
HttpCode,
|
|
HttpStatus,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiResponse,
|
|
ApiBearerAuth,
|
|
} from '@nestjs/swagger';
|
|
import { RoleAdminService } from '../../services/admin/RoleAdminService';
|
|
import {
|
|
CreateRoleDto,
|
|
UpdateRoleDto,
|
|
QueryRoleDto,
|
|
BatchUpdateRoleStatusDto,
|
|
AssignMenusDto,
|
|
} from '../../dto/admin/RoleDto';
|
|
import { JwtAuthGuard } from '../../../auth/guards/JwtAuthGuard';
|
|
import { RolesGuard } from '../../../auth/guards/RolesGuard';
|
|
import { Roles } from '../../../auth/decorators/RolesDecorator';
|
|
|
|
@ApiTags('角色管理')
|
|
@Controller('adminapi/role')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@ApiBearerAuth()
|
|
export class RoleController {
|
|
constructor(private readonly roleAdminService: RoleAdminService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '创建角色' })
|
|
@ApiResponse({ status: 201, description: '角色创建成功' })
|
|
@ApiResponse({ status: 400, description: '请求参数错误' })
|
|
@Roles('admin')
|
|
async createRole(@Body() createRoleDto: CreateRoleDto) {
|
|
return await this.roleAdminService.createRole(createRoleDto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取角色列表' })
|
|
@ApiResponse({ status: 200, description: '获取角色列表成功' })
|
|
@Roles('admin')
|
|
async getRoleList(@Query() queryRoleDto: QueryRoleDto) {
|
|
return await this.roleAdminService.getRoleList(queryRoleDto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取角色详情' })
|
|
@ApiResponse({ status: 200, description: '获取角色详情成功' })
|
|
@ApiResponse({ status: 404, description: '角色不存在' })
|
|
@Roles('admin')
|
|
async getRoleDetail(@Param('id') id: string) {
|
|
return await this.roleAdminService.getRoleDetail(Number(id));
|
|
}
|
|
|
|
@Put(':id')
|
|
@ApiOperation({ summary: '更新角色' })
|
|
@ApiResponse({ status: 200, description: '角色更新成功' })
|
|
@ApiResponse({ status: 400, description: '请求参数错误' })
|
|
@ApiResponse({ status: 404, description: '角色不存在' })
|
|
@Roles('admin')
|
|
async updateRole(
|
|
@Param('id') id: string,
|
|
@Body() updateRoleDto: UpdateRoleDto,
|
|
) {
|
|
return await this.roleAdminService.updateRole(Number(id), updateRoleDto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除角色' })
|
|
@ApiResponse({ status: 200, description: '角色删除成功' })
|
|
@ApiResponse({ status: 404, description: '角色不存在' })
|
|
@HttpCode(HttpStatus.OK)
|
|
@Roles('admin')
|
|
async deleteRole(@Param('id') id: string) {
|
|
return await this.roleAdminService.deleteRole(Number(id));
|
|
}
|
|
|
|
@Delete('batch')
|
|
@ApiOperation({ summary: '批量删除角色' })
|
|
@ApiResponse({ status: 200, description: '批量删除角色成功' })
|
|
@HttpCode(HttpStatus.OK)
|
|
@Roles('admin')
|
|
async batchDeleteRoles(@Body() body: { roleIds: number[] }) {
|
|
return await this.roleAdminService.batchDeleteRoles(body.roleIds);
|
|
}
|
|
|
|
@Put(':id/status')
|
|
@ApiOperation({ summary: '更新角色状态' })
|
|
@ApiResponse({ status: 200, description: '角色状态更新成功' })
|
|
@ApiResponse({ status: 404, description: '角色不存在' })
|
|
@Roles('admin')
|
|
async updateRoleStatus(
|
|
@Param('id') id: string,
|
|
@Body() body: { status: number },
|
|
) {
|
|
return await this.roleAdminService.updateRoleStatus(
|
|
Number(id),
|
|
body.status,
|
|
);
|
|
}
|
|
|
|
@Put('batch/status')
|
|
@ApiOperation({ summary: '批量更新角色状态' })
|
|
@ApiResponse({ status: 200, description: '批量更新角色状态成功' })
|
|
@Roles('admin')
|
|
async batchUpdateRoleStatus(@Body() body: BatchUpdateRoleStatusDto) {
|
|
return await this.roleAdminService.batchUpdateRoleStatus(
|
|
body.roleIds,
|
|
body.status,
|
|
);
|
|
}
|
|
|
|
@Put(':id/menus')
|
|
@ApiOperation({ summary: '分配菜单权限' })
|
|
@ApiResponse({ status: 200, description: '菜单权限分配成功' })
|
|
@ApiResponse({ status: 404, description: '角色不存在' })
|
|
@Roles('admin')
|
|
async assignMenus(
|
|
@Param('id') id: string,
|
|
@Body() assignMenusDto: AssignMenusDto,
|
|
) {
|
|
return await this.roleAdminService.assignMenus(
|
|
Number(id),
|
|
assignMenusDto.menuIds,
|
|
);
|
|
}
|
|
|
|
@Get('stats/overview')
|
|
@ApiOperation({ summary: '获取角色统计信息' })
|
|
@ApiResponse({ status: 200, description: '获取角色统计信息成功' })
|
|
@Roles('admin')
|
|
async getRoleStats() {
|
|
return await this.roleAdminService.getRoleStats();
|
|
}
|
|
|
|
@Post('export')
|
|
@ApiOperation({ summary: '导出角色数据' })
|
|
@ApiResponse({ status: 200, description: '导出角色数据成功' })
|
|
@Roles('admin')
|
|
async exportRoles(@Body() query: any) {
|
|
return await this.roleAdminService.exportRoles();
|
|
}
|
|
}
|