diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 6940ed1cf..37b69dc0d 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -69,26 +69,26 @@ class Admins::DashboardsController < Admins::BaseController @subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"] @subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count] - - tongji_service = Baidu::TongjiService.new - @access_token = tongji_service.access_token - Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" - # @overview_data = tongji_service.api_overview - last_date = DailyPlatformStatistic.order(:date).last - start_date = last_date.date - end_date = Time.now - if @access_token.present? - @overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do - tongji_service.source_from_batch_add(start_date, end_date) - @overview_data = tongji_service.overview_batch_add(start_date, end_date) - @overview_data + if EduSetting.get("open_baidu_tongji").to_s == "true" + tongji_service = Baidu::TongjiService.new + @access_token = tongji_service.access_token + Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" + # @overview_data = tongji_service.api_overview + last_date = DailyPlatformStatistic.order(:date).last || Time.now + start_date = last_date.date + end_date = Time.now + if @access_token.present? + @overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do + tongji_service.source_from_batch_add(start_date, end_date) + @overview_data = tongji_service.overview_batch_add(start_date, end_date) + @overview_data + end end + + @current_week_statistic = DailyPlatformStatistic.where(date: current_week) + @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) end - @current_week_statistic = DailyPlatformStatistic.where(date: current_week) - @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) - - end diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 5441a1802..a55ef55e4 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -85,7 +85,9 @@ + <% if EduSetting.get("open_baidu_tongji").to_s == "true" %> <%= render partial: 'admins/dashboards/baidu_tongji' %> + <% end %>