refactor(meeting): 将学生ID从长ID改为短ID以优化性能

- 修改SaveStudentOrderDto中的studentLongIds字段为studentShortIds
- 更新MeetingController中保存和传输的学生ID参数名称
- 重构MeetingRedisService中setStudentOrder方法参数为studentShortIds
- 调整WebSocket通信中的学生ID字段名称一致性
- 在前端API调用中使用studentShortIds替代studentLongIds
- 添加监控端对学生排序变更事件的处理逻辑
- 更新学生排序对话框中使用的ID映射方式
This commit is contained in:
2026-03-14 21:28:56 +08:00
parent bc5fa9a366
commit 0e88826a9c
8 changed files with 32 additions and 22 deletions

View File

@ -109,7 +109,7 @@ export class MeetingController {
})
public async saveStudentOrder(@Body() dto: SaveStudentOrderDto) {
// 1. 保存到 Redis
await this.meetingService.saveStudentOrder(dto.roomId, dto.studentLongIds);
await this.meetingService.saveStudentOrder(dto.roomId, dto.studentShortIds);
// 2. 获取房间内所有 socket 并过滤出监控端 (monitor 模式)
const ns = this.websocketGateway.getServer();
@ -123,7 +123,7 @@ export class MeetingController {
type: 'sev_student_order_changed',
data: {
fromRoomId: dto.roomId,
studentLongIds: dto.studentLongIds,
studentShortIds: dto.studentShortIds,
},
});
}

View File

@ -48,8 +48,8 @@ export class SaveStudentOrderDto {
@IsString({ message: 'roomId 必须是字符串' })
roomId!: string;
@ApiProperty({ description: '学生 ID 数组 (按排序顺序)', example: [1234567890, 1234567891, 1234567892] })
@IsNotEmpty({ message: 'studentLongIds 不能为空' })
@IsArray({ message: 'studentLongIds 必须是数组' })
studentLongIds!: number[];
@ApiProperty({ description: '学生 ID 数组 (按排序顺序)', example: [1001, 1002, 1003] })
@IsNotEmpty({ message: 'studentShortIds 不能为空' })
@IsArray({ message: 'studentShortIds 必须是数组' })
studentShortIds!: number[];
}

View File

@ -502,14 +502,14 @@ export class MeetingRedisService {
/**
* 设置学生排序顺序
* @param roomId - 房间 ID
* @param studentLongIds - 学生 ID 数组 (按排序顺序)
* @param studentShortIds - 学生 ID 数组 (按排序顺序)
*/
async setStudentOrder(roomId: string, studentLongIds: number[]): Promise<void> {
async setStudentOrder(roomId: string, studentShortIds: number[]): Promise<void> {
const key = `${this.KEY_PREFIX.STUDENT_ORDER}${roomId}`;
const client = this.getClient();
await client.del(key); // 先删除旧数据
if (studentLongIds.length > 0) {
const stringIds = studentLongIds.map((id) => String(id));
if (studentShortIds.length > 0) {
const stringIds = studentShortIds.map((id) => String(id));
await client.rpush(key, ...stringIds);
await client.expire(key, 24 * 60 * 60);
}

View File

@ -711,10 +711,10 @@ export class MeetingWebSocketGateway implements OnGatewayConnection, OnGatewayDi
*/
@SubscribeMessage<ClientToServerMessageType>('client_student_order_changed')
public async handleStudentOrderChanged(
@MessageBody() data: { roomId: string; studentLongIds: number[] },
@MessageBody() data: { roomId: string; studentShortIds: number[] },
@ConnectedSocket() socket: MeetingSocket
): Promise<void> {
if (!data?.roomId || !Array.isArray(data.studentLongIds)) {
if (!data?.roomId || !Array.isArray(data.studentShortIds)) {
return;
}
const isHost = socket.data.user?.role !== 0;
@ -723,7 +723,7 @@ export class MeetingWebSocketGateway implements OnGatewayConnection, OnGatewayDi
return;
}
// 保存到 Redis
await this.redisService.setStudentOrder(data.roomId, data.studentLongIds);
await this.redisService.setStudentOrder(data.roomId, data.studentShortIds);
// 获取房间内所有 socket 并过滤出监控端 (monitor 模式)
const ns = this.server;
if (ns) {
@ -732,9 +732,9 @@ export class MeetingWebSocketGateway implements OnGatewayConnection, OnGatewayDi
if (monitorSocketIds.length > 0) {
// 发送给所有监控端的 socket
ns.to(monitorSocketIds).emit('message', { type: 'sev_student_order_changed', data: { fromRoomId: data.roomId, studentLongIds: data.studentLongIds } });
ns.to(monitorSocketIds).emit('message', { type: 'sev_student_order_changed', data: { fromRoomId: data.roomId, studentShortIds: data.studentShortIds } });
}
}
this.log(`创建者更新了学生排序roomId=${data.roomId}, 学生数量=${data.studentLongIds.length}`);
this.log(`创建者更新了学生排序roomId=${data.roomId}, 学生数量=${data.studentShortIds.length}`);
}
}

View File

@ -217,8 +217,8 @@ export interface MeetingRoomEndTimestampUpdatedData {
export interface MeetingStudentOrderChangedData {
/** 来源房间 */
fromRoomId: string;
/** 学生 ID 数组 (按排序顺序) */
studentLongIds: number[];
/** 学生 ID 数组 (按排序顺序) */
studentShortIds: number[];
}
export type MeetingDownlinkPacket =