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