From ab451d50cf61a66dc2ed517b78792c8b646d2634 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 7 Nov 2019 17:51:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E8=B0=83=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 22 +++++++++++++++---- .../_graduation_comments.json.jbuilder | 4 ++-- ...93428_add_column_to_exercise_user_score.rb | 6 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20191107093428_add_column_to_exercise_user_score.rb diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2f616ec71..681684295 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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 diff --git a/app/views/graduation_topics/_graduation_comments.json.jbuilder b/app/views/graduation_topics/_graduation_comments.json.jbuilder index 03002e82e..e52395fbf 100644 --- a/app/views/graduation_topics/_graduation_comments.json.jbuilder +++ b/app/views/graduation_topics/_graduation_comments.json.jbuilder @@ -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 # 主贴与子贴不一致 diff --git a/db/migrate/20191107093428_add_column_to_exercise_user_score.rb b/db/migrate/20191107093428_add_column_to_exercise_user_score.rb new file mode 100644 index 000000000..892252987 --- /dev/null +++ b/db/migrate/20191107093428_add_column_to_exercise_user_score.rb @@ -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