From 3c92d07cf343a09b4a84d9f8fc470d1171601f79 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 17:21:12 +0800 Subject: [PATCH 1/2] fix bug --- .../exercise_questions_controller.rb | 36 +++++++++++-------- app/controllers/poll_questions_controller.rb | 20 ++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 490791918..8c4eb0a89 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -424,14 +424,18 @@ class ExerciseQuestionsController < ApplicationController begin choice_d_id = params[:choice_no].to_i # 选项的当前位置 question_choices = @exercise_question.exercise_choices - delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first - left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) - if left_choice.present? - left_choice.each do |p| - p.choice_position -= 1 - p.save - end - end + delete_answer = question_choices.find_by(choice_position: choice_d_id) + left_choices = question_choices.where("choice_position > ? ",choice_d_id) + left_choices.update_all("choice_position = choice_position - 1") if left_choices + # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first + # + # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) + # if left_choice.present? + # left_choice.each do |p| + # p.choice_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else @@ -450,13 +454,15 @@ class ExerciseQuestionsController < ApplicationController begin question_d_id = @exercise_question.question_number.to_i #问题的当前位置 exercise_questions = @exercise.exercise_questions - left_question = exercise_questions.left_question_choose("question_number",question_d_id) - if left_question.present? - left_question.each do |q| - q.question_number -= 1 - q.save - end - end + left_questions = exercise_questions.where("question_number > ?", question_d_id) + left_questions.update_all("question_number = question_number - 1") if left_questions + # left_question = exercise_questions.left_question_choose("question_number",question_d_id) + # if left_question.present? + # left_question.each do |q| + # q.question_number -= 1 + # q.save + # end + # end if @exercise_question.destroy normal_status(0, "问题删除成功!") else diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 47cd236a9..c7407c129 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -156,14 +156,18 @@ class PollQuestionsController < ApplicationController begin answer_d_id = params[:answer_no].to_i # 答案的当前位置 poll_answers = @poll_question.poll_answers - delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first - left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) - if left_answer.present? - left_answer.each do |p| - p.answer_position -= 1 - p.save - end - end + delete_answer = poll_answers.find_by(answer_position: answer_d_id) + left_answers = poll_answers.where("answer_position > ?",answer_d_id) + left_answers.update_all("answer_position = answer_position - 1") if left_answers + + # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first + # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) + # if left_answer.present? + # left_answer.each do |p| + # p.answer_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else From 1f224b681296eaeb517373f76d22eb4305d9520a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 17:32:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E9=94=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 19 ++++++++++++++----- .../homework_commons_controller.rb | 2 +- app/views/games/check_test_sets.json.jbuilder | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 4e7afa516..00760209e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -344,11 +344,20 @@ class GamesController < ApplicationController @game.update_attribute(:test_sets_view, true) # 扣分记录 Grade.create(:user_id => current_user.id, :container_id => @game.id, :score => -@minus_grade, :container_type => "testSet") - @status = 0 - @message = "解锁成功!" + max_query_index = game.query_index.to_i + # 区分评测过未评测过,未评测过按需求取数据 + if max_query_index > 0 + qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.compile_success, o.test_set_position, o.query_index,t.is_public,t.input, t.output, g.id as game_id, c.id as challenge_id FROM outputs o,games g ,challenges c,test_sets t where + g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and t.position =o.test_set_position order by o.query_index + ") + else + qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public,t.input, t.output,t.position FROM games g ,challenges c,test_sets t where + g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id + ") + end + testset_detail max_query_index, challenge else - @status = -1 - @message = "本操作需要扣除#{ @minus_grade }金币,您的金币不够了" + tip_exception(-1, "本操作需要扣除#{ @minus_grade }金币,您的金币不够了") end end @@ -813,7 +822,7 @@ class GamesController < ApplicationController # 评测测试机封装 def testset_detail max_query_index, challenge # 是否允许查看隐藏的测试集,以前的power - @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER + @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户 if max_query_index > 0 uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2f63f3ab9..83bfd29fc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1233,7 +1233,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - #get_new_code_reviews_result @homework + get_new_code_reviews_result @homework @current_user = current_user # 列表数据 diff --git a/app/views/games/check_test_sets.json.jbuilder b/app/views/games/check_test_sets.json.jbuilder index 017a75aea..ae44b54e9 100644 --- a/app/views/games/check_test_sets.json.jbuilder +++ b/app/views/games/check_test_sets.json.jbuilder @@ -1,2 +1 @@ -json.status @status -json.message @message \ No newline at end of file +json.partial! 'games/testset_list' \ No newline at end of file