From 6628269df16274745bd24d3680bca631ceb0d4a7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 10:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E5=93=81=E9=99=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/export_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index a23cb8a65..839686f5b 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -487,6 +487,8 @@ module ExportHelper zipfile_name = "#{output_path}/#{rename_zipfile}" + # 同名文件重命名时用 + index = 1 Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_paths.each do |filename| @@ -496,7 +498,11 @@ module ExportHelper begin zipfile.add(rename_file, filename) 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 end end @@ -516,4 +522,11 @@ module ExportHelper def format_sheet_name name name = name.gsub(":", "-") 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