forked from wangziqi/gongxue-base
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:
@@ -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}`;
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user