From 07e3cf3c862abbb3384b50d3baa3461ec1e7d9ba Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 25 Jun 2019 18:29:03 +0800 Subject: [PATCH 01/15] modify code style --- app/controllers/attachments_controller.rb | 64 +++++++++++------------ app/controllers/boards_controller.rb | 43 +++++++-------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0a89bb3f9..bf5c11856 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,51 +25,49 @@ class AttachmentsController < ApplicationController # 2. 上传到云 upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") - if upload_file - folder = edu_setting('attachment_folder') - raise "存储目录未定义" unless folder.present? + raise "未上传文件" unless upload_file - month_folder = current_month_folder - save_path = File.join(folder, month_folder) + folder = edu_setting('attachment_folder') + raise "存储目录未定义" unless folder.present? - ext = file_ext(upload_file.original_filename) + month_folder = current_month_folder + save_path = File.join(folder, month_folder) - local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) + ext = file_ext(upload_file.original_filename) - content_type = upload_file.content_type.presence || 'application/octet-stream' + local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) - remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + content_type = upload_file.content_type.presence || 'application/octet-stream' - logger.info "local_path: #{local_path}" - logger.info "remote_path: #{remote_path}" + remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + logger.info "local_path: #{local_path}" + logger.info "remote_path: #{remote_path}" - disk_filename = local_path[save_path.size + 1, local_path.size] - #存数据库 - # - @attachment = Attachment.where(disk_filename: disk_filename, - author_id: current_user.id, - cloud_url: remote_path).first - unless @attachment.present? - @attachment = Attachment.new - @attachment.filename = upload_file.original_filename - @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] - @attachment.filesize = upload_file.tempfile.size - @attachment.content_type = content_type - @attachment.digest = digest - @attachment.author_id = current_user.id - @attachment.disk_directory = month_folder - @attachment.cloud_url = remote_path - @attachment.save! - else - logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" - end + disk_filename = local_path[save_path.size + 1, local_path.size] + #存数据库 + # + @attachment = Attachment.where(disk_filename: disk_filename, + author_id: current_user.id, + cloud_url: remote_path).first - render_json + if @attachment.blank? + @attachment = Attachment.new + @attachment.filename = upload_file.original_filename + @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] + @attachment.filesize = upload_file.tempfile.size + @attachment.content_type = content_type + @attachment.digest = digest + @attachment.author_id = current_user.id + @attachment.disk_directory = month_folder + @attachment.cloud_url = remote_path + @attachment.save! else - raise "未上传文件" + logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" end + + render_json end def destroy diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 51c8397b1..2e82c36d7 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -9,46 +9,39 @@ class BoardsController < ApplicationController end def show - - end - - def new end def create ActiveRecord::Base.transaction do - begin - board = @course.course_board - new_board = Board.new(board_params) - new_board.course_id = @course.id - new_board.project_id = -1 - new_board.parent_id = board.try(:id) - new_board.position = board.children.count + 1 - new_board.save! - normal_status(0, "添加成功") - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end + board = @course.course_board + new_board = Board.new(board_params) + new_board.course_id = @course.id + new_board.project_id = -1 + new_board.parent_id = board.try(:id) + new_board.position = board.children.count + 1 + new_board.save! end + + normal_status(0, "添加成功") end # 子目录的拖动 def move_category tip_exception("移动失败") if params[:position].blank? - unless params[:position].to_i == @board.position - course_board = @course.course_board + return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position + + course_board = @course.course_board + ActiveRecord::Base.transaction do if params[:position].to_i < @board.position - course_board.children.where("position < #{@board.position} and position >= ?", params[:position]).update_all("position = position + 1") + course_board.children.where("position < ? and position >= ?", @board.position, params[:position]) + .update_all("position = position + 1") else - course_board.children.where("position > #{@board.position} and position <= ?", params[:position]).update_all("position = position - 1") + course_board.children.where("position > ? and position <= ?", @board.position, params[:position]) + .update_all("position = position - 1") end @board.update_attributes(position: params[:position]) - normal_status(0, "移动成功") - else - normal_status(-1, "位置没有变化") end + normal_status(0, "移动成功") end def destroy From d21c46339bb23595d32b04de9da259e762a56491 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 26 Jun 2019 09:58:59 +0800 Subject: [PATCH 02/15] ADD competition some eelated featrue --- app/controllers/messages_controller.rb | 8 +++++++- app/models/message.rb | 2 +- app/views/messages/reply_list.json.jbuilder | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 60a1c171c..33f4e5bfb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -43,9 +43,15 @@ class MessagesController < ApplicationController @page_size = params[:page_size] || 10 @current_user = current_user || nil - @messages = @message.children.preload_messages + @messages = @message.children.preload_messages.includes(:message_detail, :praise_treads) @messages = @messages.ordered(sort: 1) unless @message.parent_id.nil? + @user_course_identity = current_user.course_identity(@message.board.course) + case @user_course_identity + when 5 || 6 || 7 + @messages = @messages.visible + end + @messages = @messages.page(@page).per(@page_size) end diff --git a/app/models/message.rb b/app/models/message.rb index c3b3bca40..6b41cdd95 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,7 +18,7 @@ class Message < ApplicationRecord scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子 scope :reply_nodes, -> { where("parent_id IS NOT NULL") } - scope :visible, -> { where(is_hidden: false)} + scope :visible, -> { where(is_hidden: false) } scope :by_user, ->(user) { visible if user.nil? || !user.admin? } scope :preload_messages, -> { includes(:author, :message_detail) } scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) } diff --git a/app/views/messages/reply_list.json.jbuilder b/app/views/messages/reply_list.json.jbuilder index 2b7ef7178..b5c1ce256 100644 --- a/app/views/messages/reply_list.json.jbuilder +++ b/app/views/messages/reply_list.json.jbuilder @@ -1,6 +1,6 @@ json.partial! "commons/success" json.data do - json.user_course_identity @current_user.course_identity(@message.board.course) + json.user_course_identity @user_course_identity json.id @message.id json.total_count @messages.total_count json.total_replies_count @message.total_replies_count From 06db1820d619dafb495f741340e760caf2e2ef76 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 10:14:12 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=8F=AD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=9C=A8=E5=AD=90=E5=88=86=E7=8F=AD=E5=89=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 226a45570..93b8bfc50 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -247,15 +247,15 @@ module CoursesHelper def left_group_info course group_info = [] if course.course_groups_count > 0 + none_group_count = course.students.where(course_group_id: 0).size + group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, + category_count: none_group_count, category_type: false, + second_category_url: "/courses/#{@course.id}/course_groups/0"} course.course_groups.each do |course_group| group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position, category_count: course_group.course_members_count, category_type: false, second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"} end - none_group_count = course.students.where(course_group_id: 0).size - group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, - category_count: none_group_count, category_type: false, - second_category_url: "/courses/#{@course.id}/course_groups/0"} end group_info end From 7af7ad8e372bd879de948bde7144eb27d256bab0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 10:18:54 +0800 Subject: [PATCH 04/15] fix calculate_scores --- app/controllers/exercises_controller.rb | 58 +++---- app/helpers/exercises_helper.rb | 198 ++++++++++++------------ app/tasks/exercise_publish_task.rb | 95 +++++++----- 3 files changed, 184 insertions(+), 167 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2175108fc..4f72a1d46 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -12,10 +12,10 @@ class ExercisesController < ApplicationController before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise] before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合 before_action :check_course_public,only: [:set_public] - before_action :check_user_on_answer,only: [:show,:start_answer,:commit_exercise,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 + before_action :check_user_on_answer,only: [:show,:start_answer,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 before_action :only_student_in,only: [:start_answer] before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise] - before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #判断试卷时间到用户是否提交 + # before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务 before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过 before_action :check_exercise_status,only: [:redo_modal,:redo_exercise] before_action :check_exercise_is_end, only: [:review_exercise] @@ -1640,38 +1640,38 @@ class ExercisesController < ApplicationController end def check_exercise_time - @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first + @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first if @answer_committed_user.blank? normal_status(404,"答题用户不存在") - elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 # - normal_status(-1,"提交错误,试卷已截止/用户已提交!") + # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交 + # normal_status(-1,"提交错误,试卷用户已提交!") end end - def commit_user_exercise - @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 - if @user_course_identity == Course::STUDENT - if @exercise_user_current.present? - if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && - ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) - #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - objective_score = calculate_student_score(@exercise,current_user)[:total_score] - subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score - total_score = objective_score + subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => objective_score, - :score => total_score, - :subjective_score => subjective_score - } - @exercise_user_current.update_attributes(commit_option) - normal_status(0,"已交卷成功!") - end - end - end - end + # def commit_user_exercise + # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题 + # if @user_course_identity == Course::STUDENT + # if @exercise_user_current.present? + # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && + # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 + # objective_score = calculate_student_score(@exercise,current_user)[:total_score] + # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score + # total_score = objective_score + subjective_score + # commit_option = { + # :status => 1, + # :commit_status => 1, + # :end_at => Time.now, + # :objective_score => objective_score, + # :score => total_score, + # :subjective_score => subjective_score + # } + # @exercise_user_current.update_attributes(commit_option) + # normal_status(0,"已交卷成功!") + # end + # end + # end + # end #打回重做时的初步判断 def check_exercise_status diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 604258c32..9ea7578f2 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -353,117 +353,123 @@ module ExercisesHelper score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) - exercise_questions.each do |q| - if q.question_type != 5 - answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 - else - answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 - end - if q.question_type <= 2 #为选择题或判断题时 - if answers_content.present? #学生有回答时 - answer_choice_array = [] - answers_content.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 - end - user_answer_content = answer_choice_array.sort - standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 - if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.count > 0 - q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 - else - q_score_1 = 0.0 - end - answers_content.update_all(:score => q_score_1) - score1 = score1 + q.question_score - end + exercise_questions&.each do |q| + begin + if q.question_type != 5 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - score1 += 0.0 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end - elsif q.question_type == 3 #填空题 - if answers_content.present? - null_standard_answer = q.exercise_standard_answers - standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - standard_answer_count = standard_answer_ids.count - if standard_answer_count > 0 #存在标准答案时才有分数 - q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 - else - q_score_2 = 0.0 - end - if q.is_ordered - answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - u.update_column('score',q_score_2) - score2 = score2 + q_score_2 + if q.question_type <= 2 #为选择题或判断题时 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + if standard_answer.count > 0 + q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + else + q_score_1 = 0.0 end + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - answers_content.each do |u| - u_answer_text = u.answer_text.downcase - if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - u.update_column("score",q_score_2) - score2 = score2 + q_score_2 - st_answer_text.delete(u_answer_text) + score1 += 0.0 + end + elsif q.question_type == 3 #填空题 + if answers_content.present? + null_standard_answer = q.exercise_standard_answers + standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + standard_answer_count = standard_answer_ids.count + if standard_answer_count > 0 #存在标准答案时才有分数 + q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 + else + q_score_2 = 0.0 + end + if q.is_ordered + answers_content.each do |u| + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + u.update_column('score',q_score_2) + score2 = score2 + q_score_2 + end + end + else + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + answers_content.each do |u| + u_answer_text = u.answer_text.downcase + if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + u.update_column("score",q_score_2) + score2 = score2 + q_score_2 + st_answer_text.delete(u_answer_text) + end end end + else + score2 += 0.0 end - else - score2 += 0.0 - end - elsif q.question_type == 5 #实训题时,主观题这里不评分 - q.exercise_shixun_challenges.each do |exercise_cha| - game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 - if game.present? - exercise_cha_score = 0.0 - answer_status = 0 - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = exercise_cha.question_score #每一关卡的得分 - answer_status = 1 - end - ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path(exercise_cha.challenge&.path) - game_challenge = game.game_codes.search_challenge_path(cha_path)&.first - if game_challenge.present? - game_code = game_challenge - code = game_code.try(:new_code) + elsif q.question_type == 5 #实训题时,主观题这里不评分 + q.exercise_shixun_challenges&.each do |exercise_cha| + game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 + if game.present? + exercise_cha_score = 0.0 + answer_status = 0 + if game.status == 2 && game.final_score >= 0 + exercise_cha_score = exercise_cha.question_score #每一关卡的得分 + answer_status = 1 + end + ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + cha_path = challenge_path(exercise_cha.challenge&.path) + game_challenge = game.game_codes.search_challenge_path(cha_path)&.first + if game_challenge.present? + game_code = game_challenge + code = game_code.try(:new_code) + else + code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + end + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + score5 += 0.0 end - score5 += exercise_cha_score - else - score5 += 0.0 end end + user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum + if user_scores > 0.0 + stand_answer = 1 + else + stand_answer = 0 + end + ques_option = { + "q_id":q.id, #该问题的id + "q_type":q.question_type, + "q_position":q.question_number, #该问题的位置 + "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 + "user_score":user_scores.round(1) #每个问题的总得分 + } + ques_stand.push(ques_option) + rescue Exception => e + Rails.logger.info("calcuclate_score_have_error____________________________#{e}") + next end - user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 - if user_scores > 0.0 - stand_answer = 1 - else - stand_answer = 0 - end - ques_option = { - "q_id":q.id, #该问题的id - "q_type":q.question_type, - "q_position":q.question_number, #该问题的位置 - "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 - "user_score":user_scores.round(1) #每个问题的总得分 - } - ques_stand.push(ques_option) + end total_score = score1 + score2 + score5 { diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 4c8ee39e8..3df5f84ae 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -6,7 +6,7 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_publish start") puts "--------------------------------exercise_publish start" exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - exercises.each do |exercise| + exercises&.each do |exercise| exercise.update_column('exercise_status', 2) course = exercise.course tid_str = "" @@ -45,7 +45,7 @@ class ExercisePublishTask # 分组设置发布时间的测验 exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) - exercise_group_settings.each do |exercise_group| + exercise_group_settings&.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? course = exercise.course @@ -71,29 +71,35 @@ class ExercisePublishTask 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.each do |exercise| + 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.present? - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - if ex_type.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise.exercise_users&.each do |exercise_user| + begin + 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 + else + subjective_score = -1.0 + end + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("rescue errors ___________________________#{e}") + next end + end end @@ -101,36 +107,41 @@ class ExercisePublishTask 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| + ex_group_settings&.each do |exercise_setting| exercise = exercise_setting.exercise - if exercise&.end_time <= Time.now + 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)) - - exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - if ex_types.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise_users&.each do |exercise_user| + begin + if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 + end + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}") + next end + end end Rails.logger.info("log--------------------------------exercise_end end") From d8e7d8203c9533fa5dd57122bd44da0859813001 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 10:32:15 +0800 Subject: [PATCH 05/15] fix bug --- app/controllers/exercises_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4f72a1d46..f10bc81ff 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first if @exercise_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 exercise_user_params = { From 5689b2924349f9be0b42c00ff66462a8f2796b10 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 26 Jun 2019 10:46:20 +0800 Subject: [PATCH 06/15] FIX --- app/controllers/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 33f4e5bfb..bad54b88e 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -48,7 +48,7 @@ class MessagesController < ApplicationController @user_course_identity = current_user.course_identity(@message.board.course) case @user_course_identity - when 5 || 6 || 7 + when 5, 6, 7 @messages = @messages.visible end From 870952ecda289510032e0b837f79d53b1edea760 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:20:30 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 4 ++-- app/helpers/homework_commons_helper.rb | 12 +++++----- app/models/homework_common.rb | 24 +++++++++---------- .../homework_commons/index.json.jbuilder | 4 ++-- .../homework_commons/works_list.json.jbuilder | 6 ++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 58e68dfce..e58484941 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) elsif @homework_type == 3 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else @@ -134,7 +134,7 @@ class HomeworkCommonsController < ApplicationController @student_works = [] end elsif @user_course_identity < Course::STUDENT - @student_works = @homework.teacher_works(@current_user.id) + @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.count elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 0d166729c..2d3827fac 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -174,8 +174,8 @@ module HomeworkCommonsHelper end # 作品数统计:type: 1 已提交 0 未提交 - def studentwork_count homework_common, type, user_id - student_works = homework_common.teacher_works(user_id) + def studentwork_count homework_common, type, member + student_works = homework_common.teacher_works(member) type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size end @@ -223,10 +223,10 @@ module HomeworkCommonsHelper end # 作品状态 - def homework_status homework, user_id - [{id: 0, name: "未提交", count: homework.unfinished_count(user_id)}, - {id: 1, name: "按时提交", count: homework.finished_count(user_id)}, - {id: 2, name: "延时提交", count: homework.delay_finished_count(user_id)}] + def homework_status homework, member + [{id: 0, name: "未提交", count: homework.unfinished_count(member)}, + {id: 1, name: "按时提交", count: homework.finished_count(member)}, + {id: 2, name: "延时提交", count: homework.delay_finished_count(member)}] end # 作品分数的显示 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c3bfd2dd9..6a117eff1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,20 +78,20 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.where(user_id: self.course.students.where( - course_group_id: self.published_settings.pluck(:course_group_id)). - pluck(:user_id)) + self.student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 - def teacher_works user_id - member = course.course_member(user_id) + def teacher_works member + # member = course.course_member(user_id) teacher_course_groups = member.try(:teacher_course_groups) all_student_works = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + all_student_works = all_student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: group_ids}) end all_student_works end @@ -216,17 +216,17 @@ class HomeworkCommon < ApplicationRecord end # 作品未提交数 - def unfinished_count user_id - self.teacher_works(user_id).unfinished.count + def unfinished_count member + self.teacher_works(member).unfinished.count end # 任务按时提交数 - def finished_count user_id - self.teacher_works(user_id).finished.count + def finished_count member + self.teacher_works(member).finished.count end - def delay_finished_count user_id - self.teacher_works(user_id).delay_finished.count + def delay_finished_count member + self.teacher_works(member).delay_finished.count end # 分组作业的最大分组id diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 262d4d92d..d718550c1 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -23,8 +23,8 @@ json.homeworks @homework_commons.each do |homework| json.allow_late homework.allow_late unless curr_status[:status].include?("未发布") - json.commit_count studentwork_count homework, 1, @user.id - json.uncommit_count studentwork_count homework, 0, @user.id + json.commit_count studentwork_count homework, 1, @member + json.uncommit_count studentwork_count homework, 0, @member end if @user_course_identity < Course::STUDENT diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index a1618d8ff..0c1ed0c5b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -20,12 +20,12 @@ if @user_course_identity < Course::STUDENT if @homework.homework_type != "practice" json.teacher_comment teacher_comment @homework, @current_user.id end - json.task_status homework_status @homework, @current_user.id + json.task_status homework_status @homework, @member json.course_group_info course_group_info @course, @current_user.id elsif @user_course_identity == Course::STUDENT - json.commit_count studentwork_count @homework, 1, @current_user.id - json.uncommit_count studentwork_count @homework, 0, @current_user.id + json.commit_count studentwork_count @homework, 1, @member + json.uncommit_count studentwork_count @homework, 0, @member json.left_time left_time @homework, @current_user.id if @homework.homework_type == "practice" From 88f9dbc68e531113dbb190aa2233ea9027285cb6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:23:10 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index e58484941..3aacd71fa 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) elsif @homework_type == 3 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else From 383723612df1075ac165c82b34d2481a434557a7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:28:51 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/homework_common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 6a117eff1..9cc2c9a69 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,7 +78,7 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end @@ -90,7 +90,7 @@ class HomeworkCommon < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + all_student_works = all_student_works.joins("join course_members course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end all_student_works From e22ec14690dbaa202cf44c8f9ab1a32b1413918d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:26:07 +0800 Subject: [PATCH 10/15] fix bug --- app/controllers/poll_votes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 789d5748e..644cc8949 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -123,7 +123,7 @@ class PollVotesController < ApplicationController if @poll_question.blank? normal_status(-1,"问卷试题不存在!") else - @poll = @poll_question.poll.includes(:poll_users) + @poll = @poll_question.poll @course = @poll.course if @poll.blank? normal_status(-1,"问卷不存在!") From 650df60bedfe4291b563a4cf12a7cb3173353978 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:28:53 +0800 Subject: [PATCH 11/15] fix bug --- app/controllers/poll_votes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 644cc8949..813e35bba 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -156,7 +156,7 @@ class PollVotesController < ApplicationController if question_max_choices > 0 && user_vote_count > question_max_choices normal_status(-1,"多选题答案超过最大限制!") end - elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3 + elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3 normal_status(-1,"已提交/已结束的问卷不允许修改!") end end From 102226efdf58584d941bc96665ce8309b4ccc234 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:32:00 +0800 Subject: [PATCH 12/15] fix bug --- app/controllers/poll_votes_controller.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 813e35bba..f1da3a1b2 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -134,17 +134,11 @@ class PollVotesController < ApplicationController end def check_answer_in_question - # poll_answer_ids = @poll_question.poll_answers.pluck(:id) - # if @poll_question.question_type == 1 #单选题/多选题 - # unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?) - # normal_status(-1, "答案ID错误!") - # end - # end poll_user_status = @poll.get_poll_status(current_user.id) poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 question_type = @poll_question&.question_type - if [1,2].include?(question_type) && params[:poll_answer_id].blank? + if (question_type == 1) && params[:poll_answer_id].blank? normal_status(-1,"答案ID错误!") elsif question_type == 2 user_vote_count = params[:poll_answer_id].size @@ -153,7 +147,7 @@ class PollVotesController < ApplicationController else question_max_choices = 0 end - if question_max_choices > 0 && user_vote_count > question_max_choices + if question_max_choices > 0 && (user_vote_count > question_max_choices) normal_status(-1,"多选题答案超过最大限制!") end elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3 From e808b0bb3d366192829fd4519104cfc1e5fa5186 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 13:59:37 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_commons_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 2d3827fac..261fc85e9 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -176,7 +176,7 @@ module HomeworkCommonsHelper # 作品数统计:type: 1 已提交 0 未提交 def studentwork_count homework_common, type, member student_works = homework_common.teacher_works(member) - type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size + type == 1 ? student_works.where("work_status != 0").size : student_works.where(work_status: 0).size end # 上次查重的时间 From b6300cfc846fa030b2823dc6e2a93e69c01b1a67 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:31:37 +0800 Subject: [PATCH 14/15] fix bug --- app/controllers/poll_questions_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 69aef41c0..59af29758 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -197,22 +197,22 @@ class PollQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @poll_question.question_number.to_i #问题的当前位置 - last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 - next_q_p = @poll.poll_questions.next_poll(current_q_p) # 当前问题的后一个问题 if @poll.polls_status.to_i == 1 if opr.present? if opr.to_s == "up" + last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p - 1)) - last_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i + 1)) # 重新获取当前问题的位置 + @poll_question.update_attribute("question_number", (current_q_p - 1)) + last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") end elsif opr.to_s == "down" + next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p + 1)) - next_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i - 1)) + @poll_question.update_attribute("question_number", (current_q_p + 1)) + next_q_p.update_attribute("question_number", current_q_p) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") From d0249457473611d77d6a01de9a6b5224248286e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:41:33 +0800 Subject: [PATCH 15/15] fix bug --- app/controllers/poll_questions_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 59af29758..dfff147c4 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -202,8 +202,8 @@ class PollQuestionsController < ApplicationController if opr.to_s == "up" last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p - 1)) last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 + @poll_question.update_attribute("question_number", (current_q_p - 1)) normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") @@ -211,8 +211,8 @@ class PollQuestionsController < ApplicationController elsif opr.to_s == "down" next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p + 1)) next_q_p.update_attribute("question_number", current_q_p) + @poll_question.update_attribute("question_number", (current_q_p + 1)) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!")