-- 作业表
CREATE TABLE IF NOT EXISTS `t_biz_homework` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键 ID',
    `tenant_id` BIGINT NOT NULL COMMENT '租户 ID',
    `name` VARCHAR(200) NOT NULL COMMENT '作业名称',
    `content` TEXT DEFAULT NULL COMMENT '作业内容（富文本）',
    `status` VARCHAR(50) DEFAULT 'unpublished' COMMENT '作业状态：unpublished/published',
    `publish_time` DATETIME DEFAULT NULL COMMENT '发布时间',
    `submit_start_time` DATETIME NOT NULL COMMENT '提交开始时间',
    `submit_end_time` DATETIME NOT NULL COMMENT '提交结束时间',
    `attachments` JSON DEFAULT NULL COMMENT '附件列表',
    `publish_scope` JSON DEFAULT NULL COMMENT '公开范围（班级 ID 数组）',
    `review_rule_id` BIGINT DEFAULT NULL COMMENT '评审规则 ID',
    `valid_state` TINYINT DEFAULT 1 COMMENT '有效状态：1-有效，2-失效',
    `create_by` VARCHAR(50) DEFAULT NULL COMMENT '创建人',
    `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `update_by` VARCHAR(50) DEFAULT NULL COMMENT '更新人',
    `update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted` TINYINT DEFAULT 0 COMMENT '逻辑删除标识',
    PRIMARY KEY (`id`),
    KEY `idx_tenant_id` (`tenant_id`),
    KEY `idx_status` (`status`),
    KEY `idx_valid_state` (`valid_state`),
    KEY `idx_publish_time` (`publish_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='作业表';

-- 作业提交表
CREATE TABLE IF NOT EXISTS `t_biz_homework_submission` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键 ID',
    `tenant_id` BIGINT NOT NULL COMMENT '租户 ID',
    `homework_id` BIGINT NOT NULL COMMENT '作业 ID',
    `student_id` BIGINT NOT NULL COMMENT '学生用户 ID',
    `student_name` VARCHAR(100) DEFAULT NULL COMMENT '学生姓名',
    `content` TEXT DEFAULT NULL COMMENT '提交内容',
    `attachments` JSON DEFAULT NULL COMMENT '提交附件列表',
    `status` VARCHAR(50) DEFAULT 'submitted' COMMENT '提交状态：submitted/reviewing/returned',
    `submit_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '提交时间',
    `review_time` DATETIME DEFAULT NULL COMMENT '批改时间',
    `reviewer_id` BIGINT DEFAULT NULL COMMENT '批改人 ID',
    `review_comment` TEXT DEFAULT NULL COMMENT '批改评语',
    `review_score` DECIMAL(10,2) DEFAULT NULL COMMENT '批改分数',
    `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted` TINYINT DEFAULT 0 COMMENT '逻辑删除标识',
    PRIMARY KEY (`id`),
    KEY `idx_tenant_id` (`tenant_id`),
    KEY `idx_homework_id` (`homework_id`),
    KEY `idx_student_id` (`student_id`),
    KEY `idx_status` (`status`),
    KEY `idx_submit_time` (`submit_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='作业提交表';

-- 作业评审规则表
CREATE TABLE IF NOT EXISTS `t_biz_homework_review_rule` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键 ID',
    `tenant_id` BIGINT NOT NULL COMMENT '租户 ID',
    `rule_name` VARCHAR(100) NOT NULL COMMENT '规则名称',
    `rule_type` VARCHAR(50) DEFAULT 'custom' COMMENT '规则类型：default/custom',
    `total_score` DECIMAL(10,2) DEFAULT 100 COMMENT '总分',
    `description` VARCHAR(500) DEFAULT NULL COMMENT '规则描述',
    `create_by` VARCHAR(50) DEFAULT NULL COMMENT '创建人',
    `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `deleted` TINYINT DEFAULT 0 COMMENT '逻辑删除标识',
    PRIMARY KEY (`id`),
    KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='作业评审规则表';

-- 作业评分表
CREATE TABLE IF NOT EXISTS `t_biz_homework_score` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键 ID',
    `tenant_id` BIGINT NOT NULL COMMENT '租户 ID',
    `submission_id` BIGINT NOT NULL COMMENT '提交 ID',
    `homework_id` BIGINT NOT NULL COMMENT '作业 ID',
    `reviewer_id` BIGINT NOT NULL COMMENT '评分人 ID',
    `score` DECIMAL(10,2) NOT NULL COMMENT '得分',
    `comment` VARCHAR(500) DEFAULT NULL COMMENT '评语',
    `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `deleted` TINYINT DEFAULT 0 COMMENT '逻辑删除标识',
    PRIMARY KEY (`id`),
    KEY `idx_tenant_id` (`tenant_id`),
    KEY `idx_submission_id` (`submission_id`),
    KEY `idx_homework_id` (`homework_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='作业评分表';
