fix: repair 5 sites where StudentDingMapping.studentId was misused as User FK

- dingtalk.service.ts syncOneUser: query studentRepo (not userRepo) by mapping.studentId
- sync.service.ts importDingTalkUsers: skip User role lookup for existing mappings
- attendance.service.ts autoMatchDingRecords: use studentId directly, remove second-hop query
- schedule-sync.service.ts syncAll: skip teacher mapping block (deprecated)
- rbac.service.ts getUnboundUsers: return [] (method deleted in Task 4)
This commit is contained in:
2026-07-09 17:00:00 +08:00
parent ef1b46b9f4
commit 86f126671c
5 changed files with 14 additions and 38 deletions

View File

@@ -87,11 +87,8 @@ export class ScheduleSyncService {
}
// ── Step 2: 获取教师→钉钉用户ID映射 ──
const teacherIds = [...new Set(schedules.map((s) => s.teacherId!).filter(Boolean))];
const mappings = await this.studentDingMappingRepo.find({
where: { studentId: In(teacherIds) },
});
const userIdToDingId = new Map(mappings.map((m) => [m.studentId, m.dingUserId]));
// ponytail: teacher scheduling deprecated; StudentDingMapping.studentId is Student FK, not User
const userIdToDingId = new Map<number, string>();
// ── Step 3: 按 (startTime, endTime) 创建/匹配班次 ──
const shiftKey = (start: string, end: string) => `${start}-${end}`;

View File

@@ -199,13 +199,9 @@ export class SyncService {
if (existingMapping) {
skipped++;
// ponytail: studentDingMapping.studentId is Student FK, not User; full rewrite in Task 4
userId = existingMapping.studentId;
// 判断是老师还是学生:查角色
const existingUser = await manager.findOne(User, {
where: { id: userId },
relations: ['roles'],
});
isTeacher = (existingUser?.roles?.length ?? 0) > 0;
isTeacher = false;
} else {
// 检查是否已存在syncAll 或历史导入),避免撞 username 唯一约束
const username = `dd_${u.dingUserId}`;