/*
 Navicat Premium Dump SQL

 Source Server         : DockerMySQLDB
 Source Server Type    : MySQL
 Source Server Version : 90500 (9.5.0)
 Source Host           : localhost:3306
 Source Schema         : score_management

 Target Server Type    : MySQL
 Target Server Version : 90500 (9.5.0)
 File Encoding         : 65001

 Date: 21/12/2025 22:47:56
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for classes
-- ----------------------------
DROP TABLE IF EXISTS `classes`;
CREATE TABLE `classes`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '班级ID',
  `class_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '班级名称',
  `grade` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '年级',
  `major` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '专业',
  `teacher_id` int NULL DEFAULT NULL COMMENT '班主任ID',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_class_name`(`class_name` ASC) USING BTREE,
  INDEX `idx_teacher_id`(`teacher_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '班级表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of classes
-- ----------------------------
INSERT INTO `classes` VALUES (1, '计算机2301', '2023', '计算机科学与技术', 2001, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `classes` VALUES (2, '软件工程2302', '2023', '软件工程', 2002, '2025-12-21 14:23:14', '2025-12-21 14:23:14');

-- ----------------------------
-- Table structure for courses
-- ----------------------------
DROP TABLE IF EXISTS `courses`;
CREATE TABLE `courses`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '课程ID',
  `course_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '课程代码',
  `course_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '课程名称',
  `credit` decimal(3, 1) NOT NULL DEFAULT 2.0 COMMENT '学分',
  `teacher_id` int NOT NULL COMMENT '授课教师ID',
  `class_id` int NOT NULL COMMENT '授课班级ID',
  `semester` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '学期',
  `academic_year` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '学年',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `course_code`(`course_code` ASC) USING BTREE,
  INDEX `idx_course_code`(`course_code` ASC) USING BTREE,
  INDEX `idx_teacher_id`(`teacher_id` ASC) USING BTREE,
  INDEX `idx_class_id`(`class_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '课程表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of courses
-- ----------------------------
INSERT INTO `courses` VALUES (1, 'CS101', '高级程序设计', 4.0, 2001, 1, NULL, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `courses` VALUES (2, 'SE201', '软件工程导论', 3.0, 2002, 2, NULL, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `courses` VALUES (3, 'MAT101', '高等数学', 5.0, 2003, 1, NULL, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');

-- ----------------------------
-- Table structure for grades
-- ----------------------------
DROP TABLE IF EXISTS `grades`;
CREATE TABLE `grades`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '成绩ID',
  `student_id` int NOT NULL COMMENT '学生ID',
  `course_id` int NOT NULL COMMENT '课程ID',
  `usual_score` decimal(5, 2) NULL DEFAULT NULL COMMENT '平时成绩',
  `midterm_score` decimal(5, 2) NULL DEFAULT NULL COMMENT '期中成绩',
  `final_score` decimal(5, 2) NULL DEFAULT NULL COMMENT '期末成绩',
  `total_score` decimal(5, 2) NULL DEFAULT NULL COMMENT '总评成绩',
  `grade_point` decimal(3, 2) NULL DEFAULT NULL COMMENT '绩点',
  `grade_level` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '成绩等级（A/B/C/D/F）',
  `teacher_id` int NOT NULL COMMENT '录入教师ID',
  `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '备注',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_student_course`(`student_id` ASC, `course_id` ASC) USING BTREE,
  INDEX `idx_student_id`(`student_id` ASC) USING BTREE,
  INDEX `idx_course_id`(`course_id` ASC) USING BTREE,
  INDEX `idx_teacher_id`(`teacher_id` ASC) USING BTREE,
  INDEX `idx_total_score`(`total_score` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '成绩表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of grades
-- ----------------------------
INSERT INTO `grades` VALUES (1, 3001, 1, 90.00, 85.00, 88.00, 87.70, 3.00, NULL, 2001, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `grades` VALUES (2, 3001, 3, 80.00, 75.00, 82.00, 79.30, 2.00, NULL, 2003, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `grades` VALUES (3, 3002, 1, 95.00, 92.00, 94.00, 93.70, 4.00, NULL, 2001, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `grades` VALUES (4, 3003, 2, 88.00, 80.00, 85.00, 84.40, 3.00, NULL, 2002, NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');

-- ----------------------------
-- Table structure for operation_logs
-- ----------------------------
DROP TABLE IF EXISTS `operation_logs`;
CREATE TABLE `operation_logs`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '日志ID',
  `user_id` int NOT NULL COMMENT '操作用户ID',
  `operation_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '操作类型',
  `operation_target` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作目标',
  `operation_details` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '操作详情',
  `ip_address` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'IP地址',
  `user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '用户代理',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_user_id`(`user_id` ASC) USING BTREE,
  INDEX `idx_operation_type`(`operation_type` ASC) USING BTREE,
  INDEX `idx_created_at`(`created_at` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of operation_logs
-- ----------------------------

-- ----------------------------
-- Table structure for scores
-- ----------------------------
DROP TABLE IF EXISTS `scores`;
CREATE TABLE `scores`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '成绩记录ID',
  `student_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '学生ID',
  `course` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '课程名称',
  `score` decimal(5, 2) NOT NULL COMMENT '成绩',
  `teacher_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '教师ID',
  `class` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '班级',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_student_id`(`student_id` ASC) USING BTREE,
  INDEX `idx_teacher_id`(`teacher_id` ASC) USING BTREE,
  INDEX `idx_class`(`class` ASC) USING BTREE,
  CONSTRAINT `scores_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
  CONSTRAINT `scores_ibfk_2` FOREIGN KEY (`teacher_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
  CONSTRAINT `scores_chk_1` CHECK ((`score` >= 0) and (`score` <= 100))
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '成绩记录表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of scores
-- ----------------------------

-- ----------------------------
-- Table structure for sessions
-- ----------------------------
DROP TABLE IF EXISTS `sessions`;
CREATE TABLE `sessions`  (
  `session_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `expires` int UNSIGNED NOT NULL,
  `data` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
  PRIMARY KEY (`session_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of sessions
-- ----------------------------
INSERT INTO `sessions` VALUES ('KY6QaavAiws7rkdEBFIFDoHefl2bxzlI', 1766334525, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:28:44.650Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('KaDFs4HogLmkjS0HAs6qki6g2FmE3sTL', 1766334465, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:27:45.314Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('P-_AKfysnsUwA6PypoYdyXCxa-_8TiCE', 1766414033, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-22T14:25:01.323Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"3001\",\"name\":\"陈同学\",\"role\":\"student\",\"class\":\"计算机2301\",\"studentInfo\":{\"id\":\"3001\",\"name\":\"陈同学\",\"class\":\"计算机2301\"}}}');
INSERT INTO `sessions` VALUES ('QAhXDQ1FOlhU6RhaFOm3ghRtLOW4hBTd', 1766334812, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:33:31.987Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('SAuQyktAI9gAHpXbjARpe-9BL42pDRiV', 1766334764, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:32:43.695Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('XduN1lYhGPeIaLTHbLTNVnTCBtKUCkJR', 1766334689, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:31:28.994Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('Y59PFvvqK7M0DKZshc6ONTmFQjzGyMmV', 1766334426, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:27:05.673Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('rlscT2Pi2EAyLXHs1CNXyQmNSiW8vEo4', 1766334271, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T16:24:30.682Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"teststudent\",\"name\":\"????\",\"role\":\"student\",\"class\":\"2023?1?\"}}');
INSERT INTO `sessions` VALUES ('rsaOCJRjYQLPtUWlDmUFJgWcCYZbOCgJ', 1766410574, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-21T15:54:39.935Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"123\",\"name\":\"经济局\",\"role\":\"student\",\"class\":\"123\"}}');
INSERT INTO `sessions` VALUES ('wXxRpNTGY0wqLaHsebSAsw1I6Pb7Ed6w', 1766410584, '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2025-12-22T13:35:43.191Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"user\":{\"id\":\"567\",\"name\":\"急急急\",\"role\":\"teacher\",\"class\":\"567\"}}');

-- ----------------------------
-- Table structure for students
-- ----------------------------
DROP TABLE IF EXISTS `students`;
CREATE TABLE `students`  (
  `id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '学生ID（与users表id一致）',
  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '姓名',
  `class` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '班级',
  PRIMARY KEY (`id`) USING BTREE,
  CONSTRAINT `students_ibfk_1` FOREIGN KEY (`id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '学生详细信息表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of students
-- ----------------------------
INSERT INTO `students` VALUES ('3001', '陈同学', '计算机2301');
INSERT INTO `students` VALUES ('3002', '林同学', '计算机2301');
INSERT INTO `students` VALUES ('3003', '黄同学', '软件工程2302');
INSERT INTO `students` VALUES ('3004', '吴同学', '软件工程2302');

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users`  (
  `id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户ID（学号/工号）',
  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '姓名',
  `password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '密码（bcrypt加密）',
  `role` enum('student','teacher','admin') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '角色',
  `class` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '班级（学生和教师需要，管理员为NULL）',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_role`(`role` ASC) USING BTREE,
  INDEX `idx_class`(`class` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('1000', '超级管理员', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'admin', NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('2001', '张教授', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'teacher', NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('2002', '李老师', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'teacher', NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('2003', '王助教', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'teacher', NULL, '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('3001', '陈同学', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'student', '计算机2301', '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('3002', '林同学', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'student', '计算机2301', '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('3003', '黄同学', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'student', '软件工程2302', '2025-12-21 14:23:14', '2025-12-21 14:23:14');
INSERT INTO `users` VALUES ('3004', '吴同学', '$2a$10$clM161mG1P9oAkxs6yQq5ugu83Gc/hrnVuL.zWRC/vBZ./5TWuYGa', 'student', '软件工程2302', '2025-12-21 14:23:14', '2025-12-21 14:23:14');

SET FOREIGN_KEY_CHECKS = 1;
