From 244f356fdef72cae7859b0385e3bd0e5cc17ccab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 11:01:42 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= 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 9a12634cf..97b9ecc44 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.student_works.where(user_id: user_ids) end - myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids). includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)}) challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| From 6f474391d323e11f939c28fdd6189dd1d34fca7c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 14:20:06 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5f93bc36b..163ba1847 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -77,7 +77,7 @@ class GamesController < ApplicationController # 区分选择题和编程题,st:0编程题; if @st == 0 - has_answer = game_challenge.challenge_answers.size == 0 ? false : true + has_answer = game_challenge.challenge_answers.size != 0 game_challenge.answer = nil mirror_name = @shixun.mirror_name @@ -87,7 +87,7 @@ class GamesController < ApplicationController rescue uid_logger("实训平台繁忙,繁忙等级(81)") end - tpm_cases_modified = (game_challenge.modify_time != @game.modify_time ? true : false) # modify_time 决定TPM测试集是否有更新 + tpm_cases_modified = (game_challenge.modify_time != @game.modify_time) # modify_time 决定TPM测试集是否有更新 @task_result = {tpm_modified: tpm_modified, tpm_cases_modified: tpm_cases_modified, mirror_name: mirror_name, has_answer: has_answer} @@ -629,7 +629,7 @@ class GamesController < ApplicationController # user_answer虽然是传的数组,但是可能存在多选择提的情况. user_answer_tran = user_answer[index].size > 1 ? user_answer[index].split("").sort.join("") : user_answer[index] standard_answer_tran = choose.standard_answer.size > 1 ? choose.standard_answer.split("").sort.join("") : choose.standard_answer - correct = (user_answer_tran == standard_answer_tran) ? true : false + correct = (user_answer_tran == standard_answer_tran) if str.present? str += "," end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index ffa2ccc3b..4a886dfc8 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -278,7 +278,6 @@ class MyshixunsController < ApplicationController end end - if game.status == 2 @resubmit = Time.now.to_i end From 15437ab72439eb709035c925f290139e275ab2d4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 14:31:02 +0800 Subject: [PATCH 03/11] =?UTF-8?q?run=5Fcode=5Fmessages=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190708062910_add_index_for_run_code_message.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20190708062910_add_index_for_run_code_message.rb diff --git a/db/migrate/20190708062910_add_index_for_run_code_message.rb b/db/migrate/20190708062910_add_index_for_run_code_message.rb new file mode 100644 index 000000000..4449d58a2 --- /dev/null +++ b/db/migrate/20190708062910_add_index_for_run_code_message.rb @@ -0,0 +1,5 @@ +class AddIndexForRunCodeMessage < ActiveRecord::Migration[5.2] + def change + add_index :run_code_messages, :game_id + end +end From 914c0e0ea17dc6e830f8613589b0130d65d44286 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 14:38:14 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=88=90=E7=BB=A9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 97b9ecc44..9048b0046 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -255,7 +255,7 @@ class HomeworkCommonsController < ApplicationController challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) + if work && myshixun games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end @@ -276,13 +276,13 @@ class HomeworkCommonsController < ApplicationController myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) ActiveRecord::Base.transaction do begin - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) + if work && myshixun challenge_settings = @homework.homework_challenge_settings games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings normal_status("更新成功") else - normal_status("已是最新成绩") + normal_status("还开启挑战,暂不能更新成绩") end rescue Exception => e uid_logger(e.message) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index ffa2ccc3b..95fbf8200 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -33,7 +33,7 @@ class MyshixunsController < ApplicationController uid_logger_error("版本库删除异常,详情:#{e.message}") end - StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0) + StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0) rescue Exception => e uid_logger_error("myshixun reset failed #{e}") From 63c2dc69d2a9e512fda074617e91da82cad3016f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 15:33:32 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 163ba1847..e5106ff59 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -311,7 +311,7 @@ class GamesController < ApplicationController # 扣除总分计算 @game.update_attributes!(:answer_open => 1, :answer_deduction => 100) end - @challenge_answers = @challenge.challenge_chooses + @challenge_chooses = @challenge.challenge_chooses rescue Exception => e uid_logger_error("#######金币扣除异常: #{e.message}") raise ActiveRecord::Rollback From 09801538560b2a88b91736b5745f17cb160499e3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 15:42:01 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E6=9F=A5=E7=9C=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e5106ff59..6ffc7f0ce 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -903,7 +903,7 @@ class GamesController < ApplicationController end # actual_output为空表示暂时没有评测答题,不允许查看 actual_output = output.try(:actual_output).try(:strip) - has_answer << choose.answer if choose.answer.present? + #has_answer << choose.answer if choose.answer.present? # 标准答案处理,错误的不让用户查看,用-1替代 standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer result = output.try(:result) @@ -914,7 +914,7 @@ class GamesController < ApplicationController @chooses << sin_choose test_sets << sin_test_set end - @has_answer = has_answer.present? + @has_answer = true # 选择题永远都有答案 @choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count, :choose_correct_num => choose_correct_num, :test_sets => test_sets} end From f96e8e70e3315f9f9e03573ae4d3e2290c356e31 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 16:24:12 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=AD=94=E9=A2=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E5=88=86=E7=8F=AD=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 4 ++-- app/models/homework_common.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index f61ff1e2a..d36d5d2c5 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -308,12 +308,12 @@ class Course < ApplicationRecord teacher_power_courses = [] if course_groups.present? common_ids.each do |i| - student_count = students.where(course_group_id:i).count if i == 0 + student_count = students.where(course_group_id:i).count teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count} else course_group_name = course_groups.find_by(id:i) - teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:student_count} + teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count} end end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 193d9aa6c..70755e508 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -79,7 +79,8 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - 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)}) + 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 # 分班权限的老师可见的作品列表 From e3d21286f363134b41aa6f0b9345d1b61a7704b4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 16:37:32 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 606132c27..290032f24 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -60,7 +60,8 @@ class Exercise < ApplicationRecord ex_users = exercise_users group_ids = common_published_ids(user_id) if group_ids.present? - ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id)) + ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end ex_users end @@ -69,8 +70,9 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - un_group_ids = (course.none_group_count > 0) ? [0] : [] - published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + # un_group_ids = (course.none_group_count > 0) ? [0] : [] + # published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + published_group_ids = current_user_groups else ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id From 17b8f21a2ad2d1202b1e3422a730ff5ca00982ae Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:19:41 +0800 Subject: [PATCH 09/11] =?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/controllers/exercises_controller.rb | 8 ++--- app/helpers/exercises_helper.rb | 23 +++++++++------ app/models/exercise.rb | 39 ++++++++++++++++++++----- app/models/homework_common.rb | 2 +- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 93a243c2a..9a7838a96 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -89,7 +89,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 15 @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) + @exercises = @exercises&.includes(:published_settings) else @exercises = [] end @@ -1183,12 +1183,12 @@ class ExercisesController < ApplicationController 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) #当前老师所在班级的全部学生 - get_exercise_answers(@exercise_users_list) + get_exercise_answers(@exercise_users_list, @exercise_status) end elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_all_users) # 未答和已答的 + get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) if exercise_current_user.present? @exercise_current_user_status = 1 #当前用户的状态,为学生 @@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController end else @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_all_users) # 未答和已答的 + get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 @exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_users_list = [] end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 796337c8e..655620db7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -250,10 +250,15 @@ module ExercisesHelper end #获取试卷的已答/未答人数 - def get_exercise_answers(ex_users) - @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 - course_all_members_count = ex_users.size - @exercise_unanswers = (course_all_members_count - @exercise_answers) + def get_exercise_answers(ex_users, status) + if status == 1 + @exercise_answers = 0 + @exercise_unanswers = 0 + else + @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 + course_all_members_count = ex_users.size + @exercise_unanswers = (course_all_members_count - @exercise_answers) + end end def exercise_index_show(exercise,course,is_teacher_or,user) @@ -281,8 +286,8 @@ module ExercisesHelper if is_teacher_or == 1 exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生 - unreview_count = exercise_users_list.exercise_unreview.size - get_exercise_answers(exercise_users_list) + unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size + get_exercise_answers(exercise_users_list, exercise_status) ex_pb_time = exercise.get_exercise_times(user.id,true) exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] @@ -295,8 +300,8 @@ module ExercisesHelper end elsif is_teacher_or == 2 exercise_users_list = exercise.get_stu_exercise_users - get_exercise_answers(exercise_users_list) # 未答和已答的 - unreview_count = exercise_users_list.exercise_unreview.size + get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的 + unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size ex_pb_time = exercise.get_exercise_times(user.id,false) exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] @@ -307,7 +312,7 @@ module ExercisesHelper end else exercise_users_list = exercise.get_stu_exercise_users - get_exercise_answers(exercise_users_list) # 未答和已答的 + get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的 exercise_publish_time = exercise.publish_time exercise_end_time = exercise.end_time unreview_count = nil diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 290032f24..8c1ad34d4 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -7,6 +7,8 @@ class Exercise < ApplicationRecord has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser" has_many :exercise_questions, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all + has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting" + has_many :tidings, as: :container has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all @@ -41,8 +43,8 @@ class Exercise < ApplicationRecord exercise_users else ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id) - course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) - exercise_users.where(user_id:course_user_ids) + exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: ex_group_setting_ids}) end end @@ -55,17 +57,38 @@ class Exercise < ApplicationRecord end end - #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 - def all_exercise_users(user_id) - ex_users = exercise_users - group_ids = common_published_ids(user_id) - if group_ids.present? - ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + # 根据是否统一发布获取作业的作品列表 + def all_works + exercise_users = self.unified_setting ? self.exercise_users : + self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + end + + # 分班权限的老师可见的作品列表 + def all_exercise_users user_id + # member = course.course_member(user_id) + teacher_course_groups = course.teacher_course_groups.where(user_id: user_id) + ex_users = self.all_works + # 有分班权限的统计管理的分班且已发布的学生情况 + if teacher_course_groups.exists? + group_ids = teacher_course_groups.pluck(:course_group_id) + ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users end + # #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 + # def all_exercise_users(user_id) + # ex_users = exercise_users + # group_ids = common_published_ids(user_id) + # if group_ids.present? + # ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + # where(course_members: {course_group_id: group_ids}) + # end + # ex_users + # end + #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 70755e508..80b92d175 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -89,7 +89,7 @@ class HomeworkCommon < ApplicationRecord teacher_course_groups = member.try(:teacher_course_groups) all_student_works = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 - if member.present? && teacher_course_groups.size > 0 + if member.present? && teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) From e4624252c8c66f5c3e70f65a461ba7126eb52a0b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:21:30 +0800 Subject: [PATCH 10/11] =?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/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 8c1ad34d4..85419ff3d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) - ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). + ex_users = ex_users.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users From 4fe212c05d2895ad90e228c8204947b26a204d75 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:22:31 +0800 Subject: [PATCH 11/11] =?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/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 85419ff3d..e3a89a19a 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) - ex_users = ex_users.joins("join course_members on student_works.user_id=course_members.user_id"). + ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users