Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
daiao 6 years ago
commit 2abcd40853

@ -424,14 +424,18 @@ class ExerciseQuestionsController < ApplicationController
begin begin
choice_d_id = params[:choice_no].to_i # 选项的当前位置 choice_d_id = params[:choice_no].to_i # 选项的当前位置
question_choices = @exercise_question.exercise_choices question_choices = @exercise_question.exercise_choices
delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first delete_answer = question_choices.find_by(choice_position: choice_d_id)
left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) left_choices = question_choices.where("choice_position > ? ",choice_d_id)
if left_choice.present? left_choices.update_all("choice_position = choice_position - 1") if left_choices
left_choice.each do |p| # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first
p.choice_position -= 1 #
p.save # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id)
end # if left_choice.present?
end # left_choice.each do |p|
# p.choice_position -= 1
# p.save
# end
# end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else
@ -450,13 +454,15 @@ class ExerciseQuestionsController < ApplicationController
begin begin
question_d_id = @exercise_question.question_number.to_i #问题的当前位置 question_d_id = @exercise_question.question_number.to_i #问题的当前位置
exercise_questions = @exercise.exercise_questions exercise_questions = @exercise.exercise_questions
left_question = exercise_questions.left_question_choose("question_number",question_d_id) left_questions = exercise_questions.where("question_number > ?", question_d_id)
if left_question.present? left_questions.update_all("question_number = question_number - 1") if left_questions
left_question.each do |q| # left_question = exercise_questions.left_question_choose("question_number",question_d_id)
q.question_number -= 1 # if left_question.present?
q.save # left_question.each do |q|
end # q.question_number -= 1
end # q.save
# end
# end
if @exercise_question.destroy if @exercise_question.destroy
normal_status(0, "问题删除成功!") normal_status(0, "问题删除成功!")
else else

@ -729,7 +729,6 @@ class ExercisesController < ApplicationController
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
exercise.exercise_group_settings.destroy_all exercise.exercise_group_settings.destroy_all
ex_unified = true ex_unified = true
notify_receiver_ids = @course.students.pluck(:user_id)
else else
ex_unified = false ex_unified = false
g_course.each do |i| g_course.each do |i|
@ -749,12 +748,11 @@ class ExercisesController < ApplicationController
end end
end end
notify_receiver_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) group_ids = params[:group_ids]
end end
else else
exercise.exercise_group_settings.destroy_all exercise.exercise_group_settings.destroy_all
ex_unified = true ex_unified = true
notify_receiver_ids = @course.students.pluck(:user_id)
end end
if exercise.end_time.blank? if exercise.end_time.blank?
e_time = ex_end_time e_time = ex_end_time
@ -775,7 +773,7 @@ class ExercisesController < ApplicationController
if exercise.course_acts.size == 0 if exercise.course_acts.size == 0
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end end
ExercisePublishNotifyJob.perform_later(exercise.id, notify_receiver_ids) ExercisePublishNotifyJob.perform_later(exercise.id, group_ids)
end end
end end
end end

@ -156,14 +156,18 @@ class PollQuestionsController < ApplicationController
begin begin
answer_d_id = params[:answer_no].to_i # 答案的当前位置 answer_d_id = params[:answer_no].to_i # 答案的当前位置
poll_answers = @poll_question.poll_answers poll_answers = @poll_question.poll_answers
delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first delete_answer = poll_answers.find_by(answer_position: answer_d_id)
left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) left_answers = poll_answers.where("answer_position > ?",answer_d_id)
if left_answer.present? left_answers.update_all("answer_position = answer_position - 1") if left_answers
left_answer.each do |p|
p.answer_position -= 1 # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first
p.save # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id)
end # if left_answer.present?
end # left_answer.each do |p|
# p.answer_position -= 1
# p.save
# end
# end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else

@ -65,7 +65,7 @@ module HomeworkCommonsHelper
# 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份
if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || 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 case ho_detail_manual.comment_status
when 0 when 0
status << "未发布" status << "未发布"

@ -2,11 +2,20 @@
class ExercisePublishNotifyJob < ApplicationJob class ExercisePublishNotifyJob < ApplicationJob
queue_as :notify queue_as :notify
def perform(exercise_id, receiver_ids) def perform(exercise_id, group_ids)
exercise = Exercise.find_by(id: exercise_id) exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank? return if exercise.blank?
user = exercise.user 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[ attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type 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 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' viewed: 0, tiding_type: 'Exercise'
} }
Tiding.bulk_insert(*attrs) do |worker| 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) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids)
exercise.course.teachers.find_each do |teacher| teacher_ids.find_each do |user_id|
worker.add same_attrs.merge(user_id: teacher.user_id) worker.add same_attrs.merge(user_id: user_id)
end end
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) worker.add same_attrs.merge(user_id: user_id)
end end
end end

@ -31,8 +31,8 @@ class PollPublishNotifyJob < ApplicationJob
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|
teacher_ids = teachers.pluck(:user_id) teacher_ids = teachers.pluck(:user_id)
unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids)
poll.course.teachers.find_each do |teacher| teacher_ids.find_each do |user_id|
worker.add same_attrs.merge(user_id: teacher.user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end

@ -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 = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises&.each do |exercise| exercises&.each do |exercise|
exercise.update_column('exercise_status', 2) exercise.update_column('exercise_status', 2)
if exercise.unified_setting
ExercisePublishNotifyJob.perform_later(exercise.id, nil)
else
course = exercise.course course = exercise.course
teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id))
tid_str = "" tid_str = ""
course.teachers.find_each do |member| teachers.find_each do |member|
tid_str += "," if tid_str != "" 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')}')" 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 exercise.unified_setting
course.students.find_each do |student|
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')}')"
end
end
if tid_str != "" 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 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 ActiveRecord::Base.connection.execute tid_sql
end 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
end
end end
if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(user_id: exercise.user_id, course_id: exercise.course_id) if !exercise.course_acts.exists?
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end
end end
# 分组设置发布时间的测验 # 分组设置发布时间的测验
@ -48,18 +33,8 @@ class ExercisePublishTask
exercise_group_settings&.each do |exercise_group| exercise_group_settings&.each do |exercise_group|
exercise = exercise_group.exercise exercise = exercise_group.exercise
if exercise.present? if exercise.present?
course = exercise.course
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
tid_str = "" ExercisePublishNotifyJob.perform_later(exercise.id, [exercise_group.course_group_id])
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
end end
end end
Rails.logger.info("log--------------------------------exercise_publish end") Rails.logger.info("log--------------------------------exercise_publish end")

Loading…
Cancel
Save