From 254a643b4f8ab7eb2145726813c01bfdb4fbcd7b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 18:10:08 +0800 Subject: [PATCH] fix bug --- app/controllers/exercises_controller.rb | 2 -- .../graduation_tasks_controller.rb | 10 ++++-- .../homework_commons_controller.rb | 3 +- app/controllers/zips_controller.rb | 19 +++++++--- .../batch_export_shixun_report_service.rb | 36 ++++++++++--------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d19de52c4..79bed2d25 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,8 +1300,6 @@ class ExercisesController < ApplicationController if @export_ex_users.exercise_user_committed.size == 0 normal_status(-1,"暂无用户提交") else - @exercise = @exercise.includes(:exercise_questions) - @export_ex_users = @export_ex_users.includes(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 41ddb7659..1931c26a0 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,9 +129,13 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - graduation_work_to_xlsx(@work_excel,@task,current_user) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @task.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + if @work_count > 1 + graduation_work_to_xlsx(@work_excel,@task,current_user) + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + else + normal_status(-1,"暂无提交的学生!") + end end } format.zip{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b3953c7dd..89e301f93 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,8 +206,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.present? - @homework = @homework.includes(:shixuns,:homework_detail_manual) + if @work_count > 1 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') diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a70d4c332..e88f4d552 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,9 +6,11 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - student_work_ids = Array.wrap(params[:student_work_ids]) + # student_work_ids = Array.wrap(params[:student_work_ids]) + + # service = BatchExportShixunReportService.new(@homework, @student_work_ids) + service = BatchExportShixunReportService.new(@homework, @all_student_works) - service = BatchExportShixunReportService.new(@homework, student_work_ids) filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' @@ -57,9 +59,9 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end - default_ex_users_size = @ex_users.size + default_ex_users_size = @ex_users&.size - if default_ex_users_size == 0 + if default_ex_users_size.blank? || default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 normal_status(-2,"100") @@ -75,5 +77,14 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + @all_student_works = @homework.teacher_works(@member) + student_work_sizes = @all_student_works&.size + if student_work_sizes.blank? || student_work_sizes == 0 + normal_status(-1,"导出失败,暂时没有已提交的学生") + elsif student_work_sizes > 100 + normal_status(-2,"100") + end end end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 6ea38b23f..ebb273a87 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,11 +3,15 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - attr_reader :homework, :student_work_ids + # attr_reader :homework, :student_work_ids + attr_reader :homework, :all_student_works - def initialize(homework, student_work_ids) + + def initialize(homework, all_student_works) @homework = homework - @student_work_ids = student_work_ids + # @student_work_ids = student_work_ids + @all_student_works = all_student_works + end def filename @@ -15,8 +19,8 @@ class BatchExportShixunReportService end def zip - validate! - student_works = homework.student_works.where(id: student_work_ids).includes(:myshixun, user: :user_extension) + # validate! + student_works = all_student_works.includes(:myshixun, user: :user_extension) if student_works.count.zero? raise Error, '请选择要导出的学生实训报告' @@ -41,15 +45,15 @@ class BatchExportShixunReportService end end - private - - def validate! - if student_work_ids.size.zero? - raise Error, '请选择学生实训作业' - end - - if student_work_ids.size > MAX_BATCH_LIMIT - raise Error, '导出实训报告太多,请分批导出' - end - end + # private + # + # def validate! + # if student_work_ids.size.zero? + # raise Error, '请选择学生实训作业' + # end + # + # if student_work_ids.size > MAX_BATCH_LIMIT + # raise Error, '导出实训报告太多,请分批导出' + # end + # end end