From 8f2be183f6885306961d41ff118198f6286458c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 17:11:46 +0800 Subject: [PATCH 1/2] fix bug --- app/controllers/exercises_controller.rb | 15 +++++++++------ app/controllers/polls_controller.rb | 13 +++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index b3cf1f0be..1d81ed4c2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,7 +1173,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id - @exercise = @exercise + @exercise = @exercise.joins(:exercise_questions,:exercise_users) exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1271,16 +1271,17 @@ class ExercisesController < ApplicationController #搜索 if params[:search].present? - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end + exercise_user_joins = @exercise_users_list.joins(user: :user_extension) + if order == "student_id" - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + @exercise_users_list = exercise_user_joins.order("user_extensions.student_id DESC") elsif order == "score" - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("#{order} DESC") + @exercise_users_list = exercise_user_joins.order("#{order} DESC") else - @exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC") + @exercise_users_list = exercise_user_joins.order("end_at DESC, start_at DESC") end @export_ex_users = @exercise_users_list @@ -1297,9 +1298,11 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if @exercise_users_size == 0 + if @export_ex_users.exercise_user_committed.size == 0 normal_status(-1,"暂无用户提交") else + @exercise = @exercise.includes(:exercise_questions) + @export_ex_users = @export_ex_users.joins(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index eb03345e7..44cdc6512 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -920,11 +920,6 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin - # @poll_questions = @poll.poll_questions.order("question_number ASC") - # 全部页面,需返回 - # @poll_questions_count = @poll_questions.size - # 分页 - # @poll = @poll.includes(:poll_users,user: :user_extension) @poll_users = @poll.poll_users @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @@ -937,7 +932,7 @@ class PollsController < ApplicationController format.xlsx{ if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif @poll_export_questions.size == 0 || (@poll_users.where("commit_status = ?",1).size == 0) + elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) normal_status(-1,"暂时没有提交的用户") else polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" @@ -1035,10 +1030,12 @@ class PollsController < ApplicationController @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") end + poll_users_joins = @poll_users_list.joins(user: :user_extension) + if order == "student_id" - @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + @poll_users_list = poll_users_joins.order("user_extensions.student_id DESC") else - @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") + @poll_users_list = poll_users_joins.order("end_at DESC") end @poll_users_size = @poll_users_list.count From 35b91d96d896e57ee9d07e598fbefc8e1cdbf5f7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 17:15:44 +0800 Subject: [PATCH 2/2] fix bug --- app/controllers/exercises_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 1d81ed4c2..d19de52c4 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,7 +1173,6 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id - @exercise = @exercise.joins(:exercise_questions,:exercise_users) exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1302,7 +1301,7 @@ class ExercisesController < ApplicationController normal_status(-1,"暂无用户提交") else @exercise = @exercise.includes(:exercise_questions) - @export_ex_users = @export_ex_users.joins(user: :user_extension) + @export_ex_users = @export_ex_users.includes(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"