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

@@ -35,4 +35,4 @@ export { LearningRecord } from './learning-record.entity';
export { ResultArchive } from './result-archive.entity';
export { ArchiveAttachment } from './archive-attachment.entity';
export { StudentReport } from './student-report.entity';
export { UserDingMapping } from './user-ding-mapping.entity';
export { StudentDingMapping } from './student-ding-mapping.entity';

View File

@@ -0,0 +1,24 @@
import {
Entity, PrimaryGeneratedColumn, Column, CreateDateColumn,
ManyToOne, JoinColumn,
} from 'typeorm';
import { Student } from './student.entity';
@Entity('student_ding_mapping')
export class StudentDingMapping {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'ding_user_id', length: 100, unique: true })
dingUserId: string;
@Column({ name: 'student_id', type: 'integer', unique: true })
studentId: number;
@ManyToOne(() => Student, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'student_id' })
student: Student;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
}

View File

@@ -1,52 +0,0 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { User } from './user.entity';
/**
* Maps DingTalk user IDs to local User records.
* Used for incremental sync and attendance auto-matching.
*
* Mapping chain:
* dingtalk userid → UserDingMapping.dingUserId → UserDingMapping.userId
* → User.id → Student.userId → Student.id
* → DingAttendanceRaw.dingUserId → UserDingMapping.dingUserId → auto-match
*/
@Entity('user_ding_mapping')
export class UserDingMapping {
@PrimaryGeneratedColumn()
id: number;
/** DingTalk user ID (from DingTalk API) */
@Column({ name: 'ding_user_id', length: 100, unique: true })
dingUserId: string;
/** Local User ID */
@Column({ name: 'user_id', type: 'integer', unique: true })
userId: number;
@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user: User;
/** DingTalk user name (cached for display) */
@Column({ name: 'ding_name', length: 100, nullable: true })
dingName: string;
/** DingTalk mobile (cached for display) */
@Column({ name: 'ding_mobile', length: 20, nullable: true })
dingMobile: string;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
}