From 28c48c996eb3dc94f4e0388d7cd3fec38c7756fb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 16:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E5=85=B3=E5=8D=A1=E8=AE=BE=E7=BD=AE=E5=8A=A0=E5=94=AF=E4=B8=80?= =?UTF-8?q?=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- app/services/homeworks_service.rb | 2 +- ...20_add_uniq_index_to_homework_challenge_settings.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6217b08c3..6e2e1df40 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -530,7 +530,7 @@ class HomeworkCommonsController < ApplicationController if setting && setting.score != score score_change = true setting.update_attributes(score: score) - else + elsif setting.blank? score_change = true HomeworkChallengeSetting.create!(homework_common_id: @homework.id, challenge_id: challenge[:challenge_id], shixun_id: @homework.homework_commons_shixun.try(:shixun_id), score: score) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 536d62c66..2affec0ba 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -165,7 +165,7 @@ class HomeworksService homework = work.homework_common #logger.info("#############member_course_group_id: #{member.try(:course_group_id)}") setting_time = homework.homework_group_setting work.user_id - if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && !homework.course.is_end)) + if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && homework.late_time && homework.late_time > Time.now)) #logger.info("#############setting_time: #{setting_time.end_time}") user_total_score = 0 diff --git a/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb b/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb new file mode 100644 index 000000000..49a385ad9 --- /dev/null +++ b/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb @@ -0,0 +1,10 @@ +class AddUniqIndexToHomeworkChallengeSettings < ActiveRecord::Migration[5.2] + def change + remove_index :homework_challenge_settings, [:homework_common_id, :challenge_id] if index_exists?(:homework_challenge_settings, [:homework_common_id, :challenge_id]) + sql = %Q(delete from homework_challenge_settings where (homework_common_id, challenge_id) in + (select * from (select homework_common_id, challenge_id from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1) a) + and id not in (select * from (select max(id) from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql + add_index :homework_challenge_settings, [:homework_common_id, :challenge_id], unique: true, name: "index_on_homework_common_id_challenge_id" + end +end