195 lines
5.6 KiB
Python
195 lines
5.6 KiB
Python
"""利润模拟 Schema
|
|
|
|
利润模拟测算相关的请求和响应模型
|
|
"""
|
|
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class PeriodType(str, Enum):
|
|
"""周期类型"""
|
|
DAILY = "daily" # 日
|
|
WEEKLY = "weekly" # 周
|
|
MONTHLY = "monthly" # 月
|
|
|
|
|
|
# 利润模拟相关
|
|
|
|
class ProfitSimulationBase(BaseModel):
|
|
"""利润模拟基础字段"""
|
|
|
|
pricing_plan_id: int = Field(..., description="定价方案ID")
|
|
simulation_name: str = Field(..., min_length=1, max_length=100, description="模拟名称")
|
|
price: float = Field(..., gt=0, description="模拟价格")
|
|
estimated_volume: int = Field(..., gt=0, description="预估客量")
|
|
period_type: PeriodType = Field(..., description="周期类型")
|
|
|
|
|
|
class ProfitSimulationCreate(ProfitSimulationBase):
|
|
"""创建利润模拟请求"""
|
|
pass
|
|
|
|
|
|
class SimulateProfitRequest(BaseModel):
|
|
"""执行利润模拟请求"""
|
|
|
|
price: float = Field(..., gt=0, description="模拟价格")
|
|
estimated_volume: int = Field(..., gt=0, description="预估客量")
|
|
period_type: PeriodType = Field(PeriodType.MONTHLY, description="周期类型")
|
|
|
|
|
|
class SimulationInput(BaseModel):
|
|
"""模拟输入参数"""
|
|
|
|
price: float
|
|
cost_per_unit: float
|
|
estimated_volume: int
|
|
period_type: str
|
|
|
|
|
|
class SimulationResult(BaseModel):
|
|
"""模拟计算结果"""
|
|
|
|
estimated_revenue: float = Field(..., description="预估收入")
|
|
estimated_cost: float = Field(..., description="预估成本")
|
|
estimated_profit: float = Field(..., description="预估利润")
|
|
profit_margin: float = Field(..., description="利润率(%)")
|
|
profit_per_unit: float = Field(..., description="单位利润")
|
|
|
|
|
|
class BreakevenAnalysis(BaseModel):
|
|
"""盈亏平衡分析"""
|
|
|
|
breakeven_volume: int = Field(..., description="盈亏平衡客量")
|
|
current_volume: int = Field(..., description="当前预估客量")
|
|
safety_margin: int = Field(..., description="安全边际(客量)")
|
|
safety_margin_percentage: float = Field(..., description="安全边际率(%)")
|
|
|
|
|
|
class SimulateProfitResponse(BaseModel):
|
|
"""执行利润模拟响应"""
|
|
|
|
simulation_id: int
|
|
pricing_plan_id: int
|
|
project_name: str
|
|
input: SimulationInput
|
|
result: SimulationResult
|
|
breakeven_analysis: BreakevenAnalysis
|
|
created_at: datetime
|
|
|
|
|
|
class ProfitSimulationResponse(BaseModel):
|
|
"""利润模拟响应"""
|
|
|
|
id: int
|
|
pricing_plan_id: int
|
|
plan_name: Optional[str] = None
|
|
project_name: Optional[str] = None
|
|
simulation_name: str
|
|
price: float
|
|
estimated_volume: int
|
|
period_type: str
|
|
estimated_revenue: float
|
|
estimated_cost: float
|
|
estimated_profit: float
|
|
profit_margin: float
|
|
breakeven_volume: int
|
|
created_at: datetime
|
|
created_by_name: Optional[str] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class ProfitSimulationListResponse(BaseModel):
|
|
"""利润模拟列表响应"""
|
|
|
|
id: int
|
|
pricing_plan_id: int
|
|
plan_name: Optional[str] = None
|
|
project_name: Optional[str] = None
|
|
simulation_name: str
|
|
price: float
|
|
estimated_volume: int
|
|
period_type: str
|
|
estimated_profit: float
|
|
profit_margin: float
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class ProfitSimulationQuery(BaseModel):
|
|
"""利润模拟查询参数"""
|
|
|
|
page: int = Field(1, ge=1, description="页码")
|
|
page_size: int = Field(20, ge=1, le=100, description="每页数量")
|
|
pricing_plan_id: Optional[int] = Field(None, description="定价方案筛选")
|
|
period_type: Optional[PeriodType] = Field(None, description="周期类型筛选")
|
|
sort_by: str = Field("created_at", description="排序字段")
|
|
sort_order: str = Field("desc", description="排序方向")
|
|
|
|
|
|
# 敏感性分析相关
|
|
|
|
class SensitivityAnalysisRequest(BaseModel):
|
|
"""敏感性分析请求"""
|
|
|
|
price_change_rates: List[float] = Field(
|
|
default=[-20, -15, -10, -5, 0, 5, 10, 15, 20],
|
|
description="价格变动率列表(%)"
|
|
)
|
|
|
|
|
|
class SensitivityResultItem(BaseModel):
|
|
"""敏感性分析单项结果"""
|
|
|
|
price_change_rate: float = Field(..., description="价格变动率(%)")
|
|
adjusted_price: float = Field(..., description="调整后价格")
|
|
adjusted_profit: float = Field(..., description="调整后利润")
|
|
profit_change_rate: float = Field(..., description="利润变动率(%)")
|
|
|
|
|
|
class SensitivityInsights(BaseModel):
|
|
"""敏感性分析洞察"""
|
|
|
|
price_elasticity: str = Field(..., description="价格弹性描述")
|
|
risk_level: str = Field(..., description="风险等级")
|
|
recommendation: str = Field(..., description="建议")
|
|
|
|
|
|
class SensitivityAnalysisResponse(BaseModel):
|
|
"""敏感性分析响应"""
|
|
|
|
simulation_id: int
|
|
base_price: float
|
|
base_profit: float
|
|
sensitivity_results: List[SensitivityResultItem]
|
|
insights: Optional[SensitivityInsights] = None
|
|
|
|
|
|
# 盈亏平衡分析
|
|
|
|
class BreakevenRequest(BaseModel):
|
|
"""盈亏平衡分析请求"""
|
|
|
|
target_profit: Optional[float] = Field(None, description="目标利润(可选)")
|
|
|
|
|
|
class BreakevenResponse(BaseModel):
|
|
"""盈亏平衡分析响应"""
|
|
|
|
pricing_plan_id: int
|
|
project_name: str
|
|
price: float
|
|
unit_cost: float
|
|
fixed_cost_monthly: float
|
|
breakeven_volume: int = Field(..., description="盈亏平衡客量")
|
|
current_margin: float = Field(..., description="当前边际贡献")
|
|
target_profit_volume: Optional[int] = Field(None, description="达到目标利润所需客量")
|