|
|
@ -1,7 +1,6 @@
|
|
|
|
class ExerciseAnswersController < ApplicationController
|
|
|
|
class ExerciseAnswersController < ApplicationController
|
|
|
|
before_action :require_login
|
|
|
|
before_action :require_login
|
|
|
|
before_action :get_exercise_question
|
|
|
|
before_action :get_exercise_question
|
|
|
|
before_action :commit_exercise_time
|
|
|
|
|
|
|
|
include ExercisesHelper
|
|
|
|
include ExercisesHelper
|
|
|
|
|
|
|
|
|
|
|
|
def create #每一次答案的点击,请求一次,实训题不在这里回答
|
|
|
|
def create #每一次答案的点击,请求一次,实训题不在这里回答
|
|
|
@ -95,9 +94,11 @@ class ExerciseAnswersController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
def get_exercise_question
|
|
|
|
def get_exercise_question
|
|
|
|
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
|
|
|
|
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
|
|
|
|
@exercise = @exercise_question.exercise
|
|
|
|
@exercise = @exercise_question.exercise.includes(:exercise_users)
|
|
|
|
@course = @exercise.course
|
|
|
|
@course = @exercise.course
|
|
|
|
@exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first #当前用户
|
|
|
|
@exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户
|
|
|
|
|
|
|
|
@exercise_user_status = @exercise.get_exercise_status(current_user.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if @exercise_question.blank?
|
|
|
|
if @exercise_question.blank?
|
|
|
|
normal_status(-1,"试卷问题不存在!")
|
|
|
|
normal_status(-1,"试卷问题不存在!")
|
|
|
@ -105,34 +106,15 @@ class ExerciseAnswersController < ApplicationController
|
|
|
|
normal_status(-1,"试卷不存在!")
|
|
|
|
normal_status(-1,"试卷不存在!")
|
|
|
|
elsif @course.blank?
|
|
|
|
elsif @course.blank?
|
|
|
|
normal_status(-1,"该课堂不存在!")
|
|
|
|
normal_status(-1,"该课堂不存在!")
|
|
|
|
elsif (@exercise_user.present? && @exercise_user.commit_status == 1) || (@exercise.end_time.present? && @exercise.end_time < Time.now) #已提交答案的/时间已结束的试卷不允许再修改
|
|
|
|
elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改
|
|
|
|
normal_status(-1,"已提交/已结束的试卷不允许修改!")
|
|
|
|
normal_status(-1,"已提交/已结束的试卷不允许修改!")
|
|
|
|
elsif @exercise.time > 0
|
|
|
|
elsif @exercise.time > 0
|
|
|
|
user_start_at = @exercise.exercise_users.exercise_commit_users(current_user.id).first.start_at
|
|
|
|
user_start_at = @exercise_user&.start_at
|
|
|
|
exercise_time = @exercise.time.to_i
|
|
|
|
exercise_time = @exercise.time.to_i + 1 #
|
|
|
|
if (user_start_at + exercise_time.minutes) < Time.now
|
|
|
|
if (user_start_at + exercise_time.minutes) < Time.now
|
|
|
|
normal_status(-1,"限时试卷已结束!")
|
|
|
|
normal_status(-1,"限时试卷已结束!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def commit_exercise_time
|
|
|
|
|
|
|
|
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题
|
|
|
|
|
|
|
|
if @exercise.exercise_status == 3 || (@exercise.time > 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(-1,"考试时间已到,已交卷成功!")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|