USE teachcloud_db;

ALTER TABLE `mark_question` ADD INDEX `index_1` (`exam_id` ASC, `paper_number` ASC, `main_number` ASC, `sub_number` ASC);

ALTER TABLE `basic_exam_student`
    ADD COLUMN `exam_date` VARCHAR(20) NULL COMMENT '考试日期' AFTER `exam_end_time`,
ADD COLUMN `exam_time` VARCHAR(20) NULL COMMENT '考试时间' AFTER `exam_date`;

update basic_exam_student set exam_date = DATE_FORMAT(FROM_UNIXTIME(exam_start_time/1000), '%Y-%m-%d') where exam_start_time is not null and exam_date is null;
update basic_exam_student set exam_time = concat(DATE_FORMAT(FROM_UNIXTIME(exam_start_time/1000), '%H:%i'),'-',DATE_FORMAT(FROM_UNIXTIME(exam_end_time/1000), '%H:%i')) where exam_start_time is not null and exam_time is null;

ALTER TABLE `exam_detail`
    ADD COLUMN `exam_date` VARCHAR(20) NULL COMMENT '考试日期' AFTER `exam_end_time`,
ADD COLUMN `exam_time` VARCHAR(20) NULL COMMENT '考试时间' AFTER `exam_date`;

update exam_detail set exam_date = DATE_FORMAT(FROM_UNIXTIME(exam_start_time/1000), '%Y-%m-%d') where exam_start_time is not null and exam_date is null;
update exam_detail set exam_time = concat(DATE_FORMAT(FROM_UNIXTIME(exam_start_time/1000), '%H:%i'),'-',DATE_FORMAT(FROM_UNIXTIME(exam_end_time/1000), '%H:%i')) where exam_start_time is not null and exam_time is null;

ALTER TABLE `sys_user_role` ADD INDEX `idx_1` (`role_id` ASC, `user_id` ASC);
ALTER TABLE `t_f_flow_log` DROP INDEX `flow_log_idx` , ADD INDEX `flow_log_idx` USING BTREE (`flow_id`);
ALTER TABLE `exam_task` ADD INDEX `idx_1` (`flow_id` ASC);

-- 2025-02-21
ALTER TABLE `mark_paper`
    ADD COLUMN `merge_marker` TINYINT(1) NULL COMMENT '填空题是否合并设置评卷员' AFTER `double_mark`,
CHANGE COLUMN `open_double_marking` `double_mark` TINYINT(1) NULL DEFAULT '0' COMMENT '是否开启双评：true-开启，false-关闭' ;

ALTER TABLE `mark_question`
    ADD COLUMN `pic_list` MEDIUMTEXT NULL COMMENT '评卷区坐标' AFTER `update_time`,
    ADD COLUMN `double_rate` DOUBLE NULL COMMENT '双评比例' AFTER `pic_list`,
    ADD COLUMN `arbitrate_threshold` DOUBLE NULL COMMENT '仲裁阈值' AFTER `double_rate`,
    ADD COLUMN `score_policy` VARCHAR(10) NULL COMMENT '合分策略' AFTER `arbitrate_threshold`,
    ADD COLUMN `task_count` INT NULL COMMENT '任务总量' AFTER `score_policy`,
    ADD COLUMN `marked_count` INT NULL COMMENT '已评数量' AFTER `task_count`,
    ADD COLUMN `left_count` INT NULL COMMENT '剩余数量' AFTER `marked_count`;

ALTER TABLE `mark_user_group`
    ADD COLUMN `question_id` BIGINT(20) NULL COMMENT '题目ID' AFTER `paper_number`,
ADD COLUMN `enable` TINYINT(1) NULL DEFAULT 1 COMMENT '是否启用' AFTER `reject_count`, RENAME TO  `mark_user_question` ;

ALTER TABLE `mark_task`
    ADD COLUMN `question_id` BIGINT(1) NULL COMMENT '题目ID' AFTER `paper_number`,
ADD COLUMN `marker_track_list` MEDIUMTEXT NULL COMMENT '评卷分数轨迹' AFTER `marker_score_list`,
ADD COLUMN `marker_tag_list` MEDIUMTEXT NULL COMMENT '评卷特殊标记' AFTER `marker_track_list`,
ADD COLUMN `header_track_list` MEDIUMTEXT NULL COMMENT '复核轨迹' AFTER `header_score_list`,
ADD COLUMN `header_tag_list` MEDIUMTEXT NULL COMMENT '复核特殊标记' AFTER `header_track_list`;

ALTER TABLE `mark_subjective_score`
    ADD COLUMN `question_id` BIGINT(20) NULL COMMENT '题目ID' AFTER `paper_number`;

CREATE TABLE `mark_user_paper` (
      `id` BIGINT(20) NOT NULL,
      `exam_id` BIGINT(20) NULL,
      `paper_number` VARCHAR(100) NULL,
      `user_id` BIGINT(20) NULL COMMENT '用户ID',
      `question_model` VARCHAR(10) NULL COMMENT '评卷模式（SINGLE：单题阅，MULTI：多题阅）',
      PRIMARY KEY (`id`))
    COMMENT = '试卷评卷员设置';

ALTER TABLE `mark_problem_history`
    ADD COLUMN `question_id` BIGINT(20) NULL COMMENT '题目ID' AFTER `paper_number`;

ALTER TABLE `mark_arbitrate_history`
    ADD COLUMN `question_id` BIGINT(20) NULL COMMENT '题目ID' AFTER `paper_number`;

ALTER TABLE `mark_reject_history`
    ADD COLUMN `question_id` BIGINT(20) NULL COMMENT '题目ID' AFTER `paper_number`;

CREATE TABLE `mark_header_history` (
          `id` BIGINT(20) NOT NULL,
          `exam_id` BIGINT(20) NULL COMMENT '考试ID',
          `paper_number` VARCHAR(100) NULL COMMENT '试卷编号',
          `student_id` BIGINT(20) NULL COMMENT '考生ID',
          `question_id` BIGINT(20) NULL COMMENT '题目ID',
          `main_number` INT NULL COMMENT '大题号',
          `sub_number` INT NULL COMMENT '小题号',
          `user_id` BIGINT(20) NULL COMMENT '用户ID',
          `score` DOUBLE NULL COMMENT '分数',
          `track_list` MEDIUMTEXT NULL COMMENT '轨迹',
          `original_score` DOUBLE NULL COMMENT '原分数',
          `original_track_list` MEDIUMTEXT NULL COMMENT '原轨迹',
          `create_time` BIGINT(20) NULL COMMENT '创建时间',
          PRIMARY KEY (`id`))
    COMMENT = '复核历史表';

ALTER TABLE `mark_user_paper`
    ADD COLUMN `mode` VARCHAR(45) NULL COMMENT '阅卷模式' AFTER `question_model`;

ALTER TABLE `mark_task`
    ADD COLUMN `main_number` INT NULL COMMENT '大题号' AFTER `question_id`,
ADD COLUMN `sub_nubmer` INT NULL COMMENT '小题号' AFTER `main_number`;

ALTER TABLE `mark_paper`
    CHANGE COLUMN `open_mark_class` `class_mark` TINYINT NULL DEFAULT '0' COMMENT '是否开启分班阅' AFTER `paper_type`;
