|
|
@ -487,6 +487,8 @@ module ExportHelper
|
|
|
|
|
|
|
|
|
|
|
|
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
|
|
|
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 同名文件重命名时用
|
|
|
|
|
|
|
|
index = 1
|
|
|
|
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
|
|
|
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
|
|
|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
|
|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
|
|
files_paths.each do |filename|
|
|
|
|
files_paths.each do |filename|
|
|
|
@ -496,7 +498,11 @@ module ExportHelper
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
zipfile.add(rename_file, filename)
|
|
|
|
zipfile.add(rename_file, filename)
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"}
|
|
|
|
rename_file = rename_same_file(rename_file, index)
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
zipfile.add(rename_file, filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"}
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -516,4 +522,11 @@ module ExportHelper
|
|
|
|
def format_sheet_name name
|
|
|
|
def format_sheet_name name
|
|
|
|
name = name.gsub(":", "-")
|
|
|
|
name = name.gsub(":", "-")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rename_same_file(name, index)
|
|
|
|
|
|
|
|
basename = File.basename(name, ".*")
|
|
|
|
|
|
|
|
new_basename = basename + "_" + index.to_s
|
|
|
|
|
|
|
|
extname = File.extname(name)
|
|
|
|
|
|
|
|
new_basename + extname
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|