-- ============================================================
-- 灵越智报 2.0 - 数据库初始化 & Mock数据
-- 场景: 成都院-安全生产标准化复审报告
-- 生成时间: 2026-02-12
-- ============================================================

-- 使用事务确保原子性
BEGIN;

-- ============================================================
-- 0. 扩展（可选）
-- ============================================================
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'vector') THEN
        EXECUTE 'CREATE EXTENSION IF NOT EXISTS vector';
    ELSE
        RAISE NOTICE 'pgvector extension not installed, skip vector features';
    END IF;
END $$;

-- ============================================================
-- 0.x 基础业务表（auth/document/parse/ai/extract）
-- ============================================================

-- 用户与会话
CREATE TABLE IF NOT EXISTS users (
    id VARCHAR(36) PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100) UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    display_name VARCHAR(100),
    avatar_url VARCHAR(500),
    role VARCHAR(20) DEFAULT 'user',
    preferences JSONB DEFAULT '{}',
    is_active BOOLEAN DEFAULT TRUE,
    last_login_at TIMESTAMP,
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);

CREATE TABLE IF NOT EXISTS sessions (
    id VARCHAR(36) PRIMARY KEY,
    user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    token_hash VARCHAR(255) NOT NULL,
    refresh_token_hash VARCHAR(255),
    expires_at TIMESTAMP,
    ip_address VARCHAR(100),
    user_agent TEXT,
    last_used_at TIMESTAMP,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);

-- 文档与解析
CREATE TABLE IF NOT EXISTS documents (
    id VARCHAR(36) PRIMARY KEY,
    user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    name VARCHAR(255) NOT NULL,
    file_name VARCHAR(500) NOT NULL,
    file_path VARCHAR(500) NOT NULL,
    file_size BIGINT,
    file_type VARCHAR(20) NOT NULL,
    status VARCHAR(20) DEFAULT 'uploaded',
    parsed_text TEXT,
    page_count INT,
    word_count INT,
    entity_count INT DEFAULT 0,
    relation_count INT DEFAULT 0,
    rule_count INT DEFAULT 0,
    metadata JSONB DEFAULT '{}',
    del_flag BOOLEAN DEFAULT FALSE,
    create_by VARCHAR(36),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_documents_user ON documents(user_id);
CREATE INDEX IF NOT EXISTS idx_documents_type ON documents(file_type);
CREATE INDEX IF NOT EXISTS idx_documents_status ON documents(status);

CREATE TABLE IF NOT EXISTS document_sections (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    parent_id VARCHAR(36) REFERENCES document_sections(id) ON DELETE CASCADE,
    section_index INT NOT NULL,
    level INT NOT NULL DEFAULT 1,
    title VARCHAR(500),
    content TEXT,
    start_page INT,
    end_page INT,
    start_char INT,
    end_char INT,
    section_type VARCHAR(32) DEFAULT 'heading',
    table_data JSONB,
    image_path VARCHAR(500),
    image_caption VARCHAR(500),
    metadata JSONB DEFAULT '{}',
    sort_order INT DEFAULT 0,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_doc_sections_document ON document_sections(document_id);
CREATE INDEX IF NOT EXISTS idx_doc_sections_parent ON document_sections(parent_id);
CREATE INDEX IF NOT EXISTS idx_doc_sections_level ON document_sections(level);
CREATE INDEX IF NOT EXISTS idx_doc_sections_type ON document_sections(section_type);

CREATE TABLE IF NOT EXISTS document_chunks (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    section_id VARCHAR(36) REFERENCES document_sections(id) ON DELETE SET NULL,
    chunk_index INT NOT NULL,
    content TEXT NOT NULL,
    start_char INT,
    end_char INT,
    page_number INT,
    token_count INT,
    metadata JSONB DEFAULT '{}',
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_doc_chunks_document ON document_chunks(document_id);
CREATE INDEX IF NOT EXISTS idx_doc_chunks_section ON document_chunks(section_id);

CREATE TABLE IF NOT EXISTS parse_tasks (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    status VARCHAR(20) DEFAULT 'pending',
    progress INT DEFAULT 0,
    current_step VARCHAR(32),
    error_message TEXT,
    options JSONB DEFAULT '{}',
    started_at TIMESTAMP,
    completed_at TIMESTAMP,
    parse_status VARCHAR(20) DEFAULT 'pending',
    parse_progress INT DEFAULT 0,
    rag_status VARCHAR(20) DEFAULT 'pending',
    rag_progress INT DEFAULT 0,
    structured_status VARCHAR(20) DEFAULT 'pending',
    structured_progress INT DEFAULT 0,
    structured_element_count INT,
    structured_image_count INT,
    structured_table_count INT,
    ner_status VARCHAR(20) DEFAULT 'pending',
    ner_progress INT DEFAULT 0,
    ner_task_id VARCHAR(100),
    ner_entity_count INT,
    ner_relation_count INT,
    ner_message TEXT,
    graph_status VARCHAR(20) DEFAULT 'pending',
    graph_progress INT DEFAULT 0,
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_parse_tasks_document ON parse_tasks(document_id);

CREATE TABLE IF NOT EXISTS document_elements (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    element_index INT,
    element_type VARCHAR(50),
    content TEXT,
    style JSONB DEFAULT '{}',
    runs JSONB DEFAULT '[]',
    image_url VARCHAR(500),
    image_path VARCHAR(500),
    image_alt VARCHAR(500),
    image_width INT,
    image_height INT,
    image_format VARCHAR(20),
    table_index INT,
    table_data JSONB,
    table_row_count INT,
    table_col_count INT,
    table_text TEXT,
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_document_elements_document ON document_elements(document_id);

CREATE TABLE IF NOT EXISTS document_blocks (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    parent_id VARCHAR(36),
    children JSONB DEFAULT '[]',
    block_index INT,
    block_type VARCHAR(50),
    text_elements JSONB DEFAULT '[]',
    table_data JSONB,
    image_path VARCHAR(500),
    image_url VARCHAR(500),
    metadata JSONB DEFAULT '{}',
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_document_blocks_document ON document_blocks(document_id);

-- AI 相关
CREATE TABLE IF NOT EXISTS elements (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) REFERENCES documents(id) ON DELETE CASCADE,
    user_id VARCHAR(36) REFERENCES users(id) ON DELETE SET NULL,
    type VARCHAR(50),
    label VARCHAR(200),
    value TEXT,
    position JSONB DEFAULT '{}',
    confidence DECIMAL(10,4),
    extraction_method VARCHAR(50),
    graph_node_id VARCHAR(36),
    metadata JSONB DEFAULT '{}',
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_elements_document ON elements(document_id);

CREATE TABLE IF NOT EXISTS annotations (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) REFERENCES documents(id) ON DELETE CASCADE,
    user_id VARCHAR(36) REFERENCES users(id) ON DELETE SET NULL,
    text TEXT,
    position JSONB DEFAULT '{}',
    type VARCHAR(50),
    suggestion TEXT,
    ai_generated BOOLEAN DEFAULT FALSE,
    confidence DECIMAL(10,4),
    status VARCHAR(20) DEFAULT 'pending',
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_annotations_document ON annotations(document_id);

CREATE TABLE IF NOT EXISTS embeddings (
    id VARCHAR(36) PRIMARY KEY,
    chunk_id VARCHAR(36) NOT NULL REFERENCES document_chunks(id) ON DELETE CASCADE,
    embedding vector(1536),
    model_name VARCHAR(100) DEFAULT 'text-embedding-ada-002',
    model_version VARCHAR(50),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_embeddings_chunk ON embeddings(chunk_id);
CREATE INDEX IF NOT EXISTS idx_embeddings_vector ON embeddings USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);

-- 提取与模板
CREATE TABLE IF NOT EXISTS extract_projects (
    id VARCHAR(36) PRIMARY KEY,
    user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    name VARCHAR(200) NOT NULL,
    description TEXT,
    status VARCHAR(50) DEFAULT 'draft',
    config JSONB DEFAULT '{}',
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_extract_projects_user ON extract_projects(user_id);

CREATE TABLE IF NOT EXISTS rules (
    id VARCHAR(36) PRIMARY KEY,
    document_id VARCHAR(36) REFERENCES documents(id) ON DELETE SET NULL,
    user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    name VARCHAR(200) NOT NULL,
    description TEXT,
    category VARCHAR(50),
    rule_type VARCHAR(32) NOT NULL,
    source VARCHAR(32) DEFAULT 'auto',
    priority INT DEFAULT 0,
    status VARCHAR(20) DEFAULT 'draft',
    embedding vector(1536),
    is_global BOOLEAN DEFAULT FALSE,
    del_flag BOOLEAN DEFAULT FALSE,
    create_by VARCHAR(36),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_rules_document ON rules(document_id);
CREATE INDEX IF NOT EXISTS idx_rules_user ON rules(user_id);

CREATE TABLE IF NOT EXISTS templates (
    id VARCHAR(36) PRIMARY KEY,
    user_id VARCHAR(36) NOT NULL,
    name VARCHAR(200),
    description TEXT,
    base_document_id VARCHAR(36),
    status VARCHAR(20) DEFAULT 'draft',
    config JSONB DEFAULT '{}',
    is_public BOOLEAN DEFAULT FALSE,
    use_count INT DEFAULT 0,
    rating DOUBLE PRECISION,
    create_by VARCHAR(36),
    create_by_name VARCHAR(100),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_by_name VARCHAR(100),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_templates_user ON templates(user_id);

CREATE TABLE IF NOT EXISTS variables (
    id VARCHAR(36) PRIMARY KEY,
    template_id VARCHAR(36) NOT NULL REFERENCES templates(id) ON DELETE CASCADE,
    name VARCHAR(100) NOT NULL,
    display_name VARCHAR(200),
    variable_group VARCHAR(100),
    category VARCHAR(50),
    location JSONB,
    example_value TEXT,
    value_type VARCHAR(20),
    source_file_alias VARCHAR(100),
    source_type VARCHAR(30),
    source_config JSONB DEFAULT '{}',
    extract_type VARCHAR(30),
    extract_config JSONB DEFAULT '{}',
    display_order INT DEFAULT 0,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_variables_template ON variables(template_id);

CREATE TABLE IF NOT EXISTS source_files (
    id VARCHAR(36) PRIMARY KEY,
    template_id VARCHAR(36) NOT NULL REFERENCES templates(id) ON DELETE CASCADE,
    alias VARCHAR(100) NOT NULL,
    description TEXT,
    file_types JSONB DEFAULT '[]',
    required BOOLEAN DEFAULT TRUE,
    example_document_id VARCHAR(36),
    display_order INT DEFAULT 0,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_source_files_template ON source_files(template_id);

-- 报告/附件
CREATE TABLE IF NOT EXISTS reports (
    id VARCHAR(36) PRIMARY KEY,
    user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    project_id VARCHAR(36),
    title VARCHAR(500) NOT NULL,
    report_type VARCHAR(100),
    status VARCHAR(20) NOT NULL DEFAULT 'draft',
    content_template TEXT,
    content_rendered TEXT,
    auto_saved_at TIMESTAMP,
    report_score DECIMAL(10,2),
    report_level VARCHAR(50),
    report_metrics JSONB DEFAULT '{}',
    generation_id VARCHAR(36),
    source_document_id VARCHAR(36),
    archived_at TIMESTAMP,
    published_at TIMESTAMP,
    del_flag BOOLEAN DEFAULT FALSE,
    create_by VARCHAR(36),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(36),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_reports_user ON reports(user_id);
CREATE INDEX IF NOT EXISTS idx_reports_status ON reports(status);

CREATE TABLE IF NOT EXISTS report_attachments (
    id VARCHAR(36) PRIMARY KEY,
    report_id VARCHAR(36) NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
    display_name VARCHAR(255),
    file_name VARCHAR(500) NOT NULL,
    file_path VARCHAR(500) NOT NULL,
    file_type VARCHAR(50),
    file_size BIGINT,
    sort_order INT DEFAULT 0,
    saved_to_knowledge_base BOOLEAN DEFAULT FALSE,
    knowledge_base_item_id VARCHAR(36),
    uploaded_by VARCHAR(36) REFERENCES users(id) ON DELETE SET NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_report_attachments_report ON report_attachments(report_id);

-- ============================================================
-- 1. 建表 (DDL)
-- ============================================================

-- 1.1 节点类型定义表
CREATE TABLE IF NOT EXISTS node_types (
    id            SERIAL       PRIMARY KEY,
    type_code     VARCHAR(50)  NOT NULL UNIQUE,
    type_name     VARCHAR(100) NOT NULL,
    description   TEXT,
    icon          VARCHAR(100),
    color         VARCHAR(20),
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.2 关系类型定义表
CREATE TABLE IF NOT EXISTS edge_types (
    id             SERIAL       PRIMARY KEY,
    type_code      VARCHAR(50)  NOT NULL UNIQUE,
    type_name      VARCHAR(100) NOT NULL,
    from_node_type VARCHAR(50),
    to_node_type   VARCHAR(50),
    description    TEXT,
    created_at     TIMESTAMP    DEFAULT NOW()
);

-- 1.3 节点表（核心）
CREATE TABLE IF NOT EXISTS nodes (
    id            BIGSERIAL    PRIMARY KEY,
    node_type     VARCHAR(50)  NOT NULL,
    node_key      VARCHAR(200),
    name          VARCHAR(500) NOT NULL,
    status        VARCHAR(50)  DEFAULT 'active',
    created_by    BIGINT,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.4 关系表（核心）
CREATE TABLE IF NOT EXISTS edges (
    id            BIGSERIAL    PRIMARY KEY,
    edge_type     VARCHAR(50)  NOT NULL,
    from_node_id  BIGINT       NOT NULL REFERENCES nodes(id),
    to_node_id    BIGINT       NOT NULL REFERENCES nodes(id),
    sort_order    INT          DEFAULT 0,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.5 节点属性表
CREATE TABLE IF NOT EXISTS node_properties (
    id            BIGSERIAL    PRIMARY KEY,
    node_id       BIGINT       NOT NULL REFERENCES nodes(id),
    prop_key      VARCHAR(100) NOT NULL,
    prop_value    TEXT,
    prop_json     JSONB,
    prop_number   DECIMAL(20,4),
    prop_date     TIMESTAMP,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.6 关系属性表
CREATE TABLE IF NOT EXISTS edge_properties (
    id            BIGSERIAL    PRIMARY KEY,
    edge_id       BIGINT       NOT NULL REFERENCES edges(id),
    prop_key      VARCHAR(100) NOT NULL,
    prop_value    TEXT,
    prop_json     JSONB,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.7 属性定义表
CREATE TABLE IF NOT EXISTS property_definitions (
    id            SERIAL       PRIMARY KEY,
    owner_type    VARCHAR(20)  NOT NULL,
    target_type   VARCHAR(50)  NOT NULL,
    prop_key      VARCHAR(100) NOT NULL,
    prop_name     VARCHAR(200) NOT NULL,
    data_type     VARCHAR(50)  NOT NULL,
    required      BOOLEAN      DEFAULT false,
    default_value TEXT,
    description   TEXT,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- ============================================================
-- 1.x 兼容字段与触发器（兼容后端实体字段命名）
-- ============================================================

-- node_properties: 兼容 graph-service 使用 prop_text 字段
ALTER TABLE node_properties ADD COLUMN IF NOT EXISTS prop_text TEXT;

CREATE OR REPLACE FUNCTION sync_node_properties_text() RETURNS trigger AS $$
BEGIN
    IF NEW.prop_text IS NULL AND NEW.prop_value IS NOT NULL THEN
        NEW.prop_text := NEW.prop_value;
    ELSIF NEW.prop_value IS NULL AND NEW.prop_text IS NOT NULL THEN
        NEW.prop_value := NEW.prop_text;
    END IF;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS trg_sync_node_properties_text ON node_properties;
CREATE TRIGGER trg_sync_node_properties_text
BEFORE INSERT OR UPDATE ON node_properties
FOR EACH ROW EXECUTE FUNCTION sync_node_properties_text();

-- edge_properties: 兼容 graph-service 使用 prop_text 字段
ALTER TABLE edge_properties ADD COLUMN IF NOT EXISTS prop_text TEXT;

CREATE OR REPLACE FUNCTION sync_edge_properties_text() RETURNS trigger AS $$
BEGIN
    IF NEW.prop_text IS NULL AND NEW.prop_value IS NOT NULL THEN
        NEW.prop_text := NEW.prop_value;
    ELSIF NEW.prop_value IS NULL AND NEW.prop_text IS NOT NULL THEN
        NEW.prop_value := NEW.prop_text;
    END IF;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS trg_sync_edge_properties_text ON edge_properties;
CREATE TRIGGER trg_sync_edge_properties_text
BEFORE INSERT OR UPDATE ON edge_properties
FOR EACH ROW EXECUTE FUNCTION sync_edge_properties_text();

-- property_definitions: 兼容 graph-service 使用 type_code/is_required 字段
ALTER TABLE property_definitions ADD COLUMN IF NOT EXISTS type_code VARCHAR(50);
ALTER TABLE property_definitions ADD COLUMN IF NOT EXISTS is_required BOOLEAN;

CREATE OR REPLACE FUNCTION sync_property_definitions_fields() RETURNS trigger AS $$
BEGIN
    IF NEW.type_code IS NULL AND NEW.target_type IS NOT NULL THEN
        NEW.type_code := NEW.target_type;
    ELSIF NEW.target_type IS NULL AND NEW.type_code IS NOT NULL THEN
        NEW.target_type := NEW.type_code;
    END IF;

    IF NEW.is_required IS NULL AND NEW.required IS NOT NULL THEN
        NEW.is_required := NEW.required;
    ELSIF NEW.required IS NULL AND NEW.is_required IS NOT NULL THEN
        NEW.required := NEW.is_required;
    END IF;

    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS trg_sync_property_definitions_fields ON property_definitions;
CREATE TRIGGER trg_sync_property_definitions_fields
BEFORE INSERT OR UPDATE ON property_definitions
FOR EACH ROW EXECUTE FUNCTION sync_property_definitions_fields();

-- ============================================================
-- 1.8 前端业务支撑表
-- ============================================================

-- 1.8.1 用户扩展表（扩展nodes中的USER节点）
CREATE TABLE IF NOT EXISTS sys_users (
    id            BIGSERIAL    PRIMARY KEY,
    node_id       BIGINT       REFERENCES nodes(id),
    username      VARCHAR(100) NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    salt          VARCHAR(50),
    email         VARCHAR(200),
    phone         VARCHAR(20),
    avatar        VARCHAR(500),
    real_name     VARCHAR(100),
    department    VARCHAR(200),
    position      VARCHAR(100),
    status        VARCHAR(20)  DEFAULT 'active',
    last_login_at TIMESTAMP,
    last_login_ip VARCHAR(50),
    login_count   INT          DEFAULT 0,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.2 会话表
CREATE TABLE IF NOT EXISTS sys_sessions (
    id            BIGSERIAL    PRIMARY KEY,
    user_id       BIGINT       NOT NULL REFERENCES sys_users(id),
    session_token VARCHAR(255) NOT NULL UNIQUE,
    refresh_token VARCHAR(255),
    device_type   VARCHAR(50),
    device_info   TEXT,
    ip_address    VARCHAR(50),
    user_agent    TEXT,
    expires_at    TIMESTAMP    NOT NULL,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.3 登录日志表
CREATE TABLE IF NOT EXISTS sys_login_logs (
    id            BIGSERIAL    PRIMARY KEY,
    user_id       BIGINT       REFERENCES sys_users(id),
    username      VARCHAR(100),
    login_type    VARCHAR(20),
    ip_address    VARCHAR(50),
    user_agent    TEXT,
    device_type   VARCHAR(50),
    location      VARCHAR(200),
    status        VARCHAR(20)  NOT NULL,
    message       TEXT,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.4 角色表
CREATE TABLE IF NOT EXISTS sys_roles (
    id            SERIAL       PRIMARY KEY,
    role_code     VARCHAR(50)  NOT NULL UNIQUE,
    role_name     VARCHAR(100) NOT NULL,
    description   TEXT,
    sort_order    INT          DEFAULT 0,
    status        VARCHAR(20)  DEFAULT 'active',
    created_by    BIGINT,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.5 权限表
CREATE TABLE IF NOT EXISTS sys_permissions (
    id            SERIAL       PRIMARY KEY,
    perm_code     VARCHAR(100) NOT NULL UNIQUE,
    perm_name     VARCHAR(200) NOT NULL,
    perm_type     VARCHAR(20)  NOT NULL,
    parent_id     INT          REFERENCES sys_permissions(id),
    path          VARCHAR(500),
    icon          VARCHAR(100),
    component     VARCHAR(200),
    sort_order    INT          DEFAULT 0,
    status        VARCHAR(20)  DEFAULT 'active',
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.6 用户角色关联表
CREATE TABLE IF NOT EXISTS sys_user_roles (
    id            SERIAL       PRIMARY KEY,
    user_id       BIGINT       NOT NULL REFERENCES sys_users(id),
    role_id       INT          NOT NULL REFERENCES sys_roles(id),
    created_at    TIMESTAMP    DEFAULT NOW(),
    UNIQUE(user_id, role_id)
);

-- 1.8.7 角色权限关联表
CREATE TABLE IF NOT EXISTS sys_role_permissions (
    id            SERIAL       PRIMARY KEY,
    role_id       INT          NOT NULL REFERENCES sys_roles(id),
    permission_id INT          NOT NULL REFERENCES sys_permissions(id),
    created_at    TIMESTAMP    DEFAULT NOW(),
    UNIQUE(role_id, permission_id)
);

-- 1.8.8 系统配置表
CREATE TABLE IF NOT EXISTS sys_configs (
    id            SERIAL       PRIMARY KEY,
    config_key    VARCHAR(100) NOT NULL UNIQUE,
    config_value  TEXT,
    config_json   JSONB,
    config_type   VARCHAR(50),
    description   TEXT,
    is_public     BOOLEAN      DEFAULT false,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.9 数据字典类型表
CREATE TABLE IF NOT EXISTS sys_dict_types (
    id            SERIAL       PRIMARY KEY,
    dict_code     VARCHAR(100) NOT NULL UNIQUE,
    dict_name     VARCHAR(200) NOT NULL,
    description   TEXT,
    status        VARCHAR(20)  DEFAULT 'active',
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.10 数据字典项表
CREATE TABLE IF NOT EXISTS sys_dict_items (
    id            SERIAL       PRIMARY KEY,
    dict_type_id  INT          NOT NULL REFERENCES sys_dict_types(id),
    item_code     VARCHAR(100) NOT NULL,
    item_name     VARCHAR(200) NOT NULL,
    item_value    TEXT,
    sort_order    INT          DEFAULT 0,
    status        VARCHAR(20)  DEFAULT 'active',
    extra         JSONB,
    created_at    TIMESTAMP    DEFAULT NOW(),
    UNIQUE(dict_type_id, item_code)
);

-- 1.8.11 操作日志表
CREATE TABLE IF NOT EXISTS sys_operation_logs (
    id            BIGSERIAL    PRIMARY KEY,
    user_id       BIGINT,
    username      VARCHAR(100),
    module        VARCHAR(100),
    action        VARCHAR(100),
    method        VARCHAR(10),
    url           VARCHAR(500),
    params        TEXT,
    result        TEXT,
    ip_address    VARCHAR(50),
    user_agent    TEXT,
    duration_ms   INT,
    status        VARCHAR(20),
    error_msg     TEXT,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.12 文件存储表
CREATE TABLE IF NOT EXISTS sys_files (
    id            BIGSERIAL    PRIMARY KEY,
    file_key      VARCHAR(100) NOT NULL UNIQUE,
    original_name VARCHAR(500) NOT NULL,
    storage_name  VARCHAR(200) NOT NULL,
    storage_path  VARCHAR(500) NOT NULL,
    file_type     VARCHAR(100),
    file_size     BIGINT,
    md5_hash      VARCHAR(32),
    storage_type  VARCHAR(20)  DEFAULT 'local',
    bucket        VARCHAR(100),
    url           VARCHAR(1000),
    thumbnail_url VARCHAR(1000),
    uploaded_by   BIGINT,
    created_at    TIMESTAMP    DEFAULT NOW()
);

-- 1.8.13 任务队列表（异步任务）
CREATE TABLE IF NOT EXISTS sys_tasks (
    id            BIGSERIAL    PRIMARY KEY,
    task_type     VARCHAR(50)  NOT NULL,
    task_key      VARCHAR(100),
    payload       JSONB,
    status        VARCHAR(20)  DEFAULT 'pending',
    priority      INT          DEFAULT 0,
    retry_count   INT          DEFAULT 0,
    max_retries   INT          DEFAULT 3,
    result        JSONB,
    error_msg     TEXT,
    started_at    TIMESTAMP,
    finished_at   TIMESTAMP,
    created_by    BIGINT,
    created_at    TIMESTAMP    DEFAULT NOW(),
    updated_at    TIMESTAMP    DEFAULT NOW()
);

-- ============================================================
-- 2. 索引
-- ============================================================

-- nodes
CREATE INDEX IF NOT EXISTS idx_nodes_type ON nodes(node_type);
CREATE INDEX IF NOT EXISTS idx_nodes_type_status ON nodes(node_type, status);
CREATE INDEX IF NOT EXISTS idx_nodes_key ON nodes(node_key);
CREATE UNIQUE INDEX IF NOT EXISTS idx_nodes_type_key ON nodes(node_type, node_key) WHERE node_key IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_nodes_created_by ON nodes(created_by);
CREATE INDEX IF NOT EXISTS idx_nodes_created_at ON nodes(created_at DESC);

-- edges
CREATE INDEX IF NOT EXISTS idx_edges_type ON edges(edge_type);
CREATE INDEX IF NOT EXISTS idx_edges_from ON edges(from_node_id);
CREATE INDEX IF NOT EXISTS idx_edges_to ON edges(to_node_id);
CREATE INDEX IF NOT EXISTS idx_edges_type_from ON edges(edge_type, from_node_id);
CREATE INDEX IF NOT EXISTS idx_edges_type_to ON edges(edge_type, to_node_id);
CREATE UNIQUE INDEX IF NOT EXISTS idx_edges_unique ON edges(edge_type, from_node_id, to_node_id);

-- node_properties
CREATE INDEX IF NOT EXISTS idx_node_props_node ON node_properties(node_id);
CREATE UNIQUE INDEX IF NOT EXISTS idx_node_props_unique ON node_properties(node_id, prop_key);
CREATE INDEX IF NOT EXISTS idx_node_props_key ON node_properties(prop_key);

-- edge_properties
CREATE INDEX IF NOT EXISTS idx_edge_props_edge ON edge_properties(edge_id);
CREATE UNIQUE INDEX IF NOT EXISTS idx_edge_props_unique ON edge_properties(edge_id, prop_key);

-- sys_users
CREATE INDEX IF NOT EXISTS idx_sys_users_node ON sys_users(node_id);
CREATE INDEX IF NOT EXISTS idx_sys_users_status ON sys_users(status);
CREATE INDEX IF NOT EXISTS idx_sys_users_email ON sys_users(email);
CREATE INDEX IF NOT EXISTS idx_sys_users_phone ON sys_users(phone);

-- sys_sessions
CREATE INDEX IF NOT EXISTS idx_sys_sessions_user ON sys_sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_sys_sessions_expires ON sys_sessions(expires_at);
CREATE INDEX IF NOT EXISTS idx_sys_sessions_refresh ON sys_sessions(refresh_token);

-- sys_login_logs
CREATE INDEX IF NOT EXISTS idx_sys_login_logs_user ON sys_login_logs(user_id);
CREATE INDEX IF NOT EXISTS idx_sys_login_logs_time ON sys_login_logs(created_at DESC);

-- sys_roles
CREATE INDEX IF NOT EXISTS idx_sys_roles_status ON sys_roles(status);

-- sys_permissions
CREATE INDEX IF NOT EXISTS idx_sys_perms_parent ON sys_permissions(parent_id);
CREATE INDEX IF NOT EXISTS idx_sys_perms_type ON sys_permissions(perm_type);

-- sys_operation_logs
CREATE INDEX IF NOT EXISTS idx_sys_op_logs_user ON sys_operation_logs(user_id);
CREATE INDEX IF NOT EXISTS idx_sys_op_logs_time ON sys_operation_logs(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_sys_op_logs_module ON sys_operation_logs(module);

-- sys_files
CREATE INDEX IF NOT EXISTS idx_sys_files_uploaded ON sys_files(uploaded_by);
CREATE INDEX IF NOT EXISTS idx_sys_files_type ON sys_files(file_type);
CREATE INDEX IF NOT EXISTS idx_sys_files_time ON sys_files(created_at DESC);

-- sys_tasks
CREATE INDEX IF NOT EXISTS idx_sys_tasks_status ON sys_tasks(status);
CREATE INDEX IF NOT EXISTS idx_sys_tasks_type ON sys_tasks(task_type);
CREATE INDEX IF NOT EXISTS idx_sys_tasks_priority ON sys_tasks(priority DESC, created_at);

-- ============================================================
-- 3. 视图 (Views)
-- ============================================================

-- 3.1 原始文件视图
CREATE OR REPLACE VIEW v_source_files AS
SELECT 
    n.id,
    n.name AS file_name,
    n.node_key AS file_key,
    n.status,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'original_name') AS original_name,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'file_path') AS file_path,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'file_type') AS file_type,
    (SELECT prop_number FROM node_properties WHERE node_id = n.id AND prop_key = 'file_size')::bigint AS file_size,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'content_html') AS content_html,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'content_json') AS content_json,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'parse_status') AS parse_status,
    (SELECT prop_date FROM node_properties WHERE node_id = n.id AND prop_key = 'parsed_at') AS parsed_at,
    (SELECT n2.id FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'PARSED_TO' LIMIT 1) AS template_id,
    n.created_by,
    (SELECT n2.name FROM nodes n2 WHERE n2.id = n.created_by) AS created_by_name
FROM nodes n
WHERE n.node_type = 'SOURCE_FILE';

-- 3.2 模板视图
CREATE OR REPLACE VIEW v_templates AS
SELECT 
    n.id,
    n.name,
    n.node_key AS template_code,
    n.status,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'category') AS category,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'description') AS description,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'content_html') AS content_html,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'content_json') AS content_json,
    (SELECT COUNT(*) FROM edges e WHERE e.from_node_id = n.id AND e.edge_type = 'HAS_ELEMENT') AS element_count,
    (SELECT n2.name FROM nodes n2 WHERE n2.id = n.created_by) AS created_by_name
FROM nodes n
WHERE n.node_type = 'TEMPLATE';

-- 3.3 报告视图
CREATE OR REPLACE VIEW v_reports AS
SELECT 
    n.id,
    n.name AS title,
    n.node_key AS report_code,
    n.status,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'report_type') AS report_type,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'content_html') AS content_html,
    (SELECT n2.id FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'INSTANCE_OF' LIMIT 1) AS template_id,
    (SELECT n2.name FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'INSTANCE_OF' LIMIT 1) AS template_name,
    (SELECT n2.id FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'BELONGS_TO' AND n2.node_type = 'PROJECT' LIMIT 1) AS project_id,
    (SELECT n2.name FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'BELONGS_TO' AND n2.node_type = 'PROJECT' LIMIT 1) AS project_name,
    (SELECT n2.id FROM edges e JOIN nodes n2 ON n2.id = e.to_node_id 
     WHERE e.from_node_id = n.id AND e.edge_type = 'COPIED_FROM' LIMIT 1) AS source_report_id,
    (SELECT COUNT(*) FROM edges e WHERE e.from_node_id = n.id AND e.edge_type = 'HAS_ATTACHMENT') AS attachment_count,
    n.created_by,
    (SELECT n2.name FROM nodes n2 WHERE n2.id = n.created_by) AS created_by_name
FROM nodes n
WHERE n.node_type = 'REPORT';

-- 3.4 模板动态要素视图
CREATE OR REPLACE VIEW v_template_elements AS
SELECT 
    n.id,
    n.name AS element_name,
    n.node_key AS element_key,
    n.created_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'element_type') AS element_type,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'namespace') AS namespace,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'field_name') AS field_name,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'table_columns') AS table_columns,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'required')::boolean AS required,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'default_value') AS default_value,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'description') AS description,
    (SELECT e.from_node_id FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_ELEMENT' LIMIT 1) AS template_id,
    (SELECT e.sort_order FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_ELEMENT' LIMIT 1) AS sort_order
FROM nodes n
WHERE n.node_type = 'ELEMENT';

-- 3.5 报告要素值视图
CREATE OR REPLACE VIEW v_report_element_values AS
SELECT 
    n.id AS value_id,
    n.node_key AS element_key,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'value_text') AS value_text,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'value_json') AS value_json,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'is_filled')::boolean AS is_filled,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'fill_source') AS fill_source,
    (SELECT e.from_node_id FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_VALUE' LIMIT 1) AS report_id
FROM nodes n
WHERE n.node_type = 'VALUE';

-- 3.6 附件视图
CREATE OR REPLACE VIEW v_attachments AS
SELECT 
    n.id,
    n.name AS display_name,
    n.node_key AS file_key,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'file_name') AS file_name,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'file_path') AS file_path,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'file_type') AS file_type,
    (SELECT prop_number FROM node_properties WHERE node_id = n.id AND prop_key = 'file_size')::bigint AS file_size,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'parse_status') AS parse_status,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'parsed_text') AS parsed_text,
    (SELECT prop_date FROM node_properties WHERE node_id = n.id AND prop_key = 'parsed_at') AS parsed_at,
    (SELECT COUNT(*) FROM edges e WHERE e.from_node_id = n.id AND e.edge_type = 'HAS_ENTITY') AS entity_count,
    (SELECT e.from_node_id FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_ATTACHMENT' LIMIT 1) AS report_id,
    (SELECT e.sort_order FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_ATTACHMENT' LIMIT 1) AS sort_order
FROM nodes n
WHERE n.node_type = 'ATTACHMENT';

-- 3.7 实体视图
CREATE OR REPLACE VIEW v_entities AS
SELECT 
    n.id,
    n.name AS entity_text,
    n.node_key AS entity_key,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'entity_type') AS entity_type,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'business_label') AS business_label,
    (SELECT prop_number FROM node_properties WHERE node_id = n.id AND prop_key = 'confidence') AS confidence,
    (SELECT prop_number FROM node_properties WHERE node_id = n.id AND prop_key = 'occurrence_count')::int AS occurrence_count,
    (SELECT e.from_node_id FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_ENTITY' LIMIT 1) AS attachment_id
FROM nodes n
WHERE n.node_type = 'ENTITY';

-- 3.8 规则视图
CREATE OR REPLACE VIEW v_rules AS
SELECT 
    n.id,
    n.name AS rule_name,
    n.node_key AS element_key,
    n.status,
    n.created_at,
    n.updated_at,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'description') AS description,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'rule_type') AS rule_type,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'action_type') AS action_type,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'action_config') AS action_config,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'dsl_content') AS dsl_content,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'last_output_text') AS last_output_text,
    (SELECT prop_json FROM node_properties WHERE node_id = n.id AND prop_key = 'last_output_json') AS last_output_json,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'last_run_status') AS last_run_status,
    (SELECT prop_date FROM node_properties WHERE node_id = n.id AND prop_key = 'last_run_time') AS last_run_time,
    (SELECT prop_value FROM node_properties WHERE node_id = n.id AND prop_key = 'last_run_error') AS last_run_error,
    (SELECT e.from_node_id FROM edges e WHERE e.to_node_id = n.id AND e.edge_type = 'HAS_RULE' LIMIT 1) AS report_id
FROM nodes n
WHERE n.node_type = 'RULE';

-- 3.9 规则输入视图
CREATE OR REPLACE VIEW v_rule_inputs AS
SELECT 
    e.id AS input_id,
    e.from_node_id AS rule_id,
    e.to_node_id AS source_node_id,
    e.sort_order,
    (SELECT prop_value FROM edge_properties WHERE edge_id = e.id AND prop_key = 'input_key') AS input_key,
    (SELECT prop_value FROM edge_properties WHERE edge_id = e.id AND prop_key = 'input_name') AS input_name,
    (SELECT prop_value FROM edge_properties WHERE edge_id = e.id AND prop_key = 'input_type') AS input_type,
    (SELECT prop_value FROM edge_properties WHERE edge_id = e.id AND prop_key = 'fixed_value') AS fixed_value,
    n.node_type AS source_type,
    n.name AS source_name
FROM edges e
JOIN nodes n ON n.id = e.to_node_id
WHERE e.edge_type = 'INPUT_FROM';

-- 3.10 报告完整视图（聚合）
CREATE OR REPLACE VIEW v_report_full AS
SELECT 
    r.*,
    (SELECT COUNT(*) FROM v_report_element_values v WHERE v.report_id = r.id AND v.is_filled = true) AS filled_count,
    (SELECT COUNT(*) FROM v_template_elements te WHERE te.template_id = r.template_id) AS total_elements,
    (SELECT COUNT(*) FROM v_rules ru WHERE ru.report_id = r.id) AS rule_count,
    (SELECT COUNT(*) FROM v_rules ru WHERE ru.report_id = r.id AND ru.last_run_status = 'success') AS success_rule_count
FROM v_reports r;

-- ============================================================
-- 4. 初始化数据 (DML)
-- ============================================================

-- 4.1 节点类型
INSERT INTO node_types (type_code, type_name, description) VALUES
('SOURCE_FILE', '原始文件', '用户上传的原始样本文件'),
('TEMPLATE',    '模板',     '报告模板（规则骨架）'),
('ELEMENT',     '要素定义', '动态要素定义（属于模板）'),
('REPORT',      '报告',     '报告实例（属于项目）'),
('VALUE',       '要素值',   '要素值（属于报告）'),
('RULE',        '规则',     '规则实例（属于报告）'),
('ATTACHMENT',  '附件',     '附件（属于报告）'),
('ENTITY',      '实体',     '识别实体（属于样本文件或附件）'),
('USER',        '用户',     '系统用户'),
('PROJECT',     '项目',     '项目');

-- 4.2 关系类型
INSERT INTO edge_types (type_code, type_name, from_node_type, to_node_type, description) VALUES
('PARSED_TO',      '解析生成',   'SOURCE_FILE', 'TEMPLATE',   '原始文件解析生成模板'),
('HAS_ELEMENT',    '包含要素',   'TEMPLATE',    'ELEMENT',    '模板包含要素定义'),
('INSTANCE_OF',    '实例化',     'REPORT',      'TEMPLATE',   '报告基于模板'),
('HAS_VALUE',      '有要素值',   'REPORT',      'VALUE',      '报告有要素值'),
('HAS_RULE',       '有规则',     'REPORT',      'RULE',       '报告有规则'),
('FOR_ELEMENT',    '对应要素',   NULL,          'ELEMENT',    '规则/值对应的要素'),
('HAS_ATTACHMENT', '有附件',     'REPORT',      'ATTACHMENT', '报告有附件'),
('HAS_ENTITY',     '有实体',     NULL,          'ENTITY',     '文件有实体（本文或附件）'),
('INPUT_FROM',     '输入来源',   'RULE',        NULL,         '规则输入来源'),
('COPIED_FROM',    '复制来源',   'REPORT',      'REPORT',     '复制来源'),
('BELONGS_TO',     '归属',       'REPORT',      'PROJECT',    '归属关系'),
('CREATED_BY',     '创建者',     NULL,          'USER',       '创建者');

-- 4.3 属性定义
INSERT INTO property_definitions (owner_type, target_type, prop_key, prop_name, data_type, required, description) VALUES
-- SOURCE_FILE 节点属性
('node', 'SOURCE_FILE', 'original_name',  '原始文件名',   'text',   true,  '上传时的原始文件名'),
('node', 'SOURCE_FILE', 'file_path',      '存储路径',     'text',   true,  '服务器存储路径'),
('node', 'SOURCE_FILE', 'file_type',      '文件类型',     'text',   true,  'MIME类型'),
('node', 'SOURCE_FILE', 'file_size',      '文件大小',     'number', false, '字节数'),
('node', 'SOURCE_FILE', 'content_html',   'HTML内容',     'text',   false, '解析后的HTML'),
('node', 'SOURCE_FILE', 'content_json',   '结构化内容',   'json',   false, '解析后的JSON结构'),
('node', 'SOURCE_FILE', 'parse_status',   '解析状态',     'text',   false, 'pending/parsing/completed/failed'),
('node', 'SOURCE_FILE', 'parsed_at',      '解析时间',     'date',   false, '解析完成时间'),
-- TEMPLATE 节点属性
('node', 'TEMPLATE', 'category',      '分类',         'text',   false, '模板分类'),
('node', 'TEMPLATE', 'description',   '描述',         'text',   false, '模板描述'),
('node', 'TEMPLATE', 'content_html',  'HTML内容',     'text',   false, '模板HTML（含占位符）'),
('node', 'TEMPLATE', 'content_json',  '结构化内容',   'json',   false, '模板JSON结构'),
-- ELEMENT 节点属性
('node', 'ELEMENT', 'element_type',   '要素类型',     'text',   true,  'text/paragraph/table'),
('node', 'ELEMENT', 'namespace',      '命名空间',     'text',   false, '如basicInfo/project'),
('node', 'ELEMENT', 'field_name',     '字段名',       'text',   false, '如projectCode'),
('node', 'ELEMENT', 'table_columns',  '表格列定义',   'json',   false, '表格类型的列定义'),
('node', 'ELEMENT', 'required',       '是否必填',     'text',   false, 'true/false'),
('node', 'ELEMENT', 'default_value',  '默认值',       'text',   false, '默认填充值'),
('node', 'ELEMENT', 'description',    '描述',         'text',   false, '要素描述'),
-- REPORT 节点属性
('node', 'REPORT', 'report_type',    '报告类型',     'text',   false, '报告类型标识'),
('node', 'REPORT', 'content_html',   'HTML内容',     'text',   false, '生成的报告HTML'),
-- VALUE 节点属性
('node', 'VALUE', 'value_text',   '文本值',       'text',   false, '要素的文本值'),
('node', 'VALUE', 'value_json',   'JSON值',       'json',   false, '要素的JSON值（表格等）'),
('node', 'VALUE', 'is_filled',    '是否已填充',   'text',   false, 'true/false'),
('node', 'VALUE', 'fill_source',  '填充来源',     'text',   false, 'manual/rule/default'),
-- RULE 节点属性
('node', 'RULE', 'description',      '描述',         'text',   false, '规则描述'),
('node', 'RULE', 'rule_type',        '规则类型',     'text',   false, 'extract/aggregate/calculate'),
('node', 'RULE', 'action_type',      '动作类型',     'text',   false, 'llm/script/lookup'),
('node', 'RULE', 'action_config',    '动作配置',     'json',   false, '动作参数配置'),
('node', 'RULE', 'dsl_content',      'DSL内容',      'text',   false, '规则DSL定义'),
('node', 'RULE', 'last_output_text', '最后输出文本', 'text',   false, '最后执行的文本输出'),
('node', 'RULE', 'last_output_json', '最后输出JSON', 'json',   false, '最后执行的JSON输出'),
('node', 'RULE', 'last_run_status',  '最后执行状态', 'text',   false, 'pending/running/success/failed'),
('node', 'RULE', 'last_run_time',    '最后执行时间', 'date',   false, '最后执行时间'),
('node', 'RULE', 'last_run_error',   '最后执行错误', 'text',   false, '错误信息'),
-- ATTACHMENT 节点属性
('node', 'ATTACHMENT', 'file_name',     '文件名',       'text',   true,  '附件文件名'),
('node', 'ATTACHMENT', 'file_path',     '存储路径',     'text',   true,  '服务器存储路径'),
('node', 'ATTACHMENT', 'file_type',     '文件类型',     'text',   false, 'MIME类型'),
('node', 'ATTACHMENT', 'file_size',     '文件大小',     'number', false, '字节数'),
('node', 'ATTACHMENT', 'parse_status',  '解析状态',     'text',   false, 'pending/parsing/completed/failed'),
('node', 'ATTACHMENT', 'parsed_text',   '解析文本',     'text',   false, '解析后的纯文本'),
('node', 'ATTACHMENT', 'parsed_at',     '解析时间',     'date',   false, '解析完成时间'),
-- ENTITY 节点属性
('node', 'ENTITY', 'entity_type',      '实体类型',     'text',   true,  'PERSON/ORG/DATE/PHONE等'),
('node', 'ENTITY', 'business_label',   '业务标签',     'text',   false, '业务含义标签'),
('node', 'ENTITY', 'confidence',       '置信度',       'number', false, 'NER识别置信度'),
('node', 'ENTITY', 'occurrence_count', '出现次数',     'number', false, '在文档中出现次数'),
-- USER 节点属性
('node', 'USER', 'email',      '邮箱',     'text',   false, '用户邮箱'),
('node', 'USER', 'phone',      '手机号',   'text',   false, '用户手机号'),
('node', 'USER', 'department', '部门',     'text',   false, '所属部门'),
-- PROJECT 节点属性
('node', 'PROJECT', 'description', '描述',     'text',   false, '项目描述'),
('node', 'PROJECT', 'start_date',  '开始日期', 'date',   false, '项目开始日期'),
('node', 'PROJECT', 'end_date',    '结束日期', 'date',   false, '项目结束日期'),
-- INPUT_FROM 关系属性
('edge', 'INPUT_FROM', 'input_key',   '输入键',     'text',   true,  '输入参数标识'),
('edge', 'INPUT_FROM', 'input_name',  '输入名称',   'text',   false, '输入参数显示名'),
('edge', 'INPUT_FROM', 'input_type',  '输入类型',   'text',   false, 'entity_ref/value_ref/fixed'),
('edge', 'INPUT_FROM', 'fixed_value', '固定值',     'text',   false, '固定值（当input_type=fixed时）');

-- 4.4 初始化角色
INSERT INTO sys_roles (role_code, role_name, description, sort_order) VALUES
('super_admin', '超级管理员', '系统最高权限，可管理所有功能', 1),
('admin',       '管理员',     '可管理用户、项目、模板等', 2),
('editor',      '编辑员',     '可编辑报告、管理附件', 3),
('viewer',      '查看者',     '只读权限', 4);

-- 4.5 初始化权限（菜单+按钮）
INSERT INTO sys_permissions (perm_code, perm_name, perm_type, parent_id, path, icon, sort_order) VALUES
-- 一级菜单
('dashboard',        '工作台',       'menu', NULL, '/dashboard',        'Dashboard',    1),
('project',          '项目管理',     'menu', NULL, '/project',          'Folder',       2),
('template',         '模板管理',     'menu', NULL, '/template',         'FileText',     3),
('report',           '报告管理',     'menu', NULL, '/report',           'File',         4),
('system',           '系统管理',     'menu', NULL, '/system',           'Settings',     5);

INSERT INTO sys_permissions (perm_code, perm_name, perm_type, parent_id, path, component, sort_order) VALUES
-- 项目管理子菜单
('project:list',     '项目列表',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'project'), '/project/list',   'project/List',   1),
('project:create',   '创建项目',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'project'), NULL, NULL, 2),
('project:edit',     '编辑项目',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'project'), NULL, NULL, 3),
('project:delete',   '删除项目',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'project'), NULL, NULL, 4),
-- 模板管理子菜单
('template:list',    '模板列表',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'template'), '/template/list',  'template/List',  1),
('template:create',  '创建模板',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'template'), NULL, NULL, 2),
('template:edit',    '编辑模板',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'template'), NULL, NULL, 3),
('template:delete',  '删除模板',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'template'), NULL, NULL, 4),
-- 报告管理子菜单
('report:list',      '报告列表',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'report'), '/report/list',    'report/List',    1),
('report:create',    '创建报告',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'report'), NULL, NULL, 2),
('report:edit',      '编辑报告',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'report'), NULL, NULL, 3),
('report:delete',    '删除报告',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'report'), NULL, NULL, 4),
('report:export',    '导出报告',     'button', (SELECT id FROM sys_permissions WHERE perm_code = 'report'), NULL, NULL, 5),
-- 系统管理子菜单
('system:user',      '用户管理',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'system'), '/system/user',    'system/User',    1),
('system:role',      '角色管理',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'system'), '/system/role',    'system/Role',    2),
('system:config',    '系统配置',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'system'), '/system/config',  'system/Config',  3),
('system:dict',      '数据字典',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'system'), '/system/dict',    'system/Dict',    4),
('system:log',       '操作日志',     'menu',   (SELECT id FROM sys_permissions WHERE perm_code = 'system'), '/system/log',     'system/Log',     5);

-- 4.6 角色权限关联（超级管理员拥有所有权限）
INSERT INTO sys_role_permissions (role_id, permission_id)
SELECT (SELECT id FROM sys_roles WHERE role_code = 'super_admin'), id FROM sys_permissions;

-- 4.7 管理员权限（除系统管理外）
INSERT INTO sys_role_permissions (role_id, permission_id)
SELECT (SELECT id FROM sys_roles WHERE role_code = 'admin'), id FROM sys_permissions 
WHERE perm_code NOT LIKE 'system:%' OR perm_code IN ('system:user', 'system:dict');

-- 4.8 编辑员权限
INSERT INTO sys_role_permissions (role_id, permission_id)
SELECT (SELECT id FROM sys_roles WHERE role_code = 'editor'), id FROM sys_permissions 
WHERE perm_code IN ('dashboard', 'project', 'project:list', 'template', 'template:list', 
                    'report', 'report:list', 'report:create', 'report:edit', 'report:export');

-- 4.9 查看者权限
INSERT INTO sys_role_permissions (role_id, permission_id)
SELECT (SELECT id FROM sys_roles WHERE role_code = 'viewer'), id FROM sys_permissions 
WHERE perm_code IN ('dashboard', 'project', 'project:list', 'template', 'template:list', 'report', 'report:list');

-- 4.10 初始化管理员用户（密码: [REDACTED]，实际部署时需修改）
-- 注：password_hash 使用 bcrypt 加密，此处为示例值
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1, 'USER', 'USR-001', '管理员', 'active', NULL);
INSERT INTO sys_users (node_id, username, password_hash, salt, real_name, department, status) VALUES
(1, 'admin', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iAt6Z5EH', 'random_salt', '管理员', '技术部', 'active');

-- 4.11 管理员角色关联
INSERT INTO sys_user_roles (user_id, role_id) VALUES
(1, (SELECT id FROM sys_roles WHERE role_code = 'super_admin'));

-- 4.12 初始化系统配置
INSERT INTO sys_configs (config_key, config_value, config_type, description, is_public) VALUES
('site_name',           '灵越智报 2.0',                    'string',  '系统名称',           true),
('site_logo',           '/assets/logo.png',                'string',  '系统Logo',           true),
('upload_max_size',     '52428800',                        'number',  '上传文件大小限制(字节)', false),
('upload_allowed_types','docx,doc,pdf,xlsx,xls,png,jpg',   'string',  '允许上传的文件类型', false),
('session_timeout',     '7200',                            'number',  '会话超时时间(秒)',   false),
('llm_api_url',         'https://api.openai.com/v1',       'string',  'LLM API地址',        false),
('llm_model',           'gpt-4',                           'string',  'LLM模型名称',        false);

-- 4.13 初始化数据字典
INSERT INTO sys_dict_types (dict_code, dict_name, description) VALUES
('parse_status',    '解析状态',   '文件解析状态'),
('element_type',    '要素类型',   '动态要素类型'),
('rule_type',       '规则类型',   '规则类型'),
('action_type',     '动作类型',   '规则动作类型'),
('fill_source',     '填充来源',   '要素值填充来源'),
('entity_type',     '实体类型',   'NER实体类型'),
('task_status',     '任务状态',   '异步任务状态');

INSERT INTO sys_dict_items (dict_type_id, item_code, item_name, sort_order) VALUES
-- 解析状态
((SELECT id FROM sys_dict_types WHERE dict_code = 'parse_status'), 'pending',   '待解析',   1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'parse_status'), 'parsing',   '解析中',   2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'parse_status'), 'completed', '已完成',   3),
((SELECT id FROM sys_dict_types WHERE dict_code = 'parse_status'), 'failed',    '解析失败', 4),
-- 要素类型
((SELECT id FROM sys_dict_types WHERE dict_code = 'element_type'), 'text',      '文本',     1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'element_type'), 'paragraph', '段落',     2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'element_type'), 'table',     '表格',     3),
-- 规则类型
((SELECT id FROM sys_dict_types WHERE dict_code = 'rule_type'), 'extract',   '提取',     1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'rule_type'), 'aggregate', '聚合',     2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'rule_type'), 'calculate', '计算',     3),
-- 动作类型
((SELECT id FROM sys_dict_types WHERE dict_code = 'action_type'), 'llm',    'LLM调用',  1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'action_type'), 'script', '脚本执行', 2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'action_type'), 'lookup', '查表',     3),
-- 填充来源
((SELECT id FROM sys_dict_types WHERE dict_code = 'fill_source'), 'manual',  '手动填写', 1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'fill_source'), 'rule',    '规则生成', 2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'fill_source'), 'default', '默认值',   3),
-- 实体类型
((SELECT id FROM sys_dict_types WHERE dict_code = 'entity_type'), 'PERSON', '人名',     1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'entity_type'), 'ORG',    '组织机构', 2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'entity_type'), 'DATE',   '日期',     3),
((SELECT id FROM sys_dict_types WHERE dict_code = 'entity_type'), 'PHONE',  '电话',     4),
((SELECT id FROM sys_dict_types WHERE dict_code = 'entity_type'), 'LOC',    '地点',     5),
-- 任务状态
((SELECT id FROM sys_dict_types WHERE dict_code = 'task_status'), 'pending',   '待执行',   1),
((SELECT id FROM sys_dict_types WHERE dict_code = 'task_status'), 'running',   '执行中',   2),
((SELECT id FROM sys_dict_types WHERE dict_code = 'task_status'), 'success',   '成功',     3),
((SELECT id FROM sys_dict_types WHERE dict_code = 'task_status'), 'failed',    '失败',     4);

-- ============================================================
-- 5. Mock数据 - nodes
-- ============================================================

INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2, 'PROJECT', 'PRJ-001', '成都院-安全生产标准化复审报告', 'active', 1);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (100, 'SOURCE_FILE', 'SF-001', '成都院复审报告样本.docx', 'active', 1);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (101, 'TEMPLATE', 'TPL-001', '电力安全生产标准化复审报告模板', 'active', 1);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1001, 'ELEMENT', 'basicInfo.projectCode', '项目编号', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1002, 'ELEMENT', 'project.reviewObject', '评审对象', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1003, 'ELEMENT', 'basicInfo.requestLevel', '申请级别', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1004, 'ELEMENT', 'project.resultScore', '评审得分', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1005, 'ELEMENT', 'project.resultLevel', '评审级别', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1006, 'ELEMENT', 'project.workStartAt', '评审开始日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1007, 'ELEMENT', 'project.workEndAt', '评审结束日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1008, 'ELEMENT', 'project.createdAt', '报告日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1009, 'ELEMENT', 'project.reviewObjectSummary', '评审对象简介（前言）', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1010, 'ELEMENT', 'project.reviewObjectAlias', '评审对象简称', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1011, 'ELEMENT', 'basicInfo.reviewObjectCertificate2GetAt', '首次达标证书获取日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1012, 'ELEMENT', 'basicInfo.reviewObjectCertificateGetAt', '证书获取日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1013, 'ELEMENT', 'basicInfo.reviewObjectCertificateCode', '证书编号', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1014, 'ELEMENT', 'basicInfo.applyAt', '申请日期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1015, 'ELEMENT', 'project.reviewPeriod', '评审期', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1016, 'ELEMENT', 'project.reviewObjectDescription', '企业简介', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1017, 'ELEMENT', 'project.target', '目标', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1018, 'ELEMENT', 'project.duty', '组织机构和职责', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1019, 'ELEMENT', 'project.fullParticipation', '全员参与', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1020, 'ELEMENT', 'project.safetyInvestment', '安全生产投入', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1021, 'ELEMENT', 'project.safetyCulture', '安全文化建设', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1022, 'ELEMENT', 'project.systematicManagement', '制度化管理', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1023, 'ELEMENT', 'project.employeeTraining', '人员教育培训', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1024, 'ELEMENT', 'project.assetManagement', '设备设施管理', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1025, 'ELEMENT', 'project.jobSafety', '作业安全', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1026, 'ELEMENT', 'project.positionQualified', '岗位达标', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1027, 'ELEMENT', 'project.partner', '相关方', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1028, 'ELEMENT', 'project.occupationalHealth', '职业健康', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1029, 'ELEMENT', 'project.riskAssessment', '风险辨识与评价', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1030, 'ELEMENT', 'project.majorHazardManagement', '重大危险源管理', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1031, 'ELEMENT', 'project.hazardInspection', '隐患排查', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1032, 'ELEMENT', 'project.changeManagement', '变更管理', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1033, 'ELEMENT', 'project.earlyWarning', '预测预警', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1034, 'ELEMENT', 'project.emergencyResponse', '应急救援', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1035, 'ELEMENT', 'project.incidentManagement', '事故管理', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1036, 'ELEMENT', 'project.continuousImprovement', '持续改进', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1037, 'ELEMENT', 'project.safetyStandardizationStatus', '安全生产标准化建设和持续运行情况', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1038, 'ELEMENT', 'project.safetyHighlight', '安全生产管理亮点', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1039, 'ELEMENT', 'project.reviewObjectSelfAssessmentProcess', '自评过程', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1040, 'ELEMENT', 'project.moreWorkReference', '补充工作依据', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1041, 'ELEMENT', 'project.reviewRange', '复审范围', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1042, 'ELEMENT', 'project.workProcess', '现场复审工作过程', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1043, 'ELEMENT', 'project.closingMeetingAt', '末次会议时间', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1044, 'ELEMENT', 'SPSRRReviewProject', '现场复审项目选择（表格）', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1045, 'ELEMENT', 'SPSRRReviewer', '现场复审人员（表格）', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1046, 'ELEMENT', 'review_status', '现场复审情况（表格）', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (1047, 'ELEMENT', 'target_responsibility', '目标职责复审情况（表格）', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (200, 'REPORT', 'RPT-001', '成都院2024年安全生产标准化复审报告', 'draft', 1);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2001, 'VALUE', 'RPT-001:basicInfo.projectCode', '项目编号值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2002, 'VALUE', 'RPT-001:project.reviewObject', '评审对象值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2003, 'VALUE', 'RPT-001:basicInfo.requestLevel', '申请级别值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2004, 'VALUE', 'RPT-001:project.resultScore', '评审得分值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2005, 'VALUE', 'RPT-001:project.resultLevel', '评审级别值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2006, 'VALUE', 'RPT-001:project.workStartAt', '评审开始日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2007, 'VALUE', 'RPT-001:project.workEndAt', '评审结束日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2008, 'VALUE', 'RPT-001:project.createdAt', '报告日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2009, 'VALUE', 'RPT-001:project.reviewObjectSummary', '评审对象简介值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2010, 'VALUE', 'RPT-001:project.reviewObjectAlias', '评审对象简称值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2011, 'VALUE', 'RPT-001:basicInfo.reviewObjectCertificate2GetAt', '首次达标证书获取日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2012, 'VALUE', 'RPT-001:basicInfo.reviewObjectCertificateGetAt', '证书获取日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2013, 'VALUE', 'RPT-001:basicInfo.reviewObjectCertificateCode', '证书编号值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2014, 'VALUE', 'RPT-001:basicInfo.applyAt', '申请日期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2015, 'VALUE', 'RPT-001:project.reviewPeriod', '评审期值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2016, 'VALUE', 'RPT-001:project.reviewObjectDescription', '企业简介值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2017, 'VALUE', 'RPT-001:project.target', '目标值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2018, 'VALUE', 'RPT-001:project.duty', '组织机构和职责值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2019, 'VALUE', 'RPT-001:project.fullParticipation', '全员参与值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2020, 'VALUE', 'RPT-001:project.safetyInvestment', '安全生产投入值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2021, 'VALUE', 'RPT-001:project.safetyCulture', '安全文化建设值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2022, 'VALUE', 'RPT-001:project.systematicManagement', '制度化管理值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2023, 'VALUE', 'RPT-001:project.employeeTraining', '人员教育培训值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2024, 'VALUE', 'RPT-001:project.assetManagement', '设备设施管理值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2025, 'VALUE', 'RPT-001:project.jobSafety', '作业安全值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2026, 'VALUE', 'RPT-001:project.positionQualified', '岗位达标值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2027, 'VALUE', 'RPT-001:project.partner', '相关方值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2028, 'VALUE', 'RPT-001:project.occupationalHealth', '职业健康值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2029, 'VALUE', 'RPT-001:project.riskAssessment', '风险辨识与评价值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2030, 'VALUE', 'RPT-001:project.majorHazardManagement', '重大危险源管理值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2031, 'VALUE', 'RPT-001:project.hazardInspection', '隐患排查值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2032, 'VALUE', 'RPT-001:project.changeManagement', '变更管理值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2033, 'VALUE', 'RPT-001:project.earlyWarning', '预测预警值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2034, 'VALUE', 'RPT-001:project.emergencyResponse', '应急救援值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2035, 'VALUE', 'RPT-001:project.incidentManagement', '事故管理值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2036, 'VALUE', 'RPT-001:project.continuousImprovement', '持续改进值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2037, 'VALUE', 'RPT-001:project.safetyStandardizationStatus', '安全生产标准化建设和持续运行情况值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2038, 'VALUE', 'RPT-001:project.safetyHighlight', '安全生产管理亮点值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2039, 'VALUE', 'RPT-001:project.reviewObjectSelfAssessmentProcess', '自评过程值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2040, 'VALUE', 'RPT-001:project.moreWorkReference', '补充工作依据值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2041, 'VALUE', 'RPT-001:project.reviewRange', '复审范围值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2042, 'VALUE', 'RPT-001:project.workProcess', '现场复审工作过程值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2043, 'VALUE', 'RPT-001:project.closingMeetingAt', '末次会议时间值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2044, 'VALUE', 'RPT-001:SPSRRReviewProject', '现场复审项目选择值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2045, 'VALUE', 'RPT-001:SPSRRReviewer', '现场复审人员值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2046, 'VALUE', 'RPT-001:review_status', '现场复审情况值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (2047, 'VALUE', 'RPT-001:target_responsibility', '目标职责复审情况值', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (300, 'REPORT', 'RPT-002', '华东院2024年安全生产标准化复审报告', 'draft', 1);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (400, 'ATTACHMENT', 'ATT-001', '现场检测点位布置图', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (401, 'ATTACHMENT', 'ATT-002', '现场检测照片', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (402, 'ATTACHMENT', 'ATT-003', '检测计划与检测方案', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (403, 'ATTACHMENT', 'ATT-004', '工况记录表', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (404, 'ATTACHMENT', 'ATT-005', '噪声检测原始记录表', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (405, 'ATTACHMENT', 'ATT-006', '工频电场、工频磁场检测原始记录表', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (500, 'ENTITY', 'ENT-001', '中国电建集团成都勘测设计研究院有限公司', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (501, 'ENTITY', 'ENT-002', '中国电力建设集团（股份）有限公司', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (502, 'ENTITY', 'ENT-003', '湖北安源安全环保科技有限公司', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (503, 'ENTITY', 'ENT-004', '成都院', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (504, 'ENTITY', 'ENT-005', 'BZ-0092-2024', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (505, 'ENTITY', 'ENT-006', 'ZGDIDBOY-083', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (506, 'ENTITY', 'ENT-007', '何彦锋', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (507, 'ENTITY', 'ENT-008', '张世殊', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (508, 'ENTITY', 'ENT-009', '鞠其凤', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (509, 'ENTITY', 'ENT-010', '向林', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (510, 'ENTITY', 'ENT-011', '刘建冰', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (511, 'ENTITY', 'ENT-012', '93.33', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (512, 'ENTITY', 'ENT-013', '一级', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (513, 'ENTITY', 'ENT-014', '2024年7月13日', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (514, 'ENTITY', 'ENT-015', '2024年10月17日', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (515, 'ENTITY', 'ENT-016', '2024年7月8日', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (516, 'ENTITY', 'ENT-017', '2019年12月9日', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (517, 'ENTITY', 'ENT-018', '2023年7月8日至2024年7月7日', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (518, 'ENTITY', 'ENT-019', '2024年11月', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (519, 'ENTITY', 'ENT-020', '2019年', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (520, 'ENTITY', 'ENT-021', '葛学福', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (521, 'ENTITY', 'ENT-022', '余正坚', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (522, 'ENTITY', 'ENT-023', '苏经仪', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (523, 'ENTITY', 'ENT-024', '周建胜', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (524, 'ENTITY', 'ENT-025', '赵泓', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (525, 'ENTITY', 'ENT-026', '朱晓莉', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (526, 'ENTITY', 'ENT-027', '向义', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (600, 'RULE', 'RPT-001:basicInfo.projectCode', '项目编号提取规则', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (601, 'RULE', 'RPT-001:project.reviewObject', '评审对象-直接引用实体', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (602, 'RULE', 'RPT-001:project.resultScore', '评审得分提取规则', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (603, 'RULE', 'RPT-001:project.reviewObjectAlias', '评审对象简称-直接引用实体', 'active', NULL);
INSERT INTO nodes (id, node_type, node_key, name, status, created_by) VALUES (604, 'RULE', 'RPT-001:basicInfo.requestLevel', '申请级别-直接引用实体', 'active', NULL);

-- 重置序列
SELECT setval('nodes_id_seq', (SELECT MAX(id) FROM nodes));

-- ============================================================
-- 6. Mock数据 - edges
-- ============================================================

INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (1, 'CREATED_BY', 2, 1, 0);  -- 项目 → 用户
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (2, 'CREATED_BY', 100, 1, 0);  -- 样本文件 → 用户
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (3, 'CREATED_BY', 200, 1, 0);  -- 成都院报告 → 用户
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (10, 'PARSED_TO', 100, 101, 0);  -- 样本文件 → 模板
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (20, 'HAS_ELEMENT', 101, 1001, 1);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (21, 'HAS_ELEMENT', 101, 1002, 2);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (22, 'HAS_ELEMENT', 101, 1003, 3);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (23, 'HAS_ELEMENT', 101, 1004, 4);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (24, 'HAS_ELEMENT', 101, 1005, 5);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (25, 'HAS_ELEMENT', 101, 1006, 6);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (26, 'HAS_ELEMENT', 101, 1007, 7);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (27, 'HAS_ELEMENT', 101, 1008, 8);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (28, 'HAS_ELEMENT', 101, 1009, 9);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (29, 'HAS_ELEMENT', 101, 1010, 10);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (30, 'HAS_ELEMENT', 101, 1011, 11);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (31, 'HAS_ELEMENT', 101, 1012, 12);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (32, 'HAS_ELEMENT', 101, 1013, 13);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (33, 'HAS_ELEMENT', 101, 1014, 14);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (34, 'HAS_ELEMENT', 101, 1015, 15);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (35, 'HAS_ELEMENT', 101, 1016, 16);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (36, 'HAS_ELEMENT', 101, 1017, 17);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (37, 'HAS_ELEMENT', 101, 1018, 18);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (38, 'HAS_ELEMENT', 101, 1019, 19);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (39, 'HAS_ELEMENT', 101, 1020, 20);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (40, 'HAS_ELEMENT', 101, 1021, 21);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (41, 'HAS_ELEMENT', 101, 1022, 22);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (42, 'HAS_ELEMENT', 101, 1023, 23);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (43, 'HAS_ELEMENT', 101, 1024, 24);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (44, 'HAS_ELEMENT', 101, 1025, 25);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (45, 'HAS_ELEMENT', 101, 1026, 26);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (46, 'HAS_ELEMENT', 101, 1027, 27);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (47, 'HAS_ELEMENT', 101, 1028, 28);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (48, 'HAS_ELEMENT', 101, 1029, 29);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (49, 'HAS_ELEMENT', 101, 1030, 30);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (50, 'HAS_ELEMENT', 101, 1031, 31);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (51, 'HAS_ELEMENT', 101, 1032, 32);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (52, 'HAS_ELEMENT', 101, 1033, 33);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (53, 'HAS_ELEMENT', 101, 1034, 34);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (54, 'HAS_ELEMENT', 101, 1035, 35);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (55, 'HAS_ELEMENT', 101, 1036, 36);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (56, 'HAS_ELEMENT', 101, 1037, 37);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (57, 'HAS_ELEMENT', 101, 1038, 38);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (58, 'HAS_ELEMENT', 101, 1039, 39);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (59, 'HAS_ELEMENT', 101, 1040, 40);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (60, 'HAS_ELEMENT', 101, 1041, 41);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (61, 'HAS_ELEMENT', 101, 1042, 42);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (62, 'HAS_ELEMENT', 101, 1043, 43);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (63, 'HAS_ELEMENT', 101, 1044, 44);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (64, 'HAS_ELEMENT', 101, 1045, 45);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (65, 'HAS_ELEMENT', 101, 1046, 46);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (66, 'HAS_ELEMENT', 101, 1047, 47);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (100, 'INSTANCE_OF', 200, 101, 0);  -- 成都院报告 → 模板
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (101, 'BELONGS_TO', 200, 2, 0);  -- 成都院报告 → 项目
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (200, 'HAS_VALUE', 200, 2001, 1);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (201, 'HAS_VALUE', 200, 2002, 2);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (202, 'HAS_VALUE', 200, 2003, 3);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (203, 'HAS_VALUE', 200, 2004, 4);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (204, 'HAS_VALUE', 200, 2005, 5);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (205, 'HAS_VALUE', 200, 2006, 6);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (206, 'HAS_VALUE', 200, 2007, 7);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (207, 'HAS_VALUE', 200, 2008, 8);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (208, 'HAS_VALUE', 200, 2009, 9);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (209, 'HAS_VALUE', 200, 2010, 10);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (210, 'HAS_VALUE', 200, 2011, 11);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (211, 'HAS_VALUE', 200, 2012, 12);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (212, 'HAS_VALUE', 200, 2013, 13);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (213, 'HAS_VALUE', 200, 2014, 14);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (214, 'HAS_VALUE', 200, 2015, 15);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (215, 'HAS_VALUE', 200, 2016, 16);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (216, 'HAS_VALUE', 200, 2017, 17);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (217, 'HAS_VALUE', 200, 2018, 18);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (218, 'HAS_VALUE', 200, 2019, 19);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (219, 'HAS_VALUE', 200, 2020, 20);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (220, 'HAS_VALUE', 200, 2021, 21);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (221, 'HAS_VALUE', 200, 2022, 22);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (222, 'HAS_VALUE', 200, 2023, 23);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (223, 'HAS_VALUE', 200, 2024, 24);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (224, 'HAS_VALUE', 200, 2025, 25);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (225, 'HAS_VALUE', 200, 2026, 26);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (226, 'HAS_VALUE', 200, 2027, 27);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (227, 'HAS_VALUE', 200, 2028, 28);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (228, 'HAS_VALUE', 200, 2029, 29);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (229, 'HAS_VALUE', 200, 2030, 30);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (230, 'HAS_VALUE', 200, 2031, 31);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (231, 'HAS_VALUE', 200, 2032, 32);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (232, 'HAS_VALUE', 200, 2033, 33);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (233, 'HAS_VALUE', 200, 2034, 34);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (234, 'HAS_VALUE', 200, 2035, 35);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (235, 'HAS_VALUE', 200, 2036, 36);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (236, 'HAS_VALUE', 200, 2037, 37);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (237, 'HAS_VALUE', 200, 2038, 38);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (238, 'HAS_VALUE', 200, 2039, 39);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (239, 'HAS_VALUE', 200, 2040, 40);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (240, 'HAS_VALUE', 200, 2041, 41);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (241, 'HAS_VALUE', 200, 2042, 42);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (242, 'HAS_VALUE', 200, 2043, 43);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (243, 'HAS_VALUE', 200, 2044, 44);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (244, 'HAS_VALUE', 200, 2045, 45);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (245, 'HAS_VALUE', 200, 2046, 46);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (246, 'HAS_VALUE', 200, 2047, 47);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (300, 'FOR_ELEMENT', 2001, 1001, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (301, 'FOR_ELEMENT', 2002, 1002, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (302, 'FOR_ELEMENT', 2003, 1003, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (303, 'FOR_ELEMENT', 2004, 1004, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (304, 'FOR_ELEMENT', 2005, 1005, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (305, 'FOR_ELEMENT', 2006, 1006, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (306, 'FOR_ELEMENT', 2007, 1007, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (307, 'FOR_ELEMENT', 2008, 1008, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (308, 'FOR_ELEMENT', 2009, 1009, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (309, 'FOR_ELEMENT', 2010, 1010, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (310, 'FOR_ELEMENT', 2011, 1011, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (311, 'FOR_ELEMENT', 2012, 1012, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (312, 'FOR_ELEMENT', 2013, 1013, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (313, 'FOR_ELEMENT', 2014, 1014, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (314, 'FOR_ELEMENT', 2015, 1015, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (315, 'FOR_ELEMENT', 2016, 1016, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (316, 'FOR_ELEMENT', 2017, 1017, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (317, 'FOR_ELEMENT', 2018, 1018, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (318, 'FOR_ELEMENT', 2019, 1019, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (319, 'FOR_ELEMENT', 2020, 1020, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (320, 'FOR_ELEMENT', 2021, 1021, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (321, 'FOR_ELEMENT', 2022, 1022, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (322, 'FOR_ELEMENT', 2023, 1023, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (323, 'FOR_ELEMENT', 2024, 1024, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (324, 'FOR_ELEMENT', 2025, 1025, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (325, 'FOR_ELEMENT', 2026, 1026, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (326, 'FOR_ELEMENT', 2027, 1027, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (327, 'FOR_ELEMENT', 2028, 1028, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (328, 'FOR_ELEMENT', 2029, 1029, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (329, 'FOR_ELEMENT', 2030, 1030, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (330, 'FOR_ELEMENT', 2031, 1031, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (331, 'FOR_ELEMENT', 2032, 1032, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (332, 'FOR_ELEMENT', 2033, 1033, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (333, 'FOR_ELEMENT', 2034, 1034, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (334, 'FOR_ELEMENT', 2035, 1035, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (335, 'FOR_ELEMENT', 2036, 1036, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (336, 'FOR_ELEMENT', 2037, 1037, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (337, 'FOR_ELEMENT', 2038, 1038, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (338, 'FOR_ELEMENT', 2039, 1039, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (339, 'FOR_ELEMENT', 2040, 1040, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (340, 'FOR_ELEMENT', 2041, 1041, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (341, 'FOR_ELEMENT', 2042, 1042, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (342, 'FOR_ELEMENT', 2043, 1043, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (343, 'FOR_ELEMENT', 2044, 1044, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (344, 'FOR_ELEMENT', 2045, 1045, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (345, 'FOR_ELEMENT', 2046, 1046, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (346, 'FOR_ELEMENT', 2047, 1047, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (400, 'HAS_ATTACHMENT', 200, 400, 1);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (401, 'HAS_ATTACHMENT', 200, 401, 2);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (402, 'HAS_ATTACHMENT', 200, 402, 3);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (403, 'HAS_ATTACHMENT', 200, 403, 4);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (404, 'HAS_ATTACHMENT', 200, 404, 5);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (405, 'HAS_ATTACHMENT', 200, 405, 6);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (500, 'HAS_ENTITY', 100, 500, 1);  -- 样本文件 → 实体
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (501, 'HAS_ENTITY', 100, 501, 2);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (502, 'HAS_ENTITY', 100, 502, 3);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (503, 'HAS_ENTITY', 100, 503, 4);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (504, 'HAS_ENTITY', 100, 504, 5);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (505, 'HAS_ENTITY', 100, 505, 6);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (506, 'HAS_ENTITY', 100, 506, 7);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (507, 'HAS_ENTITY', 100, 507, 8);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (508, 'HAS_ENTITY', 100, 508, 9);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (509, 'HAS_ENTITY', 100, 509, 10);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (510, 'HAS_ENTITY', 100, 510, 11);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (511, 'HAS_ENTITY', 100, 511, 12);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (512, 'HAS_ENTITY', 100, 512, 13);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (513, 'HAS_ENTITY', 100, 513, 14);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (514, 'HAS_ENTITY', 100, 514, 15);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (515, 'HAS_ENTITY', 100, 515, 16);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (516, 'HAS_ENTITY', 100, 516, 17);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (517, 'HAS_ENTITY', 100, 517, 18);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (518, 'HAS_ENTITY', 100, 518, 19);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (519, 'HAS_ENTITY', 100, 519, 20);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (520, 'HAS_ENTITY', 100, 520, 21);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (521, 'HAS_ENTITY', 100, 521, 22);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (522, 'HAS_ENTITY', 100, 522, 23);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (523, 'HAS_ENTITY', 100, 523, 24);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (524, 'HAS_ENTITY', 100, 524, 25);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (525, 'HAS_ENTITY', 100, 525, 26);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (526, 'HAS_ENTITY', 100, 526, 27);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (600, 'HAS_RULE', 200, 600, 1);  -- 报告 → 规则
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (601, 'HAS_RULE', 200, 601, 2);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (602, 'HAS_RULE', 200, 602, 3);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (603, 'HAS_RULE', 200, 603, 4);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (604, 'HAS_RULE', 200, 604, 5);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (610, 'FOR_ELEMENT', 600, 1001, 0);  -- 规则 → 要素
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (611, 'FOR_ELEMENT', 601, 1002, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (612, 'FOR_ELEMENT', 602, 1004, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (613, 'FOR_ELEMENT', 603, 1010, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (614, 'FOR_ELEMENT', 604, 1003, 0);
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (620, 'INPUT_FROM', 600, 100, 1);  -- 规则输入 ← 样本文件
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (621, 'INPUT_FROM', 601, 500, 1);  -- 规则输入 ← 实体（评审对象）
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (622, 'INPUT_FROM', 602, 100, 1);  -- 规则输入 ← 样本文件
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (623, 'INPUT_FROM', 603, 503, 1);  -- 规则输入 ← 实体（成都院）
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (624, 'INPUT_FROM', 604, 512, 1);  -- 规则输入 ← 实体（一级）
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (700, 'INSTANCE_OF', 300, 101, 0);  -- 华东院报告 → 模板
INSERT INTO edges (id, edge_type, from_node_id, to_node_id, sort_order) VALUES (701, 'COPIED_FROM', 300, 200, 0);  -- 华东院报告 ← 成都院报告

-- 重置序列
SELECT setval('edges_id_seq', (SELECT MAX(id) FROM edges));

-- ============================================================
-- 7. Mock数据 - node_properties
-- ============================================================

INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (100, 'original_name', '成都院复审报告样本.docx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (100, 'file_path', '/uploads/2026/02/SF-001.docx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (100, 'file_type', 'docx');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (100, 'file_size', NULL, 2048000);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (100, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (100, 'content_text', '[原文全文内容，见mock数据.txt第8-337行]');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (101, 'template_code', 'TPL-SPSRR-2024');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (101, 'category', '电力安全生产标准化复审');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (101, 'content_template', '[模板全文内容，见mock数据.txt第338-516行]');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1001, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1001, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1001, 'field_name', 'projectCode');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1001, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1002, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1002, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1002, 'field_name', 'reviewObject');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1002, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1003, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1003, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1003, 'field_name', 'requestLevel');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1003, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1004, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1004, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1004, 'field_name', 'resultScore');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1004, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1005, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1005, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1005, 'field_name', 'resultLevel');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1005, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1006, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1006, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1006, 'field_name', 'workStartAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1006, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1007, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1007, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1007, 'field_name', 'workEndAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1007, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1008, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1008, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1008, 'field_name', 'createdAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1009, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1009, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1009, 'field_name', 'reviewObjectSummary');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1010, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1010, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1010, 'field_name', 'reviewObjectAlias');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1010, 'required', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1011, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1011, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1011, 'field_name', 'reviewObjectCertificate2GetAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1012, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1012, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1012, 'field_name', 'reviewObjectCertificateGetAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1013, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1013, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1013, 'field_name', 'reviewObjectCertificateCode');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1014, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1014, 'namespace', 'basicInfo');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1014, 'field_name', 'applyAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1015, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1015, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1015, 'field_name', 'reviewPeriod');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1016, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1016, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1016, 'field_name', 'reviewObjectDescription');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1017, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1017, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1017, 'field_name', 'target');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1018, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1018, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1018, 'field_name', 'duty');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1019, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1019, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1019, 'field_name', 'fullParticipation');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1020, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1020, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1020, 'field_name', 'safetyInvestment');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1021, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1021, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1021, 'field_name', 'safetyCulture');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1022, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1022, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1022, 'field_name', 'systematicManagement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1023, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1023, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1023, 'field_name', 'employeeTraining');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1024, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1024, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1024, 'field_name', 'assetManagement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1025, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1025, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1025, 'field_name', 'jobSafety');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1026, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1026, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1026, 'field_name', 'positionQualified');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1027, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1027, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1027, 'field_name', 'partner');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1028, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1028, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1028, 'field_name', 'occupationalHealth');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1029, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1029, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1029, 'field_name', 'riskAssessment');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1030, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1030, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1030, 'field_name', 'majorHazardManagement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1031, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1031, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1031, 'field_name', 'hazardInspection');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1032, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1032, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1032, 'field_name', 'changeManagement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1033, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1033, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1033, 'field_name', 'earlyWarning');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1034, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1034, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1034, 'field_name', 'emergencyResponse');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1035, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1035, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1035, 'field_name', 'incidentManagement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1036, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1036, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1036, 'field_name', 'continuousImprovement');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1037, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1037, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1037, 'field_name', 'safetyStandardizationStatus');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1038, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1038, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1038, 'field_name', 'safetyHighlight');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1039, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1039, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1039, 'field_name', 'reviewObjectSelfAssessmentProcess');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1040, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1040, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1040, 'field_name', 'moreWorkReference');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1041, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1041, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1041, 'field_name', 'reviewRange');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1042, 'element_type', 'paragraph');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1042, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1042, 'field_name', 'workProcess');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1043, 'element_type', 'text');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1043, 'namespace', 'project');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1043, 'field_name', 'closingMeetingAt');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1044, 'element_type', 'table');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1044, 'namespace', 'SPSRRReviewProject');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1044, 'field_name', 'SPSRRReviewProject');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1045, 'element_type', 'table');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1045, 'namespace', 'SPSRRReviewer');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1045, 'field_name', 'SPSRRReviewer');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1046, 'element_type', 'table');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1046, 'namespace', 'review_status');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1046, 'field_name', 'review_status');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1047, 'element_type', 'table');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1047, 'namespace', 'target_responsibility');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (1047, 'field_name', 'target_responsibility');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (200, 'report_code', 'RPT-SPSRR-CDY-2024');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (200, 'title', '中国电建集团成都勘测设计研究院有限公司安全生产标准化复审报告');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2001, 'value_text', 'BZ-0092-2024');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2001, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2001, 'fill_source', 'rule');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2002, 'value_text', '中国电建集团成都勘测设计研究院有限公司');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2002, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2002, 'fill_source', 'rule');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2003, 'value_text', '一级');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2003, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2003, 'fill_source', 'rule');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2004, 'value_text', '93.33');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2004, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2004, 'fill_source', 'rule');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2005, 'value_text', '一级');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2005, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2005, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2006, 'value_text', '2024年7月13日');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2006, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2006, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2007, 'value_text', '2024年10月17日');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2007, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2007, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2008, 'value_text', '2024年11月');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2008, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2008, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2009, 'value_text', '中国电建集团成都勘测设计研究院有限公司（以下简称"成都院"或"公司"）是中国电力建设集团（股份）有限公司（以下简称"股份公司"）的全资子企业，其历史可以追溯至1950年成立的燃料工业部西南水力发电工程处，建制于1955年成立的电力工业部成都勘测设计局。经过70多年发展壮大，已成为在能源电力、水资源与环境、城市建设与基础设施等领域，为全球客户提供规划咨询、勘测设计、施工建造、投资运营全产业链一体化综合服务的大型综合性勘测设计研究单位。成都院致力于为全球清洁能源工程及基础设施、环境工程提供系统产品与整体解决方案和服务，技术实力始终保持行业领先地位。');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2009, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2009, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2010, 'value_text', '成都院');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2010, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2010, 'fill_source', 'rule');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2011, 'value_text', '2019年');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2011, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2011, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2012, 'value_text', '2019年12月9日');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2012, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2012, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2013, 'value_text', 'ZGDIDBOY-083');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2013, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2013, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2014, 'value_text', '2024年7月8日');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2014, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2014, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2015, 'value_text', '2023年7月8日至2024年7月7日');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2015, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2015, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2016, 'value_text', '中国电建集团成都勘测设计研究院有限公司为中国电力建设集团（股份）有限公司（以下简称"股份公司"）的全资子企业，其历史可以追溯至1950年成立的燃料工业部西南水力发电工程处。经过70多年发展壮大，已成为在能源电力、水资源与环境、城市建设与基础设施领域，为全球客户提供规划咨询、勘测设计、施工建造、投资运营全产业链一体化综合服务的大型综合性勘测设计研究单位。
成都院致力于为全球清洁能源工程及基础设施、环境工程提供系统产品与整体解决方案和服务。公司现有1名首届国家卓越工程师、2名全国工程勘察设计大师、2名国家百千万人才专家、7名全国行业大师、15名四川省勘察设计大师在内的近7000名高素质人才队伍。');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2016, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2016, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2040, 'value_text', '《关于深入开展电力安全生产标准化建设暨安全环保提升专项行动的通知》（蓉设安环〔2024〕20号）');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2040, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2040, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2041, 'value_text', '成都院本部各职能部门、勘测设计分公司/YX工程院/抽蓄院（简称：设计分公司）、工程建设分公司（简称：建设分公司）、重庆云阳建全抽水蓄能电站EPC总承包监理项目（简称：云阳监理项目）、漳州高新区绿色发展生态治理项目工程总承包（EPC）建设项目（简称：漳州总包项目）、大邑抽水蓄能电站地质勘察项目（简称：大邑地勘项目）、大渡河双江口设计项目（简称：双江口设计项目）');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2041, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2041, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2043, 'value_text', '2024年10月17日上10：30～12：00');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2043, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2043, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2045, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2045, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_json) VALUES (2045, 'value_json', NULL, '[{"序号": 1, "姓名": "葛学福", "职务": "专家组长", "专业": "安全管理、作业安全", "工作单位": "江西水电"}, {"序号": 2, "姓名": "余正坚", "职务": "专家", "专业": "安全管理、设备设施", "工作单位": "水电七局"}, {"序号": 3, "姓名": "苏经仪", "职务": "专家", "专业": "安全管理、作业安全", "工作单位": "昆明院"}, {"序号": 4, "姓名": "周建胜", "职务": "专家", "专业": "安全管理、设备设施", "工作单位": "安源公司"}, {"序号": 5, "姓名": "赵泓", "职务": "专家", "专业": "安全管理", "工作单位": "安源公司"}, {"序号": 6, "姓名": "朱晓莉", "职务": "项目经理", "专业": "安全管理", "工作单位": "安源公司"}, {"序号": 7, "姓名": "向义", "职务": "现场经理", "专业": "安全管理", "工作单位": "安源公司"}]'::jsonb);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2047, 'is_filled', 'true');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (2047, 'fill_source', 'manual');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_json) VALUES (2047, 'value_json', NULL, '[{"序号": 1, "项目": "5.1.1.1\n目标制定", "存在的问题": "大邑地勘项目部制定的2024年度安全生产目标，缺少设备设施方面的事故控制目标。", "扣分标准": "依据评分标准②目标内容有缺失，扣1分/项，共扣1分。"}, {"序号": 2, "项目": "5.1.1.2\n目标落实", "存在的问题": "双江口设计项目部项目经理与各专业部门负责人签订的《2024年度安全责任书》中，目标分解不明确，不满足要求。", "扣分标准": "依据评分标准②签订责任书、目标分解不满足要求，扣1分/单位，共扣1分。"}, {"序号": 3, "项目": "5.1.1.3\n目标考核", "存在的问题": "云阳监理项目未对二季度安全生产目标及工作计划完成情况进行考核、监督检查。", "扣分标准": "依据评分标准①未对目标的完成情况进行评估和考核，扣2分/次，共扣2分。"}, {"序号": 4, "项目": "5.1.2.1\n机构设置", "存在的问题": "漳州总包项目部安委会组成不符合规定，未包含分包单位负责人。", "扣分标准": "依据评分标准①安委会组成不符合规定或未及时调整，扣2分/次，共扣2分"}, {"序号": 5, "项目": "5.1.2.2\n主要负责人及管理层职责", "存在的问题": "双江口设计项目部9月召开的安全生产例会中，未针对成都院隐患大排查、设计分公司安全风险隐患专项整治工作等要求，部署安排隐患排查相关工作。", "扣分标准": "依据评分标准④会议未布置安全生产工作，扣1分/项，共扣1分。"}]'::jsonb);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (400, 'file_name', '现场检测点位布置图.pdf');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (400, 'file_type', 'pdf');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (400, 'file_path', '/uploads/2026/02/ATT-001.pdf');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (400, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (401, 'file_name', '现场检测照片.zip');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (401, 'file_type', 'zip');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (401, 'file_path', '/uploads/2026/02/ATT-002.zip');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (401, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (402, 'file_name', '检测计划与检测方案.docx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (402, 'file_type', 'docx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (402, 'file_path', '/uploads/2026/02/ATT-003.docx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (402, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (403, 'file_name', '工况记录表.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (403, 'file_type', 'xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (403, 'file_path', '/uploads/2026/02/ATT-004.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (403, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (404, 'file_name', '噪声检测原始记录表.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (404, 'file_type', 'xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (404, 'file_path', '/uploads/2026/02/ATT-005.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (404, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (405, 'file_name', '工频电场、工频磁场检测原始记录表.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (405, 'file_type', 'xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (405, 'file_path', '/uploads/2026/02/ATT-006.xlsx');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (405, 'parse_status', 'completed');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (500, 'entity_type', 'organization');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (500, 'business_label', '评审对象');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (500, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (501, 'entity_type', 'organization');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (501, 'business_label', '上级公司');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (501, 'confidence', NULL, 0.98);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (502, 'entity_type', 'organization');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (502, 'business_label', '评审机构');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (502, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (503, 'entity_type', 'alias');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (503, 'business_label', '评审对象简称');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (503, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (504, 'entity_type', 'code');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (504, 'business_label', '项目编号');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (504, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (505, 'entity_type', 'code');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (505, 'business_label', '证书编号');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (505, 'confidence', NULL, 0.98);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (506, 'entity_type', 'person');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (506, 'business_label', '董事长');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (506, 'confidence', NULL, 0.97);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (507, 'entity_type', 'person');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (507, 'business_label', '总经理');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (507, 'confidence', NULL, 0.96);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (508, 'entity_type', 'person');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (508, 'business_label', '分管安全副总经理');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (508, 'confidence', NULL, 0.96);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (509, 'entity_type', 'person');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (509, 'business_label', '安全总监');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (509, 'confidence', NULL, 0.95);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (510, 'entity_type', 'person');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (510, 'business_label', '安质环部主任');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (510, 'confidence', NULL, 0.95);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (511, 'entity_type', 'number');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (511, 'business_label', '评审得分');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (511, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (512, 'entity_type', 'level');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (512, 'business_label', '评审级别');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (512, 'confidence', NULL, 0.99);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (513, 'entity_type', 'date');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (513, 'business_label', '评审开始日期');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (513, 'confidence', NULL, 0.98);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (514, 'entity_type', 'date');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (514, 'business_label', '评审结束日期');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_number) VALUES (514, 'confidence', NULL, 0.98);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (600, 'rule_type', 'extraction');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (600, 'action_type', 'extract_pattern');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_json) VALUES (600, 'action_config', NULL, '{"pattern": "项目编号[：:]\\s*(\\S+)", "group": 1}'::jsonb);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (600, 'dsl_content', 'EXTRACT pattern="项目编号[：:]\s*(\S+)" FROM input1');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (600, 'last_output_text', 'BZ-0092-2024');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (600, 'last_run_status', 'success');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (601, 'rule_type', 'direct_entity');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (601, 'action_type', 'use_entity_value');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (601, 'description', '直接使用附件实体值填充评审对象');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (601, 'last_output_text', '中国电建集团成都勘测设计研究院有限公司');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (601, 'last_run_status', 'success');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (602, 'rule_type', 'extraction');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (602, 'action_type', 'extract_pattern');
INSERT INTO node_properties (node_id, prop_key, prop_value, prop_json) VALUES (602, 'action_config', NULL, '{"pattern": "评审得分[：:]\\s*([\\d.]+)", "group": 1}'::jsonb);
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (602, 'dsl_content', 'EXTRACT pattern="评审得分[：:]\s*([\d.]+)" FROM input1');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (602, 'last_output_text', '93.33');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (602, 'last_run_status', 'success');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (603, 'rule_type', 'direct_entity');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (603, 'action_type', 'use_entity_value');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (603, 'description', '直接使用实体值填充评审对象简称');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (603, 'last_output_text', '成都院');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (603, 'last_run_status', 'success');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (604, 'rule_type', 'direct_entity');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (604, 'action_type', 'use_entity_value');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (604, 'description', '直接使用实体值填充申请级别');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (604, 'last_output_text', '一级');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (604, 'last_run_status', 'success');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (300, 'report_code', 'RPT-SPSRR-HDY-2024');
INSERT INTO node_properties (node_id, prop_key, prop_value) VALUES (300, 'title', '华东院2024年安全生产标准化复审报告');

-- ============================================================
-- 8. Mock数据 - edge_properties
-- ============================================================

INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (620, 'input_key', 'input1');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (620, 'input_type', 'source_file_ref');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (621, 'input_key', 'entity');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (621, 'input_type', 'entity_ref');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (622, 'input_key', 'input1');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (622, 'input_type', 'source_file_ref');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (623, 'input_key', 'entity');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (623, 'input_type', 'entity_ref');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (624, 'input_key', 'entity');
INSERT INTO edge_properties (edge_id, prop_key, prop_value) VALUES (624, 'input_type', 'entity_ref');

-- ============================================================
-- 完成
-- ============================================================
COMMIT;

-- 验证数据
-- SELECT node_type, COUNT(*) FROM nodes GROUP BY node_type ORDER BY node_type;
-- SELECT edge_type, COUNT(*) FROM edges GROUP BY edge_type ORDER BY edge_type;
-- SELECT * FROM v_reports;
-- SELECT * FROM v_template_elements WHERE template_id = 101 ORDER BY sort_order;
-- SELECT * FROM v_report_element_values WHERE report_id = 200;
