use scan_db;
-- ----------------------------
-- Table structure for sc_answer_card
-- ----------------------------
DROP TABLE IF EXISTS `sc_answer_card`;
CREATE TABLE `sc_answer_card`
(
    `exam_id`      bigint       NOT NULL,
    `number`       int          NOT NULL,
    `subject_code` varchar(64)  DEFAULT NULL,
    `subject_name` varchar(64)  DEFAULT NULL,
    `paper_count`  int          NOT NULL,
    `path`         varchar(255) NOT NULL,
    `md5`          varchar(32)  NOT NULL,
    `source`       varchar(16)  NOT NULL,
    `need_adapte`  bit(1)       NOT NULL,
    `single_page`  bit(1)       NOT NULL,
    `slice_config` text         NOT NULL,
    `slice_name`   text         DEFAULT NULL,
    `parameter`    text         DEFAULT NULL,
    `remark`       varchar(255) DEFAULT NULL,
    `creator_id`   bigint       DEFAULT NULL,
    `updater_id`   bigint       DEFAULT NULL,
    `create_time`  bigint       DEFAULT NULL,
    `update_time`  bigint       DEFAULT NULL,
    PRIMARY KEY (`exam_id`, `number`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for sc_exam
-- ----------------------------
DROP TABLE IF EXISTS `sc_exam`;
CREATE TABLE `sc_exam`
(
    `id`                         bigint       NOT NULL AUTO_INCREMENT,
    `school_id`                  bigint       NOT NULL,
    `school_name`                varchar(64)  NOT NULL,
    `name`                       varchar(128) NOT NULL,
    `enable`                     bit(1)       NOT NULL,
    `mode`                       varchar(16)  NOT NULL,
    `scan_by_package`            bit(1)       NOT NULL,
    `allow_unexist_paper`        bit(1)       NOT NULL,
    `answer_front_card_type`     int          NOT NULL,
    `enable_single_page_answer`  bit(1)       NOT NULL,
    `enable_upload`              bit(1)       NOT NULL,
    `enable_sync_verify`         bit(1)       NOT NULL,
    `paper_type_barcode_content` text        DEFAULT NULL,
    `absent_barcode_content`     varchar(16) DEFAULT NULL,
    `image_transfer_mode`        varchar(32) DEFAULT NULL,
    `image_check_ratio`          double      DEFAULT NULL,
	`data_sync_time`             bigint      DEFAULT NULL,
	`card_sync_time`             bigint      DEFAULT NULL,
    `creator_id`                 bigint      DEFAULT NULL,
    `updater_id`                 bigint      DEFAULT NULL,
    `create_time`                bigint      DEFAULT NULL,
    `update_time`                bigint      DEFAULT NULL,
    PRIMARY KEY (`id`),
    INDEX `school_enable` (`enable`, `school_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for sc_omr_task
-- ----------------------------
DROP TABLE IF EXISTS `sc_omr_task`;
CREATE TABLE `sc_omr_task`
(
    `id`           bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`      bigint      NOT NULL,
    `group_id`     bigint      NOT NULL,
    `student_id`   bigint      NOT NULL,
    `paper_number` int         NOT NULL,
    `paper_id`     int         NOT NULL,
    `card_number`  int         NOT NULL,
    `status`       varchar(16) NOT NULL,
    `device`       varchar(64) DEFAULT NULL,
    `pages`        text        NOT NULL,
    `creator_id`   bigint      DEFAULT NULL,
    `updater_id`   bigint      DEFAULT NULL,
    `create_time`  bigint      DEFAULT NULL,
    `update_time`  bigint      DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `group_paper` (`group_id`, `paper_id`),
    KEY `exam_status` (`exam_id`, `status`, `student_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for sc_package_card
-- ----------------------------
DROP TABLE IF EXISTS `sc_package_card`;
CREATE TABLE `sc_package_card`
(
    `id`          bigint       NOT NULL AUTO_INCREMENT,
    `exam_id`     bigint       NOT NULL,
    `path`        varchar(255) NOT NULL,
    `md5`         varchar(32)  NOT NULL,
    `source`      varchar(16)  NOT NULL,
    `creator_id`  bigint DEFAULT NULL,
    `updater_id`  bigint DEFAULT NULL,
    `create_time` bigint DEFAULT NULL,
    `update_time` bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `exam` (`exam_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for sc_package_task
-- ----------------------------
DROP TABLE IF EXISTS `sc_package_task`;
CREATE TABLE `sc_package_task`
(
    `id`           bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`      bigint      NOT NULL,
    `package_code` varchar(64) NOT NULL,
    `status`       varchar(16) NOT NULL,
    `device`       varchar(64) NOT NULL,
    `creator_id`   bigint DEFAULT NULL,
    `updater_id`   bigint DEFAULT NULL,
    `create_time`  bigint DEFAULT NULL,
    `update_time`  bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `exam_package` (`exam_id`, `package_code`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for sc_scanner
-- ----------------------------
DROP TABLE IF EXISTS `sc_scanner`;
CREATE TABLE `sc_scanner`
(
    `device`          varchar(64) NOT NULL,
    `last_login_time` bigint DEFAULT NULL,
    `create_time`     bigint DEFAULT NULL,
    `update_time`     bigint DEFAULT NULL,
    PRIMARY KEY (`device`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Table structure for ss_system_config
-- ----------------------------
DROP TABLE IF EXISTS `sc_system_config`;
CREATE TABLE `sc_system_config`
(
    `id`                   bigint      NOT NULL AUTO_INCREMENT,
    `scanner_enable_login` bit(1)       DEFAULT NULL,
    `scanner_password`     varchar(16)  DEFAULT NULL,
    `system_mode`          varchar(16) NOT NULL,
    `client_version`       varchar(16)  DEFAULT NULL,
    `client_uri`           varchar(255) DEFAULT NULL,
    `client_md5`           varchar(32)  DEFAULT NULL,
    `client_update_time`   bigint       DEFAULT NULL,
    `creator_id`           bigint       DEFAULT NULL,
    `updater_id`           bigint       DEFAULT NULL,
    `create_time`          bigint       DEFAULT NULL,
    `update_time`          bigint       DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_package_result`;
CREATE TABLE `sc_package_result`
(
    `exam_id`      bigint      NOT NULL,
    `package_code` varchar(64) NOT NULL,
    `device`       varchar(64) NOT NULL,
    `path`         text        NOT NULL,
    `assigned`     bit(1)      NOT NULL,
    `creator_id`   bigint DEFAULT NULL,
    `updater_id`   bigint DEFAULT NULL,
    `create_time`  bigint DEFAULT NULL,
    `update_time`  bigint DEFAULT NULL,
    `upload_time`  bigint DEFAULT NULL,
    PRIMARY KEY (`exam_id`, `package_code`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_scanner_card`;
CREATE TABLE `sc_scanner_card`
(
    `exam_id`     bigint      NOT NULL,
    `device`      varchar(64) NOT NULL,
    `card_number` int         NOT NULL,
    `creator_id`  bigint DEFAULT NULL,
    `updater_id`  bigint DEFAULT NULL,
    `create_time` bigint DEFAULT NULL,
    `update_time` bigint DEFAULT NULL,
    PRIMARY KEY (`exam_id`, `device`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_batch`;
CREATE TABLE `sc_batch`
(
    `id`                  bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`             bigint      NOT NULL,
    `device`              varchar(64) NOT NULL,
    `package_code`        varchar(64) DEFAULT NULL,
    `scan_count`          int         NOT NULL,
    `assigned_count`      int         NOT NULL,
    `status`              varchar(16) NOT NULL,
    `verify_status`       varchar(16) DEFAULT NULL,
    `check_status`        varchar(16) DEFAULT NULL,
    `check_image_user_id` bigint      DEFAULT NULL,
    `check_image_time`    bigint      DEFAULT NULL,
    `creator_id`          bigint      DEFAULT NULL,
    `updater_id`          bigint      DEFAULT NULL,
    `create_time`         bigint      DEFAULT NULL,
    `update_time`         bigint      DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `exam_verify_status` (`exam_id`, `verify_status`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_batch_paper`;
CREATE TABLE `sc_batch_paper`
(
    `batch_id`     bigint(20) NOT NULL,
    `student_id`   bigint(20) NOT NULL,
    `paper_number` int(11)    NOT NULL,
    `paper_id`     bigint(20) NOT NULL,
    `card_number`  int(11)    NOT NULL,
    `assigned`     bit(1)     NOT NULL,
    `need_check`   bit(1) DEFAULT NULL,
    PRIMARY KEY (`batch_id`, `student_id`, `paper_number`),
    UNIQUE KEY `paper_id` (`paper_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_paper`;
CREATE TABLE `sc_paper`
(
    `id`              bigint NOT NULL AUTO_INCREMENT,
    `exam_id`         bigint NOT NULL,
    `card_number`     int    NOT NULL,
    `number`          int    NOT NULL,
    `page_count`      int    NOT NULL,
    `mismatch`        bit(1) NOT NULL,
    `assigned`        bit(1) NOT NULL,
    `question_filled` bit(1) NOT NULL,
    `creator_id`      bigint DEFAULT NULL,
    `updater_id`      bigint DEFAULT NULL,
    `create_time`     bigint DEFAULT NULL,
    `update_time`     bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `mismatch` (`exam_id`, `mismatch`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_paper_page`;
CREATE TABLE `sc_paper_page`
(
    `paper_id`    bigint       NOT NULL,
    `page_index`  int          NOT NULL,
    `absent`      text     DEFAULT NULL,
    `breach`      text     DEFAULT NULL,
    `paper_type`  text     DEFAULT NULL,
    `question`    text     DEFAULT NULL,
    `selective`   text     DEFAULT NULL,
    `sheet_path`  varchar(255) NOT NULL,
    `slice_path`  text     DEFAULT NULL,
    `recog_data`  longtext DEFAULT NULL,
    `creator_id`  bigint   DEFAULT NULL,
    `updater_id`  bigint   DEFAULT NULL,
    `create_time` bigint   DEFAULT NULL,
    `update_time` bigint   DEFAULT NULL,
    PRIMARY KEY (`paper_id`, `page_index`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_paper_structure`;
CREATE TABLE `sc_paper_structure`
(
    `id`              bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`         bigint      NOT NULL,
    `card_number`     int         NOT NULL,
    `paper_number`    int         NOT NULL,
    `page_index`      int         NOT NULL,
    `field`           varchar(16) NOT NULL,
    `question_number` int         NOT NULL,
    `single`          bit(1)      NOT NULL,
    `creator_id`      bigint DEFAULT NULL,
    `updater_id`      bigint DEFAULT NULL,
    `create_time`     bigint DEFAULT NULL,
    `update_time`     bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `IDX_PAPER_STRUCTURE_001` (`exam_id`, `card_number`, `paper_number`, `page_index`, `field`,
                                          `question_number`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_question`;
CREATE TABLE `sc_question`
(
    `id`           int(11)      NOT NULL AUTO_INCREMENT COMMENT '主键',
    `exam_id`      int(11)      NOT NULL COMMENT '考试ID',
    `subject_code` varchar(32)  NOT NULL COMMENT '科目代码',
    `paper_type`   varchar(8)   NOT NULL COMMENT '试卷类型',
    `objective`    tinyint(1)   NOT NULL COMMENT '是否客观题',
    `main_number`  int(11)      NOT NULL COMMENT '大题号',
    `sub_number`   varchar(32)  NOT NULL COMMENT '小题号',
    `main_title`   varchar(128) NOT NULL COMMENT '大题名称',
    `total_score`  double DEFAULT NULL COMMENT '满分',
    `creator_id`   bigint DEFAULT NULL,
    `updater_id`   bigint DEFAULT NULL,
    `create_time`  bigint DEFAULT NULL,
    `update_time`  bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `index1` (`exam_id`, `subject_code`, `objective`, `paper_type`, `main_number`, `sub_number`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='小题信息表';


DROP TABLE IF EXISTS `sc_omr_group`;
CREATE TABLE `sc_omr_group`
(
    `id`          bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`     bigint      NOT NULL,
    `fixed`       bit(1)      NOT NULL,
    `stage`       varchar(16) NOT NULL,
    `conditions`  text        NOT NULL,
    `total_count` int         NOT NULL,
    `creator_id`  bigint DEFAULT NULL,
    `updater_id`  bigint DEFAULT NULL,
    `create_time` bigint DEFAULT NULL,
    `update_time` bigint DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `exam_fixed` (`exam_id`, `fixed`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;


DROP TABLE IF EXISTS `sc_refix_batch`;
CREATE TABLE `sc_refix_batch`
(
    `id`           bigint NOT NULL AUTO_INCREMENT,
    `exam_id`      bigint NOT NULL,
    `card_number`  int    NOT NULL,
    `conditions`   text   NOT NULL,
    `update_slice` bit(1) NOT NULL,
    `total_count`  int    NOT NULL,
    `sucess_count` int    NOT NULL,
    `finished`     bit(1) NOT NULL,
    `creator_id`   bigint DEFAULT NULL,
    `updater_id`   bigint DEFAULT NULL,
    `create_time`  bigint DEFAULT NULL,
    `update_time`  bigint DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_student`;
CREATE TABLE `sc_student`
(
    `id`                 bigint      NOT NULL AUTO_INCREMENT,
    `exam_id`            bigint      NOT NULL,
    `exam_number`        varchar(64) NOT NULL,
    `student_code`       varchar(64) NOT NULL,
    `name`               varchar(64) NOT NULL,
    `subject_code`       varchar(64) NOT NULL,
    `package_code`       varchar(64) DEFAULT NULL,
    `exam_site`          varchar(64) DEFAULT NULL,
    `exam_site_name`     varchar(64) DEFAULT NULL,
    `exam_room`          varchar(64) DEFAULT NULL,
    `seat_number`        varchar(16) DEFAULT NULL,
    `campus_name`        varchar(64) DEFAULT NULL,
    `campus_code`        varchar(64) DEFAULT NULL,
    `status`             varchar(16) NOT NULL,
    `omr_absent`         bit(1)      NOT NULL,
    `question_filled`    bit(1)      NOT NULL,
    `assigned`           bit(1)      NOT NULL,
    `absent_suspect`     bit(1)      NOT NULL,
    `incomplete`         bit(1)      NOT NULL,
    `card_number`        int         DEFAULT NULL,
    `device`             varchar(32) DEFAULT NULL,
    `paper_type`         varchar(16) NOT NULL,
    `exam_status`        varchar(32) DEFAULT NULL,
    `breach_code`        varchar(32) DEFAULT NULL,
    `file_upload_status` varchar(16) DEFAULT NULL,
    `data_upload_status` varchar(16) DEFAULT NULL,
    `creator_id`         bigint      DEFAULT NULL,
    `updater_id`         bigint      DEFAULT NULL,
    `create_time`        bigint      DEFAULT NULL,
    `update_time`        bigint      DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `exam_number` (`exam_id`, `exam_number`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_student_paper`;
CREATE TABLE `sc_student_paper`
(
    `student_id`   bigint NOT NULL,
    `paper_number` int    NOT NULL,
    `paper_id`     bigint NOT NULL,
    PRIMARY KEY (`student_id`, `paper_number`),
    UNIQUE KEY `paper_id` (`paper_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_subject`;
CREATE TABLE `sc_subject`
(
    `exam_id`                    bigint      NOT NULL,
    `code`                       varchar(64) NOT NULL,
    `name`                       varchar(64) NOT NULL,
    `paper_type_barcode_content` text   DEFAULT NULL,
    `creator_id`                 bigint DEFAULT NULL,
    `updater_id`                 bigint DEFAULT NULL,
    `create_time`                bigint DEFAULT NULL,
    `update_time`                bigint DEFAULT NULL,
    PRIMARY KEY (`exam_id`, `code`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_file_property`;
CREATE TABLE `sc_file_property`
(
    `path`        varchar(255) NOT NULL,
    `md5`         varchar(32)  NOT NULL,
    `exam_id`     bigint       NOT NULL,
    `file_size`   bigint       NOT NULL,
    `create_time` bigint DEFAULT NULL,
    `update_time` bigint DEFAULT NULL,
    PRIMARY KEY (`path`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_user`;
CREATE TABLE `sc_user`
(
    `id`          int(11)     NOT NULL AUTO_INCREMENT,
    `login_name`  varchar(64) NOT NULL,
    `name`        varchar(64) NOT NULL,
    `password`    varchar(64) NOT NULL,
    `role`        varchar(16) NOT NULL,
    `enable`      tinyint(1)  NOT NULL,
    `school_id`   bigint      NOT NULL,
    `device`      varchar(64) DEFAULT NULL,
    `creator_id`  bigint      DEFAULT NULL,
    `updater_id`  bigint      DEFAULT NULL,
    `create_time` bigint      DEFAULT NULL,
    `update_time` bigint      DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `login_name` (`login_name`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

DROP TABLE IF EXISTS `sc_adapte_file`;
CREATE TABLE `sc_adapte_file`
(
    `exam_id`     bigint       NOT NULL,
    `card_number` int          NOT NULL,
    `role`        varchar(16)  NOT NULL,
    `device`      varchar(64)  NOT NULL,
    `uri`         varchar(255) NOT NULL,
    `md5`         varchar(32)  NOT NULL,
    `create_time` bigint DEFAULT NULL,
    `update_time` bigint DEFAULT NULL,
    PRIMARY KEY (`exam_id`, `card_number`, `role`, `device`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;
