Merge branch 'dev_aliyun' into dev_cxt

dev_hjm_a
cxt 5 years ago
commit 8c25443967

@ -1036,6 +1036,7 @@ class HomeworkCommonsController < ApplicationController
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
group_ids = @course.charge_group_ids(@current_user) - @homework.homework_group_settings.group_published.pluck(:course_group_id)
@course_groups = @course.course_groups.where(id: group_ids)
@group_settings = @homework.homework_group_settings.where(id: group_ids)
else
tip_exception("没有可发布的分班")
end
@ -1043,16 +1044,28 @@ class HomeworkCommonsController < ApplicationController
def publish_homework
tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0
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)
if params[:detail].blank?
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)
else
group_end_times = params[:group_end_times].reject(&:blank?).map{|time| time.to_time}
group_ids = params[:group_ids].reject(&:blank?)
tip_exception("缺少截止时间参数") if group_end_times.blank?
tip_exception("截止时间和分班参数的个数不一致") if group_end_times.length != group_ids.length
group_end_times.each do |time|
tip_exception("分班截止时间不能早于当前时间") if time <= Time.now
tip_exception("分班截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")}") if
@course.end_date.present? && time > @course.end_date.end_of_day
end
end
homeworks = @course.homework_commons.where(id: params[:homework_ids])
homeworks = homeworks.includes(:homework_group_settings, :homework_detail_manual)
charge_group_ids = @course.charge_group_ids(current_user)
publish_groups = charge_group_ids & params[:group_ids] if params[:group_ids]
publish_groups = charge_group_ids & group_ids if group_ids
# ActiveRecord::Base.transaction do
begin
@ -1062,18 +1075,26 @@ class HomeworkCommonsController < ApplicationController
if !params[:group_ids].blank?
# 全选即统一设置unified_setting为true
if @course.course_groups.where(id: publish_groups).size == @course.course_groups.size
if @course.course_groups.where(id: publish_groups).size == @course.course_groups.size &&
((params[:detail] && group_end_times.min == group_end_times.max) || params[:detail].blank?)
homework.homework_group_settings.destroy_all
homework.unified_setting = true
homework.end_time = params[:end_time]
homework.end_time = params[:detail] ? group_end_times.max : params[:end_time]
else
homework.unified_setting = false
# 创建作业分班设置homework_group_setting
create_homework_group_settings(homework)
# 选中的分班设置的发布时间改为当前时间,截止时间改为传的截止时间参数
homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now,
end_time: params[:end_time])
if params[:detail]
group_ids.each_with_index do |group_id, index|
homework.homework_group_settings.find_by(course_group_id: group_id)&.update_attributes!(publish_time: Time.now,
end_time: group_end_times[index])
end
else
homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now,
end_time: params[:end_time])
end
# 发消息
tiding_group_ids = publish_groups
end
@ -1086,7 +1107,7 @@ class HomeworkCommonsController < ApplicationController
# 截止时间的处理
if homework.end_time.nil?
homework.end_time = params[:end_time]
homework.end_time = params[:detail] ? group_end_times.max : params[:end_time]
elsif homework.max_group_end_time
homework.end_time = homework.max_group_end_time
end
@ -1101,12 +1122,22 @@ class HomeworkCommonsController < ApplicationController
create_homework_group_settings(homework)
none_publish_settings = homework.homework_group_settings.where(course_group_id: publish_groups).none_published
none_publish_settings.update_all(publish_time: Time.now, end_time: params[:end_time])
if params[:detail]
group_ids.each_with_index do |group_id, index|
none_publish_settings.find_by(course_group_id: group_id)&.update_attributes!(publish_time: Time.now,
end_time: group_end_times[index])
end
else
none_publish_settings.update_all(publish_time: Time.now, end_time: params[:end_time])
end
if homework.max_group_end_time
homework.end_time = homework.max_group_end_time
end
HomeworkCommonPushNotifyJob.perform_later(homework.id, none_publish_settings.pluck(:course_group_id))
end
if homework.end_time > Time.now && homework.homework_detail_manual.try(:comment_status) > 1
homework.homework_detail_manual.update_attribute("comment_status", 1)
end

@ -2,10 +2,10 @@ class PollsController < ApplicationController
# before_action :check_poll_status 问卷的发消息和定时任务没有做
before_action :require_login, :check_auth,except: [:index]
before_action :find_course, except: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer,:commit_poll,
:commit_result,:poll_lists,:cancel_publish,:cancel_publish_modal,:common_header]
:commit_result,:poll_lists,:cancel_publish,:cancel_publish_modal,:common_header,:publish_groups]
before_action :get_poll_and_course, only: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer,
:commit_poll,:commit_result,:poll_lists,:cancel_publish,
:cancel_publish_modal,:common_header]
:cancel_publish_modal,:common_header, :publish_groups]
before_action :user_course_identity
before_action :is_course_teacher, except: [:index,:start_answer,:poll_setting,:commit_poll,:commit_result,:poll_lists,:common_header] #判断是否为课堂老师
before_action :check_user_status
@ -242,12 +242,35 @@ class PollsController < ApplicationController
end
end
end
# 详情页的立即发布弹框
def publish_groups
@current_user = current_user
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
group_ids = @course.charge_group_ids(@current_user) - @poll.poll_group_settings.poll_group_published.pluck(:course_group_id)
@course_groups = @course.course_groups.where(id: group_ids)
@group_settings = @poll.poll_group_settings.where(id: group_ids)
end
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
def publish
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)
if params[:detail].blank?
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)
else
group_end_times = params[:group_end_times].reject(&:blank?).map{|time| time.to_time}
group_ids = params[:group_ids].reject(&:blank?)
tip_exception("缺少截止时间参数") if group_end_times.blank?
tip_exception("截止时间和分班参数的个数不一致") if group_end_times.length != group_ids.length
group_end_times.each do |time|
tip_exception("分班截止时间不能早于当前时间") if time <= Time.now
tip_exception("分班截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")}") if
@course.end_date.present? && time > @course.end_date.end_of_day
end
end
ActiveRecord::Base.transaction do
begin
check_ids = Poll.where(id: params[:check_ids])
@ -259,26 +282,27 @@ class PollsController < ApplicationController
pl_status = poll.poll_group_settings.find_in_poll_group("course_group_id",params[:group_ids]).poll_group_not_published.present? ? 1 : 0 #立即发布针对分组设置的全部未发布的班级才生效
end
if pl_status == 1 #如果问卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改
g_course = group_ids #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改
if g_course
user_course_groups = @course.charge_group_ids(current_user)
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
user_course_groups = @course.course_groups.pluck(:id)
if g_course.map(&:to_i).sort == user_course_groups.sort &&
((params[:detail] && group_end_times.min == group_end_times.max) || params[:detail].blank?) # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
poll.poll_group_settings.destroy_all
poll_unified = true
e_time = ex_end_time
else
poll_unified = false
g_course.each do |i|
g_course.each_with_index do |i, index|
poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id寻找问卷所在的班级
if poll_group_setting #如果该问卷分组存在,则更新,否则新建
poll_group_setting.update_attributes(publish_time:Time.now,end_time:ex_end_time)
poll_group_setting.update_attributes(publish_time:Time.now, end_time: params[:detail] ? group_end_times[index] : ex_end_time)
else
p_course_group = {
:poll_id => poll.id,
:course_group_id => i,
:course_id => poll.course.id,
:publish_time => Time.now,
:end_time => ex_end_time,
:end_time => params[:detail] ? group_end_times[index] : ex_end_time,
}
new_poll_group = poll.poll_group_settings.new p_course_group
new_poll_group.save

@ -1,4 +1,6 @@
json.course_groups @course_groups do |group|
json.id group.id
json.name group.name
end
json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time
end
json.end_time @homework.end_time

@ -0,0 +1,6 @@
json.course_groups @course_groups do |group|
json.id group.id
json.name group.name
json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time
end
json.end_time @poll.end_time

@ -587,6 +587,7 @@ Rails.application.routes.draw do
post :cancel_publish #撤销发布
get :cancel_publish_modal #撤销发布的弹窗
get :common_header
get :publish_groups
end
resources :poll_questions,only:[:new,:create]
end

Loading…
Cancel
Save