From 01017c3bd32cc33c5e0710b6f822d4354f177d6c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 27 Apr 2019 11:01:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?checkout=20box=E9=80=89=E6=8B=A9=E8=BF=90?= =?UTF-8?q?=E8=90=A5=E4=BA=BA=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/managements/update_user.html.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/managements/update_user.html.erb b/app/views/managements/update_user.html.erb index 3203614d..554ea2a2 100644 --- a/app/views/managements/update_user.html.erb +++ b/app/views/managements/update_user.html.erb @@ -188,7 +188,7 @@ name="business" value="<%= @user.business? ? "1" : "0" %>" id="person_business" class="magic-checkbox" style="float:left; margin-top: 8px;"> - +
  • @@ -621,6 +621,13 @@ $("#user_form_link").on("click",function(){ + var check = document.getElementById('person_business').checked; + if(check){ + document.getElementById('person_business').value = "1"; + }else{ + document.getElementById('person_business').value = "0"; + } + my_account_form_submit(); }); function my_account_form_submit(){ From 26455d0efb085c82a3040a61d825f17b329a28bf Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 11:20:12 +0800 Subject: [PATCH 2/3] add index to fix order slow issue --- app/services/management/school_data_contrast_service.rb | 8 +++----- .../20190427025209_add_index_to_school_daily_reports.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190427025209_add_index_to_school_daily_reports.rb diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb index 9390e46f..47c7f117 100644 --- a/app/services/management/school_data_contrast_service.rb +++ b/app/services/management/school_data_contrast_service.rb @@ -24,10 +24,8 @@ class Management::SchoolDataContrastService reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%") end - reports = reports.group(:school_id) - count = reports.count.count - - reports = reports.limit(PAGE_SIZE).offset(offset) + count = reports.count('distinct(school_id)') + reports = reports.group(:school_id).limit(PAGE_SIZE).offset(offset) [count, reports] end @@ -56,7 +54,7 @@ class Management::SchoolDataContrastService end def select_columns - "school_id, school_name,"\ + "school_id, school_name, @total:=0, @other_total:=0,"\ "(@total:=SUM(IF(date BETWEEN '#{format_date(params[:begin_date])}' AND '#{format_date(params[:end_date])}', #{contrast_column}, 0))) total,"\ "(@other_total:=SUM(IF(date BETWEEN '#{format_date(params[:other_begin_date])}' AND '#{format_date(params[:other_end_date])}', #{contrast_column}, 0))) other_total,"\ "(IF(@other_total - @total = 0, 0.0, round((@other_total - @total) / IF(@total = 0, 1, @total), 5))) percentage,"\ diff --git a/db/migrate/20190427025209_add_index_to_school_daily_reports.rb b/db/migrate/20190427025209_add_index_to_school_daily_reports.rb new file mode 100644 index 00000000..5cfc2796 --- /dev/null +++ b/db/migrate/20190427025209_add_index_to_school_daily_reports.rb @@ -0,0 +1,9 @@ +class AddIndexToSchoolDailyReports < ActiveRecord::Migration + def change + add_index :school_daily_reports, [:date, :teacher_increase_count] + add_index :school_daily_reports, [:date, :student_increase_count] + add_index :school_daily_reports, [:date, :course_increase_count] + add_index :school_daily_reports, [:date, :shixun_increase_count] + add_index :school_daily_reports, [:date, :active_user_count] + end +end From 92451b97205f57f66ed7d813b6c33c3c0d9f1e19 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 11:39:25 +0800 Subject: [PATCH 3/3] fix issue --- app/controllers/managements/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements/base_controller.rb b/app/controllers/managements/base_controller.rb index cbb61c33..8d5ada3b 100644 --- a/app/controllers/managements/base_controller.rb +++ b/app/controllers/managements/base_controller.rb @@ -1,5 +1,5 @@ class Managements::BaseController < ApplicationController layout 'base_management' - before_filter :require_admin + before_filter :require_business end \ No newline at end of file