|
|
|
@ -1077,22 +1077,38 @@ class ExercisesController < ApplicationController
|
|
|
|
|
def commit_exercise
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #为学生时
|
|
|
|
|
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
|
|
|
|
|
subjective_score = @answer_committed_user.subjective_score
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = objective_score + total_score_subjective_score
|
|
|
|
|
commit_option = {
|
|
|
|
|
can_commit_exercise = false
|
|
|
|
|
if (@user_course_identity > Course::ASSISTANT_PROFESSOR) && params[:commit_method].present? #为学生时
|
|
|
|
|
if params[:commit_method].to_i == 2 #自动提交时
|
|
|
|
|
user_left_time = get_exercise_left_time(@exercise,current_user)
|
|
|
|
|
if user_left_time.to_i <= 0
|
|
|
|
|
can_commit_exercise = true
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
can_commit_exercise = true
|
|
|
|
|
end
|
|
|
|
|
if can_commit_exercise
|
|
|
|
|
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
|
|
|
|
|
subjective_score = @answer_committed_user.subjective_score
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = objective_score + total_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
|
|
|
|
|
}
|
|
|
|
|
@answer_committed_user.update_attributes(commit_option)
|
|
|
|
|
CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id)
|
|
|
|
|
normal_status(0,"试卷提交成功!")
|
|
|
|
|
:subjective_score => subjective_score,
|
|
|
|
|
:commit_method => @answer_committed_user&.commit_method.to_i > 0 ? @answer_committed_user&.commit_method.to_i : params[:commit_method].to_i
|
|
|
|
|
}
|
|
|
|
|
@answer_committed_user.update_attributes(commit_option)
|
|
|
|
|
CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id)
|
|
|
|
|
normal_status(0,"试卷提交成功!")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1,"提交失败,请重试!")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1,"提交失败,请重试!")
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|