调整实训作品的关卡分数

dev_forum
cxt 5 years ago
parent 0366af3a88
commit 3f6049df39

@ -631,16 +631,35 @@ class StudentWorksController < ApplicationController
# 查重作品调分
def adjust_review_score
if params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?
tip_exception("缺少type参数") if params[:type].blank? || ["review", "report"].include?(params[:type])
if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?)
tip_exception("参数错误score和challenge_id和code_rate和copy_user_id不能为空")
elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?)
tip_exception("参数错误score和challenge_id")
end
challenge_setting = @homework.homework_challenge_settings.find_by(challenge_id: params[:challenge_id])
challenge = challenge_setting&.challenge
tip_exception("不能小于零") if params[:score] < 0
tip_exception("不能大于关卡分值:#{challenge_setting.score}") if challenge_setting.score < params[:score]
ActiveRecord::Base.transaction do
begin
if params[:type] == "review"
copy_user = User.find params[:copy_user_id]
comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%"
else
comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数"
end
challenge_score = @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
comment: comment)
challenge_score.create_tiding current_user.id
HomeworksService.new.update_myshixun_work_score @work, @work&.myshixun, @work&.myshixun&.games, @homework, @homework.homework_challenge_settings
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
copy_user = User.find params[:copy_user_id]
comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%"
@work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
comment: comment)
HomeworksService.new.set_shixun_final_score(@work)
@work_score = @homework.student_works.find_by(id: @work.id).try(:work_score)
end

@ -2,4 +2,12 @@ class ChallengeWorkScore < ApplicationRecord
belongs_to :user
belongs_to :student_work
belongs_to :challenge
has_many :tidings, as: :container, dependent: :destroy
def create_tiding trigger_user_id
tidings << Tiding.new(user_id: student_work.user_id, trigger_user_id: trigger_user_id, container_id: id,
container_type: "ChallengeWorkScore", parent_container_id: student_work_id,
parent_container_type: "StudentWork", belong_container_id: student_work&.homework_common&.course_id,
belong_container_type: "Course", viewed: 0, tiding_type: "HomeworkCommon")
end
end

@ -0,0 +1,3 @@
json.status 0
json.message "调分成功"
json.work_score @work.work_score

@ -24,6 +24,7 @@ if @shixun
json.myself_experience game.final_score
json.experience game.challenge.all_score
json.complete_status game_status(game, @homework)
json.challenge_id game.challenge_id
end
end

Loading…
Cancel
Save