feat(meeting): 实现学生排序功能并优化Redis存储
- 将Redis中的学生排序存储从长ID改为短ID - 在监控端按studentListForSort顺序重新排列学生列表 - 添加新加入学生的处理逻辑 - 实现WebSocket消息处理学生排序变更事件 - 更新类型定义支持学生排序变更数据结构 - 优化Redis服务注释说明短ID存储格式
This commit is contained in:
@ -97,21 +97,21 @@ export class MeetingService {
|
||||
|
||||
// 如果提供了 roomId,从 Redis 获取排序并应用
|
||||
if (roomId) {
|
||||
const orderedIds = await this.redis.getStudentOrder(roomId);
|
||||
if (orderedIds.length > 0) {
|
||||
// 创建映射表
|
||||
const orderedShortIds = await this.redis.getStudentOrder(roomId);
|
||||
if (orderedShortIds.length > 0) {
|
||||
// 创建短 ID 到学生的映射
|
||||
const studentMap = new Map<number, StudentDetailInfo>();
|
||||
finalResults.forEach((student) => {
|
||||
studentMap.set(student.longId, student);
|
||||
studentMap.set(student.shortId, student);
|
||||
});
|
||||
|
||||
// 按 Redis 中的顺序重新排列
|
||||
// 按 Redis 中的短 ID 顺序重新排列
|
||||
const orderedResults: StudentDetailInfo[] = [];
|
||||
for (const longId of orderedIds) {
|
||||
const student = studentMap.get(longId);
|
||||
for (const shortId of orderedShortIds) {
|
||||
const student = studentMap.get(shortId);
|
||||
if (student) {
|
||||
orderedResults.push(student);
|
||||
studentMap.delete(longId); // 移除已添加的学生
|
||||
studentMap.delete(shortId); // 移除已添加的学生
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -74,8 +74,8 @@ export class MeetingRedisService {
|
||||
* 用途:存储学生列表的排序顺序
|
||||
* 数据结构:List
|
||||
* Key 格式:meeting:student-order:{roomId}
|
||||
* List 内容:按顺序存储学生的长 ID (字符串)
|
||||
* 适用场景:教师端拖动排序后,监控端按相同顺序显示
|
||||
* List 内容:按顺序存储学生的短 ID (数字字符串)
|
||||
* 适用场景:教师端拖动排序后,监控端和学生端按相同顺序显示
|
||||
* 过期时间:24 小时
|
||||
*/
|
||||
STUDENT_ORDER: 'meeting:student-order:',
|
||||
@ -518,7 +518,7 @@ export class MeetingRedisService {
|
||||
/**
|
||||
* 获取学生排序顺序
|
||||
* @param roomId - 房间 ID
|
||||
* @returns 学生长 ID 数组 (按排序顺序),未设置返回空数组
|
||||
* @returns 学生短 ID 数组 (按排序顺序),未设置返回空数组
|
||||
*/
|
||||
async getStudentOrder(roomId: string): Promise<number[]> {
|
||||
const key = `${this.KEY_PREFIX.STUDENT_ORDER}${roomId}`;
|
||||
|
||||
Reference in New Issue
Block a user