CREATE TABLE user
(
    user_id  INT AUTO_INCREMENT PRIMARY KEY,
    name     VARCHAR(50)  NOT NULL,
    number   VARCHAR(15)  NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    status   BOOLEAN      NOT NULL
);

INSERT INTO user (name, number, password, identity, status)
VALUES ('学生', '1', '$2b$12$okY88GrzlUHb/Ox1ENwtqeBUnE0bgMOCPy.UKmFaTnu3El7EYX8Em', 'student', TRUE),
       ('老师', '2', '$2b$12$okY88GrzlUHb/Ox1ENwtqeBUnE0bgMOCPy.UKmFaTnu3El7EYX8Em', 'teacher', TRUE);



CREATE TABLE menu_items
(
    id        INT AUTO_INCREMENT PRIMARY KEY,
    menu_name VARCHAR(100),
    path      VARCHAR(255),
    role      ENUM('student', 'teacher'),
    `order`   INT
);


INSERT INTO menu_items (menu_name, role, path, `order`)
VALUES ('课程信息', 'student', '/course-info', 1),
       ('课程签到', 'student', '/attendance', 2),
       ('公告信息', 'student', '/announcement', 3),
       ('签到提醒', 'student', '/attendance-reminder', 4);


INSERT INTO menu_items (menu_name, role, path, `order`)
VALUES ('课程类别', 'teacher', '/course-category', 1),
       ('课程信息', 'teacher', '/course-info', 2),
       ('课程签到', 'teacher', '/attendance-teacher', 3),
       ('签到提醒', 'teacher', '/attendance-reminder', 4);


CREATE TABLE course
(
    course_id   INT AUTO_INCREMENT PRIMARY KEY,
    course_name VARCHAR(255) NOT NULL,
    course_code VARCHAR(50)  NOT NULL,
    course_type ENUM('选修', '必修') NOT NULL,
    credits     INT,
    description TEXT
);

INSERT INTO course (course_name, course_code, course_type, credits, description)
VALUES ('大学计算机基础', 'CF001', '必修', 3, '介绍计算机基础知识和应用'),
       ('计算机导论', 'ITC002', '必修', 2, '概述计算机科学的基本概念和原理'),
       ('C++程序设计', 'CP001', '必修', 4, '学习C++编程语言及其应用'),
       ('健康教育', 'HE001', '必修', 1, '提升学生的健康意识和生活方式'),
       ('线性代数及其应用', 'LAAA001', '必修', 4, '学习线性代数的基础理论和实际应用'),
       ('高等数学2A', 'AM_2A', '必修', 4, '深化数学知识，包括微积分、矩阵理论等'),
       ('思想道德修养与法律基础', 'MALS001', '必修', 2, '培养学生的道德素质和法律意识'),
       ('体育A', 'PE_A', '必修', 1, '提高学生的身体素质和运动技能'),
       ('英语读写译1A', 'ERWT_1A', '必修', 3, '提升学生的英语阅读、写作和翻译能力'),
       ('英语听力1A', 'EL_1A', '必修', 2, '提高学生的英语听力理解能力'),
       ('英语口语1A', 'ES_1A', '必修', 2, '提升学生的英语口语表达能力'),
       ('法制安全教育', 'LASE001', '必修', 1, '增强学生的法制观念和安全意识'),
       ('大学二外日语A', 'JSFL_A', '选修', 3, '学习基础的日语语法和词汇'),
       ('军事理论', 'MT01', '必修', 2, '了解军事基本理论和国防知识'),
       ('程序设计实践', 'PP02', '必修', 3, '通过实践项目提升编程能力'),
       ('高等数学2B', 'AM_2B', '必修', 4, '进一步深化高等数学知识'),
       ('中国近现代史纲要', 'OFCMH010', '必修', 2, '概述中国近现代历史发展脉络'),
       ('体育B', 'PE_B', '必修', 1, '继续提升学生的身体素质和运动技能'),
       ('英语听力1B', 'EL_1B', '必修', 2, '进一步提高学生的英语听力理解能力'),
       ('英语读写译1B', 'ERWT_1B', '必修', 3, '深化英语阅读、写作和翻译能力'),
       ('英语口语1B', 'ES_1B', '必修', 2, '进一步提升学生的英语口语表达能力'),
       ('大学生心理健康', 'CSMH01', '必修', 2, '关注和提升大学生的心理健康水平'),
       ('大学物理2A', 'UP_2A', '必修', 4, '学习大学物理的基础理论和实验'),
       ('数字逻辑', 'DL002', '必修', 3, '学习数字电路和逻辑设计的基础知识'),
       ('C++面向对象程序设计', 'CPOB02', '必修', 4, '深入学习C++的面向对象特性及其应用'),
       ('创新人才与大学文化', 'IND010', '选修', 2, '探讨创新人才培养和大学文化建设'),
       ('数据结构', 'DS001', '必修', 4, '学习各种数据结构及其算法'),
       ('Java语言程序设计', 'JS012', '必修', 4, '学习Java编程语言及其应用'),
       ('离散数学导论', 'IDTM01', '必修', 3, '介绍离散数学的基础知识和应用'),
       ('计算机网络', 'CN002', '必修', 4, '学习计算机网络的基础理论和协议');


CREATE TABLE attendance_records
(
    record_id  INT AUTO_INCREMENT PRIMARY KEY,
    course_id  INT  NOT NULL,
    student_id INT  NOT NULL,
    date       DATE NOT NULL,
    status     ENUM('present', 'absent', 'late', 'excused'),
    FOREIGN KEY (course_id) REFERENCES course (course_id),
    FOREIGN KEY (student_id) REFERENCES student (student_id)
);


CREATE TABLE major
(
    id       INT AUTO_INCREMENT PRIMARY KEY,
    major_id VARCHAR(20) NOT NULL UNIQUE,
    major    VARCHAR(255)
);


INSERT INTO major(major_id,major)
values ('000', '计算机科学与技术'),
       ('001', '电子工程'),
       ('002', '经济学'),
       ('003', '生物学');

CREATE TABLE student
(
    student_id     INT AUTO_INCREMENT PRIMARY KEY,
    user_id        INT          NOT NULL,
    student_number VARCHAR(20)  NOT NULL UNIQUE,
    student_name   VARCHAR(255) NOT NULL,
    class_name     VARCHAR(20)  NOT NULL,
    major_id       VARCHAR(20)  NOT NULL,
    FOREIGN KEY (user_id) REFERENCES user (user_id),
    FOREIGN KEY (major_id) REFERENCES major (major_id)
);

INSERT INTO student (user_id, student_number, student_name, class_id)
VALUES (5,'王伟', 202300001000, 1),
       (6,'李娜', 202300001001, 1),
       (7,'张伟', 202300001002, 1),
       (8,'刘洋', 202300001003, 1),
       (9,'陈敏', 202300001004, 1),
       (10,'杨静', 202300001005, 2),
       (11,'赵媛媛', 202300001006, 2),
       (12,'黄进', 202300001007, 2),
       (13,'周杰', 202300001008, 2),
       (14,'吴琳', 202300001009, 2),
       (15,'徐涛', 202300001010, 3),
       (16,'孙怡', 202300001011, 3),
       (17,'朱元璋', 202300001012, 3),
       (18,'马云', 202300001013, 3),
       (19,'胡雪', 202300001014, 3),
       (20,'郭敬明', 202300001015, 4),
       (21,'林芳', 202300001016, 4),
       (22,'段誉', 202300001017, 4),
       (23,'曹操', 202300001018, 4),
       (24,'刘备', 202300001019, 4);

CREATE TABLE teacher
(
    teacher_id     INT AUTO_INCREMENT,
    name           VARCHAR(100) NOT NULL,
    user_id        INT,
    teacher_number VARCHAR(20)  NOT NULL UNIQUE,
    PRIMARY KEY (teacher_id),
    FOREIGN KEY (user_id) REFERENCES user (user_id)
);

INSERT INTO teacher (name, user_id)
VALUES ('教师1', 1),
       ('教师2', 2),
       ('教师3', 3),
       ('教师4', 4);

CREATE TABLE major_course
(
    id        INT AUTO_INCREMENT PRIMARY KEY,
    major_id  VARCHAR(20) NOT NULL,
    course_id INT         NOT NULL,
    FOREIGN KEY (major_id) REFERENCES major (major_id),
    FOREIGN KEY (course_id) REFERENCES course (course_id)
);

INSERT INTO major_course (major_id, course_id) VALUES
 ('000',1),
 ('000',2),
 ('000',3),
 ('000',4),
 ('000',5),
 ('000',6),
 ('000',7),
 ('000',8);

CREATE TABLE teacher_class_course
(
    id             INT AUTO_INCREMENT,
    teacher_number VARCHAR(20) NOT NULL,
    course_id      INT         NOT NULL,
    class_name     VARCHAR(20) NOT NULL,
    major_id       VARCHAR(20) NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (teacher_number) REFERENCES teacher (teacher_number),
    FOREIGN KEY (course_id) REFERENCES course (course_id),
    FOREIGN KEY (major_id) REFERENCES major (major_id)
);

INSERT INTO teacher_class_course(teacher_number, course_id, class_name,major_id) VALUES
('G0000',1,'2023级01班','000'),
('G0000',3,'2023级01班','000'),
('G0001',2,'2023级01班','000'),
('G0001',4,'2023级01班','000');


CREATE TABLE schedule
(
    schedule_id    INT AUTO_INCREMENT UNIQUE,
    day_of_week    INT,
    period_id      INT,
    teacher_number INT,
    class_number   INT,
    course_id      INT,
    PRIMARY KEY (schedule_id),
    FOREIGN KEY (period_id) REFERENCES time_period (period_id),
    FOREIGN KEY (teacher_number) REFERENCES teacher (teacher_number),
    FOREIGN KEY (course_id) REFERENCES course (course_id)
);


INSERT INTO schedule (day_of_week, period_id, teacher_number, class_number, course_id) VALUES
(1,1,'G0000','2023级01班',1),
(1,2,'G0000','2023级01班',3),
(1,3,'G0001','2023级01班',2),
(1,4,'G0001','2023级01班',4),
(2,1,'G0001','2023级01班',4),
(2,2,'G0001','2023级01班',2),
(2,3,'G0000','2023级01班',1),
(2,4,'G0000','2023级01班',3),
(3,1,'G0000','2023级01班',1),
(3,2,'G0000','2023级01班',3),
(3,3,'G0001','2023级01班',2),
(3,4,'G0001','2023级01班',4),
(4,1,'G0001','2023级01班',4),
(4,2,'G0001','2023级01班',2),
(4,3,'G0000','2023级01班',1),
(4,4,'G0000','2023级01班',3),
(1,1,'G0000','2023级01班',1),
(1,2,'G0000','2023级01班',3),
(1,3,'G0001','2023级01班',2),
(1,4,'G0001','2023级01班',4);

CREATE TABLE time_period
(
    period_id   INT AUTO_INCREMENT UNIQUE,
    period_name VARCHAR(10),
    start_time  TIME,
    end_time    TIME,
    PRIMARY KEY (period_id)
);

INSERT INTO time_period (period_name, start_time, end_time)
VALUES ('一、二节', '08:00:00', '09:30:00'),
       ('三、四节', '10:00:00', '11:30:00'),
       ('五、六节', '14:30:00', '16:00:00'),
       ('七、八节', '16:30:00', '18:00:00');

