From ddba2ab19d03c7b5a1c20e902ead7541ebf0bd0a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 5 Dec 2019 15:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E4=BD=9C=E4=B8=9A=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 2 +- app/controllers/weapps/courses_controller.rb | 2 +- .../weapps/homework_commons_controller.rb | 2 +- ...update_homework_publish_setting_service.rb | 21 ++++++++++--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1c19c745f..e11fefea1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1652,7 +1652,7 @@ class HomeworkCommonsController < ApplicationController end def publish_params - params.permit(:unified_setting, :publish_time, :end_time, group_settings: []) + params.permit(:unified_setting, :publish_time, :end_time, group_settings: [:publish_time, :end_time, group_id: []]) end end diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index 1ccefcbe2..17e7450b4 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -107,7 +107,7 @@ class Weapps::CoursesController < Weapps::BaseController # 批量修改角色 def change_member_roles @course = current_course - tip_exception("请至少选择一个角色") if params[:roles].blank? + tip_exception("请至少选择一个角色") if params[:roles].reject(&:blank?).blank? tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") params[:user_ids].each do |user_id| diff --git a/app/controllers/weapps/homework_commons_controller.rb b/app/controllers/weapps/homework_commons_controller.rb index 3f74d6ba4..fd1d5cc9c 100644 --- a/app/controllers/weapps/homework_commons_controller.rb +++ b/app/controllers/weapps/homework_commons_controller.rb @@ -31,7 +31,7 @@ class Weapps::HomeworkCommonsController < Weapps::BaseController end def publish_params - params.permit(:unified_setting, :publish_time, :end_time, group_settings: []) + params.permit(:unified_setting, :publish_time, :end_time, group_settings: [:publish_time, :end_time, group_id: []]) end end \ No newline at end of file diff --git a/app/services/update_homework_publish_setting_service.rb b/app/services/update_homework_publish_setting_service.rb index 3ada2fbc4..69a68b613 100644 --- a/app/services/update_homework_publish_setting_service.rb +++ b/app/services/update_homework_publish_setting_service.rb @@ -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])