diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 92d146c82..62d96c424 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -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 diff --git a/app/models/challenge_work_score.rb b/app/models/challenge_work_score.rb index 8316e228b..1e7c9f7fe 100644 --- a/app/models/challenge_work_score.rb +++ b/app/models/challenge_work_score.rb @@ -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 diff --git a/app/views/student_works/adjust_review_score.json.jbuilder b/app/views/student_works/adjust_review_score.json.jbuilder index e69de29bb..399b52c13 100644 --- a/app/views/student_works/adjust_review_score.json.jbuilder +++ b/app/views/student_works/adjust_review_score.json.jbuilder @@ -0,0 +1,3 @@ +json.status 0 +json.message "调分成功" +json.work_score @work.work_score \ No newline at end of file diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 1c6ed5899..f0aa8119e 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -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