|
|
@ -4,7 +4,7 @@ class Management::SchoolReportService
|
|
|
|
attr_reader :params
|
|
|
|
attr_reader :params
|
|
|
|
|
|
|
|
|
|
|
|
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
|
|
|
|
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
|
|
|
|
:course_count, :active_course_count, :nearly_course_time,
|
|
|
|
:course_count, :active_course_count, :nearly_course_time, :shixun_count, :shixun_evaluate_count,
|
|
|
|
default_by: :teacher_count, default_direction: :desc
|
|
|
|
default_by: :teacher_count, default_direction: :desc
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
def initialize(params)
|
|
|
@ -47,6 +47,11 @@ class Management::SchoolReportService
|
|
|
|
nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at')
|
|
|
|
nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at')
|
|
|
|
active_course_map = courses.where(is_end: false).count
|
|
|
|
active_course_map = courses.where(is_end: false).count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 })
|
|
|
|
|
|
|
|
.group('school_id').sum(:evaluate_count)
|
|
|
|
|
|
|
|
|
|
|
|
schools.map do |school|
|
|
|
|
schools.map do |school|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
id: school.id,
|
|
|
|
id: school.id,
|
|
|
@ -58,6 +63,8 @@ class Management::SchoolReportService
|
|
|
|
course_count: course_map[school.id],
|
|
|
|
course_count: course_map[school.id],
|
|
|
|
nearly_course_time: nearly_course_time_map[school.id],
|
|
|
|
nearly_course_time: nearly_course_time_map[school.id],
|
|
|
|
active_course_count: active_course_map[school.id],
|
|
|
|
active_course_count: active_course_map[school.id],
|
|
|
|
|
|
|
|
shixun_count: shixun_map.fetch(school.id, 0),
|
|
|
|
|
|
|
|
shixun_evaluate_count: evaluate_count_map.fetch(school.id, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -78,6 +85,12 @@ class Management::SchoolReportService
|
|
|
|
when 'course_count' then
|
|
|
|
when 'course_count' then
|
|
|
|
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
|
|
|
|
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
|
|
|
|
.select("#{base_query_column}, COUNT(*) course_count")
|
|
|
|
.select("#{base_query_column}, COUNT(*) course_count")
|
|
|
|
|
|
|
|
when 'shixun_count' then
|
|
|
|
|
|
|
|
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id')
|
|
|
|
|
|
|
|
.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")
|
|
|
|
when 'nearly_course_time' then
|
|
|
|
when 'nearly_course_time' then
|
|
|
|
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
|
|
|
|
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')
|
|
|
|
.joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id')
|
|
|
|