|
|
|
@ -75,16 +75,21 @@ class ZipdownController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def zip_homework_by_user(homeattach)
|
|
|
|
|
homeworks_attach_path = []
|
|
|
|
|
not_exist_file = []
|
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
|
# 并且返回zip路径
|
|
|
|
|
homeattach.attachments.each do |attach|
|
|
|
|
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
|
|
|
|
if File.exist?(attach.diskfile)
|
|
|
|
|
homeworks_attach_path << attach.diskfile
|
|
|
|
|
else
|
|
|
|
|
not_exist_file << attach.filename
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
|
|
|
|
zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false)
|
|
|
|
|
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
|
|
|
|
|
# 输入待打包的文件列表,已经打包文件定位到ouput_path
|
|
|
|
|
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
|
|
|
|
|
input_filename = files_paths
|
|
|
|
@ -101,9 +106,11 @@ class ZipdownController < ApplicationController
|
|
|
|
|
|
|
|
|
|
zipfile.add(rename_file, filename)
|
|
|
|
|
end
|
|
|
|
|
#zipfile.get_output_stream('ReadMe') do |os|
|
|
|
|
|
# os.write 'Homeworks'
|
|
|
|
|
#end
|
|
|
|
|
unless not_exist_file.empty?
|
|
|
|
|
zipfile.get_output_stream('FILE_LOST.txt') do |os|
|
|
|
|
|
os.write l(:label_file_lost) + not_exist_file.join(',').to_s
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
zipfile_name
|
|
|
|
|
rescue Errno => e
|
|
|
|
@ -119,4 +126,4 @@ class ZipdownController < ApplicationController
|
|
|
|
|
attach = Attachment.find_by_disk_filename(name)
|
|
|
|
|
attach.filename
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|