From 203ccd383cbba4f9c3658852a399f6ab049f1ceb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:26:44 +0800 Subject: [PATCH 1/4] fix bug --- .../exercise_questions_controller.rb | 2 +- app/controllers/question_banks_controller.rb | 51 +++++++++++++------ app/helpers/exercises_helper.rb | 2 +- app/tasks/exercise_publish_task.rb | 4 +- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index a0b88a97e..96951ac48 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -127,7 +127,7 @@ class ExerciseQuestionsController < ApplicationController shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组 shixun_name = params[:shixun_name] || shixun.name question_score = 0 - shixun.challenges.each_with_index do |challenge,index| + shixun.challenges.try(:each_with_index) do |challenge,index| shixun_option = { :challenge_id => challenge.id, :shixun_id => shixun.id, diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index bf55db9dd..cfb4d7763 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -181,31 +181,50 @@ class QuestionBanksController < ApplicationController :shixun_id => q.shixun_id } exercise_question = new_exercise.exercise_questions.new option - # question_type:5实训题;其他是非实训题 - if q.question_type != 5 - # 复制选择题题目选项 - q.exercise_bank_choices.try(:each_with_index) do |choice, index| - exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) - end + if exercise_question.save + if q.question_type != 5 + # 复制选择题题目选项 + q.exercise_bank_choices.try(:each_with_index) do |choice, index| + exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) + end - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) + # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + q.exercise_bank_standard_answers.try(:each) do |answer| + exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + end + else + # 复制实训题 + q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) + end end end + # question_type:5实训题;其他是非实训题 + # if q.question_type != 5 + # # 复制选择题题目选项 + # q.exercise_bank_choices.try(:each_with_index) do |choice, index| + # exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) + # end + # + # # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + # q.exercise_bank_standard_answers.try(:each) do |answer| + # exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + # end + # else + # # 复制实训题 + # q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + # exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, + # shixun_id: sc.shixun_id, question_score: sc.question_score}) + # end + # end end # 添加学生 # if new_exercise.save # new_exercise.create_exercise_list # exercise.update_column(:quotes, exercise.quotes+1) # end - new_exercise if new_exercise.save! + # new_exercise if new_exercise.save! end end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9526acaf1..4530167ba 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -451,7 +451,7 @@ module ExercisesHelper end end user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 - if user_scores > 0 + if user_scores > 0.0 stand_answer = 1 else stand_answer = 0 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 282968755..932fe00fb 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -70,7 +70,7 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) @@ -98,7 +98,7 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| From f3885408a570cd1f9e5e0d6691a1272a38ebc9b7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:28:15 +0800 Subject: [PATCH 2/4] fix bug --- app/controllers/question_banks_controller.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index b304c8d41..0fcdaf941 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -188,8 +188,6 @@ class QuestionBanksController < ApplicationController q.exercise_bank_choices.try(:each_with_index) do |choice, index| exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) end - -<<<<<<< HEAD # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 q.exercise_bank_standard_answers.try(:each) do |answer| exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) @@ -200,18 +198,6 @@ class QuestionBanksController < ApplicationController exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, shixun_id: sc.shixun_id, question_score: sc.question_score}) end -======= - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, - answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) ->>>>>>> 97ffdc47dfa2949ba2f4ca008a469f6d8ff1d0a2 end end # question_type:5实训题;其他是非实训题 From 96a613a9c9c411597181b5be6d95b555f980c65c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:28:57 +0800 Subject: [PATCH 3/4] fix bug --- app/controllers/question_banks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0fcdaf941..0184fa81a 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -200,7 +200,7 @@ class QuestionBanksController < ApplicationController end end end - # question_type:5实训题;其他是非实训题 + # question_type:5实训题;其他是非实训题git # if q.question_type != 5 # # 复制选择题题目选项 # q.exercise_bank_choices.try(:each_with_index) do |choice, index| From 1fe4a8c986d78422b3fecb37074705d79d8555be Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:35:00 +0800 Subject: [PATCH 4/4] fix bug --- app/controllers/question_banks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0184fa81a..0f9ed4d31 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -224,7 +224,7 @@ class QuestionBanksController < ApplicationController # new_exercise.create_exercise_list # exercise.update_column(:quotes, exercise.quotes+1) # end - # new_exercise if new_exercise.save! + new_exercise if new_exercise.save! end end