diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 490791918..8c4eb0a89 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -424,14 +424,18 @@ class ExerciseQuestionsController < ApplicationController begin choice_d_id = params[:choice_no].to_i # 选项的当前位置 question_choices = @exercise_question.exercise_choices - delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first - left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) - if left_choice.present? - left_choice.each do |p| - p.choice_position -= 1 - p.save - end - end + delete_answer = question_choices.find_by(choice_position: choice_d_id) + left_choices = question_choices.where("choice_position > ? ",choice_d_id) + left_choices.update_all("choice_position = choice_position - 1") if left_choices + # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first + # + # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) + # if left_choice.present? + # left_choice.each do |p| + # p.choice_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else @@ -450,13 +454,15 @@ class ExerciseQuestionsController < ApplicationController begin question_d_id = @exercise_question.question_number.to_i #问题的当前位置 exercise_questions = @exercise.exercise_questions - left_question = exercise_questions.left_question_choose("question_number",question_d_id) - if left_question.present? - left_question.each do |q| - q.question_number -= 1 - q.save - end - end + left_questions = exercise_questions.where("question_number > ?", question_d_id) + left_questions.update_all("question_number = question_number - 1") if left_questions + # left_question = exercise_questions.left_question_choose("question_number",question_d_id) + # if left_question.present? + # left_question.each do |q| + # q.question_number -= 1 + # q.save + # end + # end if @exercise_question.destroy normal_status(0, "问题删除成功!") else diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4b96afc85..01a2d540a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -729,7 +729,6 @@ class ExercisesController < ApplicationController if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 exercise.exercise_group_settings.destroy_all ex_unified = true - notify_receiver_ids = @course.students.pluck(:user_id) else ex_unified = false g_course.each do |i| @@ -749,12 +748,11 @@ class ExercisesController < ApplicationController end end - notify_receiver_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) + group_ids = params[:group_ids] end else exercise.exercise_group_settings.destroy_all ex_unified = true - notify_receiver_ids = @course.students.pluck(:user_id) end if exercise.end_time.blank? e_time = ex_end_time @@ -775,7 +773,7 @@ class ExercisesController < ApplicationController if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) end - ExercisePublishNotifyJob.perform_later(exercise.id, notify_receiver_ids) + ExercisePublishNotifyJob.perform_later(exercise.id, group_ids) end end end diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 47cd236a9..c7407c129 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -156,14 +156,18 @@ class PollQuestionsController < ApplicationController begin answer_d_id = params[:answer_no].to_i # 答案的当前位置 poll_answers = @poll_question.poll_answers - delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first - left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) - if left_answer.present? - left_answer.each do |p| - p.answer_position -= 1 - p.save - end - end + delete_answer = poll_answers.find_by(answer_position: answer_d_id) + left_answers = poll_answers.where("answer_position > ?",answer_d_id) + left_answers.update_all("answer_position = answer_position - 1") if left_answers + + # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first + # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) + # if left_answer.present? + # left_answer.each do |p| + # p.answer_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 261fc85e9..c77ae5937 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -65,7 +65,7 @@ module HomeworkCommonsHelper # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || - (identity < Course::STUDENT && teacher_course_groups.size == 0) + (identity < Course::STUDENT && teacher_course_groups.blank?) case ho_detail_manual.comment_status when 0 status << "未发布" diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index c66fa5660..563f6ceb0 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -2,11 +2,20 @@ class ExercisePublishNotifyJob < ApplicationJob queue_as :notify - def perform(exercise_id, receiver_ids) + def perform(exercise_id, group_ids) exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + if group_ids.present? + students = course.students.where(course_group_id: group_ids) + subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id) + teachers = course.teachers.where(id: subquery) + else + students = course.students + teachers = course.teachers + end + attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type belong_container_id belong_container_type viewed tiding_type created_at updated_at @@ -19,14 +28,14 @@ class ExercisePublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'Exercise' } Tiding.bulk_insert(*attrs) do |worker| - teacher_ids = exercise.course.teachers.pluck(:user_id) + teacher_ids = teachers.pluck(:user_id) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) - exercise.course.teachers.find_each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + teacher_ids.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end - receiver_ids.each do |user_id| + students.pluck(:user_id).each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index d7ed1ae02..89fb45ea5 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -31,8 +31,8 @@ class PollPublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) - poll.course.teachers.find_each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + teacher_ids.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 3df5f84ae..220512664 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -8,39 +8,24 @@ class ExercisePublishTask exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises&.each do |exercise| exercise.update_column('exercise_status', 2) - course = exercise.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end + if exercise.unified_setting - course.students.find_each do |student| + ExercisePublishNotifyJob.perform_later(exercise.id, nil) + else + course = exercise.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" + teachers.find_each do |member| tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - - if exercise.exercise_users.size == 0 - str = "" - course.students.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql end end - if exercise.course_acts.size == 0 - exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) - end + exercise.course_acts << CourseActivity.new(user_id: exercise.user_id, course_id: exercise.course_id) if !exercise.course_acts.exists? end # 分组设置发布时间的测验 @@ -48,18 +33,8 @@ class ExercisePublishTask exercise_group_settings&.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? - course = exercise.course exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 - tid_str = "" - members = course.students.where(:course_group_id => exercise_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end + ExercisePublishNotifyJob.perform_later(exercise.id, [exercise_group.course_group_id]) end end Rails.logger.info("log--------------------------------exercise_publish end")