commit
e6ed988c10
|
@ -948,6 +948,7 @@ class StudentWorkController < ApplicationController
|
||||||
}
|
}
|
||||||
uri = URI(url)
|
uri = URI(url)
|
||||||
body = solutions.to_json
|
body = solutions.to_json
|
||||||
|
binding.pry
|
||||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||||
request = Net::HTTP::Post.new(uri.path)
|
request = Net::HTTP::Post.new(uri.path)
|
||||||
request.body = body
|
request.body = body
|
||||||
|
|
|
@ -134,8 +134,11 @@ class ZipdownController < ApplicationController
|
||||||
homework_common.student_works.each do |work|
|
homework_common.student_works.each do |work|
|
||||||
unless work.attachments.empty?
|
unless work.attachments.empty?
|
||||||
out_file = zip_student_work_by_user(work)
|
out_file = zip_student_work_by_user(work)
|
||||||
|
|
||||||
bid_homework_path << out_file.file_path
|
bid_homework_path << out_file.file_path
|
||||||
digests << out_file.file_digest
|
digests << out_file.file_digest
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
homework_id = homework_common.id
|
homework_id = homework_common.id
|
||||||
|
@ -172,7 +175,11 @@ class ZipdownController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
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 = []
|
homeworks_attach_path = []
|
||||||
not_exist_file = []
|
not_exist_file = []
|
||||||
# 需要将所有homework.attachments遍历加入zip
|
# 需要将所有homework.attachments遍历加入zip
|
||||||
|
@ -186,11 +193,24 @@ class ZipdownController < ApplicationController
|
||||||
digests << 'not_exist_file'
|
digests << 'not_exist_file'
|
||||||
end
|
end
|
||||||
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){
|
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)
|
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
out_file
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def find_or_pack(homework_id, user_id, digests)
|
def find_or_pack(homework_id, user_id, digests)
|
||||||
|
|
Loading…
Reference in New Issue