|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
class ExerciseAnswersController < ApplicationController
|
|
|
|
|
before_action :require_login
|
|
|
|
|
before_action :get_exercise_question
|
|
|
|
|
before_action :commit_exercise_time
|
|
|
|
|
include ExercisesHelper
|
|
|
|
|
|
|
|
|
|
def create #每一次答案的点击,请求一次,实训题不在这里回答
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
@ -31,6 +33,7 @@ class ExerciseAnswersController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
elsif q_type == 1 #多选题的
|
|
|
|
|
choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : []
|
|
|
|
|
|
|
|
|
|
ea_ids = ea.pluck(:exercise_choice_id)
|
|
|
|
|
common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id
|
|
|
|
|
new_ids = choice_ids - common_answer_ids # 新增的id
|
|
|
|
@ -113,4 +116,24 @@ class ExerciseAnswersController < ApplicationController
|
|
|
|
|
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
|
|
|
|
|