certflow.models.model_param_mapping 源代码
"""型号参数对照表模型
对标 VBA CanShuSheet 的 "型号压力转换表" 命名范围。
存储型号→压力/标准号/温度/介质的对照关系。
在 SQLite certflow.db 中创建,由 DatabaseManager._migrate_missing_columns() 自动管理。
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import Column, DateTime, Index, Integer, String
from certflow.models.base import Base
[文档]
class ModelParamMapping(Base):
"""型号参数对照表
Attributes:
id: 主键ID
product_model: 产品型号(如 Z41H-25C),唯一
pressure_value: 公称压力值(如 2.5MPa / 150Lb)
test_standard: 试压标准号(如 GB/T 13927-2008)
working_temp: 工作温度(如 ≤425℃)
working_medium: 适用介质(如水、蒸汽)
source: 来源 manual / auto-learned / import
usage_count: 使用次数(热门度)
created_at: 创建时间
updated_at: 更新时间
"""
__tablename__ = "model_param_mappings"
id = Column(Integer, primary_key=True, autoincrement=True)
product_model = Column(String(200), nullable=False, comment="产品型号")
pressure_value = Column(String(50), comment="公称压力值")
test_standard = Column(String(200), comment="试压标准号")
working_temp = Column(String(50), comment="工作温度")
working_medium = Column(String(100), comment="适用介质")
source = Column(String(20), default="manual", comment="来源")
usage_count = Column(Integer, default=0, comment="使用次数")
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
__table_args__ = (Index("idx_mapping_model", "product_model", unique=True),)
def __repr__(self) -> str:
return f"<ModelParamMapping(model={self.product_model}, pn={self.pressure_value})>"