diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 76f7b080..344976ab 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,7 +2,7 @@ class ChallengesController < ApplicationController layout "base_shixun" # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - #before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] + before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] before_filter :check_authentication, :except => [:index] before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 9f8833eb..61e56f9a 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -2,7 +2,7 @@ class SubjectsController < ApplicationController layout 'base_subject' # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - #before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:show] + before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:show] before_filter :require_login, :except => [:show, :index] before_filter :check_authentication, :except => [:show, :index] before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course] diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index 4784db31..2b18950d 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -42,7 +42,7 @@ class Management::SchoolReportService shixun_homework_map = homeworks.where(homework_type: 4, courses: { school_id: ids }).group('school_id').count other_homework_map = homeworks.where(homework_type: [1, 3], courses: { school_id: ids }).group('school_id').count - courses = Course.where(school_id: ids).group('school_id') + courses = Course.where(is_delete: 0, school_id: ids).group('school_id') course_map = courses.count nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at') active_course_map = courses.where(is_end: false).count @@ -76,11 +76,15 @@ class Management::SchoolReportService when 'other_homework_count' then schools.joins(courses: :other_homework_commons).select("#{base_query_column}, COUNT(*) other_homework_count") when 'course_count' then - schools.joins(:courses).select("#{base_query_column}, COUNT(*) course_count") + schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') + .select("#{base_query_column}, COUNT(*) course_count") when 'nearly_course_time' then - schools.joins(courses: :course_activities).select("#{base_query_column}, MAX(course_activities.updated_at) nearly_course_time") + schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') + .joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id') + .select("#{base_query_column}, MAX(acs.updated_at) nearly_course_time") when 'active_course_count' then - schools.joins(:active_courses).select("#{base_query_column}, COUNT(*) active_course_count") + schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0 AND cs.is_end = false') + .select("#{base_query_column}, COUNT(*) active_course_count") else schools.joins(:teacher_extensions).select("#{base_query_column}, COUNT(*) teacher_count") end diff --git a/app/views/managements/schools/statistics_xlsx.xlsx.axlsx b/app/views/managements/schools/statistics_xlsx.xlsx.axlsx index 85f28531..a451586d 100644 --- a/app/views/managements/schools/statistics_xlsx.xlsx.axlsx +++ b/app/views/managements/schools/statistics_xlsx.xlsx.axlsx @@ -4,9 +4,9 @@ wb.add_worksheet(name: '统计总表') do |sheet| @schools.each do |school| sheet.add_row([ - school['id'].to_s, school['name'].to_s, (school['teacher_count'] || 0).to_s, (school['student_count'] || 0).to_s, - (school['course_count'] || 0).to_s, (school['active_course_count'] || 0).to_s, (school['homework_count'] || 0).to_s, - (school['other_homework_count'] || 0).to_s, format_time(school['nearly_course_time']) + school[:id].to_s, school[:name].to_s, (school[:teacher_count] || 0).to_s, (school[:student_count] || 0).to_s, + (school[:course_count] || 0).to_s, (school[:active_course_count] || 0).to_s, (school[:homework_count] || 0).to_s, + (school[:other_homework_count] || 0).to_s, format_time(school[:nearly_course_time]) ]) end end \ No newline at end of file diff --git a/db/migrate/20190509032337_add_index_to_courses.rb b/db/migrate/20190509032337_add_index_to_courses.rb new file mode 100644 index 00000000..210025a0 --- /dev/null +++ b/db/migrate/20190509032337_add_index_to_courses.rb @@ -0,0 +1,5 @@ +class AddIndexToCourses < ActiveRecord::Migration + def change + add_index :courses, [:school_id, :is_delete] + end +end