v1.6更新

This commit is contained in:
2026-05-12 22:24:53 +08:00
parent 35bcac54c5
commit 74a71ddaf5
7 changed files with 396 additions and 106 deletions

View File

@@ -138,6 +138,7 @@ CREATE TABLE IF NOT EXISTS `attendance_records` (
`attendance_id` INT PRIMARY KEY AUTO_INCREMENT,
`student_id` INT NOT NULL,
`date` DATE NOT NULL,
`slot` ENUM('morning', 'afternoon', 'evening') DEFAULT 'morning' COMMENT '考勤时段:早上/中午/晚修',
`status` ENUM('present', 'absent', 'late', 'leave') DEFAULT 'present',
`reason` VARCHAR(255) DEFAULT NULL,
`recorder_id` INT NOT NULL,
@@ -149,7 +150,7 @@ CREATE TABLE IF NOT EXISTS `attendance_records` (
FOREIGN KEY (`recorder_id`) REFERENCES `users`(`user_id`),
FOREIGN KEY (`deduction_record_id`) REFERENCES `conduct_records`(`record_id`) ON DELETE SET NULL,
FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`) ON DELETE SET NULL,
UNIQUE KEY `uk_student_date` (`student_id`, `date`)
UNIQUE KEY `uk_student_date_slot` (`student_id`, `date`, `slot`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 操作日志表
@@ -402,6 +403,36 @@ PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 迁移attendance_records 表新增 slot 字段(考勤时段系统 v1.3
SET @column_exists = (
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'classmanagerdb'
AND TABLE_NAME = 'attendance_records'
AND COLUMN_NAME = 'slot'
);
SET @sql = IF(@column_exists = 0,
'ALTER TABLE `attendance_records` ADD COLUMN `slot` ENUM(''morning'', ''afternoon'', ''evening'') DEFAULT ''morning'' COMMENT ''考勤时段:早上/中午/晚修'' AFTER `date`',
'SELECT ''attendance_records.slot already exists'' AS message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 迁移attendance_records 唯一索引从 (student_id, date) 改为 (student_id, date, slot)
SET @index_exists = (
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'classmanagerdb'
AND TABLE_NAME = 'attendance_records'
AND INDEX_NAME = 'uk_student_date_slot'
);
SET @sql = IF(@index_exists = 0,
'ALTER TABLE `attendance_records` DROP INDEX `uk_student_date`, ADD UNIQUE KEY `uk_student_date_slot` (`student_id`, `date`, `slot`)',
'SELECT ''attendance_records.uk_student_date_slot already exists'' AS message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 插入初始科目(仅语数英,如不存在)
INSERT IGNORE INTO `subjects` (`subject_name`, `subject_code`, `sort_order`) VALUES
('语文', 'CHI', 1),