dev_partners
jingquan huang 6 years ago
commit fb1ba699cb

@ -27,7 +27,9 @@ class Management::SchoolDataContrastService
reports = reports.group(:school_id)
count = reports.count.count
[count, SchoolDailyReport.find_by_sql(query_report_sql(reports.to_sql))]
reports = reports.limit(PAGE_SIZE).offset(offset)
[count, reports]
end
private
@ -55,12 +57,9 @@ class Management::SchoolDataContrastService
def select_columns
"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
def query_report_sql(from_sql)
"SELECT reports.*, (other_total - total) increase, (IF(other_total - total = 0, 0.0, round((other_total - total) / IF(total = 0, 1, total), 5))) percentage "\
"FROM (#{from_sql}) reports ORDER BY percentage #{sort_direction} LIMIT #{PAGE_SIZE} OFFSET #{offset}"
"(@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"
end
end

@ -17,7 +17,8 @@
<th width="24%">时段一<br><%= "#{params[:begin_date]}至#{params[:end_date]}" %></th>
<th width="24%">时段二<br><%= "#{params[:other_begin_date]}至#{params[:other_end_date]}" %></th>
<th width="16%" colspan="2">
<%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
<%#= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
变化情况
<br> 新 增 数 | 新增百分比)
</th>
</tr>

Loading…
Cancel
Save