From d9ce239fcff097b9c3b8003d846488222f93e27d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 14:43:46 +0800 Subject: [PATCH] fixbug --- .../exercise_answers_controller.rb | 12 ++-- .../exercise_questions_controller.rb | 2 +- app/controllers/exercises_controller.rb | 61 ++++++++----------- app/controllers/polls_controller.rb | 2 +- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 27e4aba11..babdd50f7 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -9,11 +9,11 @@ class ExerciseAnswersController < ApplicationController q_type = @exercise_question.question_type #试卷的类型 choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : "" answer_text = params[:answer_text].present? ? params[:answer_text] : "" #为字符串 - if q_type < 4 && (q_type != 1) && choice_id.blank? + if q_type < Exercise::SUBJECTIVE && (q_type != Exercise::MULTIPLE) && choice_id.blank? normal_status(-1,"请选择序号") else ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案 - if q_type == 0 || q_type == 2 #选择题(单选)/判断题 + if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题 ea_choice = ea.search_exercise_answer("exercise_choice_id",choice_id).first answer_option = { :user_id => current_user.id, @@ -30,7 +30,7 @@ class ExerciseAnswersController < ApplicationController ex_a = ExerciseAnswer.new(answer_option) ex_a.save! end - elsif q_type == 1 #多选题的 + elsif q_type == Exercise::MULTIPLE #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] ea_ids = ea.pluck(:exercise_choice_id) @@ -53,7 +53,7 @@ class ExerciseAnswersController < ApplicationController ea_answer = ea.search_answer_users("exercise_choice_id",old_ids) ea_answer.destroy_all end - elsif q_type == 3 #填空题 + elsif q_type == Exercise::COMPLETION #填空题 answer_option = { :user_id => current_user.id, :exercise_question_id => @exercise_question.id, @@ -67,7 +67,7 @@ class ExerciseAnswersController < ApplicationController ex_new = ExerciseAnswer.new(answer_option) ex_new.save! end - elsif q_type == 4 #简答题 + elsif q_type == Exercise::SUBJECTIVE #简答题 answer_option = { :user_id => current_user.id, :exercise_question_id => @exercise_question.id @@ -110,7 +110,7 @@ class ExerciseAnswersController < ApplicationController elsif @exercise_user.commit_status == 1 normal_status(-1,"已提交/已结束的试卷不允许修改!") else - if (@exercise_user_status == 3 && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) + if (@exercise_user_status == Exercise::DEADLINE && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) objective_score = calculate_student_score(@exercise,current_user)[:total_score] subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score total_score = objective_score + subjective_score diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 65fd77d98..3718e18d5 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -590,7 +590,7 @@ class ExerciseQuestionsController < ApplicationController end def validate_params - normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i !=5 ) #除了实训题,其余题目必需有题干 + normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i != Exercise::PRACTICAL ) #除了实训题,其余题目必需有题干 normal_status(-1,"问题类型不允许为空!" ) if params[:question_type].blank? normal_status(-1,"分值不允许为空!" ) if params[:question_score].blank? && params[:question_scores].blank? #分值的数组或参数必需存在一个 if params[:question_score].present? && params[:question_score].to_f <= 0.0 #问题类型存在,则分值不能为空,且必需大于0 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4ac1db0d4..995b1b75a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -208,13 +208,13 @@ class ExercisesController < ApplicationController @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,Exercise::PUBLISHED).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,Exercise::UNPUBLISHED).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 - if @ex_status == 1 + if @ex_status == Exercise::UNPUBLISHED @exercise_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候 - elsif @ex_status == 2 + elsif @ex_status == Exercise::PUBLISHED @exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候 end end @@ -368,7 +368,7 @@ class ExercisesController < ApplicationController exercise_bank_question = current_ex_bank.exercise_bank_questions.new option exercise_bank_question.save ## 试卷选项的输入 - if q.question_type != 5 #不为实训题时,试卷选项加入试题答案库 + if q.question_type != Exercise::PRACTICAL #不为实训题时,试卷选项加入试题答案库 ex_choices = q.exercise_choices ex_standard = q.exercise_standard_answers ex_choices.each do |c| @@ -422,8 +422,8 @@ class ExercisesController < ApplicationController @user_published_setting = @exercise.exercise_group_settings .find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置 exercise_ids = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 @exercise_users_count = @exercise.exercise_users.commit_exercise_by_status(1).count #判断当前试卷是否有已提交的 # ## 需添加发送消息的接口,稍后添加 rescue Exception => e @@ -444,7 +444,7 @@ class ExercisesController < ApplicationController exercise_status = @exercise.get_exercise_status(current_user) - if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 + if exercise_status == Exercise::UNPUBLISHED && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @exercise.unified_setting @@ -469,7 +469,7 @@ class ExercisesController < ApplicationController params_end_time = params[:end_time].to_time end - if (exercise_status != 1) && (@exercise.publish_time != params_publish_time) + if (exercise_status != Exercise::UNPUBLISHED) && (@exercise.publish_time != params_publish_time) normal_status(-1,"已发布/已截止,不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") @@ -590,7 +590,7 @@ class ExercisesController < ApplicationController :end_time => e_time } @exercise.update_attributes(exercise_params) - if @exercise.exercise_status == 2 + if @exercise.exercise_status == Exercise::PUBLISHED if @exercise.course_acts.size == 0 @exercise.course_acts << CourseActivity.new(:user_id => @exercise.user_id,:course_id => @exercise.course_id) end @@ -784,15 +784,9 @@ class ExercisesController < ApplicationController course_students = @course.students #课堂的全部学生数 check_ids.each do |exercise| exercise_status= exercise.get_exercise_status(current_user) - if exercise_status == 2 #跳过已截止的或未发布的 + if exercise_status == Exercise::PUBLISHED #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? - # user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) - # if user_course_groups.present? - # teacher_course_group_ids = user_course_groups.pluck(:course_group_id) - # else - # teacher_course_group_ids = @course.course_groups.pluck(:id) - # end teacher_course_group_ids = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == teacher_course_group_ids.sort #开始为统一设置 exercise.exercise_group_settings.destroy_all @@ -878,7 +872,7 @@ class ExercisesController < ApplicationController ex_question_ids = @exercise.exercise_questions.pluck(:id) exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first if exercise_user.present? - if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == 2 #用户已提交且试卷提交中 + if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == Exercise::PUBLISHED #用户已提交且试卷提交中 if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0) @@ -976,12 +970,9 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - ex_users_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id) + ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise_id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 @exercise_user_current = ex_users_current&.first - logger.info("############______________ex_users_current________#######{ex_users_current.pluck(:user_id,:exercise_id)}") if ex_users_current.exists? - logger.info("############______________ex_users_current_exists?________#########################") - if @exercise_user_current.start_at.blank? @exercise_user_current.update_attribute("start_at",Time.now) end @@ -1020,7 +1011,7 @@ class ExercisesController < ApplicationController :exercise_answers, :exercise_standard_answers) - if @t_user_exercise_status == 3 + if @t_user_exercise_status == Exercise::DEADLINE get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) end get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status) @@ -1051,9 +1042,9 @@ class ExercisesController < ApplicationController end end @exercise_questions.each do |q| - if q.question_type == 5 #当为实训题时 + if q.question_type == Exercise::PRACTICAL #当为实训题时 user_myshixun = q.shixun.myshixuns.search_myshixun_user(current_user.id) - if user_myshixun.blank? || user_myshixun.first.status != 1 #当前用户的实训是否做完 + if user_myshixun.blank? || user_myshixun.first.status != Exercise::UNPUBLISHED #当前用户的实训是否做完 @shixun_undo += 1 end else @@ -1163,7 +1154,7 @@ class ExercisesController < ApplicationController #试卷的答题列表页的显示用户 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷 @exercise_current_user_status = 0 - unless @exercise_status == 1 + unless @exercise_status == Exercise::UNPUBLISHED ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) @exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生 @@ -1176,7 +1167,7 @@ class ExercisesController < ApplicationController exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) if exercise_current_user.exists? #表示为课堂学生或已回答的 @exercise_current_user_status = 1 - if @exercise.score_open && @exercise_status == 3 #勾选了成绩公开且试卷已截止的 + if @exercise.score_open && @exercise_status == Exercise::DEADLINE #勾选了成绩公开且试卷已截止的 all_user_ids = @exercise_all_users.pluck(:user_id) all_user_ids.delete(current_user.id) #删除了当前用户的ID @exercise_users_list = @exercise_all_users.exercise_commit_users(all_user_ids).distinct @@ -1468,32 +1459,32 @@ class ExercisesController < ApplicationController @exercise_ques_scores = exercise_questions.pluck(:question_score).sum #单选题的数量及分数 - exercise_single_ques = exercise_questions.find_by_custom("question_type",0) + exercise_single_ques = exercise_questions.find_by_custom("question_type",Exercise::SINGLE) @exercise_single_ques_count = exercise_single_ques.size @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum #多选题的数量及分数 - exercise_double_ques = exercise_questions.find_by_custom("question_type",1) + exercise_double_ques = exercise_questions.find_by_custom("question_type",Exercise::MULTIPLE) @exercise_double_ques_count = exercise_double_ques.size @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum # 判断题数量及分数 - exercise_ques_judge = exercise_questions.find_by_custom("question_type",2) + exercise_ques_judge = exercise_questions.find_by_custom("question_type",Exercise::JUDGMENT) @exercise_ques_judge_count = exercise_ques_judge.size @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum #填空题数量及分数 - exercise_ques_null = exercise_questions.find_by_custom("question_type",3) + exercise_ques_null = exercise_questions.find_by_custom("question_type",Exercise::COMPLETION) @exercise_ques_null_count = exercise_ques_null.size @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum #简答题数量及分数 - exercise_ques_main = exercise_questions.find_by_custom("question_type",4) + exercise_ques_main = exercise_questions.find_by_custom("question_type",Exercise::SUBJECTIVE) @exercise_ques_main_count = exercise_ques_main.size @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum #实训题数量及分数 - exercise_ques_shixun = exercise_questions.find_by_custom("question_type",5) + exercise_ques_shixun = exercise_questions.find_by_custom("question_type",Exercise::PRACTICAL) @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum @@ -1576,7 +1567,7 @@ class ExercisesController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == 1 #试卷未发布,且当前用户不为老师/管理员 + if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == Exercise::UNPUBLISHED #试卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布试卷!") elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的 normal_status(-1, "试卷暂未公开!") @@ -1593,7 +1584,7 @@ class ExercisesController < ApplicationController #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 - if @exercise.get_exercise_status(current_user) != 2 + if @exercise.get_exercise_status(current_user) != Exercise::PUBLISHED normal_status(-1,"非提交中的试卷不允许打回重做!") elsif @exercise_users.count < 1 normal_status(-1,"暂无人提交试卷!") diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 77e5505a5..3fc17c661 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -840,7 +840,7 @@ class PollsController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题 + poll_user_current = PollUser.where(user_id:@poll_current_user_id,poll_id:@poll.id)&.first #查找当前用户是否有过答题 @poll_status = @poll.get_poll_status(current_user) if poll_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的