|
|
|
@ -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)
|
|
|
|
|
if poll.unified_setting
|
|
|
|
|
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 = ""
|
|
|
|
|
course.teachers.find_each do |member|
|
|
|
|
|
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|
|
|
|
|
|
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')}')"
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|