parent
0f2493e877
commit
372db525bd
@ -0,0 +1,5 @@
|
||||
class Managements::BaseController < ApplicationController
|
||||
layout 'base_management'
|
||||
|
||||
before_filter :require_admin
|
||||
end
|
@ -0,0 +1,20 @@
|
||||
class Managements::SchoolsController < Managements::BaseController
|
||||
before_filter :set_navigation_bar
|
||||
before_filter :set_default_sort_params, only: :statistics
|
||||
|
||||
def statistics
|
||||
@sub_type = 1
|
||||
schools = Management::SchoolReportService.new(params).call
|
||||
@schools = paginateHelper schools
|
||||
end
|
||||
|
||||
private
|
||||
def set_navigation_bar
|
||||
@menu_type = 1
|
||||
end
|
||||
|
||||
def set_default_sort_params
|
||||
params[:sort_by] ||= :teacher_count
|
||||
params[:sort_direction] ||= :desc
|
||||
end
|
||||
end
|
@ -0,0 +1,45 @@
|
||||
module CustomSortable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do |base|
|
||||
base.instance_variable_set("@_sort_options", {})
|
||||
base.instance_variable_set("@_sort_columns", [])
|
||||
base.instance_variable_set("@_sort_directions", %w(asc desc))
|
||||
end
|
||||
|
||||
def custom_sort(relations, sort_by, sort_direction)
|
||||
sort_by ||= self.class.sort_options[:default_by]
|
||||
sort_direction ||= self.class.sort_options[:default_direction]
|
||||
|
||||
return relations unless self.class.check_sort_parameter_validate(sort_by, sort_direction)
|
||||
|
||||
order_method = self.class.sort_options[:reorder] ? :reorder : :order
|
||||
relations.send(order_method, "#{sort_by} #{sort_direction}")
|
||||
end
|
||||
|
||||
def multiple_custom_sort(relations, **opts)
|
||||
opts.each do |sort_by, sort_direction|
|
||||
relations = custom_sort(relations, sort_by, sort_direction)
|
||||
end
|
||||
relations
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def sort_columns(*columns)
|
||||
opts = columns.extract_options!
|
||||
@_sort_options[:default_by] = opts[:default_by].to_s
|
||||
@_sort_options[:default_direction] = opts[:default_direction].to_s
|
||||
@_sort_options[:reorder] = opts[:reorder]
|
||||
|
||||
@_sort_columns = columns.map(&:to_s)
|
||||
end
|
||||
|
||||
def check_sort_parameter_validate(sort_by, sort_direction)
|
||||
(sort_by.blank? || @_sort_columns.include?(sort_by)) && @_sort_directions.include?(sort_direction)
|
||||
end
|
||||
|
||||
def sort_options
|
||||
@_sort_options
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,58 @@
|
||||
class Management::SchoolReportService
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
|
||||
:course_count, :active_course_count, :nearly_course_time,
|
||||
default_by: :teacher_count, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
schools = School.select(select_columns_sql)
|
||||
|
||||
keyword = params[:keyword]&.to_s&.strip
|
||||
if keyword.present?
|
||||
schools = schools.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
schools = custom_sort(schools, params[:sort_by], params[:sort_direction])
|
||||
|
||||
schools
|
||||
end
|
||||
|
||||
private
|
||||
def select_columns_sql
|
||||
<<-SQL
|
||||
schools.id, schools.name,
|
||||
(
|
||||
SELECT COUNT(*) FROM users u
|
||||
LEFT JOIN user_extensions ue ON ue.user_id = u.id
|
||||
LEFT JOIN ec_school_users esu ON esu.user_id = u.id
|
||||
WHERE esu.school_id = schools.id AND ue.identity = #{User::STUDENT}
|
||||
) student_count,
|
||||
(
|
||||
SELECT COUNT(*) FROM users u
|
||||
LEFT JOIN user_extensions ue ON ue.user_id = u.id
|
||||
LEFT JOIN ec_school_users esu ON esu.user_id = u.id
|
||||
WHERE esu.school_id = schools.id AND ue.identity = #{User::TEACHER}
|
||||
) teacher_count,
|
||||
(
|
||||
SELECT COUNT(*) FROM homework_commons hc
|
||||
LEFT JOIN courses ON courses.id = hc.course_id
|
||||
WHERE courses.school_id = schools.id
|
||||
) homework_count,
|
||||
(
|
||||
SELECT COUNT(*) FROM homework_commons hc
|
||||
LEFT JOIN courses ON courses.id = hc.course_id
|
||||
WHERE courses.school_id = schools.id AND hc.homework_type IN (1,3)
|
||||
) other_homework_count,
|
||||
(SELECT COUNT(*) FROM courses cs WHERE cs.school_id = schools.id) course_count ,
|
||||
(SELECT MAX(cs.updated_at) FROM courses cs WHERE cs.school_id = schools.id) nearly_course_time ,
|
||||
(SELECT COUNT(*) FROM courses acs WHERE acs.school_id = schools.id AND acs.is_end = false) active_course_count
|
||||
SQL
|
||||
end
|
||||
end
|
@ -0,0 +1,43 @@
|
||||
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="6%">序号</th>
|
||||
<th width="6%">ID</th>
|
||||
<th width="14%" class="edu-txt-left">单位名称</th>
|
||||
|
||||
<th width="10%"><%= sort_tag('教师总人数', name: 'teacher_count', path: school_report_managements_path) %></th>
|
||||
<th width="10%"><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %></th>
|
||||
<th width="10%"><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %></th>
|
||||
<th width="10%"><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %></th>
|
||||
<th width="10%"><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %></th>
|
||||
<th width="10%"><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %></th>
|
||||
<th width="14%"><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @schools.as_json.each_with_index do |data, index| %>
|
||||
<tr>
|
||||
<% school = data["school"] %>
|
||||
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
|
||||
<td><%= school['id'] %></td>
|
||||
<td class="edu-txt-left"><%= school['name'] %></td>
|
||||
<td><%= school['teacher_count'] %></td>
|
||||
<td><%= school['student_count'] %></td>
|
||||
<td><%= school['course_count'] %></td>
|
||||
<td><%= school['active_course_count'] %></td>
|
||||
<td><%= school['homework_count'] %></td>
|
||||
<td><%= school['other_homework_count'] %></td>
|
||||
<td><%= format_time school['nearly_course_time'] %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div style="text-align:center;" class="new_expand">
|
||||
<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">
|
||||
<ul id="school_report_ref_pages">
|
||||
<%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_report_managements_path(params.except(:page)) %>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,19 @@
|
||||
<div class="edu-con-top clearfix xmt10 bor-grey-e mt10">
|
||||
<%= form_tag(school_report_managements_path(params), method: :get, remote: true, id: 'school_report_search_form') do %>
|
||||
<%= text_field_tag :keyword, params[:keyword], placeholder: '请输入单位名称或者ID关键字进行搜索',
|
||||
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:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="edu-con-bg01 mt15" id="managements_school_report">
|
||||
<%= render 'managements/schools/statistics_list'%>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function clearSearchCondition(){
|
||||
$("#school_report_search_form input[name='keyword']").val("");
|
||||
$('#school_report_search_form').submit();
|
||||
}
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
$("#managements_school_report").html("<%= j(render 'managements/schools/statistics_list') %>")
|
Loading…
Reference in new issue