feat(rohs-check): 新增 RoHS 检核执行进度中增加 Excel 下载功能及相关配置

This commit is contained in:
hugo committed 2026-06-11 17:35:16 +08:00
1 parent ee39270069
commit 599d492895
14 files changed
+845 -272

No files matched your search

+22 -2
View File
@@ -1,6 +1,8 @@
from __future__ import annotations
from flask import Blueprint, jsonify, request
from io import BytesIO
from flask import Blueprint, jsonify, request, send_file
from app.auth_jwt import get_current_user
from app.errors import ForbiddenError, NotFoundError, UnauthorizedError
@@ -90,7 +92,7 @@ def _serialize_progress_run(run: ScheduleRun) -> dict:
"excel": {
"file_name": payload.get("excel_file_name"),
"file_size": payload.get("excel_file_size"),
"download_url": f"/api/workspace/schedule-runs/{run.id}/excel" if payload.get("excel_file_name") else None,
"download_url": f"/api/workspace/rohs-check/runs/{run.id}/excel" if payload.get("excel_file_name") else None,
},
"knowledge_base": {
"sync_status": payload.get("kb_sync_status"),
@@ -133,3 +135,21 @@ def workspace_rohs_run_detail(run_id: int):
if not _is_rohs_check_task(run.task):
raise ForbiddenError("Forbidden")
return jsonify({"ok": True, "run": _serialize_progress_run(run)})
@workspace_rohs_check_bp.route("/rohs-check/runs/<int:run_id>/excel", methods=["GET"])
def workspace_rohs_run_excel(run_id: int):
_require_user()
run = get_run(run_id)
if not run:
raise NotFoundError("run_not_found")
if not _is_rohs_check_task(run.task):
raise ForbiddenError("Forbidden")
if not run.excel_file_data:
raise NotFoundError("excel_not_found")
return send_file(
BytesIO(run.excel_file_data),
as_attachment=True,
download_name=run.excel_file_name or f"{run.run_no}.xlsx",
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)