From b6df2233f4460a4f801a86a8cac426e03218441a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 12 Aug 2019 16:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E8=AE=A1=E7=AE=97=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 6 +++++ .../homework_commons_controller.rb | 24 +---------------- app/models/homework_common.rb | 26 +++++++++++++++++++ app/models/student_work.rb | 4 +-- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6aaa04f12..75d515186 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1154,6 +1154,12 @@ class CoursesController < ApplicationController #课堂的作业信息 shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] + + # 更新实训作业成绩 + shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework| + homework.update_homework_work_score + end + shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user) common_homeworks = homeworks.search_homework_type(1) #全部普通作业 diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 59b807860..7f2519b99 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -255,29 +255,7 @@ class HomeworkCommonsController < ApplicationController def update_score tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now begin - 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 - - student_works = student_works.includes(:challenge_work_scores) - - challenge_settings = @homework.homework_challenge_settings - challenge_setting_ids = challenge_settings.pluck(:challenge_id) - myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids).includes(:games) - myshixuns.find_each(batch_size: 100) do |myshixun| - work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun - games = myshixun.games.select{|game| challenge_setting_ids.include?(game.challenge_id)} - HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings - end - end - HomeworksService.new.update_student_eff_score @homework if (@homework.allow_late && @homework.late_time < Time.now) || - (!@homework.allow_late && @homework.end_time < Time.now) - @homework.update_attribute('calculation_time', Time.now) + @homework.update_homework_work_score normal_status("更新成功") rescue Exception => e uid_logger(e.message) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 9aa4a8fe1..112fc523b 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -264,4 +264,30 @@ class HomeworkCommon < ApplicationRecord def challenge_score challenge_id homework_challenge_settings.find_by(challenge_id: challenge_id)&.score.to_f end + + def update_homework_work_score + if unified_setting + works = student_works + user_ids = course.students.pluck(:user_id) + else + user_ids = course.students.where(course_group_id: published_settings.pluck(:course_group_id)).pluck(:user_id) + works = student_works.where(user_id: user_ids) + end + + works = works.includes(:challenge_work_scores) + + challenge_settings = homework_challenge_settings + challenge_setting_ids = challenge_settings.pluck(:challenge_id) + myshixuns = Myshixun.where(shixun_id: homework_commons_shixun&.shixun_id, user_id: user_ids).includes(:games) + myshixuns.find_each(batch_size: 100) do |myshixun| + work = works.select{|work| work.user_id == myshixun.user_id}.first + if work && myshixun + games = myshixun.games.select{|game| challenge_setting_ids.include?(game.challenge_id)} + HomeworksService.new.update_myshixun_work_score work, myshixun, games, self, challenge_settings + end + end + HomeworksService.new.update_student_eff_score(self) if (allow_late && late_time < Time.now) || + (!allow_late && end_time < Time.now) + update_attribute('calculation_time', Time.now) + end end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 9151ca501..074068273 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -123,10 +123,10 @@ class StudentWork < ApplicationRecord # 更新作品成绩 def set_work_score - if work_status > 0 && homework_common && homework_common.homework_detail_manual && !self.ultimate_score + if work_status > 0 && homework_common && !self.ultimate_score case homework_common.homework_type when "normal", "group" - if !homework_common.homework_detail_manual.final_mode + if !homework_common&.homework_detail_manual&.final_mode tea_ass_proportion = homework_common.homework_detail_manual.ta_proportion tea_proportion = homework_common.homework_detail_manual.te_proportion if self.teacher_score