Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
4585248664
@ -0,0 +1,32 @@
|
||||
class HomeworkEndUpdateScoreJob < ApplicationJob
|
||||
# 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩
|
||||
queue_as :score
|
||||
|
||||
def perform(*args)
|
||||
homework = HomeworkCommon.find_by(id: homework_id)
|
||||
return if homework.blank?
|
||||
course = homework.course
|
||||
return if course.blank?
|
||||
|
||||
if homework.unified_setting
|
||||
student_works = homework.student_works
|
||||
user_ids = course.students.pluck(:user_id)
|
||||
else
|
||||
user_ids = course.students.where(course_group_id: homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
|
||||
student_works = homework.student_works.where(user_id: user_ids)
|
||||
end
|
||||
|
||||
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
|
||||
includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)})
|
||||
challenge_settings = homework.homework_challenge_settings
|
||||
myshixuns.find_each(batch_size: 100) do |myshixun|
|
||||
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
|
||||
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
|
||||
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
|
||||
HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings
|
||||
end
|
||||
end
|
||||
HomeworksService.new.update_student_eff_score homework
|
||||
homework.update_attribute('calculation_time', Time.now)
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe HomeworkEndUpdateScoreJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue