From d0c8ff4e4760f950c688375e6139de7a82114eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=E6=98=B5=E7=A7=B0=E9=87=8D=E8=A6=81=E5=90=97O?= Date: Sat, 14 Mar 2026 18:19:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor(meeting):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AD=A6=E7=94=9F=E8=AF=A6=E6=83=85=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=B9=B6=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将返回类型从 StudentListResponseDto 改为直接返回 StudentDetailResponseDto 数组 - 移除不必要的包装对象,简化数据结构 - 修复数据库表 meeting_user 中的字段名映射,统一使用下划线命名规范 - 更新 SQL 查询中的字段引用以匹配正确的数据库列名 - 简化服务层的数据处理逻辑,提高查询效率 --- node_api/src/modules/meeting/meeting.controller.ts | 9 +++------ node_api/src/modules/meeting/meeting.dto.ts | 11 ----------- node_api/src/modules/meeting/meeting.service.ts | 12 ++++++------ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/node_api/src/modules/meeting/meeting.controller.ts b/node_api/src/modules/meeting/meeting.controller.ts index 511bf1b..47fde9c 100644 --- a/node_api/src/modules/meeting/meeting.controller.ts +++ b/node_api/src/modules/meeting/meeting.controller.ts @@ -5,7 +5,7 @@ import { MeetingService } from './meeting.service'; import { NonEmptyStringPipe } from '@/common/pipes/non-empty-string.pipe'; import { Uint32Pipe } from '@/common/pipes/uint32.pipe'; import { ApiCustomOkResponse } from '@/common/decorators/swagger.decorator'; -import { SaveStudentOrderDto, StudentListResponseDto, TokenResponseDto } from './meeting.dto'; +import { SaveStudentOrderDto, StudentDetailResponseDto, TokenResponseDto } from './meeting.dto'; import { MeetingRedisService } from '../websocket/meeting-redis.service'; import { MeetingWebSocketGateway } from '../websocket/meeting.websocket'; @@ -98,16 +98,13 @@ export class MeetingController { @ApiQuery({ name: 'roomId', description: '房间 ID (可选,用于获取 Redis 中的排序)', required: false, example: 'n_1234567890' }) @ApiCustomOkResponse({ summary: '学生详细信息列表', - model: StudentListResponseDto, + model: [StudentDetailResponseDto], apiDescription: '学生详细信息列表,包含长 ID、短 ID (可能为 null) 和姓名', resDescription: '学生详细信息列表', }) public async getStudentDetails(@Query('homeworkId', ParseIntPipe) homeworkId: number, @Query('roomId', NonEmptyStringPipe) roomId?: string) { const students = await this.meetingService.getStudentDetailsByHomeworkId(homeworkId, roomId); - return new OkResult({ - total: students.length, - students, - }); + return new OkResult(students); } /** diff --git a/node_api/src/modules/meeting/meeting.dto.ts b/node_api/src/modules/meeting/meeting.dto.ts index 3000746..6dbc7d1 100644 --- a/node_api/src/modules/meeting/meeting.dto.ts +++ b/node_api/src/modules/meeting/meeting.dto.ts @@ -28,17 +28,6 @@ export class StudentDetailResponseDto { studentName!: string; } -/** - * 学生列表响应 DTO - */ -export class StudentListResponseDto { - @ApiProperty({ description: '学生总数', example: 30 }) - total!: number; - - @ApiProperty({ description: '学生列表', type: [StudentDetailResponseDto] }) - students!: StudentDetailResponseDto[]; -} - /** * 保存学生排序请求 DTO */ diff --git a/node_api/src/modules/meeting/meeting.service.ts b/node_api/src/modules/meeting/meeting.service.ts index e2c4064..f73de7e 100644 --- a/node_api/src/modules/meeting/meeting.service.ts +++ b/node_api/src/modules/meeting/meeting.service.ts @@ -54,7 +54,7 @@ export class MeetingService { INNER JOIN scs_studentgroup sg ON h.StudentGroupId = sg.Id INNER JOIN scs_studentgroupdetail sgd ON sg.Id = sgd.StudentGroupId INNER JOIN scs_user u ON sgd.StudentId = u.Id - LEFT JOIN meeting_user mu ON u.Id = mu.longUserId + LEFT JOIN meeting_user mu ON u.Id = mu.long_user_Id WHERE h.Id = ${id} `; @@ -66,18 +66,18 @@ export class MeetingService { if (missingIds.length > 0) { // 批量插入缺失的短 ID await this.em.getConnection().execute(` - INSERT INTO meeting_user (longUserId, createdAt) + INSERT INTO meeting_user (long_user_Id, created_at) VALUES ${missingIds.map((longUserId) => `(${longUserId}, NOW())`).join(',')} - ON DUPLICATE KEY UPDATE longUserId = longUserId + ON DUPLICATE KEY UPDATE long_user_Id = long_user_Id `); // 查询新分配的短 ID const newUsers = await this.em.getConnection().execute(` - SELECT longUserId, id FROM meeting_user WHERE longUserId IN (${missingIds.join(',')}) + SELECT long_user_Id, id FROM meeting_user WHERE long_user_Id IN (${missingIds.join(',')}) `); const shortIdMap = new Map(); - (newUsers as Array<{ longUserId: number; id: number }>).forEach((user) => { - shortIdMap.set(user.longUserId, user.id); + (newUsers as Array<{ long_user_Id: number; id: number }>).forEach((user) => { + shortIdMap.set(user.long_user_Id, user.id); }); // 更新缺失的短 ID