From 789efbe37e22f0449254e2e2ec9f2f317da5e1fe Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 27 Nov 2019 16:30:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=AE=9E=E8=AE=AD=E5=8F=91=E9=80=81=E8=87=B3=E8=AF=BE?= =?UTF-8?q?=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 12 +++++++++++- app/views/shixuns/batch_send_to_course.json.jbuilder | 4 ++++ config/routes.rb | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 app/views/shixuns/batch_send_to_course.json.jbuilder diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e7555f927..28940db10 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -10,7 +10,7 @@ class ShixunsController < ApplicationController before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, - :get_mirror_script, :download_file, :shixun_list] + :get_mirror_script, :download_file, :shixun_list, :batch_send_to_course] before_action :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, @@ -990,6 +990,16 @@ class ShixunsController < ApplicationController CreateStudentWorkJob.perform_later(homework.id) end + # 批量发送 + def batch_send_to_course + @course = Course.find_by!(id: params[:course_id]) + shixuns = Shixun.where(id: params[:shixun_ids]).unhidden + shixuns.each do |shixun| + homework = HomeworksService.new.create_homework shixun, @course, nil, current_user + CreateStudentWorkJob.perform_later(homework.id) + end + end + # 二维码扫描下载 def download_file file_path = params[:file_name] diff --git a/app/views/shixuns/batch_send_to_course.json.jbuilder b/app/views/shixuns/batch_send_to_course.json.jbuilder new file mode 100644 index 000000000..bd9002842 --- /dev/null +++ b/app/views/shixuns/batch_send_to_course.json.jbuilder @@ -0,0 +1,4 @@ +json.status 1 +json.message "发送成功" +json.course_id @course.id +json.first_category_url module_url(@course.none_hidden_course_modules.first, @course) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 577428c7a..aa4aad8ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -224,6 +224,7 @@ Rails.application.routes.draw do post :apply_shixun_mirror get :download_file get :shixun_lists + post :batch_send_to_course end member do