From 1829bada4641a42b1c753644894fe481e275a3d1 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 5 Jun 2019 11:31:12 +0800 Subject: [PATCH 1/4] fix school management data incorrent bug --- app/services/management/school_data_grow_service.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/services/management/school_data_grow_service.rb b/app/services/management/school_data_grow_service.rb index 18b72751..4187881c 100644 --- a/app/services/management/school_data_grow_service.rb +++ b/app/services/management/school_data_grow_service.rb @@ -43,8 +43,12 @@ class Management::SchoolDataGrowService def grow_summary @_grow_summary ||= begin - 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 = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id") + .where(date_condition_sql) + + subquery = SchoolDailyActiveUser.select('COUNT(distinct user_id)') + .joins('LEFT JOIN school_daily_reports sdr ON sdr.id = school_daily_active_users.school_daily_report_id') + .where(date_condition_sql) reports = search_filter(reports) reports.select( 'SUM(teacher_increase_count) teacher_increase_count,'\ @@ -53,7 +57,7 @@ class Management::SchoolDataGrowService 'SUM(shixun_increase_count) shixun_increase_count,'\ 'SUM(shixun_homework_count) shixun_homework_count,'\ 'SUM(shixun_evaluate_count) shixun_evaluate_count,'\ - 'COUNT(distinct au.user_id) uniq_active_user_count,'\ + "(#{subquery}) uniq_active_user_count,"\ 'SUM(active_user_count) active_user_count' ).first end @@ -101,3 +105,4 @@ class Management::SchoolDataGrowService (params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * PAGE_SIZE end end +# SELECT SUM(teacher_increase_count) teacher_increase_count,SUM(student_increase_count) student_increase_count,SUM(course_increase_count) course_increase_count,SUM(shixun_increase_count) shixun_increase_count,SUM(shixun_homework_count) shixun_homework_count,SUM(shixun_evaluate_count) shixun_evaluate_count,(select count(distinct user_id) from school_daily_active_users sdau left join school_daily_reports sdr on sdr.id = sdau.school_daily_report_id where date BETWEEN '2019-06-02' AND '2019-06-03') uniq_active_user_count,SUM(active_user_count) active_user_count FROM `schools` LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id where date BETWEEN '2019-06-02' AND '2019-06-03' LIMIT 1 \ No newline at end of file From cb0b5a88806c59d56f90ec6f95342c583105838c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 5 Jun 2019 13:42:02 +0800 Subject: [PATCH 2/4] fix --- app/services/management/school_data_grow_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/management/school_data_grow_service.rb b/app/services/management/school_data_grow_service.rb index 4187881c..2baf8087 100644 --- a/app/services/management/school_data_grow_service.rb +++ b/app/services/management/school_data_grow_service.rb @@ -48,7 +48,7 @@ class Management::SchoolDataGrowService subquery = SchoolDailyActiveUser.select('COUNT(distinct user_id)') .joins('LEFT JOIN school_daily_reports sdr ON sdr.id = school_daily_active_users.school_daily_report_id') - .where(date_condition_sql) + .where(date_condition_sql).to_sql reports = search_filter(reports) reports.select( 'SUM(teacher_increase_count) teacher_increase_count,'\ From 1523b992e0636d07090a856f3f05d53d3390558a Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 5 Jun 2019 13:57:04 +0800 Subject: [PATCH 3/4] modify school management view --- app/views/managements/schools/_data_contrast_list.html.erb | 4 ++-- app/views/managements/schools/_data_grow_list.html.erb | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/views/managements/schools/_data_contrast_list.html.erb b/app/views/managements/schools/_data_contrast_list.html.erb index 88eb4c6b..c25a8bc4 100644 --- a/app/views/managements/schools/_data_contrast_list.html.erb +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -21,8 +21,8 @@ 序号 ID 单位名称 - 时段一
<%= "(#{params[:begin_date]} 05:00至#{params[:end_date]} 05:00)" %> - 时段二
<%= "(#{params[:other_begin_date]} 05:00至#{params[:other_end_date]} 05:00)" %> + 时段一
<%= "(#{params[:begin_date]} 05:00至#{(Time.zone.parse(params[:end_date]) + 1.days).strftime('%Y-%m-%d')} 05:00)" %> + 时段二
<%= "(#{params[:other_begin_date]} 05:00至#{(Time.zone.parse(params[:other_end_date]) + 1.days).strftime('%Y-%m-%d')} 05:00)" %> <%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
( 新 增 数 | 新增百分比) diff --git a/app/views/managements/schools/_data_grow_list.html.erb b/app/views/managements/schools/_data_grow_list.html.erb index 81976044..af1fc200 100644 --- a/app/views/managements/schools/_data_grow_list.html.erb +++ b/app/views/managements/schools/_data_grow_list.html.erb @@ -1,12 +1,7 @@
统计总计: <% if params[:grow_begin_date].present? %> - <% if params[:grow_begin_date] == params[:grow_end_date] %> - <%= Time.zone.parse(params[:grow_begin_date]).beginning_of_day.strftime('%Y-%m-%d') %> 05:00至 - <%= (Time.zone.parse(params[:grow_begin_date]).beginning_of_day + 1.days).strftime('%Y-%m-%d') %> 05:00 - <% else %> - <%= params[:grow_begin_date] %> 05:00至<%= (Time.zone.parse(params[:grow_end_date]) + 1.days).strftime('%Y-%m-%d') %> 05:00 - <% end %> + <%= params[:grow_begin_date] %> 05:00至<%= (Time.zone.parse(params[:grow_end_date]) + 1.days).strftime('%Y-%m-%d') %> 05:00 <% else %> <%= (Time.current - 5.hour).beginning_of_day.ago(1.days).strftime('%Y-%m-%d') %> 05:00至 <%= (Time.current - 5.hour).beginning_of_day.strftime('%Y-%m-%d') %> 05:00, From 0e0396c53955bbece5fe01fed3c3037e1dffa692 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 5 Jun 2019 14:03:28 +0800 Subject: [PATCH 4/4] fix school management sort bug --- app/services/management/school_report_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index 785786b2..981498cd 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -83,11 +83,11 @@ class Management::SchoolReportService .select("#{base_query_column}, COUNT(*) student_count") when 'homework_count' then schools.joins('LEFT JOIN courses ON courses.school_id = schools.id') - .joins('LEFT JOIN homework_commons hc ON shc.course_id = courses.id AND hc.homework_type = 4') + .joins('LEFT JOIN homework_commons hc ON hc.course_id = courses.id AND hc.homework_type = 4') .select("#{base_query_column}, COUNT(*) homework_count") when 'other_homework_count' then schools.joins('LEFT JOIN courses ON courses.school_id = schools.id') - .joins('LEFT JOIN homework_commons hc ON shc.course_id = courses.id AND hc.homework_type IN (1, 3)') + .joins('LEFT JOIN homework_commons hc ON hc.course_id = courses.id AND hc.homework_type IN (1, 3)') .select("#{base_query_column}, COUNT(*) other_homework_count") when 'course_count' then schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')