dev_course
SylorHuang 6 years ago
parent e9a3068c8f
commit fb279178ae

@ -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,"试卷不存在")

@ -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

@ -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}") }

Loading…
Cancel
Save