diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index bd5a41123..a6464a151 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -605,6 +605,21 @@ class ExercisesController < ApplicationController end end + # 对未提交的用户进行调分 + 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) + + 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]) + normal_status("操作成功") + end + end + #我的题库 def my_exercises ActiveRecord::Base.transaction do diff --git a/app/models/exercise_user.rb b/app/models/exercise_user.rb index 0f2e8456e..fb2034998 100644 --- a/app/models/exercise_user.rb +++ b/app/models/exercise_user.rb @@ -1,8 +1,10 @@ class ExerciseUser < ApplicationRecord - # commit_method 0 为默认, 1为学生的手动提交,2为倒计时结束后自动提交,3为试卷定时截止的自动提交, 4为教师手动的立即截止 + # commit_method 0 为默认, 1为学生的手动提交,2为倒计时结束后自动提交,3为试卷定时截止的自动提交, 4为教师手动的立即截止, 5为老师调分 belongs_to :user belongs_to :exercise + has_many :exercise_user_scores, dependent: :destroy + scope :commit_exercise_by_status, lambda { |s| where(commit_status: s) } scope :exercise_user_committed, -> {where("commit_status != ?",0) } scope :current_exercise_user, lambda { |user_id,exercise_id| where(user_id: user_id,exercise_id:exercise_id)} diff --git a/app/models/exercise_user_score.rb b/app/models/exercise_user_score.rb new file mode 100644 index 000000000..d022b0b31 --- /dev/null +++ b/app/models/exercise_user_score.rb @@ -0,0 +1,5 @@ +class ExerciseUserScore < ApplicationRecord + belongs_to :exercise + belongs_to :exercise_user + belongs_to :user +end diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 24d1f354a..3807d5b99 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -86,7 +86,7 @@ if @homework.homework_type == "practice" json.work_efficiency @homework.work_efficiency json.student_works @student_works.each do |work| - json.(work, :id, :work_status, :update_time, :ultimate_score) + json.(work, :id, :work_status, :update_time, :ultimate_score, :myshixun_id) json.late_penalty work.late_penalty if @homework.allow_late json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) diff --git a/config/routes.rb b/config/routes.rb index 2f8f3d958..5315df7ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -510,7 +510,7 @@ Rails.application.routes.draw do post :join_exercise_banks # 加入习题集 post :publish # 立即发布 post :end_exercise # 立即截止 - +`` end end @@ -626,6 +626,7 @@ Rails.application.routes.draw do post :cancel_exercise get :begin_commit #提交前的弹窗 get :publish_groups + post :adjust_score end resources :exercise_questions,only:[:new,:create,:index] end diff --git a/db/migrate/20191030062150_create_exercise_user_scores.rb b/db/migrate/20191030062150_create_exercise_user_scores.rb new file mode 100644 index 000000000..911a8a3a5 --- /dev/null +++ b/db/migrate/20191030062150_create_exercise_user_scores.rb @@ -0,0 +1,13 @@ +class CreateExerciseUserScores < ActiveRecord::Migration[5.2] + def change + create_table :exercise_user_scores do |t| + t.references :exercise, index: true + t.references :exercise_user, index: true + t.float :score + t.text :comment + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/spec/models/exercise_user_score_spec.rb b/spec/models/exercise_user_score_spec.rb new file mode 100644 index 000000000..97f67a99a --- /dev/null +++ b/spec/models/exercise_user_score_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ExerciseUserScore, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end