|
|
@ -15,21 +15,24 @@ class Management::SchoolDataGrowService
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def call
|
|
|
|
def call
|
|
|
|
reports = query_reports.group('schools.id')
|
|
|
|
reports = School.where(nil)
|
|
|
|
|
|
|
|
|
|
|
|
count = reports.count.count
|
|
|
|
reports = search_filter(reports)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count = reports.count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reports = reports.joins("LEFT JOIN (#{joins_school_daily_report_sql}) sdr ON sdr.school_id = schools.id")
|
|
|
|
reports = reports.select(
|
|
|
|
reports = reports.select(
|
|
|
|
'schools.id school_id, schools.name school_name,'\
|
|
|
|
'schools.id school_id, schools.name school_name,'\
|
|
|
|
'SUM(teacher_increase_count) teacher_increase_count,'\
|
|
|
|
'sdr.teacher_increase_count,'\
|
|
|
|
'SUM(student_increase_count) student_increase_count,'\
|
|
|
|
'sdr.student_increase_count,'\
|
|
|
|
'SUM(course_increase_count) course_increase_count,'\
|
|
|
|
'sdr.course_increase_count,'\
|
|
|
|
'SUM(shixun_increase_count) shixun_increase_count,'\
|
|
|
|
'sdr.shixun_increase_count,'\
|
|
|
|
'SUM(shixun_homework_count) shixun_homework_count,'\
|
|
|
|
'sdr.shixun_homework_count,'\
|
|
|
|
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
|
|
|
|
'sdr.shixun_evaluate_count,'\
|
|
|
|
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\
|
|
|
|
'sdr.uniq_active_user_count,'\
|
|
|
|
'SUM(active_user_count) active_user_count'
|
|
|
|
'sdr.active_user_count'
|
|
|
|
)
|
|
|
|
).group('schools.id')
|
|
|
|
|
|
|
|
|
|
|
|
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
|
|
|
|
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
|
|
|
|
reports = reports.order('school_id asc').limit(PAGE_SIZE).offset(offset)
|
|
|
|
reports = reports.order('school_id asc').limit(PAGE_SIZE).offset(offset)
|
|
|
@ -39,37 +42,54 @@ class Management::SchoolDataGrowService
|
|
|
|
|
|
|
|
|
|
|
|
def grow_summary
|
|
|
|
def grow_summary
|
|
|
|
@_grow_summary ||= begin
|
|
|
|
@_grow_summary ||= begin
|
|
|
|
query_reports.select(
|
|
|
|
reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition_sql}")
|
|
|
|
|
|
|
|
.joins('LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id')
|
|
|
|
|
|
|
|
reports = search_filter(reports)
|
|
|
|
|
|
|
|
reports.select(
|
|
|
|
'SUM(teacher_increase_count) teacher_increase_count,'\
|
|
|
|
'SUM(teacher_increase_count) teacher_increase_count,'\
|
|
|
|
'SUM(student_increase_count) student_increase_count,'\
|
|
|
|
'SUM(student_increase_count) student_increase_count,'\
|
|
|
|
'SUM(course_increase_count) course_increase_count,'\
|
|
|
|
'SUM(course_increase_count) course_increase_count,'\
|
|
|
|
'SUM(shixun_increase_count) shixun_increase_count,'\
|
|
|
|
'SUM(shixun_increase_count) shixun_increase_count,'\
|
|
|
|
'SUM(shixun_homework_count) shixun_homework_count,'\
|
|
|
|
'SUM(shixun_homework_count) shixun_homework_count,'\
|
|
|
|
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
|
|
|
|
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
|
|
|
|
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\
|
|
|
|
'COUNT(distinct au.user_id) uniq_active_user_count,'\
|
|
|
|
'SUM(active_user_count) active_user_count'
|
|
|
|
'SUM(active_user_count) active_user_count'
|
|
|
|
).first
|
|
|
|
).first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
def query_reports
|
|
|
|
|
|
|
|
date = query_date
|
|
|
|
|
|
|
|
date_condition = if date.is_a?(Range)
|
|
|
|
|
|
|
|
"sdr.date BETWEEN '#{date.min.strftime('%Y-%m-%d')}' AND '#{date.max.strftime('%Y-%m-%d')}'"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
"sdr.date = '#{date.strftime('%Y-%m-%d')}'"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition}")
|
|
|
|
|
|
|
|
reports = reports.joins("LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search_filter(relations)
|
|
|
|
keyword = params[:keyword].try(:to_s).try(:strip)
|
|
|
|
keyword = params[:keyword].try(:to_s).try(:strip)
|
|
|
|
if keyword.present?
|
|
|
|
if keyword.present?
|
|
|
|
reports = reports.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
|
|
|
|
relations = relations.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
reports
|
|
|
|
relations
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def joins_school_daily_report_sql
|
|
|
|
|
|
|
|
SchoolDailyReport.joins('LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = school_daily_reports.id')
|
|
|
|
|
|
|
|
.select('school_id, '\
|
|
|
|
|
|
|
|
'SUM(distinct teacher_increase_count) teacher_increase_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct student_increase_count) student_increase_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct course_increase_count) course_increase_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct shixun_increase_count) shixun_increase_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct shixun_homework_count) shixun_homework_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct shixun_evaluate_count) shixun_evaluate_count,'\
|
|
|
|
|
|
|
|
'COUNT(distinct au.user_id) uniq_active_user_count,'\
|
|
|
|
|
|
|
|
'SUM(distinct active_user_count) active_user_count')
|
|
|
|
|
|
|
|
.where(date_condition_sql).group(:school_id).to_sql
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def date_condition_sql
|
|
|
|
|
|
|
|
date = query_date
|
|
|
|
|
|
|
|
if date.is_a?(Range)
|
|
|
|
|
|
|
|
"date BETWEEN '#{date.min.strftime('%Y-%m-%d')}' AND '#{date.max.strftime('%Y-%m-%d')}'"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
"date = '#{date.strftime('%Y-%m-%d')}'"
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def query_date
|
|
|
|
def query_date
|
|
|
|