diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 35373730c..3e3445e77 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -20,8 +20,9 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users) file_name = filename_for_content_disposition(exercises.filename) - logger.info("##################_______________________file_name_____________________############{file_name}") send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + logger.info("##################_______________________file_name___________1100101010010__________###########") + rescue Exception => e normal_status(-1, e.message) end @@ -40,7 +41,7 @@ class ZipsController < ApplicationController def get_exercise ActiveRecord::Base.transaction do begin - @exercise = Exercise.includes(:exercise_users).find_by(id:params[:exercise_id]) + @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 5f92aee9c..52f54163e 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,9 +41,14 @@ class ExerciseUserPdfService # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) #正式需删掉------- + logger.info("##################_______________________file_name___________5555555555__________###########") file = Tempfile.new(filename) + logger.info("##################_______________________file_name___________66666666__________###########") + kit.to_pdf(file.path) + logger.info("##################_______________________file_name___________7777777777__________###########") + file end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..4b7b10b9b 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -14,15 +14,29 @@ class ExportExercisesService end def ex_zip + logger.info("##################_______________________file_name___________11111__________###########") + zip_file = Tempfile.new(filename) + logger.info("##################_______________________file_name___________2222222__________###########") + pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| + logger.info("##################_______________________file_name___________3333333__________###########") + ex_users.each do |ex_user| export = ExerciseUserPdfService.new(exercise, ex_user) + logger.info("##################_______________________file_name___________444444__________###########") + pdf = export.ex_pdf + logger.info("##################_______________________file_name___________888888888__________###########") + pdfs << pdf + logger.info("##################_______________________file_name___________999999999__________###########") + begin zip.add(export.filename, pdf.path) + logger.info("##################_______________________file_name___________10000000000000__________###########") + rescue => ex Rails.logger.error(ex.message) zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") }