@ -85,49 +85,43 @@ namespace :poll_publish do
task :end = > :environment do
task :end = > :environment do
puts " --------------------------------poll_publish end start "
puts " --------------------------------poll_publish end start "
#1.统一设置的截止
#1.统一设置的截止
polls = Poll . includes ( :poll_users ) . where ( " polls_status = 2 AND unified_setting = true AND end_time <=?" , Time . now + 900 )
polls = Poll . includes ( :poll_users ) . where ( " polls_status = 2 AND end_time <=?" , Time . now + 900 )
polls . each do | poll |
polls . each do | poll |
poll . update_column ( 'polls_status' , 3 )
poll . update_column ( 'polls_status' , 3 )
poll . poll_users . where ( " commit_status = 0 and start_at is not null " ) . update_all ( commit_status : 1 , end_at : Time . now )
poll . poll_users . where ( " commit_status = 0 and start_at is not null " ) . update_all ( commit_status : 1 , end_at : poll . end_time ) if poll . unified_setting
end
end
#2.分班设置的截止
#2.分班设置的截止
polls = Poll . includes ( :poll_users ) . where ( " polls_status = 2 AND unified_setting = false AND end_time > ? " , Time . now + 900 )
# polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = false AND end_time > ?",Time.now + 900)
puts " --------------unified_setting_poll_ids------------------ #{ polls . pluck ( :id ) } "
# 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
# 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.poll_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
# # 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
poll_ids = polls . blank? ? " (-1) " : " ( " + polls . map ( & :id ) . join ( " , " ) + " ) "
PollGroupSetting . where ( " end_time < ? and end_time > ? " , Time . now + 1800 , Time . now - 1800 ) . each do | poll_setting |
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 = poll_setting . poll
if poll & . end_time < = Time . now
# poll.update_column('polls_status',3)
poll . update_column ( 'polls_status' , 3 )
users = poll . course . course_members . where ( :course_group_id = > poll_setting . course_group_id )
puts " # # # # # # # # __________________ # # # # # # # # # # # #{ poll . polls_status } "
poll_users = poll . poll_users . where ( :user_id = > users . map ( & :user_id ) )
end
users = poll . course . course_members . where ( course_group_id : poll_setting . course_group_id )
poll_users . where ( " commit_status = 0 and start_at is not null " ) . update_all ( commit_status : 1 , end_at : poll_setting . end_time )
poll . poll_users . where ( user_id : users . pluck ( :user_id ) ) . where ( " commit_status = 0 and start_at is not null " ) . update_all ( commit_status : 1 , end_at : Time . now )
# poll_users.each do |poll_user|
# 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.nil?
# poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
# poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
# end
# end
# end
# end
end
end
puts " --------------------------------poll_publish 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
end
end