diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 119226c87..6fbba1c3d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -263,7 +263,6 @@ class PollsController < ApplicationController if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) else poll_unified = false g_course.each do |i| @@ -282,13 +281,11 @@ class PollsController < ApplicationController new_poll_group.save end end - - notify_student_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) + group_ids = params[:group_ids] end else poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) end if poll.end_time.blank? e_time = ex_end_time @@ -309,7 +306,7 @@ class PollsController < ApplicationController if poll.course_acts.size == 0 poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) end - PollPublishNotifyJob.perform_later(poll.id, notify_student_ids) + PollPublishNotifyJob.perform_later(poll.id, group_ids) end end normal_status(0, "问卷发布成功!") diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 17cdd41a7..a7103b4bf 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -145,7 +145,7 @@ module StudentWorksHelper else user_name = message_user.real_name user_login = message_user.login - image_url = url_to_avatar(score.user) + image_url = url_to_avatar(message_user) end {user_name: user_name, user_login: user_login, user_image_url: image_url} end diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index bc31957e0..d7ed1ae02 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -2,10 +2,20 @@ class PollPublishNotifyJob < ApplicationJob queue_as :notify - def perform(poll_id, receiver_ids) + def perform(poll_id, group_ids) poll = Poll.find_by(id: poll_id) return if poll.blank? user = poll.user + course = poll.course + + 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 @@ -19,14 +29,14 @@ class PollPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'Poll' } Tiding.bulk_insert(*attrs) do |worker| - teacher_ids = poll.course.teachers.pluck(:user_id) + 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) 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/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index 0d4dff237..58f7764d0 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -7,7 +7,7 @@ namespace :graduation_task do task.update_attributes(status: 1) GraduationTaskPublishNotifyJob.perform_later(task.id) - task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists? + task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if !task.course_acts.exists? end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4c27f0317..7ee2a4a07 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -45,7 +45,7 @@ namespace :homework_publishtime do end end - homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists? + homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_acts.exists? end # 分组设置发布时间的作业 @@ -54,7 +54,7 @@ namespace :homework_publishtime do homework = homework_group.homework_common if homework.present? HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) end end Rails.logger.info("log--------------------------------homework_publish end") diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index 6ced88908..8cec43565 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -9,39 +9,22 @@ namespace :poll_publish do polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 2) - course = poll.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end if poll.unified_setting - course.students.find_each do |student| + PollPublishNotifyJob.perform_later(poll.id, nil) + else + course = poll.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}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{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 poll.poll_users.count == 0 - str = "" - course.students.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id},#{poll.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - - if str != "" - sql = "insert into poll_users (user_id, poll_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 poll.course_acts.size == 0 - poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) - end + poll.course_acts << CourseActivity.new(user_id: poll.user_id, course_id: poll.course_id) if !poll.course_acts.exists? end # 分组设置发布时间的问卷 @@ -49,19 +32,8 @@ namespace :poll_publish do poll_group_settings.each do |poll_group| poll = poll_group.poll if poll.present? - course = poll.course poll.update_attributes(:polls_status => 2) if poll.polls_status == 1 - - tid_str = "" - members = course.course_members.where(:course_group_id => poll_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{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 + PollPublishNotifyJob.perform_later(poll.id, [poll_group.course_group_id]) end end