|
|
|
@ -12,10 +12,10 @@ class ExercisesController < ApplicationController
|
|
|
|
|
before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise]
|
|
|
|
|
before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合
|
|
|
|
|
before_action :check_course_public,only: [:set_public]
|
|
|
|
|
before_action :check_user_on_answer,only: [:show,:start_answer,:commit_exercise,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限
|
|
|
|
|
before_action :check_user_on_answer,only: [:show,:start_answer,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限
|
|
|
|
|
before_action :only_student_in,only: [:start_answer]
|
|
|
|
|
before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise]
|
|
|
|
|
before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #判断试卷时间到用户是否提交
|
|
|
|
|
# before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务
|
|
|
|
|
before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过
|
|
|
|
|
before_action :check_exercise_status,only: [:redo_modal,:redo_exercise]
|
|
|
|
|
before_action :check_exercise_is_end, only: [:review_exercise]
|
|
|
|
@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController
|
|
|
|
|
def start_answer
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first
|
|
|
|
|
if @exercise_user_current.blank?
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的
|
|
|
|
|
exercise_user_params = {
|
|
|
|
@ -1640,38 +1641,38 @@ class ExercisesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_exercise_time
|
|
|
|
|
@answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
|
|
|
|
|
@answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first
|
|
|
|
|
if @answer_committed_user.blank?
|
|
|
|
|
normal_status(404,"答题用户不存在")
|
|
|
|
|
elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 #
|
|
|
|
|
normal_status(-1,"提交错误,试卷已截止/用户已提交!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commit_user_exercise
|
|
|
|
|
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题
|
|
|
|
|
if @user_course_identity == Course::STUDENT
|
|
|
|
|
if @exercise_user_current.present?
|
|
|
|
|
if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
|
|
|
|
|
((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
|
|
|
|
|
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
|
|
|
|
|
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
|
|
|
|
|
subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
|
|
|
|
|
total_score = objective_score + subjective_score
|
|
|
|
|
commit_option = {
|
|
|
|
|
:status => 1,
|
|
|
|
|
:commit_status => 1,
|
|
|
|
|
:end_at => Time.now,
|
|
|
|
|
:objective_score => objective_score,
|
|
|
|
|
:score => total_score,
|
|
|
|
|
:subjective_score => subjective_score
|
|
|
|
|
}
|
|
|
|
|
@exercise_user_current.update_attributes(commit_option)
|
|
|
|
|
normal_status(0,"已交卷成功!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
|
|
|
|
|
# normal_status(-1,"提交错误,试卷用户已提交!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# def commit_user_exercise
|
|
|
|
|
# @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
|
|
|
|
|
# if @user_course_identity == Course::STUDENT
|
|
|
|
|
# if @exercise_user_current.present?
|
|
|
|
|
# if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
|
|
|
|
|
# ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
|
|
|
|
|
# #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
|
|
|
|
|
# objective_score = calculate_student_score(@exercise,current_user)[:total_score]
|
|
|
|
|
# subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
|
|
|
|
|
# total_score = objective_score + subjective_score
|
|
|
|
|
# commit_option = {
|
|
|
|
|
# :status => 1,
|
|
|
|
|
# :commit_status => 1,
|
|
|
|
|
# :end_at => Time.now,
|
|
|
|
|
# :objective_score => objective_score,
|
|
|
|
|
# :score => total_score,
|
|
|
|
|
# :subjective_score => subjective_score
|
|
|
|
|
# }
|
|
|
|
|
# @exercise_user_current.update_attributes(commit_option)
|
|
|
|
|
# normal_status(0,"已交卷成功!")
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
#打回重做时的初步判断
|
|
|
|
|
def check_exercise_status
|
|
|
|
|