diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 9311953ca..29696cf15 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -3,7 +3,7 @@ class Subjects::DataStatisticService < ApplicationService def initialize(subject, user) @subject = subject @user = user - @shixuns = subject.shixuns + @shixun_ids = subject.shixuns.pluck(:id) end # 学习总人数 @@ -14,9 +14,11 @@ class Subjects::DataStatisticService < ApplicationService # 课堂学习人数 def course_study_count # 实训作业 - sw_user_ids = StudentWork.where.not(myshixun_id: nil).pluck(:user_id) + sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixuns) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") # 试卷的实训题 - esa_user_ids = ExerciseShixunAnswer.where() + esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) + .where(shixuns: {id: @shixun_ids}).pluck("exercise_shixun_answers.user_id") end end