fix school data contrast percentage zero issue

dev_partners
p31729568 6 years ago
parent f259ea7078
commit 35ec3b1744

@ -54,10 +54,8 @@ class Management::SchoolDataContrastService
end end
def select_columns def select_columns
"school_id, school_name, @total:=0, @other_total:=0,"\ "school_id, school_name,"\
"(@total:=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[: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,"\ "(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
end end

@ -14,10 +14,9 @@
<th width="6%">序号</th> <th width="6%">序号</th>
<th width="10%">ID</th> <th width="10%">ID</th>
<th width="20%" class="edu-txt-left">单位名称</th> <th width="20%" class="edu-txt-left">单位名称</th>
<th width="24%">时段一<br><%= "#{params[:begin_date]}至#{params[:end_date]}" %></th> <th width="22%">时段一<br><%= "#{params[:begin_date]}至#{params[:end_date]}" %></th>
<th width="24%">时段二<br><%= "#{params[:other_begin_date]}至#{params[:other_end_date]}" %></th> <th width="22%">时段二<br><%= "#{params[:other_begin_date]}至#{params[:other_end_date]}" %></th>
<th width="16%" colspan="2"> <th width="20%" colspan="2">
<%#= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
变化情况 变化情况
<br> 新 增 数 | 新增百分比) <br> 新 增 数 | 新增百分比)
</th> </th>
@ -31,21 +30,25 @@
<td class="edu-txt-left"><%= report.school_name %></td> <td class="edu-txt-left"><%= report.school_name %></td>
<td><%= report['total'] %></td> <td><%= report['total'] %></td>
<td><%= report['other_total'] %></td> <td><%= report['other_total'] %></td>
<% 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 %>
<td class="edu-txt-right pr20 right-border" style="position: relative; color: red;"> <td class="edu-txt-right pr20 right-border" style="position: relative; color: red;">
+<%= report['increase'] %> +<%= increase %>
</td> </td>
<td class="edu-txt-left pl20 c_red" style="color: red;">+<%= report['percentage'] %>%</td> <td class="edu-txt-left pl20 c_red" style="color: red;">+<%= percentage.round(5) %>%</td>
<% elsif report['increase'].zero? %> <% elsif increase.zero? %>
<td class="edu-txt-right pr20 right-border" style="position: relative;"> <td class="edu-txt-right pr20 right-border" style="position: relative;">
<%= report['increase'] %> <%= increase %>
</td> </td>
<td class="edu-txt-left pl20"><%= report['percentage'] %></td> <td class="edu-txt-left pl20"><%= percentage.round(5) %>%</td>
<% else %> <% else %>
<td class="edu-txt-right pr20 right-border c_green" style="position: relative; color: green;"> <td class="edu-txt-right pr20 right-border c_green" style="position: relative; color: green;">
<%= report['increase'] %> <%= increase %>
</td> </td>
<td class="edu-txt-left pl20" style="color: green;"><%= report['percentage'] %>%</td> <td class="edu-txt-left pl20" style="color: green;"><%= percentage.round(5) %>%</td>
<% end %> <% end %>
</tr> </tr>
<% end %> <% end %>

Loading…
Cancel
Save