dev_course
SylorHuang 6 years ago
parent e9a3068c8f
commit fb279178ae

@ -20,8 +20,9 @@ class ZipsController < ApplicationController
exercises = ExportExercisesService.new(@exercise,@ex_users) exercises = ExportExercisesService.new(@exercise,@ex_users)
file_name = filename_for_content_disposition(exercises.filename) 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' send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
logger.info("##################_______________________file_name___________1100101010010__________###########")
rescue Exception => e rescue Exception => e
normal_status(-1, e.message) normal_status(-1, e.message)
end end
@ -40,7 +41,7 @@ class ZipsController < ApplicationController
def get_exercise def get_exercise
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin 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] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")

@ -41,9 +41,14 @@ class ExerciseUserPdfService
# aa = File.open(Rails.root.join("public/123.html"),"w+") # aa = File.open(Rails.root.join("public/123.html"),"w+")
# aa.syswrite(kit.source) # aa.syswrite(kit.source)
#正式需删掉------- #正式需删掉-------
logger.info("##################_______________________file_name___________5555555555__________###########")
file = Tempfile.new(filename) file = Tempfile.new(filename)
logger.info("##################_______________________file_name___________66666666__________###########")
kit.to_pdf(file.path) kit.to_pdf(file.path)
logger.info("##################_______________________file_name___________7777777777__________###########")
file file
end end

@ -14,15 +14,29 @@ class ExportExercisesService
end end
def ex_zip def ex_zip
logger.info("##################_______________________file_name___________11111__________###########")
zip_file = Tempfile.new(filename) zip_file = Tempfile.new(filename)
logger.info("##################_______________________file_name___________2222222__________###########")
pdfs = [] pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
logger.info("##################_______________________file_name___________3333333__________###########")
ex_users.each do |ex_user| ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user) export = ExerciseUserPdfService.new(exercise, ex_user)
logger.info("##################_______________________file_name___________444444__________###########")
pdf = export.ex_pdf pdf = export.ex_pdf
logger.info("##################_______________________file_name___________888888888__________###########")
pdfs << pdf pdfs << pdf
logger.info("##################_______________________file_name___________999999999__________###########")
begin begin
zip.add(export.filename, pdf.path) zip.add(export.filename, pdf.path)
logger.info("##################_______________________file_name___________10000000000000__________###########")
rescue => ex rescue => ex
Rails.logger.error(ex.message) Rails.logger.error(ex.message)
zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") }

Loading…
Cancel
Save