|
|
|
@ -3,8 +3,9 @@ class Management::SchoolReportService
|
|
|
|
|
|
|
|
|
|
attr_reader :params
|
|
|
|
|
|
|
|
|
|
# 因为实在太慢了,所以不开放 shixun_evaluate_count 排序
|
|
|
|
|
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
|
|
|
|
|
:course_count, :active_course_count, :nearly_course_time, :shixun_count, :shixun_evaluate_count,
|
|
|
|
|
:course_count, :active_course_count, :nearly_course_time, :shixun_count,
|
|
|
|
|
default_by: :teacher_count, default_direction: :desc
|
|
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@ -49,7 +50,8 @@ class Management::SchoolReportService
|
|
|
|
|
|
|
|
|
|
shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids })
|
|
|
|
|
.group('school_id').count
|
|
|
|
|
evaluate_count_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids })
|
|
|
|
|
evaluate_count_map = Game.joins(challenge: { shixun: { creator: :user_extensions } })
|
|
|
|
|
.where(user_extensions: { identity: User::TEACHER, school_id: ids })
|
|
|
|
|
.group('school_id').sum(:evaluate_count)
|
|
|
|
|
|
|
|
|
|
schools.map do |school|
|
|
|
|
@ -90,7 +92,9 @@ class Management::SchoolReportService
|
|
|
|
|
.select("#{base_query_column}, COUNT(*) shixun_count")
|
|
|
|
|
when 'shixun_evaluate_count' then
|
|
|
|
|
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id')
|
|
|
|
|
.select("#{base_query_column}, SUM(sx.evaluate_count) shixun_evaluate_count")
|
|
|
|
|
.joins('LEFT JOIN challenges cs ON cs.shixun_id = sx.id')
|
|
|
|
|
.joins('LEFT JOIN games ON games.challenge_id = cs.id')
|
|
|
|
|
.select("#{base_query_column}, SUM(games.evaluate_count) shixun_evaluate_count")
|
|
|
|
|
when 'nearly_course_time' then
|
|
|
|
|
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
|
|
|
|
|
.joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id')
|
|
|
|
|