From 4c09c51ce93680d64d4cda6b26d6de8613a49f63 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 5 Dec 2019 11:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E8=AE=BE=E7=BD=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 10 ++-- ...update_homework_publish_setting_service.rb | 52 +++++++++---------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6918610df..4a31fc474 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -833,10 +833,12 @@ class HomeworkCommonsController < ApplicationController else tip_exception("课堂已结束不能再更新") end - rescue ApplicationService::Error => ex - uid_logger(ex.message) - render_error(ex.message) - raise ActiveRecord::Rollback + # rescue ActiveRecord::RecordInvalid + # render_error("保存失败") + # rescue ApplicationService::Error => ex + # uid_logger(ex.message) + # render_error(ex.message) + # raise ActiveRecord::Rollback rescue Exception => e uid_logger(e.backtrace) tip_exception(e.message) diff --git a/app/services/update_homework_publish_setting_service.rb b/app/services/update_homework_publish_setting_service.rb index 6350e0dc7..00d618522 100644 --- a/app/services/update_homework_publish_setting_service.rb +++ b/app/services/update_homework_publish_setting_service.rb @@ -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])