dev_cs
cxt 5 years ago
parent f1ff06df79
commit e535c92410

@ -166,6 +166,8 @@ class CoursesController < ApplicationController
CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2) CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2)
end end
CreateSubjectCourseStudentJob.perform_later(@course.id) if course.subject.subject_appointments.count > 0
Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知") Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知")
@course.create_stages @course.subject @course.create_stages @course.subject

@ -0,0 +1,20 @@
class CreateSubjectCourseStudentJob < ApplicationJob
queue_as :default
def perform(course_id)
course = Course.find_by(id: course_id)
return if course.blank? || course.subject.blank?
attrs = %i[course_id user_id role created_at updated_at]
same_attrs = {course_id: course.id, role: 4}
CourseMember.bulk_insert(*attrs) do |worker|
course.subject.subject_appointments.each do |app|
next if course.students.where(user_id: user_id).any?
worker.add same_attrs.merge(user_id: app.user_id)
end
end
course.subject.subject_appointments.destroy_all
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe CreateSubjectCourseStudentJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save