diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index d10db7a5d..48c289050 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -111,28 +111,48 @@ namespace :poll_publish do end task :end => :environment do - polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) + + #1.统一设置的截止 + polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900) polls.each do |poll| - poll.update_attributes(:polls_status => 3) + poll.update_column('polls_status', 3) poll.poll_users.each do |poll_user| - if poll_user.commit_status == 0 && !poll_user.start_at.nil? + if poll_user.commit_status == 0 && poll_user.start_at.present? poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) end end end - PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| + #2.分班设置的截止 + polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = false AND end_time > ?",Time.now + 900) + poll_ids = polls.blank? ? "(-1)" : "(" + polls.map(&:id).join(",") + ")" + polls_group_settings = PollGroupSetting.where("end_time <= '#{Time.now}' and poll_id in #{poll_ids}") + polls_group_settings.each do |poll_setting| poll = poll_setting.poll - poll.update_column('polls_status',3) - + if poll&.end_time <= Time.now + poll.update_column('polls_status', 3) + end users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) - poll_users.each do |poll_user| if poll_user.commit_status == 0 && !poll_user.start_at.nil? poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) end end end + + # PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| + # poll = poll_setting.poll + # poll.update_column('polls_status',3) + # + # users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) + # poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) + # + # poll_users.each do |poll_user| + # if poll_user.commit_status == 0 && !poll_user.start_at.nil? + # poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) + # end + # end + # end end end