USE teachcloud_db;

ALTER TABLE obe_culture_program_requirement ADD UNIQUE INDEX obe_culture_program_requirement_unique (culture_program_id ASC, name ASC);

CREATE TABLE obe_course_outline_audit_report (
         id BIGINT NOT NULL,
         course_outline_id BIGINT NOT NULL,
         weight_setting_sign BIGINT NULL COMMENT '课程权重设置标识',
         course_basic_info MEDIUMTEXT NULL COMMENT '课程基础信息',
         course_target_info MEDIUMTEXT NULL COMMENT '课程目标情况',
         rationality_evaluation MEDIUMTEXT NULL COMMENT '合理性评价',
         PRIMARY KEY (id)
)  ENGINE=INNODB DEFAULT CHARACTER SET=UTF8MB4 COLLATE=utf8mb4_general_ci COMMENT='课程目标达成情况评价依据合理性审核表';

INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3060', '课程大纲-审核', '/api/admin/obe/course_outline/audit_report', 'URL', '3000', '7', 'AUTH', '1', '1', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3061', '课程大纲-审核及合理性', '/api/admin/obe/course_outline/audit_rationality_report', 'URL', '3000', '8', 'AUTH', '1', '1', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3062', '课程大纲-审核报告保存', '/api/admin/obe/course_outline/audit/save', 'URL', '3000', '9', 'AUTH', '1', '1', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, related, enable, default_auth, front_display) VALUES ('3063', '审核', 'Audit', 'LINK', '3000', '8', 'AUTH', '3060,3062', '1', '0', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, related, enable, default_auth, front_display) VALUES ('3064', '审核&合理性', 'AuditAndRationality', 'LINK', '3000', '9', 'AUTH', '3061,3062', '1', '0', '1');

ALTER TABLE sys_config CHANGE COLUMN config_value config_value MEDIUMTEXT NULL COMMENT '参数键值' ;

INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3070', '学号配置保存', '/api/admin/set/student_number_config/save', 'URL', '508', '17', 'AUTH', '1', '0', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3071', '学号配置查询', '/api/admin/set/student_number_config/select', 'URL', '508', '18', 'AUTH', '1', '0', '1');

INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3072', '查询学号字母映射关系', '/api/scan/config/student_number_letter_relation', 'URL', '970', '40', 'AUTH', '1', '1', '1');

ALTER TABLE scan_paper_page ADD COLUMN paper_type VARCHAR(10) NULL COMMENT '卷型' AFTER recog_data;

INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3073', '卷型检查任务-状态数量', '/api/scan/student/paper_type_check/status/count', 'URL', '970', '41', 'AUTH', '1', '1', '1');
INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3074', '卷型检查任务-任务确认', '/api/scan/student/paper_type_check/confirm', 'URL', '970', '42', 'AUTH', '1', '1', '1');
UPDATE sys_privilege SET related = '971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1007,1009,1010,1148,3072,3073,3074' WHERE (id = '970');
UPDATE sys_privilege SET related = '971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1007,1009,1010,1148,3072,3073,3074' WHERE (id = '1006');

ALTER TABLE scan_paper_page CHANGE COLUMN paper_type paper_type TEXT NULL COMMENT '卷型';

UPDATE sys_privilege SET property = 'SYS', default_auth = '1' WHERE (id = '3071');

INSERT INTO sys_privilege (id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display) VALUES(2111, '平时成绩-获取作业集合', '/api/admin/course/degree/usual_score/template_download/list', 'URL', 2006, 1, 'AUTH', NULL, 1, 1, 1);
UPDATE sys_privilege SET name='管理成绩', url='Score', `type`='LINK', parent_id=2001, `sequence`=1, property='AUTH', related='2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2029,2030,2031,2032,2033,2034,3018,2111', enable=1, default_auth=0, front_display=1 WHERE id=2006;

ALTER TABLE t_c_usual_score ADD source varchar(50) NULL COMMENT '来源，EXCEL_IMPORT：excel导入，SYNC：数据同步';
ALTER TABLE t_c_usual_score CHANGE source source varchar(50) NULL COMMENT '来源，EXCEL_IMPORT：excel导入，SYNC：数据同步' AFTER enable;
ALTER TABLE t_c_final_score MODIFY COLUMN score_detail mediumtext NULL COMMENT '成绩明细';
ALTER TABLE t_c_final_score MODIFY COLUMN score double NULL COMMENT '分数';
ALTER TABLE t_c_usual_score MODIFY COLUMN score mediumtext NULL COMMENT '平常作业分数';
ALTER TABLE t_c_usual_score ADD teach_class_name varchar(100) NOT NULL COMMENT '教学班';
ALTER TABLE t_c_usual_score CHANGE teach_class_name teach_class_name varchar(100) NOT NULL COMMENT '教学班' AFTER source;
ALTER TABLE t_c_final_score ADD teach_class_name varchar(100) NOT NULL COMMENT '教学班';
ALTER TABLE t_c_final_score CHANGE teach_class_name teach_class_name varchar(100) NOT NULL COMMENT '教学班' AFTER source;
ALTER TABLE t_r_basic_info ADD teach_class_name varchar(100) NOT NULL COMMENT '教学班';
ALTER TABLE t_r_basic_info CHANGE teach_class_name teach_class_name varchar(100) NOT NULL COMMENT '教学班' AFTER enable;
ALTER TABLE t_r_basic_info DROP KEY t_r_basic_info_unique;
ALTER TABLE t_r_basic_info ADD CONSTRAINT t_r_basic_info_unique UNIQUE KEY (culture_program_id,course_id,exam_id,paper_number,teach_class_name);

UPDATE sys_privilege SET name='成绩管理', url='TargetScoreManage', `type`='MENU', parent_id=2100, `sequence`=1, property=NULL, related='2003,2004,2005,3053', enable=1, default_auth=0, front_display=1 WHERE id=2001;

ALTER TABLE `exam_task_detail` CHANGE COLUMN `draw_count` `open_ab` TINYINT(1) NULL DEFAULT 0 COMMENT '是否开启AB卷' ;
update exam_task_detail set open_ab = (case open_ab when 1 then 0 else 1 end);

ALTER TABLE `basic_print_config` ADD COLUMN `open_ab` TINYINT(1) NULL DEFAULT 0 COMMENT '是否开启AB卷' AFTER `card_rule_id`;
ALTER TABLE `mark_student` ADD COLUMN `omr_breach` TINYINT(1) NULL DEFAULT 0 COMMENT '识别违纪' AFTER `omr_absent_checked`;
ALTER TABLE mark_student ADD COLUMN paper_type_check_status VARCHAR(32) NOT NULL DEFAULT 'NORMAL' COMMENT '卷型检查状态' AFTER omr_breach;
UPDATE mark_student SET paper_type_check_status = 'NORMAL' WHERE paper_type_check_status = '' or paper_type_check_status is null;

ALTER TABLE `exam_task_detail`
DROP COLUMN `open_ab`,
ADD COLUMN `serial_number` int(2) NULL COMMENT '备用卷序号（1,2,3,4…）' AFTER `exam_task_id`,
ADD COLUMN `exposed` TINYINT(1) NULL DEFAULT 0 COMMENT '是否曝光' AFTER `remark`;
ALTER TABLE `exam_task_detail` ADD COLUMN `exposed_exam_id` BIGINT(20) NULL COMMENT '曝光的考试ID' AFTER `exposed`;

ALTER TABLE `exam_task` ADD COLUMN `open_ab` TINYINT(1) NULL DEFAULT 0 COMMENT '是否开启AB卷' AFTER `paper_number`;

ALTER TABLE `basic_card_rule`
    ADD COLUMN `contains_letter` TINYINT(1) NULL DEFAULT 0 COMMENT '学号是否包含字母' AFTER `default_option_number`,
ADD COLUMN `relation_list` VARCHAR(500) NULL COMMENT '学号字母所在位置坐标' AFTER `contains_letter`;

ALTER TABLE `exam_task`
    ADD COLUMN `paper_confirm_attachment_ids` TEXT NULL AFTER `exam_task_content`,
ADD COLUMN `remark` VARCHAR(200) NULL AFTER `paper_confirm_attachment_ids`;

update exam_task et set et.paper_confirm_attachment_ids = (select paper_confirm_attachment_ids from exam_task_detail etd where et.id = etd.exam_task_id);
update exam_task et set et.remark = (select remark from exam_task_detail etd where et.id = etd.exam_task_id);

ALTER TABLE `exam_detail_course` ADD COLUMN `serial_number` INT(2) NULL COMMENT '备用卷' AFTER `update_time`;
ALTER TABLE `mark_paper` ADD COLUMN `serial_number` INT(1) NULL COMMENT '备用卷' AFTER `user_id`;
ALTER TABLE `mark_paper_package` ADD COLUMN `serial_number` INT(1) NULL COMMENT '备用卷序号' AFTER `course_paper_id`;
ALTER TABLE `mark_student` ADD COLUMN `serial_number` INT(2) NULL COMMENT '备用卷序号' AFTER `course_paper_id`;
ALTER TABLE `scan_answer_card` ADD COLUMN `serial_number` INT(2) NULL COMMENT '备用卷序号' AFTER `course_paper_id`;

CREATE TABLE `mark_question_answer` (
        `id` BIGINT(20) NOT NULL,
        `exam_id` BIGINT(20) NULL COMMENT '考试ID',
        `paper_number` VARCHAR(50) NULL COMMENT '试卷编号',
        `paper_type` VARCHAR(10) NULL COMMENT '卷型',
        `main_number` INT NULL COMMENT '大题号',
        `sub_number` INT NULL COMMENT '小题号',
        `answer` VARCHAR(16) NULL COMMENT '客观题标答',
        `objective_policy` VARCHAR(16) NULL COMMENT '判分策略',
        `objective_policy_score` DOUBLE NULL COMMENT '客观题判分策略计分（漏选给分）',
        `create_id` BIGINT(20) NULL,
        `create_time` BIGINT(20) NULL,
        `update_id` BIGINT(20) NULL,
        `update_time` BIGINT(20) NULL,
        PRIMARY KEY (`id`))
    COMMENT = '客观题信息';

ALTER TABLE `exam_task` ADD COLUMN `exam_task_detail_enable` TINYINT(1) NULL DEFAULT 1 COMMENT '卷库启用禁用状态。是否启用，false：停用，true：启用' AFTER `enable`;

-- 2024-10-24
INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(2114, '试卷清除信息', '/api/admin/course/degree/final_score/paper_struct/clear', 'URL', 2006, 1, 'AUTH', NULL, 1, 1, 1);

UPDATE sys_privilege
SET name='管理成绩', url='Score', `type`='LINK', parent_id=2001, `sequence`=1, property='AUTH', related='2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2029,2030,2031,2032,2033,2034,3018,2111,2114', enable=1, default_auth=0, front_display=1
WHERE id=2006;
