diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 07113792d..e6f9876bc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,7 +1300,9 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else respond_to do |format| diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 8553cbb44..4089e5231 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,12 +6,9 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - # student_work_ids = Array.wrap(params[:student_work_ids]) - # service = BatchExportShixunReportService.new(@homework, @student_work_ids) service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex @@ -23,8 +20,8 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end @@ -44,7 +41,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -101,34 +98,40 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + @homework_status = @homework.present? ? @homework.homework_detail_manual.comment_status : 0 + if @homework.blank? + normal_status(-1,"该作业不存在") + elsif @homework_status == 0 + normal_status(-1,"该作业未发布") + else + @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + + @all_student_works = @homework.teacher_works(@member).where("work_status > 0") + work_status = params[:work_status] + group_id = params[:course_group] + + if work_status.present? + @all_student_works = @all_student_works.where(work_status:work_status) + end + if group_id.present? + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) + @all_student_works = @all_student_works.where(user_id: group_user_ids) + end - @course = @homework.course - ##7。2 -hs新增 - @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member).where("work_status > 0") - work_status = params[:work_status] - group_id = params[:course_group] - - if work_status.present? - @all_student_works = @all_student_works.where(work_status:work_status) - end - - if group_id.present? - group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) - @all_student_works = @all_student_works.where(user_id: group_user_ids) - end - - unless params[:search].blank? - @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? + unless params[:search].blank? + @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") - end + end - 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") + 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 end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index ebb273a87..90c8fb2af 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,7 +3,6 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - # attr_reader :homework, :student_work_ids attr_reader :homework, :all_student_works @@ -15,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{Time.now.strftime('%Y%m%d%H%M%S')}-#{homework.name}.zip" + @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" end def zip @@ -45,15 +44,4 @@ 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 end