加入课堂调整

dev_course
cxt 5 years ago
parent ba70f02acf
commit e09625df94

@ -711,7 +711,7 @@ class CoursesController < ApplicationController
student_ids = []
user_ids.each do |user_id|
existing_course_member = CourseMember.find_by(user_id: user_id.to_i, course_id: @course.id)
existing_course_member = @course.course_members.find_by(user_id: user_id.to_i)
new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4)
if existing_course_member.present?

@ -0,0 +1,30 @@
# 学生加入课堂时创建相关任务作品
class CourseAddStudentCreateWorksJob < ApplicationJob
queue_as :course_member
def perform(course_id, student_ids)
course = Course.find_by(id: course_id)
return if course.blank?
# 如果之前存在相关作品则更新is_delete字段
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0)
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: student_ids)
graduation_works.update_all(is_delete: 0)
attrs = %i[homework_common_id user_id created_at updated_at]
StudentWork.bulk_insert(*attrs) do |worker|
student_ids.each do |teacher|
worker.add same_attrs.merge(user_id: teacher.user_id)
end
end
end
end

@ -0,0 +1,7 @@
class CourseDeleteStudentDeleteWorksJob < ApplicationJob
queue_as :course_member
def perform(*args)
# Do something later
end
end

@ -52,13 +52,13 @@ class CourseMember < ApplicationRecord
def recover_works
course = self.course
student_works = StudentWork.where(user_id: self.user_id, homework_common_id: course.homework_commons)
student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.where(user_id: self.user_id, exercise_id: course.exercises)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0)
poll_users = PollUser.where(user_id: self.user_id, poll_id: course.polls)
poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: self.user_id)

@ -5,4 +5,5 @@
- [default, 3]
- [score, 4]
- [evaluation_comment, 5]
- [course_member, 6]
- [notify, 100]

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

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