|
|
|
@ -10,14 +10,14 @@ class UpdateHomeworkSettingService < ApplicationService
|
|
|
|
|
course = homework.course
|
|
|
|
|
# 作业未发布时,unified_setting参数不能为空
|
|
|
|
|
if homework.publish_time.nil? || homework.publish_time > Time.now
|
|
|
|
|
raise(Error, "缺少统一设置的参数") if params[:unified_setting].nil?
|
|
|
|
|
tip_exception("缺少统一设置的参数") if params[:unified_setting].nil?
|
|
|
|
|
if params[:unified_setting] || course.course_groups_count == 0
|
|
|
|
|
raise(Error, "发布时间不能为空") if params[:publish_time].blank?
|
|
|
|
|
raise(Error, "截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
raise(Error, "发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
raise(Error, "截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
raise(Error, "截止时间不能早于发布时间") if params[:publish_time] > params[:end_time]
|
|
|
|
|
raise(Error, "截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
tip_exception("发布时间不能为空") if params[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time]
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
course.end_date.present? && params[:end_time] > course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
homework.unified_setting = 1
|
|
|
|
@ -27,20 +27,20 @@ class UpdateHomeworkSettingService < ApplicationService
|
|
|
|
|
homework.end_time = params[:end_time]
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
raise(Error, "分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
# 创建作业的分班设置
|
|
|
|
|
homework.create_homework_group_settings
|
|
|
|
|
|
|
|
|
|
setting_group_ids = []
|
|
|
|
|
|
|
|
|
|
params[:group_settings].each do |setting|
|
|
|
|
|
raise(Error, "分班id不能为空") if setting[:group_id].length == 0
|
|
|
|
|
raise(Error, "发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
raise(Error, "截止时间不能为空") if setting[:end_time].blank?
|
|
|
|
|
raise(Error, "发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now)
|
|
|
|
|
raise(Error, "截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now)
|
|
|
|
|
raise(Error, "截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
raise(Error, "截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
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("截止时间不能晚于课堂结束时间(#{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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -73,28 +73,28 @@ class UpdateHomeworkSettingService < ApplicationService
|
|
|
|
|
# 作业在"提交中"状态时
|
|
|
|
|
else
|
|
|
|
|
if homework.end_time > Time.now && homework.unified_setting
|
|
|
|
|
raise(Error, "截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
raise(Error, "截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
raise(Error, "截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
tip_exception("截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_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)
|
|
|
|
|
|
|
|
|
|
homework.end_time = params[:end_time]
|
|
|
|
|
|
|
|
|
|
elsif !homework.unified_setting
|
|
|
|
|
homework.create_homework_group_settings
|
|
|
|
|
raise(Error, "分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
params[:group_settings].each do |setting|
|
|
|
|
|
group_settings = HomeworkGroupSetting.where(homework_common_id: homework.id, course_group_id: setting[:group_id])
|
|
|
|
|
|
|
|
|
|
raise(Error, "分班id不能为空") if setting[:group_id].length == 0
|
|
|
|
|
raise(Error, "发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
raise(Error, "截止时间不能为空") if setting[:end_time].blank?
|
|
|
|
|
tip_exception("分班id不能为空") if setting[:group_id].length == 0
|
|
|
|
|
tip_exception("发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if setting[:end_time].blank?
|
|
|
|
|
# 如果该发布规则 没有已发布的分班则需判断发布时间
|
|
|
|
|
raise(Error, "发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
|
|
|
|
|
tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
|
|
|
|
|
|
|
|
|
|
raise(Error, "截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) && group_settings.none_end.count > 0
|
|
|
|
|
raise(Error, "截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
raise(Error, "截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
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("截止时间不能晚于课堂结束时间(#{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)
|
|
|
|
|
|
|
|
|
|
group_settings.none_published.update_all(publish_time: setting[:publish_time])
|
|
|
|
|