fix: 报表导出增加诊断日志
在 CSV/XLSX 导出时记录 raw_rows 数量和 detail_map 周期键, 用于排查导出缺少订单明细的问题。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
95de290db8
commit
9fe93d1aa1
@ -128,6 +128,12 @@ class ExportService:
|
||||
raw_rows (list): 订单明细行列表,用于追加明细数据
|
||||
"""
|
||||
detail_map = self._build_detail_map(raw_rows, report["stat_type"])
|
||||
import logging
|
||||
_log = logging.getLogger(__name__)
|
||||
_log.info("[CSV导出] stat_type=%s, 汇总周期数=%d, raw_rows=%d, detail_map周期=%s",
|
||||
report["stat_type"], len(report["list"]),
|
||||
len(raw_rows) if raw_rows else 0,
|
||||
list(detail_map.keys()) if detail_map else "空")
|
||||
with file_path.open("w", encoding="utf-8-sig", newline="") as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
writer.writerow(["统计周期", "订单数", "订单金额", "固定提成", "分类明细"])
|
||||
@ -147,6 +153,7 @@ class ExportService:
|
||||
(detail.created_at.strftime("%Y-%m-%d") if detail.created_at else ""),
|
||||
])
|
||||
writer.writerow(self._build_summary_row(report["list"]))
|
||||
_log.info("[CSV导出] 写入完成,文件=%s, 行数=%d", file_path.name, sum(1 for _ in file_path.open(encoding="utf-8-sig")))
|
||||
|
||||
def _write_xlsx(self, file_path: Path, report: dict, raw_rows: list | None = None) -> None:
|
||||
"""将报表汇总和订单明细写入 Excel 文件。
|
||||
@ -180,7 +187,10 @@ class ExportService:
|
||||
sheet.column_dimensions["E"].width = 48
|
||||
|
||||
# Sheet 2: 订单明细
|
||||
import logging
|
||||
_log_xlsx = logging.getLogger(__name__)
|
||||
if raw_rows:
|
||||
_log_xlsx.info("[XLSX导出] 订单明细行数=%d", len(raw_rows))
|
||||
detail_sheet = workbook.create_sheet("订单明细")
|
||||
detail_sheet.append(["统计周期", "订单号", "客户", "产品", "数量", "单价", "金额", "利润", "提成", "日期"])
|
||||
for row in raw_rows:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user