From 098d42cbd14ac3f51a34aa815e92479e3ec36147 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 6 Dec 2016 14:47:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BD=9C=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F=E6=97=B6=E4=B9=9F=E5=BA=94?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=88=A4=E6=96=AD=E4=BD=9C=E5=93=81=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E8=BF=9F=E4=BA=A4=E3=80=81=E4=BD=9C=E4=B8=9Aid?= =?UTF-8?q?=E4=B8=BA4198=E7=9A=84=E4=BD=9C=E5=93=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 21 +++++++++++++++++++ ...0161206061652_update_student_work_score.rb | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 db/migrate/20161206061652_update_student_work_score.rb diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 3234d15c0..b7e4b9efd 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -82,6 +82,27 @@ class HomeworkCommonController < ApplicationController @homework.publish_time = params[:homework_common][:publish_time] end homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + param_end_time = Time.parse(params[:homework_common][:end_time]).strftime("%Y-%m-%d") + homework_end_time = Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") + if homework_end_time != param_end_time + if homework_end_time > param_end_time + @homework.student_works.where("work_status = 1").each do |st| + if param_end_time < Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") + st.late_penalty = @homework.late_penalty + st.work_status = 2 + st.save + end + end + else + @homework.student_works.where("work_status = 2").each do |st| + if param_end_time >= Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") + st.late_penalty = 0 + st.work_status = 1 + st.save + end + end + end + end @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] if params[:homework_type] && params[:homework_type].to_i != @homework.homework_type diff --git a/db/migrate/20161206061652_update_student_work_score.rb b/db/migrate/20161206061652_update_student_work_score.rb new file mode 100644 index 000000000..4fcd374ca --- /dev/null +++ b/db/migrate/20161206061652_update_student_work_score.rb @@ -0,0 +1,19 @@ +class UpdateStudentWorkScore < ActiveRecord::Migration + def up + homework = HomeworkCommon.where("id = 4198").first + unless homework.nil? + homework.student_works.each do |st| + if st.late_penalty != 0 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") > Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") + if st.work_status == 2 + st.work_status = 1 + end + st.late_penalty = 0 + st.save + end + end + end + end + + def down + end +end