From 949e714950206f7749351d865bb83bfdaff37343 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jun 2020 14:14:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E7=BB=9F=E8=AE=A1=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=93=E4=B8=9A=E4=BA=BA=E5=A3=AB=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tasks/statistic_school_daily_report_task.rb | 5 +++-- lib/tasks/statistic_school_daily_report.rake | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/tasks/statistic_school_daily_report_task.rb b/app/tasks/statistic_school_daily_report_task.rb index c533c55c..b8dc955c 100644 --- a/app/tasks/statistic_school_daily_report_task.rb +++ b/app/tasks/statistic_school_daily_report_task.rb @@ -7,6 +7,7 @@ class StatisticSchoolDailyReportTask teacher_count = users.where(created_on: yesterday, user_extensions: { identity: User::TEACHER }).count student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count + prefessional_count = users.where(created_on: yesterday, user_extensions: { identity: User::ENTERPRISE }).count # 活跃用户 active_user_ids = users.where(last_login_on: yesterday).pluck(:id) @@ -33,13 +34,13 @@ class StatisticSchoolDailyReportTask .where(created_at: yesterday).reorder(nil).count # 无有效数据时不记录 - data = [teacher_count, student_count, course_count, shixun_count, active_user_count, + data = [teacher_count, student_count, prefessional_count, course_count, shixun_count, active_user_count, shixun_homework_count, shixun_evaluate_count] next if data.all?(&:zero?) create_params = { school_id: school.id, school_name: school.name, teacher_increase_count: teacher_count, - student_increase_count: student_count, course_increase_count: course_count, + student_increase_count: student_count, prefessional_increase_count: prefessional_count, course_increase_count: course_count, shixun_homework_count: shixun_homework_count, shixun_evaluate_count: shixun_evaluate_count, shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date } diff --git a/lib/tasks/statistic_school_daily_report.rake b/lib/tasks/statistic_school_daily_report.rake index 2d487ff6..6bfa58bb 100644 --- a/lib/tasks/statistic_school_daily_report.rake +++ b/lib/tasks/statistic_school_daily_report.rake @@ -31,11 +31,11 @@ namespace :school_daily_report do data = reports.map do |report| # 无效数据不记录 - next if %w(teacher_count student_count course_count shixun_count shixun_homework_count shixun_evaluate_count active_user_count).all? { |key| report[key].zero? } + next if %w(teacher_count student_count professional_count course_count shixun_count shixun_homework_count shixun_evaluate_count active_user_count).all? { |key| report[key].zero? } [ - report['id'], report['name'], report['teacher_count'], report['student_count'], report['course_count'], - report['shixun_count'], report['shixun_homework_count'], report['shixun_evaluate_count'], + report['id'], report['name'], report['teacher_count'], report['student_count'], report['professional_count'], + report['course_count'], report['shixun_count'], report['shixun_homework_count'], report['shixun_evaluate_count'], report['active_user_count'], date_str, current_datetime, current_datetime ] end.compact @@ -195,7 +195,7 @@ namespace :school_daily_report do end def build_insert_report_sql(arr) - prefix = 'INSERT INTO school_daily_reports(school_id, school_name, teacher_increase_count, student_increase_count, '\ + prefix = 'INSERT INTO school_daily_reports(school_id, school_name, teacher_increase_count, student_increase_count, professional_increase_count, '\ 'course_increase_count, shixun_increase_count, shixun_homework_count, shixun_evaluate_count, active_user_count, date, created_at, updated_at) VALUES' # [[1,2], [3,4]] => ['"1", "2"', '"3", "4"'] => '("1", "2"),("3", "4")' values = '(' + arr.map { |item| '"' + item.join('","') + '"' }.join('),(') + ')' @@ -223,6 +223,11 @@ namespace :school_daily_report do WHERE cs.school_id = schools.id AND cs.created_at BETWEEN "#{begin_date}" AND "#{end_date}" ) course_count, ( + SELECT COUNT(*) FROM users u + LEFT JOIN user_extensions ue ON ue.user_id = u.id + WHERE ue.school_id = schools.id AND ue.identity = #{User::ENTERPRISE} + AND u.created_on BETWEEN "#{begin_date}" AND "#{end_date}" + ) professional_count, ( SELECT COUNT(*) FROM shixuns sx LEFT JOIN users u ON sx.user_id = u.id LEFT JOIN user_extensions ue ON ue.user_id = u.id