65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""Supplier profile API contracts."""
|
|
|
|
from pydantic import Field
|
|
|
|
from app.schemas.common import ApiSchema
|
|
|
|
|
|
class SupplierOption(ApiSchema):
|
|
name: str
|
|
anomaly_count: int
|
|
tier: str
|
|
|
|
|
|
class SupplierListData(ApiSchema):
|
|
items: list[SupplierOption] = Field(default_factory=list)
|
|
default_supplier: str | None = None
|
|
|
|
|
|
class SupplierMetric(ApiSchema):
|
|
cooperation_total: int | None = None
|
|
anomaly_total: int
|
|
anomaly_rate: float | None = None
|
|
frequency_alpha: float
|
|
risk_score: float | None = None
|
|
main_category_count: int
|
|
cooperation_count_basis: str = "按近3年采购订单去重单据编号统计"
|
|
anomaly_rate_basis: str = "暂无采购订单/生产批次总量,无法计算真实异常率"
|
|
|
|
|
|
class SupplierCategoryBreakdown(ApiSchema):
|
|
category: str
|
|
anomaly_count: int
|
|
anomaly_rate: float | None = None
|
|
top_material: str | None = None
|
|
top_problem: str | None = None
|
|
anomaly_rate_basis: str = "暂无供应商品类合作总量,无法计算真实异常率"
|
|
|
|
|
|
class SupplierRecentRecord(ApiSchema):
|
|
case_id: int
|
|
month: str | None = None
|
|
product: str | None = None
|
|
anomaly: str | None = None
|
|
defect_level: str | None = None
|
|
|
|
|
|
class FactoryRecommendation(ApiSchema):
|
|
category: str
|
|
preferred_factory: str | None = None
|
|
alternative_factory: str | None = None
|
|
reason: str
|
|
recommendation_basis: str = "暂无加工厂生产总量,无法计算真实异常率"
|
|
|
|
|
|
class SupplierProfileData(ApiSchema):
|
|
supplier_name: str
|
|
tier: str
|
|
tier_condition: str
|
|
metric: SupplierMetric
|
|
category_breakdown: list[SupplierCategoryBreakdown] = Field(default_factory=list)
|
|
monthly_trend: list[dict[str, int | str]] = Field(default_factory=list)
|
|
recent_records: list[SupplierRecentRecord] = Field(default_factory=list)
|
|
factory_recommendations: list[FactoryRecommendation] = Field(default_factory=list)
|
|
recommendation_note: str | None = None
|