From 6244a713aed8cc96711ac813b403ede8c6873db7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Jul 2022 10:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=BA=AF=E6=BA=90pdf=E5=8F=AA=E9=9C=80=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/traces/projects_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/traces/projects_controller.rb b/app/controllers/traces/projects_controller.rb index 62573a1d8..e39d77a9e 100644 --- a/app/controllers/traces/projects_controller.rb +++ b/app/controllers/traces/projects_controller.rb @@ -69,12 +69,18 @@ class Traces::ProjectsController < Traces::BaseController def task_pdf - return render_error("task_id错误") if params[:task_id].blank? - result = Trace::PdfReportService.call(current_user.trace_token, params[:task_id]) - if result.is_a?(Hash) && result[:code] == 200 - redirect_to result[:download_url] + task_id = params[:task_id] + return render_error("task_id错误") if task_id.blank? + file_save_path = "public/trace_task_results/#{task_id}/report.pdf" + if File.exists?(file_save_path) + redirect_to "/trace_task_results/#{task_id}/report.pdf" else - render_error("下载报告失败!") + result = Trace::PdfReportService.call(current_user.trace_token, task_id) + if result.is_a?(Hash) && result[:code] == 200 + redirect_to result[:download_url] + else + render_error("下载报告失败!") + end end rescue Exception => exception puts exception.message