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 0a999e1f3..0f9ed4d31 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -182,25 +182,42 @@ 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 - - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的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}) + 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.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实训题;其他是非实训题git + # 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 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|