refactor: replace UserDingMapping with StudentDingMapping entity

This commit is contained in:
2026-07-09 16:53:25 +08:00
parent 1fa336331c
commit ef1b46b9f4
18 changed files with 104 additions and 146 deletions

View File

@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository, In, Not, IsNull } from 'typeorm';
import {
ClassSchedule,
UserDingMapping,
StudentDingMapping,
ClassStudent,
ClassTeacher,
Department,
@@ -47,8 +47,8 @@ export class ScheduleSyncService {
constructor(
@InjectRepository(ClassSchedule)
private readonly scheduleRepo: Repository<ClassSchedule>,
@InjectRepository(UserDingMapping)
private readonly mappingRepo: Repository<UserDingMapping>,
@InjectRepository(StudentDingMapping)
private readonly studentDingMappingRepo: Repository<StudentDingMapping>,
@InjectRepository(ClassTeacher)
private readonly classTeacherRepo: Repository<ClassTeacher>,
@InjectRepository(Department)
@@ -88,10 +88,10 @@ export class ScheduleSyncService {
// ── Step 2: 获取教师→钉钉用户ID映射 ──
const teacherIds = [...new Set(schedules.map((s) => s.teacherId!).filter(Boolean))];
const mappings = await this.mappingRepo.find({
where: { userId: In(teacherIds) },
const mappings = await this.studentDingMappingRepo.find({
where: { studentId: In(teacherIds) },
});
const userIdToDingId = new Map(mappings.map((m) => [m.userId, m.dingUserId]));
const userIdToDingId = new Map(mappings.map((m) => [m.studentId, m.dingUserId]));
// ── Step 3: 按 (startTime, endTime) 创建/匹配班次 ──
const shiftKey = (start: string, end: string) => `${start}-${end}`;
@@ -288,8 +288,8 @@ export class ScheduleSyncService {
where: { status: 'active', teacherId: Not(IsNull()) },
});
const teacherIds = [...new Set(schedules.map((s) => s.teacherId!).filter(Boolean))];
const mappings = await this.mappingRepo.find({
where: { userId: In(teacherIds) },
const mappings = await this.studentDingMappingRepo.find({
where: { studentId: In(teacherIds) },
});
return {
activeSchedules: schedules.length,