|
|
|
@ -7,6 +7,7 @@ class UpdateHomeworkPublishSettingService < ApplicationService
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call
|
|
|
|
|
puts params
|
|
|
|
|
course = homework.course
|
|
|
|
|
# 作业未发布时,unified_setting参数不能为空
|
|
|
|
|
if homework.publish_time.nil? || homework.publish_time > Time.now
|
|
|
|
@ -37,9 +38,9 @@ class UpdateHomeworkPublishSettingService < ApplicationService
|
|
|
|
|
tip_exception("分班id不能为空") if setting[:group_id].length == 0
|
|
|
|
|
tip_exception("发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if setting[:end_time].blank?
|
|
|
|
|
tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
tip_exception("发布时间不能早于当前时间") if setting[:publish_time].to_time <= Time.now
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if setting[:end_time].to_time <= Time.now
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time].to_time > setting[:end_time].to_time
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
course.end_date.present? && setting[:end_time] > course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
@ -74,15 +75,15 @@ class UpdateHomeworkPublishSettingService < ApplicationService
|
|
|
|
|
else
|
|
|
|
|
if homework.end_time > Time.now && homework.unified_setting
|
|
|
|
|
tip_exception("截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time].to_time <= Time.now
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
course.end_date.present? && params[:end_time] > strf_time(course.end_date.end_of_day)
|
|
|
|
|
course.end_date.present? && params[:end_time].to_time > course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
homework.end_time = params[:end_time]
|
|
|
|
|
|
|
|
|
|
elsif !homework.unified_setting
|
|
|
|
|
homework.create_homework_group_settings
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].reject(&:blank?).blank?
|
|
|
|
|
params[:group_settings].each do |setting|
|
|
|
|
|
group_settings = HomeworkGroupSetting.where(homework_common_id: homework.id, course_group_id: setting[:group_id])
|
|
|
|
|
|
|
|
|
@ -90,12 +91,12 @@ class UpdateHomeworkPublishSettingService < ApplicationService
|
|
|
|
|
tip_exception("发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if setting[:end_time].blank?
|
|
|
|
|
# 如果该发布规则 没有已发布的分班则需判断发布时间
|
|
|
|
|
tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
|
|
|
|
|
tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time].to_time <= Time.now && group_settings.group_published.count == 0
|
|
|
|
|
|
|
|
|
|
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) && group_settings.none_end.count > 0
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time].to_time <= Time.now && group_settings.none_end.count > 0
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time].to_time > setting[:end_time].to_time
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
course.end_date.present? && setting[:end_time] > strf_time(course.end_date.end_of_day)
|
|
|
|
|
course.end_date.present? && setting[:end_time].to_time > course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
group_settings.none_published.update_all(publish_time: setting[:publish_time])
|
|
|
|
|
group_settings.none_end.update_all(end_time: setting[:end_time])
|
|
|
|
|