diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 95ec0ac24..1b201d875 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -352,7 +352,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers) exercise_questions.each do |q| if q.question_type != 5 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 9d62e4d2e..6f18dc403 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -70,12 +70,12 @@ 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) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if exercise_user.commit_status == 0 && exercise_user.start_at.present? s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score @@ -84,6 +84,8 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score + Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") + commit_option = { :status => 1, :commit_status => 1, @@ -98,12 +100,15 @@ 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) + 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) 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| exercise = exercise_setting.exercise - exercise.update_column('exercise_status', 3) + if exercise&.end_time <= Time.now + exercise.update_column('exercise_status', 3) + end + ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id))