analysis_report.py
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
数据模型 - 分析报告
"""
from dataclasses import dataclass, field
from decimal import Decimal
from datetime import datetime
from typing import Optional, Dict, Any
@dataclass
class AnalysisReport:
"""AI补货建议分析报告"""
task_no: str
group_id: int
dealer_grouping_id: int
id: Optional[int] = None
dealer_grouping_name: Optional[str] = None
brand_grouping_id: Optional[int] = None
report_type: str = "replenishment"
# 报告各模块 (字典结构)
replenishment_insights: Optional[Dict[str, Any]] = None
urgency_assessment: Optional[Dict[str, Any]] = None
strategy_recommendations: Optional[Dict[str, Any]] = None
execution_guide: Optional[Dict[str, Any]] = None
expected_outcomes: Optional[Dict[str, Any]] = None
# 统计信息
total_suggest_cnt: int = 0
total_suggest_amount: Decimal = Decimal("0")
shortage_risk_cnt: int = 0
excess_risk_cnt: int = 0
stagnant_cnt: int = 0
low_freq_cnt: int = 0
# LLM 元数据
llm_provider: str = ""
llm_model: str = ""
llm_tokens: int = 0
execution_time_ms: int = 0
statistics_date: str = ""
create_time: Optional[datetime] = None
def to_dict(self) -> dict:
"""转换为字典"""
return {
"task_no": self.task_no,
"group_id": self.group_id,
"dealer_grouping_id": self.dealer_grouping_id,
"dealer_grouping_name": self.dealer_grouping_name,
"brand_grouping_id": self.brand_grouping_id,
"report_type": self.report_type,
"replenishment_insights": self.replenishment_insights,
"urgency_assessment": self.urgency_assessment,
"strategy_recommendations": self.strategy_recommendations,
"execution_guide": self.execution_guide,
"expected_outcomes": self.expected_outcomes,
"total_suggest_cnt": self.total_suggest_cnt,
"total_suggest_amount": float(self.total_suggest_amount),
"shortage_risk_cnt": self.shortage_risk_cnt,
"excess_risk_cnt": self.excess_risk_cnt,
"stagnant_cnt": self.stagnant_cnt,
"low_freq_cnt": self.low_freq_cnt,
"llm_provider": self.llm_provider,
"llm_model": self.llm_model,
"llm_tokens": self.llm_tokens,
"execution_time_ms": self.execution_time_ms,
"statistics_date": self.statistics_date,
}