fix school data grow list error

dev_partners
p31729568 6 years ago
parent bfe8f6800f
commit 922553af6e

@ -25,8 +25,8 @@ class Managements::SchoolsController < Managements::BaseController
service = Management::SchoolDataGrowService.new(params)
@grow_summary = service.grow_summary
reports = service.call
@reports = paginateHelper reports
@obj_count, @reports = service.call
@obj_pages = Paginator.new(@obj_count, Management::SchoolDataGrowService::PAGE_SIZE, params[:page])
end
def data_contrast

@ -1,6 +1,8 @@
class Management::SchoolDataGrowService
include CustomSortable
PAGE_SIZE = 20
attr_reader :params
sort_columns :teacher_increase_count, :student_increase_count,
@ -12,7 +14,23 @@ class Management::SchoolDataGrowService
end
def call
custom_sort(query_reports, params[:sort_by], params[:sort_direction])
reports = query_reports.group(:school_id)
count = reports.count.count
reports = reports.select(
'school_id, school_name,'\
'SUM(teacher_increase_count) teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\
'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(active_user_count) active_user_count'
)
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
reports = reports.limit(PAGE_SIZE).offset(offset)
[count, reports]
end
def grow_summary
@ -56,4 +74,8 @@ class Management::SchoolDataGrowService
# 每日凌晨5点为节点, 25日凌晨4点、3点、2点等等未到更新数据时间点看到的数据是23日-24日的统计数据
(Time.zone.now - 5.hours).beginning_of_day - 1.days
end
def offset
(params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * PAGE_SIZE
end
end

Loading…
Cancel
Save