CREATE DATABASE IF NOT EXISTS iwb_data_tielu_standard_dev CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
USE iwb_data_tielu_standard_dev;

CREATE TABLE standard_data (
    `book_number` VARCHAR(20) COMMENT '书号',
    `quota_number` VARCHAR(20) COMMENT '定额编号',
    `quota_name` VARCHAR(200) COMMENT '定额名称',
    `work_content` TEXT COMMENT '工作内容',
    `unit` VARCHAR(10) COMMENT '单位',
    `basic_quota` VARCHAR(50) COMMENT '基本定额',
    `base_price` DECIMAL(12,2) COMMENT '基价(元)',
    `unit_weight` DECIMAL(12,2) COMMENT '单重(t)',
    `labor_cost` DECIMAL(12,2) COMMENT '工费',
    `material_cost` DECIMAL(12,2) COMMENT '料费',
    `machine_cost` DECIMAL(12,2) COMMENT '机费',
    `main_material` VARCHAR(100) COMMENT '主材',
    `created_at`  datetime COMMENT '创建时间',
    `updated_at`  datetime COMMENT '更新时间',
    PRIMARY KEY (`book_number`, `quota_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='标准数据表';

-- 创建数据库
CREATE DATABASE IF NOT EXISTS iwb_data_tielu_pdf_dev CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
USE iwb_data_tielu_pdf_dev;

-- 创建标准表
CREATE TABLE IF NOT EXISTS pdf_standard (
    id INT AUTO_INCREMENT PRIMARY KEY,
    standard_code VARCHAR(100) COMMENT '标准编号',
    standard_name VARCHAR(255) COMMENT '标准名称',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    INDEX idx_standard_code (standard_code),
    INDEX idx_standard_name (standard_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='PDF标准表';

-- 创建PDF记录表
CREATE TABLE IF NOT EXISTS pdf_records (
    id INT AUTO_INCREMENT PRIMARY KEY,
    standard_name VARCHAR(255) COMMENT '标准名称',
    chapter_name VARCHAR(255) COMMENT '章节名称',
    section_name VARCHAR(255) COMMENT '节名称',
    subsection_name VARCHAR(255) COMMENT '小节名称',
    pdf_path VARCHAR(500) COMMENT 'PDF文件路径',
    image_path TEXT COMMENT '生成的图片路径',
    markdown_text TEXT COMMENT 'AI分析生成的Markdown文本',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    INDEX idx_standard_code (standard_code),
    INDEX idx_standard_name (standard_name),
    INDEX idx_chapter_name (chapter_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='PDF文件处理记录表';
