dev_partners
cxt 6 years ago
commit 0560d0e2c5

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

@ -467,7 +467,9 @@ class ChallengesController < ApplicationController
render_404
return
else
if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || @shixun.status == -1
logger.info("operable: ##{@shixun.operable?}")
logger.info("@shixun.status: ##{@shixun.status}")
if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || (!@shixun.operable? && !User.current.admin?)
render_403
return
end

@ -9,6 +9,11 @@ class Managements::SchoolsController < Managements::BaseController
schools = Management::SchoolReportService.new(params).call
@schools = paginateHelper schools
respond_to do |format|
format.html { load_statistic_total }
format.js
end
end
def yesterday_data
@ -31,6 +36,13 @@ class Managements::SchoolsController < Managements::BaseController
raise '参数错误'
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
def set_navigation_bar
@menu_type = 1
@ -41,4 +53,13 @@ class Managements::SchoolsController < Managements::BaseController
[I18n.t("school_daily_report.#{column}"), column]
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

@ -202,7 +202,11 @@ class OauthController < ApplicationController
self.logged_user = openi.user if openi.present? && openi.user.present?
original_url = params[:original_url]
if current_user.logged?
redirect_to original_url
else
redirect_to signin_path
end
end
def get_token_callback

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

@ -55,20 +55,27 @@ class Shixun < ActiveRecord::Base
scope :visible, lambda{where(status: [2,3])}
scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier, :test_set_permission, :hide_code, :forbid_copy,
:webssh, :user_id, :code_hidden, :task_pass, :exec_time, :multi_webssh]) }
scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier,
:test_set_permission, :hide_code, :forbid_copy, :hidden, :webssh, :user_id, :code_hidden,
:task_pass, :exec_time, :multi_webssh]) }
scope :published, lambda{where(status: 2)}
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
include ApplicationHelper
has_many :tidings, :as => :container, :dependent => :destroy
scope :visible, -> { where(status: -1) }
#scope :visible, -> { where(status: -1) }
after_create :send_tiding
def should_compile?
self.mirror_repositories.published_main_mirror.first.try(:should_compile)
end
# 可供使用的实训
def operable?
logger.info("####")
self.status != -1 && !self.hidden
end
def is_published?
self.status > 1 ? true : false
end

@ -17,7 +17,8 @@ class GamesService
myshixun = Myshixun.min.find(game.myshixun_id)
shixun = Shixun.min.find(myshixun.shixun_id)
unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher)
unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) ||
current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin?
return{:status => 403}
end
game_challenge = Challenge.min.find(game.challenge_id)

@ -39,7 +39,7 @@ class Management::SchoolReportService
(
SELECT COUNT(*) FROM homework_commons hc
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,
(
SELECT COUNT(*) FROM homework_commons hc

@ -44,10 +44,6 @@
<li><%= link_to "课堂列表", classroom_classment_managements_path %></li>
<li><%= link_to "实训作业", shixun_task_managements_path%></li>
<li><%= link_to "项目列表", project_list_managements_path%></li>
<!-- <li>统计总表</li>-->
<!-- <li>统计总表对比</li>-->
<!-- <li>统计总表日新增</li>-->
</ul>
</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>

@ -35,20 +35,20 @@
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 relative color-red">
+<%= increase %>
</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? %>
<td class="edu-txt-right pr20 right-border" style="position: relative;">
<%= increase %>
</td>
<td class="edu-txt-left pl20"><%= percentage.round(5) %>%</td>
<% 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 %>
</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 %>
</tr>
<% end %>

@ -17,7 +17,7 @@
<tbody>
<% @schools.each_with_index do |school, index| %>
<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 class="edu-txt-left"><%= school['name'] %></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;' %>
<%= 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' %>
<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 %>
</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 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').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>

@ -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_yesterday_data, controller: 'managements::schools', action: 'yesterday_data'
get :school_data_contrast, controller: 'managements::schools', action: 'data_contrast'
get :school_statistics_xlsx, controller: 'managements::schools', action: 'statistics_xlsx'
end
end
# Enable Grack support

Loading…
Cancel
Save