export school statistic data feature

dev_partners
p31729568 6 years ago
parent 0817dc9e86
commit 50d7ed2deb

@ -62,6 +62,9 @@ gem 'elasticsearch-rails'
gem 'oauth2' gem 'oauth2'
# xlsx
gem 'axlsx_rails', '0.3.0'
#Ruby 2.2+ has removed test/unit from the core library. #Ruby 2.2+ has removed test/unit from the core library.
if RUBY_VERSION>='2.2' if RUBY_VERSION>='2.2'
gem 'test-unit', '~> 3.0' gem 'test-unit', '~> 3.0'

@ -9,6 +9,11 @@ class Managements::SchoolsController < Managements::BaseController
schools = Management::SchoolReportService.new(params).call schools = Management::SchoolReportService.new(params).call
@schools = paginateHelper schools @schools = paginateHelper schools
respond_to do |format|
format.html { load_statistic_total }
format.js
end
end end
def yesterday_data def yesterday_data
@ -31,6 +36,13 @@ class Managements::SchoolsController < Managements::BaseController
raise '参数错误' raise '参数错误'
end end
def statistics_xlsx
@schools = Management::SchoolReportService.new(params).call
filename = ["学校统计总表", params[:keyword], Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << ".xlsx"
render xlsx: "statistics_xlsx", filename: filename
end
private private
def set_navigation_bar def set_navigation_bar
@menu_type = 1 @menu_type = 1
@ -41,4 +53,13 @@ class Managements::SchoolsController < Managements::BaseController
[I18n.t("school_daily_report.#{column}"), column] [I18n.t("school_daily_report.#{column}"), column]
end end
end end
def load_statistic_total
@teacher_total = User.teacher.count
@student_total = User.student.count
@course_total = Course.count
@active_course_total = Course.where(is_end: false).count
@shixun_homework_total = HomeworkCommon.where(homework_type: 4).count
@other_homework_total = HomeworkCommon.where(homework_type: [1, 3]).count
end
end end

@ -63,33 +63,21 @@ class HomeworkCommon < ActiveRecord::Base
#作业类型 #作业类型
def homework_type_ch def homework_type_ch
type = self.homework_type case homework_type
case type when 1 then '普通'
when 1 when 2 then '编程'
type = "普通" when 3 then '分组'
when 2 when 4 then '实训'
type = "编程"
when 3
type = "分组"
when 4
type = "实训"
end end
type
end end
def homework_type_module def homework_type_module
type = self.homework_type case homework_type
case type when 1 then 'common_homework'
when 1 when 2 then 'code_homework'
type = "common_homework" when 3 then 'group_homework'
when 2 when 4 then 'shixun_homework'
type = "code_homework" end
when 3
type = "group_homework"
when 4
type = "shixun_homework"
end
type
end end
def act_as_activity def act_as_activity

@ -39,7 +39,7 @@ class Management::SchoolReportService
( (
SELECT COUNT(*) FROM homework_commons hc SELECT COUNT(*) FROM homework_commons hc
LEFT JOIN courses ON courses.id = hc.course_id LEFT JOIN courses ON courses.id = hc.course_id
WHERE courses.school_id = schools.id WHERE courses.school_id = schools.id AND hc.homework_type = 4
) homework_count, ) homework_count,
( (
SELECT COUNT(*) FROM homework_commons hc SELECT COUNT(*) FROM homework_commons hc

@ -44,10 +44,6 @@
<li><%= link_to "课堂列表", classroom_classment_managements_path %></li> <li><%= link_to "课堂列表", classroom_classment_managements_path %></li>
<li><%= link_to "实训作业", shixun_task_managements_path%></li> <li><%= link_to "实训作业", shixun_task_managements_path%></li>
<li><%= link_to "项目列表", project_list_managements_path%></li> <li><%= link_to "项目列表", project_list_managements_path%></li>
<!-- <li>统计总表</li>-->
<!-- <li>统计总表对比</li>-->
<!-- <li>统计总表日新增</li>-->
</ul> </ul>
</li> </li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 3 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">精选实训+</a> <li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 3 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">精选实训+</a>

@ -35,20 +35,20 @@
percentage = report['total'].zero? ? increase.to_f * 100 : (increase / report['total'].to_f) * 100 percentage = report['total'].zero? ? increase.to_f * 100 : (increase / report['total'].to_f) * 100
%> %>
<% if increase > 0 %> <% if increase > 0 %>
<td class="edu-txt-right pr20 right-border" style="position: relative; color: red;"> <td class="edu-txt-right pr20 right-border relative color-red">
+<%= increase %> +<%= increase %>
</td> </td>
<td class="edu-txt-left pl20 c_red" style="color: red;">+<%= percentage.round(5) %>%</td> <td class="edu-txt-left pl20 color-red">+<%= percentage.round(5) %>%</td>
<% elsif 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;">
<%= increase %> <%= increase %>
</td> </td>
<td class="edu-txt-left pl20"><%= percentage.round(5) %>%</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 relative color-green">
<%= increase %> <%= increase %>
</td> </td>
<td class="edu-txt-left pl20" style="color: green;"><%= percentage.round(5) %>%</td> <td class="edu-txt-left pl20 color-green"><%= percentage.round(5) %>%</td>
<% end %> <% end %>
</tr> </tr>
<% end %> <% end %>

@ -17,7 +17,7 @@
<tbody> <tbody>
<% @schools.each_with_index do |school, index| %> <% @schools.each_with_index do |school, index| %>
<tr> <tr>
<td><% p school %><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td> <td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
<td><%= school['id'] %></td> <td><%= school['id'] %></td>
<td class="edu-txt-left"><%= school['name'] %></td> <td class="edu-txt-left"><%= school['name'] %></td>
<td><%= school['teacher_count'] %></td> <td><%= school['teacher_count'] %></td>

@ -4,7 +4,26 @@
class: 'fl task-form-30 task-height-30 mt10', style: 'margin: 10px 10px 10px 25px;' %> class: 'fl task-form-30 task-height-30 mt10', style: 'margin: 10px 10px 10px 25px;' %>
<%= link_to '搜索', 'javascript:void(0)', class: 'fl task-btn task-btn-orange ml5 mt10', onclick: "$('#school_report_search_form').submit();" %> <%= link_to '搜索', 'javascript:void(0)', class: 'fl task-btn task-btn-orange ml5 mt10', onclick: "$('#school_report_search_form').submit();" %>
<%= link_to '清除', 'javascript:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %> <%= link_to '清除', 'javascript:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %>
<div style="float: right;">
<%= link_to '导出Excel', school_statistics_xlsx_managements_path(format: :xlsx),
class: 'fl task-btn task-btn-orange mt10 mr20 export-statistic-btn',
onclick: 'exportSchoolStatistic();' %>
</div>
<% end %> <% end %>
</div>
<div class="edu-con-bg01 clearfix mt10 bor-grey-e pt10 pb10">
<div class="pl15">
统计总计:
教师总人数<span class="color-red"><%= @teacher_total %></span>人,
学生总人数<span class="color-red"><%= @student_total %></span>人,
课堂总数<span class="color-red"><%= @course_total %></span>个,
正在进行课堂总数<span class="color-red"><%= @active_course_total %></span>个,
实训作业总数<span class="color-red"><%= @shixun_homework_total %></span>个,
其它作业总数<span class="color-red"><%= @other_homework_total %></span>个,
</div>
</div> </div>
<div class="edu-con-bg01 mt15" id="managements_school_report"> <div class="edu-con-bg01 mt15" id="managements_school_report">
@ -16,4 +35,11 @@
$("#school_report_search_form input[name='keyword']").val(""); $("#school_report_search_form input[name='keyword']").val("");
$('#school_report_search_form').submit(); $('#school_report_search_form').submit();
} }
function exportSchoolStatistic(){
var form = $("#school_report_search_form")
var exportLink = form.find(".export-statistic-btn");
var keyword = form.find("input[name='keyword'").val();
exportLink.attr("href", exportLink.attr("href") + "?keyword=" + keyword);
}
</script> </script>

@ -0,0 +1,20 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "统计总表") do |sheet|
sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 实训作业总数 其它作业总数 动态时间)
total = @schools.count
buffer_size = 500
times = total % 500 > 0 ? total / 500 + 1 : total / 500
times.times do |index|
schools = @schools.limit(buffer_size).offset(index * buffer_size)
schools.each do |school|
sheet.add_row([
school['id'].to_s, school['name'].to_s, school['teacher_count'].to_s, school['student_count'].to_s,
school['course_count'].to_s, school['active_course_count'].to_s, school['homework_count'].to_s,
school['other_homework_count'].to_s, format_time(school['nearly_course_time'])
])
end
end
end

@ -728,6 +728,7 @@ RedmineApp::Application.routes.draw do ## oauth相关
get :school_report, controller: 'managements::schools', action: 'statistics' get :school_report, controller: 'managements::schools', action: 'statistics'
get :school_yesterday_data, controller: 'managements::schools', action: 'yesterday_data' get :school_yesterday_data, controller: 'managements::schools', action: 'yesterday_data'
get :school_data_contrast, controller: 'managements::schools', action: 'data_contrast' get :school_data_contrast, controller: 'managements::schools', action: 'data_contrast'
get :school_statistics_xlsx, controller: 'managements::schools', action: 'statistics_xlsx'
end end
end end
# Enable Grack support # Enable Grack support

Loading…
Cancel
Save