# 2️ 解析审查项配置
from typing import List, Dict, Union
def _replace_review_suffix(items: List[str], mapping: Dict[str, Union[str, List[str]]]) -> List[str]:

    """
    将列表中字符串的下划线后内容替换为映射表中的对应值
    处理多值映射（如completeness_check对应两个值时生成两条结果）
    """
    result = []
    for item in items:
        # 拆分下划线前后部分（只拆分第一个下划线，因为后缀可能包含下划线）
        if '_' in item:
            prefix, suffix = item.split('_', 1)  # split('_', 1) 确保只拆分一次
        else:
            # 无下划线时直接保留原字符串（根据实际需求可调整）
            result.append(item)
            continue
        
        # 获取映射值，无匹配时保留原后缀
        mapped_value = mapping.get(suffix, suffix)
        
        # 处理单值映射
        if isinstance(mapped_value, str):
            result.append(f"{prefix}_{mapped_value}")
        # 处理多值映射（列表类型）
        elif isinstance(mapped_value, list):
            for val in mapped_value:
                result.append(f"{prefix}_{val}")
    
    return result

review_func_mapping: Dict[str, Union[str, List[str]]] = {
    'sensitive_word_check': 'sensitive_word_check',
    'semantic_logic_check': 'check_semantic_logic',
    'completeness_check': ['check_completeness', 'outline_check'],
    'timeliness_check': 'timeliness_basis_reviewer',
    'reference_check': 'reference_basis_reviewer',
    'sensitive_check': 'check_sensitive',
    'non_parameter_compliance_check': 'check_non_parameter_compliance',
    'parameter_compliance_check': 'check_parameter_compliance'
}


review_item_config = [
        "safety_sensitive_check",
    "overview_completeness_check",
    "basis_timeliness_check",
    "basis_sensitive_word_check",
    "catalogue_sensitive_word_check",
    "catalogue_semantic_logic_check",
    "basis_timeliness_check",

]
review_item_config = _replace_review_suffix(review_item_config, review_func_mapping)

review_item_dict = {}
for item in review_item_config:
    key, value = item.split("_", 1)
    review_item_dict.setdefault(key, []).append(value)

# 依据方案标准章节顺序进行排序
sgfa_chapter_index_order = ["catalogue", "basis", "overview", "plan","technology", "safety", "quality", "environment", 
"management", "acceptance", "other"]

all_keys = review_item_dict.keys()
sorted_keys = sorted(
    all_keys,
    key=lambda x :sgfa_chapter_index_order.index(x)
)
review_item_dict_sorted = {}
for key in sorted_keys:
    review_item_dict_sorted[key] = review_item_dict[key]
print(f"审查项配置解析完成: {review_item_dict_sorted}")

# 3️ 获取结构化内容

