From f6ae3f329328c1c99104af77506dc22c6b3efbe6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:04:21 +0800 Subject: [PATCH] fixbug --- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/zips_controller.rb | 5 ++--- app/helpers/export_helper.rb | 15 +++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 519c05c62..d09609bdc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode('UTF-8', 'gb2312', {:invalid => :replace, :undef => :replace, :replace => ' '}).strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 67c8c74f7..2b70b9b27 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -10,9 +10,8 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) filename = filename_for_content_disposition(service.filename) - Rails.logger.info("################___________file_name________________###########{filename}") - Rails.logger.info("################___________service.filename________________###########{service.filename}") - send_file service.zip, filename: filename.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' + + send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 839686f5b..7f64a99cd 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -40,10 +40,17 @@ module ExportHelper works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) - w_2 = w_user.login - w_3 = w_user.real_name - w_3_1 = w_user.mail - w_4 = w_user.student_id.present? ? w_user.student_id : "--" + if w_user.present? + w_2 = w_user&.login + w_3 = w_user&.real_name + w_3_1 = w_user&.mail + w_4 = w_user.student_id.present? ? w_user.student_id : "--" + else + w_2 = "--" + w_3 = "--" + w_3_1 = "--" + w_4 = "--" + end course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交