USE teachcloud_db;

ALTER TABLE `basic_card_rule` CHANGE COLUMN `name` `name` VARCHAR(100) NOT NULL COMMENT '题卡规则名称' ;
ALTER TABLE `basic_exam` DROP COLUMN `in_used`;
ALTER TABLE `basic_semester` DROP COLUMN `in_used`;

UPDATE `sys_privilege` SET `related` = '620,621,622,623,49' WHERE (`id` = '614');
DELETE FROM `sys_privilege` WHERE (`id` = '646');
DELETE FROM `sys_privilege` WHERE (`id` = '645');

ALTER TABLE `basic_major`
    CHANGE COLUMN `belong_org_id` `belong_org_id` BIGINT NOT NULL COMMENT '所属机构id' AFTER `org_id`,
DROP INDEX `major_schoolId_name_idx` ,
ADD UNIQUE INDEX `major_schoolId_name_idx` USING BTREE (`school_id`, `name`, `belong_org_id`);


ALTER TABLE `basic_clazz`
DROP INDEX `clazz_schoolId_name_idx` ,
ADD UNIQUE INDEX `clazz_schoolId_name_idx` USING BTREE (`school_id`, `major_id`, `clazz_name`);

DELETE FROM `sys_privilege` WHERE (`id` = '425');
DELETE FROM `sys_privilege` WHERE (`id` = '426');
DELETE FROM `sys_privilege` WHERE (`id` = '428');
DELETE FROM `sys_privilege` WHERE (`id` = '429');
DELETE FROM `sys_privilege` WHERE (`id` = '430');
DELETE FROM `sys_privilege` WHERE (`id` = '449');
DELETE FROM `sys_privilege` WHERE (`id` = '306');

UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '224');
UPDATE `sys_privilege` SET `name` = '启用/禁用' WHERE (`id` = '220');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '218');
UPDATE `sys_privilege` SET `name` = '导入' WHERE (`id` = '243');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '230');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '238');
UPDATE `sys_privilege` SET `name` = '生成图片/预览图片' WHERE (`id` = '828');
UPDATE `sys_privilege` SET `name` = '编辑题卡/编辑信息' WHERE (`id` = '630');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '250');
UPDATE `sys_privilege` SET `name` = '启用/禁用' WHERE (`id` = '253');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '511');
UPDATE `sys_privilege` SET `name` = '编辑' WHERE (`id` = '628');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '516');
DELETE FROM `sys_privilege` WHERE (`id` = '460');
DELETE FROM `sys_privilege` WHERE (`id` = '454');
UPDATE `sys_privilege` SET `name` = '导入' WHERE (`id` = '382');
UPDATE `sys_privilege` SET `name` = '批量删除' WHERE (`id` = '570');
UPDATE `sys_privilege` SET `name` = '批量删除' WHERE (`id` = '574');
UPDATE `sys_privilege` SET `name` = '删除' WHERE (`id` = '269');
UPDATE `sys_privilege` SET `name` = '导入' WHERE (`id` = '388');
DELETE FROM `sys_privilege` WHERE (`id` = '265');
UPDATE `sys_privilege` SET `name` = '查询条件' WHERE (`id` = '838');
UPDATE `sys_privilege` SET `name` = '查询' WHERE (`id` = '836');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '840');
UPDATE `sys_privilege` SET `name` = '删除' WHERE (`id` = '837');
UPDATE `sys_privilege` SET `name` = '管理' WHERE (`id` = '841');
UPDATE `sys_privilege` SET `name` = '批量新增' WHERE (`id` = '273');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '274');
UPDATE `sys_privilege` SET `name` = '启用/禁用' WHERE (`id` = '277');
UPDATE `sys_privilege` SET `name` = '指派/更改' WHERE (`id` = '448');
DELETE FROM `sys_privilege` WHERE (`id` = '276');
UPDATE `sys_privilege` SET `name` = '立即申请' WHERE (`id` = '283');
UPDATE `sys_privilege` SET `name` = '新建命题申请' WHERE (`id` = '307');
UPDATE `sys_privilege` SET `name` = '新建任务' WHERE (`id` = '463');
UPDATE `sys_privilege` SET `name` = '查询条件（未审核）' WHERE (`id` = '293');
UPDATE `sys_privilege` SET `name` = '查询条件（已审核）' WHERE (`id` = '297');
UPDATE `sys_privilege` SET `name` = '列表（未审核）' WHERE (`id` = '294');
UPDATE `sys_privilege` SET `name` = '查询（未审核）' WHERE (`id` = '288');
UPDATE `sys_privilege` SET `name` = '列表（已审核）' WHERE (`id` = '298');
UPDATE `sys_privilege` SET `name` = '查询（已审核）' WHERE (`id` = '295');
UPDATE `sys_privilege` SET `name` = '查看详情（已审核）' WHERE (`id` = '296');
UPDATE `sys_privilege` SET `name` = '审核（未审核）' WHERE (`id` = '292');
UPDATE `sys_privilege` SET `name` = '批量通过（未审核）' WHERE (`id` = '291');
UPDATE `sys_privilege` SET `name` = '批量不通过（未审核）', `front_display` = '0' WHERE (`id` = '290');
UPDATE `sys_privilege` SET `name` = '导出审核样本（未审核）' WHERE (`id` = '289');
UPDATE `sys_privilege` SET `name` = '启用/禁用' WHERE (`id` = '302');
DELETE FROM `sys_privilege` WHERE (`id` = '412');
UPDATE `sys_privilege` SET `name` = '新增' WHERE (`id` = '310');
UPDATE `sys_privilege` SET `name` = '模版下载' WHERE (`id` = '317');
UPDATE `sys_privilege` SET `name` = '导出' WHERE (`id` = '318');
DELETE FROM `sys_privilege` WHERE (`id` = '438');
UPDATE `sys_privilege` SET `name` = '查看pdf' WHERE (`id` = '332');
UPDATE `sys_privilege` SET `name` = '作废/恢复' WHERE (`id` = '447');
UPDATE `sys_privilege` SET `front_display` = '0' WHERE (`id` = '495');
UPDATE `sys_privilege` SET `name` = '上传标答文件' WHERE (`id` = '666');
UPDATE `sys_privilege` SET `name` = '查询' WHERE (`id` = '674');
UPDATE `sys_privilege` SET `name` = '查看标答文件' WHERE (`id` = '497');
UPDATE `sys_privilege` SET `front_display` = '0' WHERE (`id` = '496');
UPDATE `sys_privilege` SET `name` = '设置客观题标答' WHERE (`id` = '668');
DELETE FROM `sys_privilege` WHERE (`id` = '174');
UPDATE `sys_privilege` SET `related` = '71,167,424,477,417,420,421,441,442,640,641' WHERE (`id` = '283');
DELETE FROM `sys_privilege` WHERE (`id` = '423');
DELETE FROM `sys_privilege` WHERE (`id` = '424');
DELETE FROM `sys_privilege` WHERE (`id` = '436');
DELETE FROM `sys_privilege` WHERE (`id` = '307');
DELETE FROM `sys_privilege` WHERE (`id` = '140');
INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('174', '导入模板下载', '/api/admin/common/download_import_template', 'URL', '149', '15', 'SYS', '1', '1', '1');
UPDATE `sys_privilege` SET `url` = 'Assign' WHERE (`id` = '448');
DELETE FROM `sys_privilege` WHERE (`id` = '870');
DELETE FROM `sys_privilege` WHERE (`id` = '871');
DELETE FROM `sys_privilege` WHERE (`id` = '46');
UPDATE `sys_privilege` SET `parent_id` = '43' WHERE (`id` = '56');
UPDATE `sys_privilege` SET `parent_id` = '43' WHERE (`id` = '57');
UPDATE `sys_privilege` SET `parent_id` = '43' WHERE (`id` = '58');
UPDATE `sys_privilege` SET `parent_id` = '43' WHERE (`id` = '105');
DELETE FROM `sys_privilege` WHERE (`id` = '327');
DELETE FROM `sys_privilege` WHERE (`id` = '328');
DELETE FROM `sys_privilege` WHERE (`id` = '329');
DELETE FROM `sys_privilege` WHERE (`id` = '330');



ALTER TABLE `exam_card`
    ADD COLUMN `content` MEDIUMTEXT NULL COMMENT '题卡工具制作题卡内容' AFTER `status`,
ADD COLUMN `html_content` MEDIUMTEXT NULL COMMENT 'html格式内容' AFTER `content`,
ADD COLUMN `backup_attachment` MEDIUMTEXT NULL COMMENT '备用题卡json' AFTER `card_rule_id`,
ADD COLUMN `jpg_attachment` TEXT NULL COMMENT '题卡转换成的jpg文件信息' AFTER `backup_attachment`,
CHANGE COLUMN `create_id` `create_id` BIGINT NULL DEFAULT NULL COMMENT '创建人' AFTER `jpg_attachment`,
CHANGE COLUMN `create_time` `create_time` BIGINT NULL DEFAULT NULL COMMENT '创建时间' AFTER `create_id`,
CHANGE COLUMN `update_id` `update_id` BIGINT NULL DEFAULT NULL COMMENT '更新人' AFTER `create_time`,
CHANGE COLUMN `update_time` `update_time` BIGINT NULL DEFAULT NULL COMMENT '更新时间' AFTER `update_id`;

update exam_card a set a.content = (select b.content from exam_card_detail b where a.id = b.card_id);
update exam_card a set a.html_content = (select b.html_content from exam_card_detail b where a.id = b.card_id);
update exam_card a set a.backup_attachment = (select b.attachment_id from exam_card_detail b where a.id = b.card_id);
update exam_card a set a.jpg_attachment = (select b.jpg_attachment_info from exam_card_detail b where a.id = b.card_id);

ALTER TABLE `exam_task` DROP COLUMN `paper_number_id`;

ALTER TABLE `exam_detail_course` DROP COLUMN `org_id`;

update exam_print_plan set status = 'FINISH' where status = 'PRINT_FINISH';
update exam_print_plan set status = 'FINISH' where status = 'END';
update exam_detail set status = 'CANCEL' where status = 'EXPIRED';

ALTER TABLE `exam_detail`
    ADD COLUMN `task_id` BIGINT(20) NULL COMMENT 'pdf生成异步任务ID（t_b_task）' AFTER `backup_count`,
CHANGE COLUMN `create_id` `create_id` BIGINT NULL DEFAULT NULL COMMENT '创建人' AFTER `task_id`,
CHANGE COLUMN `create_time` `create_time` BIGINT NULL DEFAULT NULL COMMENT '创建时间' AFTER `create_id`,
CHANGE COLUMN `update_id` `update_id` BIGINT NULL DEFAULT NULL COMMENT '更新人' AFTER `create_time`,
CHANGE COLUMN `update_time` `update_time` BIGINT NULL DEFAULT NULL COMMENT '更新时间' AFTER `update_id`;

ALTER TABLE `exam_paper_structure`
    ADD COLUMN `object_answer_change` TINYINT(1) NULL DEFAULT '0' COMMENT '客观题答案有提交，需要重新统分。（1：有变动，需要统分，0：不统分）' AFTER `structure_change`;

ALTER TABLE `t_b_sync_task`
    ADD COLUMN `org_code` VARCHAR(45) NULL COMMENT '学院编码' AFTER `object_id`,
    ADD COLUMN `third_relate_name` VARCHAR(300) NULL COMMENT '云阅卷考试名称' AFTER `third_relate_id`,
    ADD COLUMN `exam_time` VARCHAR(20) NULL COMMENT '考试时间' AFTER `third_relate_name`;

ALTER TABLE `exam_card`
    ADD COLUMN `stage_content` MEDIUMTEXT NULL COMMENT '暂存内容（提交后置空）' AFTER `content`;

ALTER TABLE `basic_exam`
    ADD COLUMN `auto_sync_student` TINYINT(1) NULL DEFAULT 0 COMMENT '是否自动同步考务数据（默认否）' AFTER `name`;

ALTER TABLE `sys_role_privilege`
    ADD COLUMN `school_id` BIGINT(20) NULL COMMENT '内置角色，按学校自定义的权限' AFTER `enable`;

INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(880, '重启流程', '/api/admin/exam/task/restart', 'URL', 42, 9, 'AUTH', NULL, 1, 1, 1);
INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(881, '打回', 'Restart', 'LINK', 42, 6, 'AUTH', '880', 1, 0, 1);

CREATE TABLE `exam_paper_class_marker` (
       `id` BIGINT(20) NOT NULL,
       `exam_paper_structure_id` BIGINT(20) NULL COMMENT '评卷参数id',
       `marker_id` BIGINT(20) NULL COMMENT '评卷员id',
       `login_name` VARCHAR(100) NULL COMMENT '评卷员登录名',
       `class_name` MEDIUMTEXT 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`));

ALTER TABLE `exam_paper_structure`
    ADD COLUMN `open_class_reading` TINYINT(1) NULL DEFAULT 0 COMMENT '是否开启分班阅' AFTER `object_answer_change`;

ALTER TABLE `exam_paper_structure`
    CHANGE COLUMN `status` `status` VARCHAR(700) NULL DEFAULT NULL COMMENT '{\n    \"structure\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"group\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"class\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"objective\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"markerLeader\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"marker\":\n    {\n        \"save\": false,\n        \"sync\": false\n    },\n    \"answerFile\":\n    {\n        \"save\": false,\n        \"sync\": false\n    }\n}' ;

INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('882', '查询分班阅班级', '/api/admin/exam/structure/list_user_class', 'URL', '488', '13', 'AUTH', '1', '1', '1');
INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('883', '查询评卷参数状态', '/api/admin/exam/structure/get_structure_status', 'URL', '488', '14', 'AUTH', '1', '1', '1');

UPDATE `sys_privilege` SET `related` = '490,540,667,669,671,672,754,855,882,883' WHERE (`id` = '670');
UPDATE `sys_privilege` SET `name` = '分班阅（开关）', `url` = 'OpenClassReading', `type` = 'BUTTON', `sequence` = '9', `related` = NULL, `enable` = '1', `default_auth` = '0', `front_display` = '1' WHERE (`id` = '495');
DELETE FROM `sys_privilege` WHERE (`id` = '496');
DELETE FROM `sys_privilege` WHERE (`id` = '497');
DELETE FROM `sys_privilege` WHERE (`id` = '666');
DELETE FROM `sys_privilege` WHERE (`id` = '668');
DELETE FROM `sys_privilege` WHERE (`id` = '753');
DELETE FROM `sys_privilege` WHERE (`id` = '854');

ALTER TABLE `exam_paper_structure`
    ADD COLUMN `is_finish` TINYINT(1) NULL DEFAULT 0 COMMENT '是否完成。根据status中组合状态计算。用于当查询条件' AFTER `status`;

ALTER TABLE `t_b_sync_task`
    ADD COLUMN `semester_id` BIGINT(20) NULL COMMENT '学期' AFTER `school_id`,
ADD COLUMN `exam_id` BIGINT(20) NULL COMMENT '考试' AFTER `semester_id`,
ADD COLUMN `course_code` VARCHAR(500) NULL COMMENT '课程代码' AFTER `exam_id`,
ADD COLUMN `course_name` VARCHAR(500) NULL COMMENT '课程名称' AFTER `course_code`,
ADD COLUMN `paper_number` VARCHAR(500) NULL COMMENT '试卷编号' AFTER `course_name`;

ALTER TABLE `t_b_task`
    ADD COLUMN `semester_id` BIGINT(20) NULL COMMENT '学期' AFTER `id`,
ADD COLUMN `exam_id` BIGINT(20) NULL COMMENT '考试' AFTER `semester_id`,
ADD COLUMN `course_code` VARCHAR(500) NULL COMMENT '课程代码' AFTER `exam_id`,
ADD COLUMN `course_name` VARCHAR(500) NULL COMMENT '课程名称' AFTER `course_code`,
ADD COLUMN `paper_number` VARCHAR(500) NULL COMMENT '试卷编号' AFTER `course_name`;

UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '234');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '308');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '512');
INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES ('330', '重新生成pdf', 'CreatePdf', 'LINK', '47', '6', 'AUTH', '190', '1', '0', '1');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '857');
INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('140', '模糊查询-试卷编号', '/api/admin/exam/task/paper_number_query', 'URL', '136', '4', 'SYS', '1', '1', '1');

UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '357');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '359');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '360');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '361');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '372');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '373');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '374');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '375');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '376');
UPDATE `sys_privilege` SET `enable` = '0', `front_display` = '0' WHERE (`id` = '391');

ALTER TABLE `exam_detail_course` ADD COLUMN `clazz_name` MEDIUMTEXT NULL COMMENT '班级（取学生表中的班级集合）' AFTER `clazz_id`;

UPDATE exam_detail_course edc
SET
    edc.clazz_name = (SELECT
                          GROUP_CONCAT(DISTINCT es.clazz_name)
                      FROM
                          exam_student es
                      WHERE
                          clazz_name IS NOT NULL
                        AND edc.id = es.exam_detail_course_id
                      GROUP BY es.exam_detail_course_id);

ALTER TABLE `client_status` ADD INDEX `idx_1` (`school_id` ASC, `exam_detail_id` ASC, `course_code` ASC, `paper_number` ASC, `machine_code` ASC);

delete from t_b_sync_task  where type = 'USER_PUSH';

UPDATE basic_major bm
SET
    bm.belong_org_id = (SELECT
                            a.orgId
                        FROM
                            (SELECT
                                 bc.id, so.id orgId
                             FROM
                                 basic_college bc
                                     LEFT JOIN sys_org so ON bc.school_id = so.school_id
                                     AND bc.college_name = so.name) a
                        WHERE
                                bm.belong_org_id = a.id);

-- 必须在更新basic_major表belong_org_id后执行
UPDATE basic_student t
SET
    t.belong_org_id = (SELECT
                           bm.belong_org_id
                       FROM
                           basic_major bm
                       WHERE
                               t.major_id = bm.id);

UPDATE `sys_config` SET `config_value` = '知学知考' WHERE (`id` = '24');

INSERT INTO `sys_role` (`id`, `school_id`, `org_id`, `name`, `enable`, `type`, `create_id`, `create_time`, `update_id`, `update_time`, `default_role`, `source`, `interpret`) VALUES (12, NULL, NULL, '印刷员', 1, 'PRINT', NULL, NULL, 1, 1691114261182, 1, 'SYS', '系统内置');
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (600, 12, 199, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (601, 12, 200, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (602, 12, 201, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (603, 12, 202, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (604, 12, 203, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (605, 12, 204, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (606, 12, 205, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (607, 12, 206, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (608, 12, 207, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (609, 12, 208, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (610, 12, 209, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (611, 12, 210, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (612, 12, 211, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (613, 12, 212, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (614, 12, 213, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (615, 12, 214, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (616, 12, 215, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (617, 12, 216, 1, NULL);

-- 按顺序执行以下步骤
-- 1.更新t_b_task表exam_id字段
UPDATE t_b_task t
SET
    t.exam_id = (SELECT
                     ed.exam_id
                 FROM
                     exam_detail ed
                 WHERE
                         t.entity_id = ed.id)
WHERE
    t.entity_id IS NOT NULL;
-- 2.更新t_b_task表paper_number字段
UPDATE t_b_task t
SET
    t.paper_number = (SELECT
                          GROUP_CONCAT(edc.paper_number)
                      FROM
                          exam_detail_course edc
                              JOIN
                          exam_detail ed ON edc.exam_detail_id = ed.id
                      WHERE
                              t.school_id = ed.school_id
                        AND t.entity_id = ed.id)
WHERE
    t.entity_id IS NOT NULL;
-- 3.更新t_b_task表course_code字段
UPDATE t_b_task t
SET
    t.course_code = (SELECT
                         GROUP_CONCAT(edc.course_code)
                     FROM
                         exam_detail_course edc
                             JOIN
                         exam_detail ed ON edc.exam_detail_id = ed.id
                     WHERE
                             t.school_id = ed.school_id
                       AND t.entity_id = ed.id)
WHERE
    t.entity_id IS NOT NULL;
-- 4.更新t_b_task表course_name字段
UPDATE t_b_task t
SET
    t.course_name = (SELECT
                         GROUP_CONCAT(edc.course_name)
                     FROM
                         exam_detail_course edc
                             JOIN
                         exam_detail ed ON edc.exam_detail_id = ed.id
                     WHERE
                             t.school_id = ed.school_id
                       AND t.entity_id = ed.id)
WHERE
    t.entity_id IS NOT NULL;
-- 4.更新t_b_task表semester_id字段
UPDATE t_b_task t
SET
    t.semester_id = (SELECT
                         be.semester_id
                     FROM
                         basic_exam be
                     WHERE
                             t.exam_id = be.id);

update exam_paper_structure set is_finish = 1 , status = '{"answerFile":{"save":true,"sync":true},"markerClass":{"save":false,"sync":false},"marker":{"save":true,"sync":true},"markerLeader":{"save":true,"sync":true},"structure":{"save":true,"sync":true},"group":{"save":true,"sync":true},"objective":{"save":true,"sync":true}}' where status = 'FINISH';
update exam_paper_structure set is_finish = 0 , status = '{"answerFile":{"save":false,"sync":false},"markerClass":{"save":false,"sync":false},"marker":{"save":false,"sync":false},"markerLeader":{"save":false,"sync":false},"structure":{"save":false,"sync":false},"group":{"save":false,"sync":false},"objective":{"save":false,"sync":false}}' where status = 'INIT';

UPDATE `sys_privilege` SET `related` = '768' WHERE (`id` = '770');
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (1687280181941567488, 7, 768, 1, NULL);
INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`, `school_id`) VALUES (1687281093103779841, 8, 768, 1, NULL);

-- sys_org表中，学院code要手动加上