certflow.config.settings module¶
CertFlow 配置管理 - 所有值从 config.yaml / .env 读取,零硬编码
提供模块级配置常量(直接通过 cfg() 读取 YAML)和工具函数.
- certflow.config.settings.get_layout_groups(enabled_only=True)[源代码]¶
读取常用布局配置驱动组(output.layout_groups,D 延后仅预留接口)。
每个组是一套效果集的命名组合,UI 单选框/按钮后续加载时一键套用 target+template+layout 等到各下拉。
- certflow.config.settings.get_scan_layout_presets()[源代码]¶
读取扫描拼版推荐值(output.targets.scan.defaults.layout_presets)。
供 ScanView「推荐拼版」下拉使用:用户选中即把
rows/cols套用到拼版自旋框, 并灰显自旋框(尺寸固化思路的延伸)。列表缺失或非 list 时返回 []。
- certflow.config.settings.get_scan_default_layout()[源代码]¶
读取启动默认选中的推荐拼版 label(output.targets.scan.defaults.default_layout)。
空字符串表示启动即「自定义」(拼版自旋框可编辑);否则启动即套用该预设并灰显自旋框。
- 返回:
预设 label;未配置或为空时返回 ""。
- 返回类型:
- certflow.config.settings.get_config_value(key, env_var=None, default=None)[源代码]¶
获取配置值,优先级: 环境变量 > YAML > 传入默认值
提供统一的配置读取接口,优先使用环境变量,其次使用YAML配置, 最后使用代码中的默认值.
- 参数:
- 返回:
获取到的配置值
- 返回类型:
Any
示例
>>> get_config_value("paths.sales_plan.primary", "VALVE_SALES_PLAN_PATH") "/path/to/sales/plan.xlsx"
- certflow.config.settings.get_temp_dir()[源代码]¶
临时文件根目录。
统一走 paths.local.yaml 覆盖层(pcfg):未配置时回退系统临时目录 (tempfile.gettempdir(),云环境正确);本地开发可在 paths.local.yaml 写 paths.temp.base 指向项目内目录,以便在项目中观察临时文件。
- 返回类型:
- certflow.config.settings.DATABASE_PATH: Path = PosixPath('/workspace/database/certflow.db')¶
SQLite数据库文件完整路径
- certflow.config.settings.OUTPUT_TEST_REPORT: Path = PosixPath('/workspace/output/reports')¶
试压报告输出目录
- certflow.config.settings.OUTPUT_QUALITY_CERT: Path = PosixPath('/workspace/output/certificates')¶
质量证书输出目录
- certflow.config.settings.OUTPUT_CERTIFICATE_IMAGES: Path = PosixPath('/workspace/output/images')¶
证书图片输出目录
- certflow.config.settings.NUMBERING_FORMAT: str = '{prefix}{year}{month}{seq:03d}{suffix}'¶
编号格式模板(V2)
- certflow.config.settings.NUMBERING_SUFFIXES: dict = {'default': '', 'market': 'B', 'production': '', 'purchase': 'Y', 'repair': 'XL', 'stock': '', 'supply': 'G', 'test': 'L'}¶
编号后缀映射(V2)
- certflow.config.settings.NUMBERING_AUTO_NUMBER_MODE: dict | None = {'description': '是否启用自动编号模式', 'enabled': False, 'rules': [{'action': '清空并重新编号', 'condition': '背景色=65535 AND 未发货 AND 未编号'}, {'action': '自动获取编号', 'condition': '单元格为空'}, {'action': '保留原编号', 'condition': '单元格非空 AND 含连字符 AND 未发货 AND 未编号'}, {'action': '清空并重新编号', 'condition': '单元格非空 AND 不含连字符 AND 未发货 AND 未编号'}]}¶
自动编号模式配置(V2)
- certflow.config.settings.NUMBERING_SUFFIX_RULES: list = [{'exclude': None, 'field': '生产令号', 'keywords': ['试压'], 'suffix': 'L'}, {'exclude': None, 'field': '生产令号', 'keywords': ['市场直发提供报告'], 'suffix': 'B'}, {'exclude': None, 'field': '生产令号', 'keywords': ['生产', '库存'], 'suffix': ''}, {'exclude': None, 'field': '供货类型', 'keywords': ['供应'], 'suffix': 'G'}, {'exclude': None, 'field': '生产令号', 'keywords': ['维修', '修理', '修复', '返修'], 'suffix': 'XL'}, {'exclude': None, 'field': '种类', 'keywords': ['维修', '修理', '修复', '返修'], 'suffix': 'XL'}, {'exclude': None, 'field': '供货类型', 'keywords': ['外购'], 'suffix': 'Y'}]¶
编号后缀规则列表(V2)
- certflow.config.settings.CERTIFICATE_FORMAT_TEMPLATE: str = '{prefix}{year}{month}{seq:04d}{suffix}'¶
证书编号格式模板(V1兼容)
- certflow.config.settings.VBA_COLORS: dict = {0: '未发货', 255: '红字', 65535: '待编号', 10092543: '外购未回', 16711680: '已发货', 16777164: '外购已回', 16777215: '自产'}¶
VBA颜色索引到颜色的映射
- certflow.config.settings.FONT_COLOR_TO_SHIPPING: dict = {0: '未发货', 5: '已发货', 255: '已收款', 16711680: '已发货'}¶
字体颜色到发货状态的映射
- certflow.config.settings.BG_COLOR_TO_STATUS: dict = {65535: '特殊订单', 8421504: '订单取消', 10092543: '外购未回', 10921638: '订单取消', 16777164: '外购已回', 16777215: '透明忽略'}¶
背景颜色到状态的映射
- certflow.config.settings.THEME_FONT_COLORS: dict = {'THEME_1': '特殊标记', 'THEME_2': '警告标记'}¶
THEME 字体颜色到状态的映射
- certflow.config.settings.PN_LB_TO_MPA: dict[int, float] = {150: 2.0, 300: 5.0, 600: 10.0, 800: 13.0, 900: 15.0, 1500: 25.0, 2500: 42.0}¶
英制 LB 磅级 → 公制 MPa 压力值换算表(配置驱动,默认空→回退 PNService 内置表)
- certflow.config.settings.DUPLICATE_CHECK_FIELDS: list = ['订货单位', '产品名称', '产品型号', '口径', '数量']¶
重复检查字段列表
- certflow.config.settings.UNIQUE_KEY_FIELD_FALLBACKS: dict = {'生产令号': ['生产令号', '子项目'], '销售订单号': ['销售订单号', '设备位号']}¶
唯一键字段回退映射
- certflow.config.settings.SORT_RULES_KEYS: list = [{'field': 'plan_date', 'order': 'asc'}, {'field': 'customer', 'order': 'asc'}, {'field': 'product_model', 'order': 'asc'}, {'field': 'project_name', 'order': 'asc'}]¶
排序规则键列表
- certflow.config.settings.SORT_KEYS: list[str] = ['plan_date', 'customer', 'product_model', 'project_name']¶
排序字段名列表(向后兼容)
- certflow.config.settings.EXPORT_SUMMARY_SUM_COLUMNS: list = [{'field': '数量', 'formula': 'SUM'}, {'criteria': '是', 'field': '已发货', 'formula': 'COUNTIF'}]¶
需要求和的列列表
- certflow.config.settings.SALE_PLAN_COLUMNS: dict = {'业务归口': 'business_dept', '产品名称': 'product_name', '产品型号': 'product_model', '产品编号': 'product_code', '产品规格': 'product_spec', '付款方式': 'payment_method', '供货类型': 'supply_type', '单价': 'unit_price', '合同交货期': 'contract_delivery_date', '合同号': 'contract_no', '合格证清单备注': 'certificate_remarks', '总价': 'total_price', '执行情况': 'execution_status', '技术要求': 'tech_requirements', '数量': 'quantity', '生产令号': 'production_order_no', '种类': 'category', '计划交货期': 'planned_delivery_date', '计划单号': 'plan_no', '计划日期': 'plan_date', '订货单位': 'customer', '设备位号': 'equipment_code', '重量': 'weight', '销售计划备注': 'sales_plan_remarks', '销售订单号': 'sales_order_no', '隶属部门': 'affiliated_dept', '项目单位': 'project_unit', '项目名称': 'project_name'}¶
销售计划列映射字典
- certflow.config.settings.COLUMN_ALIASES: dict = {'affiliated_dept': ['隶属部门', '部门'], 'business_dept': ['业务归口', '业务规口', '规口'], 'category': ['种类', '产品种类'], 'cert_product_model': ['合格证型号', '合格证产品型号'], 'cert_product_name': ['合格证产品名称', '合格证名称'], 'cert_product_spec': ['合格证规格', '合格证产品规格'], 'certificate_remarks': ['备注', '合格证清单备注', '合格证备注'], 'contract_delivery_date': ['合同交货期', '合同交货期\\到货日期'], 'contract_no': ['合同编号', '合同号'], 'customer': ['订货单位', '用户单位', '客户', '订货公司', '用户名称'], 'equipment_code': ['设备位号', '设备位号/计划号/物代码', '产品位号'], 'execution_status': ['执行情况', '执行状态', '生产状态'], 'payment_method': ['付款方式'], 'plan_date': ['计划日期', '下计划日期', '日期', '排产日期'], 'plan_no': ['计划单号', '计划编号'], 'planned_delivery_date': ['计划交货期'], 'product_code': ['产品编号', '出厂编号', '合格证编号'], 'product_model': ['产品型号', '型 号', '型号', '阀门型号', '规格型号'], 'product_name': ['产品名称', '阀门名称', '名称'], 'product_spec': ['产品规格', '规格', '口径'], 'production_order_no': ['生产令号', '令号', '生产编号', 'AP'], 'project_name': ['项目名称', '项目', '工程项目'], 'project_unit': ['项目单位'], 'quantity': ['数量', '台数', '订货数量'], 'sales_order_no': ['销售订单号', '订单号', '销售订单', 'AO'], 'sales_plan_remarks': ['备 注', '备 注', '销售计划备注', '销售计划备注信息'], 'supply_type': ['供货类型', '执'], 'tech_requirements': ['技术要求'], 'total_price': ['总价', '总价(元)', '总价\n(元)'], 'unit_price': ['单价', '单价(元)'], 'weight': ['重量', '产品重量']}¶
列别名映射
- certflow.config.settings.STYLED_IMPORT_COLUMNS: list = ['contract_no', 'plan_date', 'plan_no', 'customer', 'project_name', 'product_name', 'product_model', 'product_spec', 'cert_product_name', 'cert_product_model', 'cert_product_spec', 'quantity', 'sales_order_no', 'production_order_no', 'supply_type', 'execution_status', 'sales_plan_remarks']¶
带格式导入时保留的列列表
- certflow.config.settings.IMPORT_GATE: dict = {'enabled': True, 'legacy_field': 'plan_no', 'match_keys': ['plan_date', 'customer', 'project_name'], 'mode': 'isolate', 'order_identity_fields': ['sales_order_no', 'production_order_no'], 'skip_when_missing': []}¶
导入门控配置:enabled / skip_when_missing / mode / match_keys(全配置驱动)
- certflow.config.settings.DUAL_FIELD_MAPPING: dict = {'import_mode': 'copy', 'pairs': [{'cert': 'cert_product_name', 'contract': 'product_name'}, {'cert': 'cert_product_model', 'contract': 'product_model'}, {'cert': 'cert_product_spec', 'contract': 'product_spec'}]}¶
双字段映射配置:pairs(contract→cert)+ import_mode(copy/override/lazy)
- certflow.config.settings.IMPORT_MAPPING_PREPROCESSOR: dict | None = {'delete_columns': [{'check_row': 2, 'header': '用户单位'}, {'check_row': 2, 'header': '类别'}], 'description': 'Python脚本执行预处理', 'enabled': True, 'merge_fields': {'fields': [{'null_value': '【空白】', 'prefix': '技术要求:', 'source': '技术要求'}, {'null_value': '【空白】', 'prefix': '设备位号:', 'source': '销售订单号'}, {'null_value': '【空白】', 'prefix': '子项目:', 'source': '生产令号'}, {'null_value': '【空白】', 'prefix': '产品编号:', 'source': '产品编号'}, {'null_value': '【空白】', 'prefix': '种类:', 'source': '种类'}, {'null_value': '【空白】', 'prefix': '重量:', 'source': '重量'}], 'separator': '|', 'target': '技术要求'}}¶
导入映射预处理器配置
- certflow.config.settings.IMPORT_MAPPING_COLUMN_MAPPING: list = [{'group': '业务', 'source': '合同编号', 'target': '合同号'}, {'group': '可修改', 'source': '下计划日期', 'target': '计划日期'}, {'group': '可修改', 'source': '计划单号', 'target': '计划单号'}, {'group': '可修改', 'source': '用户单位', 'target': '订货单位'}, {'group': '业务', 'source': '项目名称', 'target': '项目名称'}, {'group': '业务', 'source': '项目单位', 'target': '项目单位'}, {'group': '业务', 'source': '种类', 'target': '种类'}, {'group': '可修改', 'source': '产品名称', 'target': '产品名称'}, {'group': '可修改', 'source': '型 号', 'target': '产品型号'}, {'group': '可修改', 'source': '规格', 'target': '产品规格'}, {'group': '可修改', 'source': '数量', 'target': '数量'}, {'group': '价格', 'source': '单价(元)', 'target': '单价'}, {'group': '价格', 'source': '总价(元)', 'target': '总价'}, {'group': '业务', 'source': '业务规口', 'target': '业务归口'}, {'group': '业务', 'source': '隶属部门', 'target': '隶属部门'}, {'group': '产品', 'source': '产品编号', 'target': '产品编号'}, {'group': '交货', 'source': '合同交货期\\到货日期', 'target': '计划交货期'}, {'group': '业务', 'source': '付款方式', 'target': '付款方式'}, {'group': '业务', 'source': '执行情况', 'target': '是否发货重点'}, {'group': '交货', 'priority': 1, 'source': '计划交货期', 'target': '计划交货期'}, {'group': '交货', 'source': '执', 'target': '供货类型'}, {'group': '技术', 'source': '技术要求', 'target': '技术要求'}, {'group': '技术', 'source': '备 注', 'target': '备注2'}, {'group': '设备', 'source': '设备位号/计划号/物代码', 'target': '设备位号'}, {'group': '设备', 'source': '销售订单号', 'target': '销售订单号'}, {'group': '设备', 'source': '生产令号', 'target': '生产令号'}, {'group': '设备', 'source': '重量', 'target': '重量'}, {'group': '备份', 'source': '下计划日期', 'target': '计划日期_原始'}, {'group': '备份', 'source': '用户单位', 'target': '订货单位_原始'}, {'group': '备份', 'source': '产品名称', 'target': '产品名称_原始'}, {'group': '备份', 'source': '型 号', 'target': '产品型号_原始'}, {'group': '备份', 'source': '规格', 'target': '产品规格_原始'}, {'group': '备份', 'source': '数量', 'target': '数量_原始'}]¶
导入列映射规则列表
- certflow.config.settings.IMPORT_MAPPING_DEFAULT_VALUES: dict = {'供货商': '', '启闭件材质': '', '工作介质': '', '工作温度': '', '试压标准': '', '阀体材质': '', '阀杆材质': ''}¶
导入默认值映射
- certflow.config.settings.LOG_FORMAT: str = '{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}'¶
日志格式字符串
- certflow.config.settings.get_views_config()[源代码]¶
获取查询视图配置(canonical UI 源 = ui.yaml,Route A Phase 1)。
- 返回:
视图配置字典(view_name → view 定义),来自
ui.yaml的query_page.views;ui.yaml 不可用时返回空字典。- 返回类型:
- certflow.config.settings.get_views_config_yaml()[源代码]¶
从 ui.yaml 读取查询视图配置(canonical UI 源,Route A Phase 1)。
返回
ui.yaml的query_page.views;加载失败或 ui.yaml 不可用时返回空字典。- 返回:
视图配置字典(view_name → view 定义)。
- 返回类型:
- certflow.config.settings.get_ui_config()[源代码]¶
加载并缓存 UI 动态配置(ui.yaml → UIConfig)。
供
query_view等动态 UI 驱动层消费(§17):用户编辑ui.yaml即可 增删查询右键菜单项。加载失败或文件缺失时返回False,调用方应回退到get_views_config()``(ui.yaml ``query_page.views)基础菜单。- 返回:
加载成功返回 UIConfig 实例;不可用返回 False。
- 返回类型:
UIConfig | False
- certflow.config.settings.TEMPLATE_CERTIFICATE_CHINESE: Path = PosixPath('/workspace/data/templates/中文合格证模板.xlsx')¶
中文合格证模板路径
- certflow.config.settings.TEMPLATE_CERTIFICATE_BILINGUAL: Path = PosixPath('/workspace/data/templates/中英文合格证模板.xlsx')¶
中英文合格证模板路径
- certflow.config.settings.TEMPLATE_CERTIFICATE_RUSSIAN: Path = PosixPath('/workspace/data/templates/俄英文合格证模板.xlsx')¶
俄文合格证模板路径
- certflow.config.settings.TEMPLATE_TEST_REPORT_SMALL: Path = PosixPath('/workspace/data/templates/试压报告模板_少.xlsx')¶
小型试压报告模板路径
- certflow.config.settings.TEMPLATE_TEST_REPORT_MEDIUM: Path = PosixPath('/workspace/data/templates/试压报告模板_中.xlsx')¶
中型试压报告模板路径
- certflow.config.settings.TEMPLATE_QUALITY_CERT_FILE: Path = PosixPath('/workspace/data/templates/质保书模板.xlsx')¶
质量证书模板文件路径
- certflow.config.settings.ON_COLLISION: str = 'quarantine'¶
批内撞键(同 unique_key)处理策略: - quarantine: 后续行隔离到待处理表(默认,保持现有行为) - merge_max: 同键数量不同 → 取较大数量合并为一行(不隔离) - merge_sum: 同键数量不同 → 数量求和合并为一行(不隔离) 注:仅作用于「批内内存去重」阶段的同键撞行;跨批/跨库去重仍走 _find_existing。
- certflow.config.settings.MONITORED_FIELDS: list = ['product_name', 'product_model', 'product_spec', 'quantity', 'customer', 'project_name', 'plan_date', 'supply_type']¶
导入时监控变更的字段列表
- certflow.config.settings.get_sort_rules()[源代码]¶
获取完整排序规则列表
示例
>>> get_sort_rules() [{"field": "order_number", "order": "asc"}, {"field": "amount", "order": "desc"}]
- certflow.config.settings.GROUPING_KEYS: list = ['plan_date', 'customer', 'project_name', 'plan_no']¶
分组键列表(英文字段名)
- certflow.config.settings.GROUPING_KEYS_NO_PROJECT: list = ['plan_date', 'customer', 'plan_no']¶
无项目名称时的分组键列表(英文字段名)
- certflow.config.settings.SORTING_KEYS: list = [{'field': 'product_name', 'order': 'asc'}, {'field': 'product_model', 'order': 'asc'}, {'field': 'product_spec', 'order': 'asc'}]¶
组内排序键列表,每个元素包含 field 和 order
- certflow.config.settings.SORTING_FIELD_NAMES: list = ['product_name', 'product_model', 'product_spec']¶
排序字段名列表(按优先级顺序)
- certflow.config.settings.get_column_by_alias(excel_column)[源代码]¶
通过别名查找目标列名
在列别名映射中查找给定的Excel列名,返回对应的目标字段名.
示例
>>> get_column_by_alias("订单号") "order_number" >>> get_column_by_alias("客户名称") "customer_name"
- certflow.config.settings.get_ui_table_alternating_colors()[源代码]¶
获取UI表格是否使用交替行颜色
- 返回:
是否启用交替行颜色,默认为True
- 返回类型:
- certflow.config.settings.ensure_directories()[源代码]¶
创建所有必需的目录
遍历所有配置的目录路径,确保它们存在. 包括数据库目录、临时文件目录、日志目录、资源目录及其子目录.
- 返回类型:
None
- certflow.config.settings.reload_config()[源代码]¶
强制重新加载 YAML 配置
清除配置缓存,下次读取时会重新加载配置文件. 用于运行时动态更新配置.
- 返回类型:
None
- certflow.config.settings.merge_user_config(patch, *, merge=True)[源代码]¶
按段增量写入用户配置(推荐, T18 核心 API)。
- 仅重写 patch 中涉及键所属的文件, 不再整文件重写另一桶, 消除多写者互相覆盖:
patch 的桶2 键 → userconfig.yaml(深合并)
patch 的桶3 键 → userconfig.state.yaml(深合并)
- certflow.config.settings.get_recent_files()[源代码]¶
获取最近打开的文件列表
- 返回:
最近文件列表,每个元素包含path和last_used字段
- 返回类型:
List[Dict]
- certflow.config.settings.add_recent_file(file_path)[源代码]¶
添加文件到最近打开列表
如果文件已存在,会移到列表开头.
- 参数:
file_path (str) -- 文件路径
- 返回类型:
None
- certflow.config.settings.should_confirm_before_delete(default=True)[源代码]¶
是否在执行删除前弹出确认对话框(用户偏好,默认开启)
- certflow.config.settings.REPORT_FILENAME_FORMAT: str = '{report_type}_{variant}'¶
报告文件名自动命名格式(占位符见 ReportOutputService._build_filename)
- certflow.config.settings.REPORT_SHEET_NAME_FORMAT: str = '{report_type}({plan_date_short}计划)_{report_date}{serial}'¶
报告内工作表(数据表)标签名格式:默认带计划日期、制作日期与流水号,避免千篇一律的模板变体名
- certflow.config.settings.should_export_report_pdf()[源代码]¶
生成报告时是否同时导出 PDF。
优先级:用户覆盖层
preferences.report_export_pdf> 基础层report.export_pdf>False。默认不导出(仅生成 xlsx)。- 返回类型:
- certflow.config.settings.get_report_sheet_name_format()[源代码]¶
报告内工作表(数据表)标签名格式(同文件名占位符,默认带计划/制作日期)。
- 返回类型:
- certflow.config.settings.get_report_save_path()[源代码]¶
报告保存路径覆盖(用户覆盖层优先,回退基础层;空字符串→用 paths.report_archive.root)。
- 返回类型:
- certflow.config.settings.get_report_page_options()[源代码]¶
报告每页记录数候选(配置可选,而非数字递增),按报告类型分组。
- 返回:
{kind: [候选值列表]};kind ∈ quality/pressure/material。- 返回类型:
- certflow.config.settings.get_override(section, key, default=None)[源代码]¶
读取 userconfig 覆盖层中指定段/键的值(优先级高于 config.yaml 基础层)。
用于系统设置中用户自定义的覆盖项(如
print_layout、system_settings), 与 §10「基础层 + 覆盖层」架构一致。文件缺失或键不存在时返回default。
- certflow.config.settings.get_override_section(section)[源代码]¶
读取 userconfig 覆盖层中整个段(用于一次性合并某段覆盖到基础配置)。
- 参数:
section (str) -- 覆盖段名
- 返回:
该段的覆盖字典;缺失时返回空字典
- 返回类型:
Dict
- certflow.config.settings.set_override_section(section, data)[源代码]¶
写入 userconfig 覆盖层整个段并立即持久化。
用于一次性保存某段全部覆盖字段(如
print_layout打印版式), 与 §10「基础层 + 覆盖层」架构一致。传入空字典等效于清空该段覆盖。
- certflow.config.settings.get_recent_import_files(max_count=None)[源代码]¶
获取最近导入的文件列表
- 参数:
max_count (int | None) -- 最大返回数量,为 None 时使用用户偏好设置
- 返回:
最近导入文件列表
- 返回类型:
List[Dict]
- certflow.config.settings.ensure_ui_config()[源代码]¶
确保UI配置文件存在
如果UI配置文件不存在,创建带有默认配置的ui.yaml文件.
- 返回类型:
None