Merge branch 'szzh' into develop

Conflicts:
	db/schema.rb
This commit is contained in:
cxt 2016-02-24 17:00:08 +08:00
commit e6ed988c10
2 changed files with 28 additions and 7 deletions

View File

@ -948,6 +948,7 @@ class StudentWorkController < ApplicationController
}
uri = URI(url)
body = solutions.to_json
binding.pry
res = Net::HTTP.new(uri.host, uri.port).start do |client|
request = Net::HTTP::Post.new(uri.path)
request.body = body

View File

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