USE teachcloud_db;

-- 2025-04-10
ALTER TABLE `mark_paper` ADD COLUMN `ai_mark` VARCHAR(12) NULL DEFAULT 'NONE' COMMENT 'AI评卷（NONE：不开启，AI_ONLY：仅AI评卷，MAN_MACHINE：人机双评）' AFTER `archive`;

ALTER TABLE `mark_question` ADD COLUMN `ai_mark` VARCHAR(12) NULL DEFAULT 'NONE' COMMENT 'AI评卷（NONE：不开启，AI_ONLY：仅AI评卷，MAN_MACHINE：人机双评）' AFTER `left_count`;

ALTER TABLE `mark_task` ADD COLUMN `ai_marked` TINYINT(1) NULL DEFAULT 0 COMMENT '是否AI评卷' AFTER `reject_reason`;

CREATE TABLE `mark_ocr_student_question` (
    `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',
    `number` INT(1) NULL COMMENT '图片序号',
    `md5` VARCHAR(45) NULL COMMENT '图片md5',
    `ocr_content` MEDIUMTEXT NULL COMMENT 'ocr识别内容',
    `create_time` BIGINT(20) NULL COMMENT '识别时间',
    PRIMARY KEY (`id`))
    COMMENT = '考生主观题小题OCR识别结果';

DROP TABLE IF EXISTS `mark_ai_question_param`;
CREATE TABLE `mark_ai_question_param` (
                                          `id` bigint NOT NULL COMMENT '主键',
                                          `question_id` bigint NOT NULL COMMENT '题目id',
                                          `exam_id` bigint NOT NULL COMMENT '考试id',
                                          `course_id` bigint NOT NULL COMMENT '科目id',
                                          `paper_number` varchar(100) NOT NULL COMMENT '试卷类型',
                                          `mode` varchar(30) NOT NULL COMMENT '评分模式，POINT：按得分点，LEVEL：按档次',
                                          `main_title` varchar(1000) NOT NULL COMMENT '试题题干',
                                          `min_score` double NOT NULL COMMENT '最小分',
                                          `create_id` bigint DEFAULT NULL COMMENT '创建人id',
                                          `create_time` bigint DEFAULT NULL COMMENT '创建时间',
                                          `update_id` bigint DEFAULT NULL COMMENT '更新人id',
                                          `update_time` bigint DEFAULT NULL COMMENT '更新时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI评卷参数表';

DROP TABLE IF EXISTS `mark_ai_question_score`;
CREATE TABLE `mark_ai_question_score` (
                                          `id` bigint NOT NULL COMMENT '主键',
                                          `ai_question_id` bigint NOT NULL COMMENT 'AI评卷参数id',
                                          `score` double NOT NULL COMMENT '分值',
                                          `answer` varchar(1000) NOT NULL COMMENT '标答',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI评卷得分明细表';

DROP TABLE IF EXISTS `mark_ai_question_level`;
CREATE TABLE `mark_ai_question_level` (
                                          `id` bigint NOT NULL COMMENT '主键',
                                          `ai_question_id` bigint NOT NULL COMMENT 'AI评卷参数id',
                                          `min_score` double NOT NULL COMMENT '最小分值',
                                          `max_score` double NOT NULL COMMENT '最大分值',
                                          `answer` varchar(1000) NOT NULL COMMENT '标答',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI评卷得分明细表';

ALTER TABLE `mark_question` ADD COLUMN `person_task` TINYINT(1) NULL DEFAULT 1 COMMENT '是否有人评任务' AFTER `ai_mark`;

-- 2025-04-11
RENAME TABLE mark_ai_question_score TO mark_ai_question_point;

ALTER TABLE mark_ai_question_param ADD CONSTRAINT mark_ai_question_param_unique UNIQUE KEY (question_id);

INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(1222, 'AI评卷参数新增/修改', '/api/admin/mark/ai_question_param/save', 'URL', 897, 1, 'AUTH', NULL, 1, 1, 1);
INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(1223, 'AI评卷参数查询', '/api/admin/mark/ai_question_param/info', 'URL', 897, 1, 'AUTH', NULL, 1, 1, 1);
INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(1224, 'AI智能评卷设置查询', '/api/admin/set/ai/mark/set/select', 'URL', 508, 21, 'AUTH', NULL, 1, 0, 1);
INSERT INTO sys_privilege
(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
VALUES(1225, 'AI智能评卷设置保存', '/api/admin/set/ai/mark/set/save', 'URL', 508, 22, 'AUTH', NULL, 1, 0, 1);