|
|
@ -11,7 +11,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results,
|
|
|
|
before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results,
|
|
|
|
:code_review_detail, :show_comment, :settings, :works_list, :update_settings,
|
|
|
|
:code_review_detail, :show_comment, :settings, :works_list, :update_settings,
|
|
|
|
:reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
|
|
|
|
:reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
|
|
|
|
:update_score, :update_student_score]
|
|
|
|
:update_score, :update_student_score, :batch_comment]
|
|
|
|
before_action :user_course_identity
|
|
|
|
before_action :user_course_identity
|
|
|
|
before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer,
|
|
|
|
before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer,
|
|
|
|
:update_student_score]
|
|
|
|
:update_student_score]
|
|
|
@ -19,7 +19,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
:publish_homework, :end_homework, :set_public, :choose_category, :move_to_category,
|
|
|
|
:publish_homework, :end_homework, :set_public, :choose_category, :move_to_category,
|
|
|
|
:choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat,
|
|
|
|
:choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat,
|
|
|
|
:code_review_results, :code_review_detail, :update_explanation, :update_settings,
|
|
|
|
:code_review_results, :code_review_detail, :update_explanation, :update_settings,
|
|
|
|
:add_to_homework_bank, :publish_groups, :end_groups]
|
|
|
|
:add_to_homework_bank, :publish_groups, :end_groups, :batch_comment]
|
|
|
|
before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category,
|
|
|
|
before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category,
|
|
|
|
:add_to_homework_bank]
|
|
|
|
:add_to_homework_bank]
|
|
|
|
before_action :course_manager, only: [:alter_name]
|
|
|
|
before_action :course_manager, only: [:alter_name]
|
|
|
@ -453,105 +453,8 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
# 课堂结束后不能再更新
|
|
|
|
# 课堂结束后不能再更新
|
|
|
|
unless @course.is_end
|
|
|
|
unless @course.is_end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 发布设置
|
|
|
|
UpdateHomeworkPublishSettingService.call(@homework, publish_params)
|
|
|
|
UpdateHomeworkPublishSettingService.call(@homework, publish_params)
|
|
|
|
# 作业未发布时,unified_setting参数不能为空
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
if @homework.publish_time.nil? || @homework.publish_time > Time.now
|
|
|
|
|
|
|
|
tip_exception("缺少统一设置的参数") if params[:unified_setting].nil?
|
|
|
|
|
|
|
|
if params[:unified_setting] || @course.course_groups_count == 0
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@homework.homework_group_settings.destroy_all
|
|
|
|
|
|
|
|
@homework.publish_time = params[:publish_time]
|
|
|
|
|
|
|
|
# 截止时间为空时取发布时间后一个月
|
|
|
|
|
|
|
|
@homework.end_time = params[:end_time]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
|
|
|
# 创建作业的分班设置
|
|
|
|
|
|
|
|
create_homework_group_settings @homework
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setting_group_ids = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params[:group_settings].each do |setting|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time]
|
|
|
|
|
|
|
|
# 截止时间为空时取发布时间后一个月
|
|
|
|
|
|
|
|
end_time = setting[:end_time]
|
|
|
|
|
|
|
|
HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]).
|
|
|
|
|
|
|
|
update_all(publish_time: publish_time, end_time: end_time)
|
|
|
|
|
|
|
|
setting_group_ids << setting[:group_id]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 未设置的分班:发布时间和截止时间都为nil
|
|
|
|
|
|
|
|
HomeworkGroupSetting.where.not(course_group_id: setting_group_ids).where(homework_common_id: @homework.id).
|
|
|
|
|
|
|
|
update_all(publish_time: nil, end_time: nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 记录已发布需要发消息的分班
|
|
|
|
|
|
|
|
publish_group_ids = HomeworkGroupSetting.where(homework_common_id: @homework.id).group_published.pluck(:course_group_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@homework.unified_setting = 0
|
|
|
|
|
|
|
|
@homework.publish_time = @homework.min_group_publish_time
|
|
|
|
|
|
|
|
@homework.end_time = @homework.max_group_end_time
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 如果作业立即发布则更新状态、发消息
|
|
|
|
|
|
|
|
if @homework.publish_time <= Time.now and @homework_detail_manual.comment_status == 0
|
|
|
|
|
|
|
|
@homework_detail_manual.comment_status = 1
|
|
|
|
|
|
|
|
send_tiding = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 作业在"提交中"状态时
|
|
|
|
|
|
|
|
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("截止时间不能晚于课堂结束时间(#{@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
|
|
|
|
|
|
|
|
create_homework_group_settings @homework
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) && 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("截止时间不能晚于课堂结束时间(#{@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])
|
|
|
|
|
|
|
|
group_settings.none_end.update_all(end_time: setting[:end_time])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@homework.end_time = @homework.max_group_end_time
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 补交设置
|
|
|
|
# 补交设置
|
|
|
|
tip_exception("缺少allow_late参数") if params[:allow_late].nil?
|
|
|
|
tip_exception("缺少allow_late参数") if params[:allow_late].nil?
|
|
|
@ -880,69 +783,6 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
## 分页参数
|
|
|
|
## 分页参数
|
|
|
|
page = params[:page] || 1
|
|
|
|
page = params[:page] || 1
|
|
|
|
@shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10)
|
|
|
|
@shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10)
|
|
|
|
|
|
|
|
|
|
|
|
# 新版用下面的代码
|
|
|
|
|
|
|
|
# ## 我的实训
|
|
|
|
|
|
|
|
# @shixuns =
|
|
|
|
|
|
|
|
# if params[:order_by] == 'mine'
|
|
|
|
|
|
|
|
# current_user.my_shixuns.unhidden
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# if current_user.admin?
|
|
|
|
|
|
|
|
# Shixun.unhidden
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ## 方向
|
|
|
|
|
|
|
|
# if params[:tag_level].present? && params[:tag_id].present?
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
|
|
|
|
|
|
|
|
# case params[:tag_level].to_i
|
|
|
|
|
|
|
|
# when 1 #大类
|
|
|
|
|
|
|
|
# @search_tags = Repertoire.find(params[:tag_id].to_i).name
|
|
|
|
|
|
|
|
# when 2 #子类
|
|
|
|
|
|
|
|
# @search_tags = SubRepertoire.find(params[:tag_id].to_i).name
|
|
|
|
|
|
|
|
# when 3 #tag
|
|
|
|
|
|
|
|
# tag = TagRepertoire.find(params[:tag_id].to_i)
|
|
|
|
|
|
|
|
# @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}"
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ## 搜索关键字创建者、实训名称、院校名称
|
|
|
|
|
|
|
|
# if params[:keyword].present?
|
|
|
|
|
|
|
|
# keyword = params[:keyword].strip
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.joins(user: [user_extenison: :school]).
|
|
|
|
|
|
|
|
# where("schools.name like '%#{keyword}%'
|
|
|
|
|
|
|
|
# or concat(lastname, firstname) like '%#{keyword}%'
|
|
|
|
|
|
|
|
# or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ## 筛选 难度
|
|
|
|
|
|
|
|
# if params[:diff].present? && params[:diff].to_i != 0
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.where(trainee: params[:diff])
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ## 排序参数
|
|
|
|
|
|
|
|
# bsort = params[:sort] || 'desc'
|
|
|
|
|
|
|
|
# case params[:order_by] || 'hot'
|
|
|
|
|
|
|
|
# when 'hot'
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.order("myshixuns_count #{bsort}")
|
|
|
|
|
|
|
|
# when 'mine'
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.order("shixuns.created_at #{bsort}")
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.order("myshixuns_count #{bsort}")
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# @total_count = @shixuns.count
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ## 分页参数
|
|
|
|
|
|
|
|
# page = params[:page] || 1
|
|
|
|
|
|
|
|
# limit = params[:limit] || 15
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create_shixun_homework
|
|
|
|
def create_shixun_homework
|
|
|
@ -1248,31 +1088,6 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
# homework_challenge_settings = homework.homework_challenge_settings
|
|
|
|
# homework_challenge_settings = homework.homework_challenge_settings
|
|
|
|
unless student_works.blank?
|
|
|
|
unless student_works.blank?
|
|
|
|
student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late
|
|
|
|
student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late
|
|
|
|
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
student_works.where("work_status != 0").includes(:myshixun).each do |student_work|
|
|
|
|
|
|
|
|
unless student_work.myshixun.is_complete?
|
|
|
|
|
|
|
|
student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty)
|
|
|
|
|
|
|
|
student_work.late_penalty = homework.late_penalty
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation,
|
|
|
|
|
|
|
|
homework_challenge_settings
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
student_works.where("work_status = 0").each do |student_work|
|
|
|
|
|
|
|
|
myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first
|
|
|
|
|
|
|
|
if myshixun.present?
|
|
|
|
|
|
|
|
student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2),
|
|
|
|
|
|
|
|
late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty,
|
|
|
|
|
|
|
|
commit_time: myshixun.created_at, myshixun_id: myshixun.id)
|
|
|
|
|
|
|
|
student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty
|
|
|
|
|
|
|
|
HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation,
|
|
|
|
|
|
|
|
homework_challenge_settings
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 更新所有学生的效率分(重新取homework确保是更新后的)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
homework.save!
|
|
|
|
homework.save!
|
|
|
@ -1558,6 +1373,21 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def batch_comment
|
|
|
|
|
|
|
|
tip_exception(-1, "作业还未发布,不能评阅") if @homework_detail_manual.comment_status == 0
|
|
|
|
|
|
|
|
tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank?
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
|
|
work_ids = @homework.student_works.where(user_id: @course.teacher_group_user_ids(current_user.id)).pluck(:id)
|
|
|
|
|
|
|
|
has_comment_ids = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 0).pluck(:student_work_id)
|
|
|
|
|
|
|
|
batch_comment_works = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 1)
|
|
|
|
|
|
|
|
batch_comment_works.update_all(comment: params[:comment], hidden_comment: params[:hidden_comment])
|
|
|
|
|
|
|
|
work_ids = work_ids - has_comment_ids - batch_comment_works.pluck(:student_work_id)
|
|
|
|
|
|
|
|
@homework.student_works.where(work_status: 0, id: work_ids).update_all(work_status: 1, commit_time: @homework.end_time, update_time: Time.now, work_score: 0, final_score: 0)
|
|
|
|
|
|
|
|
HomeworkBatchCommentJob.perform_later(params[:comment], params[:hidden_comment], work_ids, @homework.id, current_user.id)
|
|
|
|
|
|
|
|
normal_status("评阅成功")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
def find_homework
|
|
|
|
def find_homework
|
|
|
|