refactor(meeting): 优化学生详情查询接口并修复数据库字段映射
- 将返回类型从 StudentListResponseDto 改为直接返回 StudentDetailResponseDto 数组 - 移除不必要的包装对象,简化数据结构 - 修复数据库表 meeting_user 中的字段名映射,统一使用下划线命名规范 - 更新 SQL 查询中的字段引用以匹配正确的数据库列名 - 简化服务层的数据处理逻辑,提高查询效率
This commit is contained in:
@ -5,7 +5,7 @@ import { MeetingService } from './meeting.service';
|
|||||||
import { NonEmptyStringPipe } from '@/common/pipes/non-empty-string.pipe';
|
import { NonEmptyStringPipe } from '@/common/pipes/non-empty-string.pipe';
|
||||||
import { Uint32Pipe } from '@/common/pipes/uint32.pipe';
|
import { Uint32Pipe } from '@/common/pipes/uint32.pipe';
|
||||||
import { ApiCustomOkResponse } from '@/common/decorators/swagger.decorator';
|
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 { MeetingRedisService } from '../websocket/meeting-redis.service';
|
||||||
import { MeetingWebSocketGateway } from '../websocket/meeting.websocket';
|
import { MeetingWebSocketGateway } from '../websocket/meeting.websocket';
|
||||||
|
|
||||||
@ -98,16 +98,13 @@ export class MeetingController {
|
|||||||
@ApiQuery({ name: 'roomId', description: '房间 ID (可选,用于获取 Redis 中的排序)', required: false, example: 'n_1234567890' })
|
@ApiQuery({ name: 'roomId', description: '房间 ID (可选,用于获取 Redis 中的排序)', required: false, example: 'n_1234567890' })
|
||||||
@ApiCustomOkResponse({
|
@ApiCustomOkResponse({
|
||||||
summary: '学生详细信息列表',
|
summary: '学生详细信息列表',
|
||||||
model: StudentListResponseDto,
|
model: [StudentDetailResponseDto],
|
||||||
apiDescription: '学生详细信息列表,包含长 ID、短 ID (可能为 null) 和姓名',
|
apiDescription: '学生详细信息列表,包含长 ID、短 ID (可能为 null) 和姓名',
|
||||||
resDescription: '学生详细信息列表',
|
resDescription: '学生详细信息列表',
|
||||||
})
|
})
|
||||||
public async getStudentDetails(@Query('homeworkId', ParseIntPipe) homeworkId: number, @Query('roomId', NonEmptyStringPipe) roomId?: string) {
|
public async getStudentDetails(@Query('homeworkId', ParseIntPipe) homeworkId: number, @Query('roomId', NonEmptyStringPipe) roomId?: string) {
|
||||||
const students = await this.meetingService.getStudentDetailsByHomeworkId(homeworkId, roomId);
|
const students = await this.meetingService.getStudentDetailsByHomeworkId(homeworkId, roomId);
|
||||||
return new OkResult({
|
return new OkResult(students);
|
||||||
total: students.length,
|
|
||||||
students,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,17 +28,6 @@ export class StudentDetailResponseDto {
|
|||||||
studentName!: string;
|
studentName!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 学生列表响应 DTO
|
|
||||||
*/
|
|
||||||
export class StudentListResponseDto {
|
|
||||||
@ApiProperty({ description: '学生总数', example: 30 })
|
|
||||||
total!: number;
|
|
||||||
|
|
||||||
@ApiProperty({ description: '学生列表', type: [StudentDetailResponseDto] })
|
|
||||||
students!: StudentDetailResponseDto[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存学生排序请求 DTO
|
* 保存学生排序请求 DTO
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export class MeetingService {
|
|||||||
INNER JOIN scs_studentgroup sg ON h.StudentGroupId = sg.Id
|
INNER JOIN scs_studentgroup sg ON h.StudentGroupId = sg.Id
|
||||||
INNER JOIN scs_studentgroupdetail sgd ON sg.Id = sgd.StudentGroupId
|
INNER JOIN scs_studentgroupdetail sgd ON sg.Id = sgd.StudentGroupId
|
||||||
INNER JOIN scs_user u ON sgd.StudentId = u.Id
|
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}
|
WHERE h.Id = ${id}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -66,18 +66,18 @@ export class MeetingService {
|
|||||||
if (missingIds.length > 0) {
|
if (missingIds.length > 0) {
|
||||||
// 批量插入缺失的短 ID
|
// 批量插入缺失的短 ID
|
||||||
await this.em.getConnection().execute(`
|
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(',')}
|
VALUES ${missingIds.map((longUserId) => `(${longUserId}, NOW())`).join(',')}
|
||||||
ON DUPLICATE KEY UPDATE longUserId = longUserId
|
ON DUPLICATE KEY UPDATE long_user_Id = long_user_Id
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// 查询新分配的短 ID
|
// 查询新分配的短 ID
|
||||||
const newUsers = await this.em.getConnection().execute(`
|
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<number, number>();
|
const shortIdMap = new Map<number, number>();
|
||||||
(newUsers as Array<{ longUserId: number; id: number }>).forEach((user) => {
|
(newUsers as Array<{ long_user_Id: number; id: number }>).forEach((user) => {
|
||||||
shortIdMap.set(user.longUserId, user.id);
|
shortIdMap.set(user.long_user_Id, user.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 更新缺失的短 ID
|
// 更新缺失的短 ID
|
||||||
|
|||||||
Reference in New Issue
Block a user