From 26455d0efb085c82a3040a61d825f17b329a28bf Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 11:20:12 +0800 Subject: [PATCH 1/7] 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 58a278f5838a93286770a02ff9d8d772a0253a4b Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 11:33:06 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 533cead1..b1a66080 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1152,9 +1152,10 @@ class ApplicationController < ActionController::Base def user_login_and_from_openi url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- #{url} -------------------------" - logger.info "----------------------- #{URI(url).host} --------------------------" - logger.info "----------------------- #{flag} -------------------------" + logger.info "----------------------- request referer: #{request.referer} -------------------------" + logger.info "----------------------- url after processed: #{url} -------------------------" + logger.info "----------------------- host: #{URI(url).host} --------------------------" + logger.info "----------------------- handle_flag: #{flag} -------------------------" flag 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/7] 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 From d067d4dbeddb312425f0e015b2dd0d17b658606d Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 12:21:57 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=B0=86request.referer=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BArequest.original=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1a66080..3e456b8f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1150,9 +1150,9 @@ class ApplicationController < ActionController::Base end def user_login_and_from_openi - url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer + url = request.original_url.nil? ? Redmine::Configuration['educoder_domain'] : request.original_url flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- request referer: #{request.referer} -------------------------" + logger.info "----------------------- request referer: #{request.original_url} -------------------------" logger.info "----------------------- url after processed: #{url} -------------------------" logger.info "----------------------- host: #{URI(url).host} --------------------------" logger.info "----------------------- handle_flag: #{flag} -------------------------" From c1b3dfadd2e53062a892dc036bc401bad924ce46 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Sat, 27 Apr 2019 14:04:04 +0800 Subject: [PATCH 5/7] removeExceptGitDir --- public/react/scripts/build.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/public/react/scripts/build.js b/public/react/scripts/build.js index cf7c1377..6dd9d3e5 100644 --- a/public/react/scripts/build.js +++ b/public/react/scripts/build.js @@ -44,16 +44,16 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { } function removeExceptGitDir(dir) { - fs2.readdir(dir, function(err, list) { - if (err) return done(err); - var pending = list.length; - if (!pending) return done(null, results); - list.forEach(function(file) { - if (file.indexOf('.git') == -1) { - file = path.resolve(dir, file); - fs.remove(file) - } - }); + // readdirSync + const list = fs2.readdirSync(dir) + // if (err) return done(err); + var pending = list.length; + // if (!pending) return done(null, results); + list.forEach(function(file) { + if (file.indexOf('.git') == -1) { + file = path.resolve(dir, file); + fs.removeSync(file) + } }); } @@ -202,6 +202,14 @@ function generateNewIndexJsp() { fs2.writeFile(outputPath, result, 'utf8', function (err) { if (err) return console.log(err); + commitAndPush(); }); }); +} + +function commitAndPush() { + var exec = require('child_process').exec; + function puts(error, stdout, stderr) { console.log(stdout) } + var options = {cwd:"./build"}; + exec("git status && git commit -am 'b' && git push", options, puts); } \ No newline at end of file From 0cea78e89e46374c8c9b18aa183d6cf6875df2d3 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 14:34:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=8E=B7?= =?UTF-8?q?=E5=8F=96referer=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3e456b8f..b1a66080 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1150,9 +1150,9 @@ class ApplicationController < ActionController::Base end def user_login_and_from_openi - url = request.original_url.nil? ? Redmine::Configuration['educoder_domain'] : request.original_url + url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- request referer: #{request.original_url} -------------------------" + logger.info "----------------------- request referer: #{request.referer} -------------------------" logger.info "----------------------- url after processed: #{url} -------------------------" logger.info "----------------------- host: #{URI(url).host} --------------------------" logger.info "----------------------- handle_flag: #{flag} -------------------------" From 35ec3b1744a04a2185cb49740fe4162236f31719 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 14:47:18 +0800 Subject: [PATCH 7/7] fix school data contrast percentage zero issue --- .../school_data_contrast_service.rb | 8 +++--- .../schools/_data_contrast_list.html.erb | 27 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb index 47c7f117..e6a39e9b 100644 --- a/app/services/management/school_data_contrast_service.rb +++ b/app/services/management/school_data_contrast_service.rb @@ -54,10 +54,8 @@ class Management::SchoolDataContrastService end def select_columns - "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,"\ - "(@other_total - @total) increase" + "school_id, school_name,"\ + "(SUM(IF(date BETWEEN '#{format_date(params[:begin_date])}' AND '#{format_date(params[:end_date])}', #{contrast_column}, 0))) total,"\ + "(SUM(IF(date BETWEEN '#{format_date(params[:other_begin_date])}' AND '#{format_date(params[:other_end_date])}', #{contrast_column}, 0))) other_total"\ end end diff --git a/app/views/managements/schools/_data_contrast_list.html.erb b/app/views/managements/schools/_data_contrast_list.html.erb index ae2ecfd2..af63aee8 100644 --- a/app/views/managements/schools/_data_contrast_list.html.erb +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -14,10 +14,9 @@ 序号 ID 单位名称 - 时段一
<%= "(#{params[:begin_date]}至#{params[:end_date]})" %> - 时段二
<%= "(#{params[:other_begin_date]}至#{params[:other_end_date]})" %> - - <%#= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %> + 时段一
<%= "(#{params[:begin_date]}至#{params[:end_date]})" %> + 时段二
<%= "(#{params[:other_begin_date]}至#{params[:other_end_date]})" %> + 变化情况
( 新 增 数 | 新增百分比) @@ -31,21 +30,25 @@ <%= report.school_name %> <%= report['total'] %> <%= report['other_total'] %> - <% if report['increase'] > 0 %> + <% + increase = report['other_total'] - report['total'] + percentage = report['total'].zero? ? increase.to_f * 100 : (increase / report['total'].to_f) * 100 + %> + <% if increase > 0 %> - +<%= report['increase'] %> + +<%= increase %> - +<%= report['percentage'] %>% - <% elsif report['increase'].zero? %> + +<%= percentage.round(5) %>% + <% elsif increase.zero? %> - <%= report['increase'] %> + <%= increase %> - <%= report['percentage'] %> + <%= percentage.round(5) %>% <% else %> - <%= report['increase'] %> + <%= increase %> - <%= report['percentage'] %>% + <%= percentage.round(5) %>% <% end %> <% end %>