feat: AI事前预警 — 现金流预测+预警扩展+准确率+情景建议
This commit is contained in:
@@ -112,6 +112,9 @@ class KPIAlert(Base):
|
||||
kpi_value_id = Column(Integer, ForeignKey("kpi_values.id"), nullable=True)
|
||||
alert_level = Column(String(20), default="yellow", comment="green/yellow/red")
|
||||
alert_message = Column(String(500), nullable=False)
|
||||
alert_type = Column(String(30), default="actual", comment="actual/forecast — 实际值超限/预测值超限")
|
||||
suggestion = Column(Text, nullable=True, comment="情景建议")
|
||||
action_plan_linked_id = Column(Integer, nullable=True, comment="关联的改善计划ID")
|
||||
status = Column(String(20), default="pending", comment="pending/processing/resolved")
|
||||
assignee = Column(String(100), nullable=True, comment="处理人")
|
||||
resolution = Column(Text, nullable=True, comment="处理结果")
|
||||
@@ -362,3 +365,42 @@ class OKRTemplate(Base):
|
||||
is_active = Column(Integer, default=1)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
class CashForecast(Base):
|
||||
"""现金流预测 — 每日未来30天预测"""
|
||||
__tablename__ = "cash_forecasts"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
entity_id = Column(Integer, ForeignKey("entities.id"), nullable=False, comment="企业ID")
|
||||
forecast_date = Column(DateTime, nullable=False, comment="预测日期(每天一条)")
|
||||
predicted_cash = Column(Float, nullable=True, comment="预测现金余额")
|
||||
lower_bound = Column(Float, nullable=True, comment="置信区间下界")
|
||||
upper_bound = Column(Float, nullable=True, comment="置信区间上界")
|
||||
alert_status = Column(String(20), default="green", comment="green/yellow/red")
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
|
||||
class ForecastAccuracy(Base):
|
||||
"""预测准确率 — 上期预测 vs 本期实际"""
|
||||
__tablename__ = "forecast_accuracy"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
entity_id = Column(Integer, ForeignKey("entities.id"), nullable=False, comment="企业ID")
|
||||
period = Column(String(20), nullable=False, comment="期间 2026-07")
|
||||
forecast_value = Column(Float, nullable=True, comment="预测值")
|
||||
actual_value = Column(Float, nullable=True, comment="实际值")
|
||||
mae = Column(Float, nullable=True, comment="绝对误差")
|
||||
mape = Column(Float, nullable=True, comment="百分比误差")
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
|
||||
class ScenarioSuggestion(Base):
|
||||
"""情景建议模板 — 根据不同预警类型自动生成建议"""
|
||||
__tablename__ = "scenario_suggestions"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
alert_type = Column(String(30), nullable=False, comment="预警类型: cash_low/cash_critical/cost_high/revenue_drop")
|
||||
title = Column(String(200), nullable=False, comment="建议标题")
|
||||
description = Column(Text, nullable=True, comment="详细建议")
|
||||
action_template = Column(Text, nullable=True, comment="改善行动模板")
|
||||
priority = Column(String(20), default="medium", comment="high/medium/low")
|
||||
sort_order = Column(Integer, default=0, comment="排序")
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
Reference in New Issue
Block a user