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 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 diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb index 9390e46f..e6a39e9b 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 @@ -57,9 +55,7 @@ class Management::SchoolDataContrastService def select_columns "school_id, school_name,"\ - "(@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" + "(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 %> 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 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