diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4bf80765c..a09db6308 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1512,7 +1512,7 @@ class HomeworkCommonsController < ApplicationController end_time = game.end_time # 用户关卡的得分 all_score = homework_challenge_settings.find_by(challenge_id: challenge.id).try(:score).to_f - final_score = @student_work.work_challenge_score game, all_score + final_score = @student_work.work_challenge_score game, all_score, challenge.id # 抄袭用户 copy_user = User.find_by_id(game_codes[0].try(:target_user_id)) copy_end_time = copy_user.games.find_by(challenge_id: challenge.id).try(:end_time) if copy_user.present? diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 57a5c7fad..3cbe5287f 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -213,7 +213,7 @@ class MessagesController < ApplicationController def notify_course_students message, course course.students.includes(:user).each do |student| - UserMailer.course_message_email(student&.user&.mail, message.id).deliver_later if student&.user&.mail + UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail end end end diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 060656a88..ad684952d 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -464,6 +464,7 @@ class StudentWorksController < ApplicationController @shixun = @homework.shixuns.take # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误 @games = @work.myshixun.games.joins(:challenge).reorder("challenges.position asc") if @work.myshixun + @challenges = @shixun.challenges if @shixun @comment = @work.shixun_work_comments.find_by(challenge_id: 0) # 用户最大评测次数 @@ -517,6 +518,7 @@ class StudentWorksController < ApplicationController @user = @work.user @shixun = @homework.shixuns.take @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun + @challenges = @shixun.challenges if @shixun # 用户最大评测次数 @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games @@ -717,27 +719,35 @@ class StudentWorksController < ApplicationController 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].to_i < 0 - tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting.score < params[:score].to_i + if challenge_setting + challenge = challenge_setting&.challenge + tip_exception("不能小于零") if params[:score].to_i < 0 + tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting && challenge_setting.score < params[:score].to_i - 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}关分数" + 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 + if @work.work_status != 0 && @work.myshixun + HomeworksService.new.update_myshixun_work_score @work, @work.myshixun, @work.myshixun&.games, @homework, @homework.homework_challenge_settings + else + update_none_commit_work @work, @homework + end + rescue Exception => e + uid_logger(e.message) + tip_exception("调分失败") + raise ActiveRecord::Rollback 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 + else + tip_exception("该关卡不记分") end end @@ -860,4 +870,20 @@ class StudentWorksController < ApplicationController end end end + + def update_none_commit_work work, homework + if work.work_status == 0 + work.work_status = 1 + work.commit_time = homework.end_time + work.update_time = Time.now + end + final_score = 0 + homework.homework_challenge_settings.each do |cha_setting| + adjust_score = work.challenge_work_scores.select{|work_score| work_score.challenge_id == cha_setting.challenge_id}.last + final_score += adjust_score.score if adjust_score.present? + end + work.final_score = final_score + work.work_score = final_score + work.save! + end end diff --git a/app/controllers/trustie_hacks_controller.rb b/app/controllers/trustie_hacks_controller.rb index 803809124..462a5a057 100644 --- a/app/controllers/trustie_hacks_controller.rb +++ b/app/controllers/trustie_hacks_controller.rb @@ -1,5 +1,5 @@ class TrustieHacksController < ApplicationController - before_action :require_admin, :except => [:index] + before_action :require_admin, :except => [:index, :entry] before_action :require_login, :except => [:index] before_action :find_hackathon before_action :find_hack, :except => [:create, :index, :edit_hackathon, :update_hackathon] @@ -15,7 +15,7 @@ class TrustieHacksController < ApplicationController hacks = hacks.where("name like ?", "%#{search}%") end - @hackathon_users_count = hacks ? 0 : hacks.sum(:hack_users_count) + @hackathon_users_count = hacks.blank? ? 0 : hacks.sum(:hack_users_count) @hacks_count = hacks.count @hacks = hacks.page(page).per(limit) @@ -49,10 +49,10 @@ class TrustieHacksController < ApplicationController # 报名入口 def entry - if @hack.hack_users.exists?(user_id: current_user) + if @hack.hack_users.exists?(user_id: current_user.id) render_error('已经报名,请勿重复操作') else - @hack.hack_users.create(user_id: current_user) + @hack.hack_users.create(user_id: current_user.id) render_ok end end diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 73d12aa2f..40759c9e0 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -19,7 +19,7 @@ module StudentWorksHelper # 作业的开启时间 def myshixun_open_time game - game.open_time ? (format_time game.open_time) : "--" + game&.open_time ? (format_time game.open_time) : "--" end # 作业完成时间 @@ -29,7 +29,7 @@ module StudentWorksHelper # 作业耗时 def time_consuming game - game.end_time.blank? ? "--" : (game_spend_time game.cost_time) + game&.end_time.blank? ? "--" : (game_spend_time game.cost_time) end # 用户个人实训总得分:user_total_score; diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 2e7f843ae..8477da774 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -196,12 +196,12 @@ class StudentWork < ApplicationRecord student_works_scores.where.not(reviewer_role: 3, score: nil).exists? end - def work_challenge_score game, score + def work_challenge_score game, score, challenge_id game_score = 0 - adjust_score = challenge_work_scores.where(challenge_id: game.challenge_id).last + adjust_score = challenge_work_scores.where(challenge_id: challenge_id).last if adjust_score.present? game_score = adjust_score.score - else + elsif game.present? setting = homework_common.homework_group_setting game.user_id if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework_common.allow_late && game.end_time && game.end_time < homework_common.late_time)) answer_open_evaluation = homework_common.homework_detail_manual.answer_open_evaluation diff --git a/app/models/trustie_hack.rb b/app/models/trustie_hack.rb index b436007ca..7c2f3264b 100644 --- a/app/models/trustie_hack.rb +++ b/app/models/trustie_hack.rb @@ -1,4 +1,5 @@ class TrustieHack < ApplicationRecord + validates_length_of :description, maximum: 500 has_many :hack_users, :dependent => :destroy belongs_to :trustie_hackathon, counter_cache: true diff --git a/app/models/trustie_hackathon.rb b/app/models/trustie_hackathon.rb index 7269e7856..65275099d 100644 --- a/app/models/trustie_hackathon.rb +++ b/app/models/trustie_hackathon.rb @@ -1,5 +1,5 @@ class TrustieHackathon < ApplicationRecord - + validates_length_of :description, maximum: 500 has_many :trustie_hacks, :dependent => :destroy end diff --git a/app/templates/shixun_work/shixun_work.html.erb b/app/templates/shixun_work/shixun_work.html.erb index c4ea11f1e..bbc81f373 100644 --- a/app/templates/shixun_work/shixun_work.html.erb +++ b/app/templates/shixun_work/shixun_work.html.erb @@ -76,22 +76,23 @@