This commit is contained in:
2026-01-16 18:16:33 +08:00
parent 9f3c96ce73
commit e53c3c838c
26 changed files with 1473 additions and 386 deletions

View File

@@ -14,14 +14,26 @@ def export_report(format: str = "xlsx", db: Session = Depends(get_db)):
generator = ReportGenerator(db)
print(f"Export request received. Format: {format}")
if format == 'xlsx':
output = generator.generate_excel()
media_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filename = "dit_attribution_report.xlsx"
try:
print("Generating Excel...")
output = generator.generate_excel()
print("Excel generated successfully.")
media_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filename = "dit_attribution_report.xlsx"
except Exception as e:
print(f"Error generating Excel: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
else:
output = generator.generate_pdf()
media_type = "application/pdf"
filename = "dit_attribution_report.pdf"
try:
output = generator.generate_pdf()
media_type = "application/pdf"
filename = "dit_attribution_report.pdf"
except Exception as e:
print(f"Error generating PDF: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
return StreamingResponse(
output,