|
|
|
@ -134,8 +134,11 @@ class ZipdownController < ApplicationController
|
|
|
|
|
homework_common.student_works.each do |work|
|
|
|
|
|
unless work.attachments.empty?
|
|
|
|
|
out_file = zip_student_work_by_user(work)
|
|
|
|
|
|
|
|
|
|
bid_homework_path << out_file.file_path
|
|
|
|
|
digests << out_file.file_digest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
homework_id = homework_common.id
|
|
|
|
@ -172,7 +175,11 @@ class ZipdownController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def zip_student_work_by_user work
|
|
|
|
|
def make_zip_name(work)
|
|
|
|
|
"#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def zip_student_work_by_user(work)
|
|
|
|
|
homeworks_attach_path = []
|
|
|
|
|
not_exist_file = []
|
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
@ -186,11 +193,24 @@ class ZipdownController < ApplicationController
|
|
|
|
|
digests << 'not_exist_file'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#单个文件的话,不需要压缩,只改名
|
|
|
|
|
out_file = nil
|
|
|
|
|
if homeworks_attach_path.size == 1
|
|
|
|
|
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
|
|
|
|
|
zipping("#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
|
|
|
|
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
|
|
|
|
|
FileUtils.cp homeworks_attach_path.first, des_path
|
|
|
|
|
des_path
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
|
|
|
|
|
zipping("#{make_zip_name(work)}.zip",
|
|
|
|
|
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
out_file
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_or_pack(homework_id, user_id, digests)
|
|
|
|
|