From 0aa403ff757e39fdf3eaffb0c7f9f691a3ccff6b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 17:18:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A=E7=AE=97?= =?UTF-8?q?=E5=88=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 20 ++++++++++--------- app/controllers/myshixuns_controller.rb | 2 +- app/models/homework_common.rb | 5 +++++ app/services/homeworks_service.rb | 2 +- lib/tasks/homework_publishtime.rake | 4 ++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3562be4f3..aaffc34a6 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -238,7 +238,7 @@ class HomeworkCommonsController < ApplicationController end def update_score - tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now + tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group begin if @homework.unified_setting student_works = @homework.student_works @@ -258,6 +258,8 @@ class HomeworkCommonsController < ApplicationController 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) normal_status("更新成功") rescue Exception => e @@ -606,14 +608,14 @@ class HomeworkCommonsController < ApplicationController @homework.score_open = params[:score_open] @homework.save! - if score_change - @homework.student_works.has_committed.each do |student_work| - HomeworksService.new.set_shixun_final_score student_work - end - end + # if score_change + # @homework.student_works.has_committed.each do |student_work| + # HomeworksService.new.set_shixun_final_score student_work + # end + # end # 更新所有学生的效率分(作业允许补交且补交已截止 或者 作业不允许补交且提交已截止) - if (score_change || update_eff_score) && @homework.end_or_late + if update_eff_score && @homework.end_or_late_none_group HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: @homework.id) end @@ -1017,8 +1019,8 @@ class HomeworkCommonsController < ApplicationController homework.save! - # 更新学生状态及成绩 - HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) + # 更新学生状态及成绩(手动点击计算) + # HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) end normal_status(0, "发布成功") rescue Exception => e diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 909533301..9c3847b3c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -167,7 +167,7 @@ class MyshixunsController < ApplicationController end # 更新实训关联的作品分数 TODO: 更新作品分数 - HomeworksService.new.update_myshixun_work_score myshixun + # HomeworksService.new.update_myshixun_work_score myshixun end # 如果过关了,下一关的状态是3(为开启),则需要把状态改成1(已开启) # next_game = game.next_game diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 8f24820e7..3e0bec5fe 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -118,6 +118,11 @@ class HomeworkCommon < ApplicationRecord status end + # 作业是否补交截止或者不允许补交且提交截止(不考虑分班) + def end_or_late_none_group + course.is_end || (allow_late && late_time < Time.now) || (!allow_late && end_time < Time.now) + end + # 作业是否可以查重 def code_review self.homework_type == 'practice' && self.publish_time.present? && self.publish_time < Time.now && self.homework_group_reviews.count == 0 diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 48db76295..306a48d3c 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -156,7 +156,7 @@ class HomeworksService end # 用户评测时更新实训作业成绩 - def update_myshixun_work_score myshixun + def update_myshixun_work_score_old myshixun ActiveRecord::Base.transaction do student_works = myshixun.student_works.where(user_id: myshixun.user_id) #logger.info("#############student_works_count: #{student_works.count}") diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 7ee2a4a07..4127a9339 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -23,7 +23,7 @@ namespace :homework_publishtime do homework_detail_manual.update_column('comment_status', 1) # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 if homework.unified_setting - HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) + # HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) else course = homework.course @@ -53,7 +53,7 @@ namespace :homework_publishtime do homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? - HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) + # HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) end end