You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
# 问卷发布 消息通知
|
|
class PollPublishNotifyJob < ApplicationJob
|
|
queue_as :notify
|
|
|
|
def perform(poll_id, receiver_ids)
|
|
poll = Poll.find_by(id: poll_id)
|
|
return if poll.blank?
|
|
user = poll.user
|
|
|
|
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
|
|
]
|
|
|
|
same_attrs = {
|
|
trigger_user_id: user.id, container_id: poll.id, container_type: 'Poll',
|
|
parent_container_id: poll.id, parent_container_type: 'PollPublish',
|
|
belong_container_id: poll.course_id, belong_container_type: 'Course',
|
|
viewed: 0, tiding_type: 'Poll'
|
|
}
|
|
Tiding.bulk_insert(*attrs) do |worker|
|
|
teacher_ids = poll.course.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|
|
|
worker.add same_attrs.merge(user_id: user_id)
|
|
end
|
|
end
|
|
end
|
|
end
|