更改作业的截止日期时也应重新判断作品是否迟交、作业id为4198的作品数据迁移

This commit is contained in:
cxt 2016-12-06 14:47:17 +08:00
parent 5bbe9e71ba
commit 098d42cbd1
2 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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