You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.8 KiB
78 lines
2.8 KiB
class ZipsController < ApplicationController
|
|
before_action :require_login
|
|
before_action :load_homework, only: [:shixun_report]
|
|
before_action :get_exercise, only: [:export_exercises]
|
|
|
|
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)
|
|
|
|
filename = filename_for_content_disposition(service.filename)
|
|
send_file service.zip, filename: filename, type: 'application/zip'
|
|
rescue BatchExportShixunReportService::Error => ex
|
|
normal_status(-1, ex.message)
|
|
end
|
|
|
|
def export_exercises
|
|
exercises = ExportExercisesService.new(@exercise,@ex_users)
|
|
|
|
file_name = filename_for_content_disposition(exercises.filename)
|
|
logger.info("##################_______________________file_name_____________________############{file_name}")
|
|
send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
|
|
rescue Exception => e
|
|
normal_status(-1, e.message)
|
|
end
|
|
|
|
private
|
|
|
|
def filename_for_content_disposition(name)
|
|
request.env['HTTP_USER_AGENT'] =~ %r{MSIE|Trident|Edge} ? ERB::Util.url_encode(name) : name
|
|
end
|
|
|
|
def require_admin_or_teacher
|
|
return if current_user.teacher_or_admin?(@course)
|
|
normal_status(403, '')
|
|
end
|
|
|
|
def get_exercise
|
|
ActiveRecord::Base.transaction do
|
|
begin
|
|
@exercise = Exercise.includes(:exercise_users).find_by(id:params[:exercise_id])
|
|
group_id = params[:exercise_group_id]
|
|
if @exercise.blank?
|
|
normal_status(-1,"试卷不存在")
|
|
else
|
|
@course = @exercise.course
|
|
|
|
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
|
|
default_ex_users_size = default_ex_users.size
|
|
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。
|
|
#可以分班选择
|
|
if group_id.present?
|
|
exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数
|
|
user_ids = exercise_students.pluck(:user_id).reject(&:blank?)
|
|
@ex_users = @ex_users.exercise_commit_users(user_ids)
|
|
end
|
|
# @ex_users = @ex_users.first(200)
|
|
if default_ex_users_size == 0
|
|
normal_status(-1,"导出失败,暂时没有已提交的学生")
|
|
elsif default_ex_users_size > 200
|
|
normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出")
|
|
end
|
|
end
|
|
rescue Exception => e
|
|
uid_logger_error(e.message)
|
|
tip_exception("导出失败!")
|
|
end
|
|
end
|
|
end
|
|
|
|
def load_homework
|
|
@homework = HomeworkCommon.find(params[:homework_common_id])
|
|
@course = @homework.course
|
|
end
|
|
end
|