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