试卷的调分接口调整

issues25489
cxt 5 years ago
parent ee238444d7
commit ab451d50cf

@ -612,13 +612,27 @@ class ExercisesController < ApplicationController
def adjust_score
exercise_user = @exercise.exercise_users.find_by!(user_id: params[:user_id])
tip_exception("已提交的作品请去评阅页进行调分") if exercise_user.commit_status == 1
tip_exception("分数不能为空") if params[:score].blank?
tip_exception("分数不能超过0-#{@exercise.question_scores}") if params[:score].to_f < 0 || params[:score].to_f.round(1) > @exercise.question_scores.round(1)
if @exercise.subjective_score > 0
tip_exception("主观题成绩不能为空") if params[:subject_score].blank?
tip_exception("主观题成绩不能小于零") if params[:subject_score].to_f < 0
tip_exception("主观题成绩不能大于总分值:#{@exercise.subjective_score}") if params[:subject_score].to_f.round(1) > @exercise.subjective_score.round(1)
end
if @exercise.objective_score > 0
tip_exception("客观题成绩不能为空") if params[:objective_score].blank?
tip_exception("客观题成绩不能小于零") if params[:objective_score].to_f < 0
tip_exception("客观题成绩不能大于总分值:#{@exercise.objective_score}") if params[:objective_score].to_f.round(1) > @exercise.objective_score.round(1)
end
ActiveRecord::Base.transaction do
start_at_time = exercise_user.start_at || Time.now
exercise_user.update_attributes!(start_at: start_at_time, end_at: Time.now, status: 1, commit_status: 1, score: params[:score].to_f.round(2), commit_method: 5)
ExerciseUserScore.create!(exercise_id: @exercise.id, exercise_user_id: exercise_user.id, score: params[:score], comment: params[:comment])
subjective_score = @exercise.subjective_score > 0 ? params[:subject_score].to_f.round(2) : 0
objective_score = @exercise.objective_score > 0 ? params[:objective_score].to_f.round(2) : 0
score = subjective_score + objective_score
exercise_user.update_attributes!(start_at: start_at_time, end_at: Time.now, status: 1, commit_status: 1, score: score,
subjective_score: subjective_score, objective_score: objective_score, commit_method: 5)
ExerciseUserScore.create!(exercise_id: @exercise.id, exercise_user_id: exercise_user.id,
subjective_score: subjective_score, objective_score: objective_score)
normal_status("操作成功")
end
end

@ -3,8 +3,8 @@ json.author do
end
json.id message.id
# json.content content_safe(message.contents_show(identity))
json.content message.contents_show(identity)
json.content content_safe(message.contents_show(identity))
# json.content message.contents_show(identity)
json.time time_from_now(message.created_at)
json.hidden message.hidden
# 主贴与子贴不一致

@ -0,0 +1,6 @@
class AddColumnToExerciseUserScore < ActiveRecord::Migration[5.2]
def change
add_column :exercise_user_scores, :subjective_score, :float, default: 0
add_column :exercise_user_scores, :objective_score, :float, default: 0
end
end
Loading…
Cancel
Save