Merge branch 'develop' into educoder

dev_partners
daiao 6 years ago
commit ed26bedad7

@ -62,8 +62,9 @@ gem 'elasticsearch-rails'
gem 'oauth2' gem 'oauth2'
# cronjob # xlsx
gem 'whenever', require: false gem 'axlsx', '3.0.0.pre'
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'

@ -1149,7 +1149,7 @@ class ApplicationController < ActionController::Base
redirect_to authorize_url redirect_to authorize_url
end end
def user_login_and_from_openi def user_login_and_from_openi?
url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer
flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged?
logger.info "----------------------- request referer: #{request.referer} -------------------------" logger.info "----------------------- request referer: #{request.referer} -------------------------"

@ -2,7 +2,7 @@
class ChallengesController < ApplicationController class ChallengesController < ApplicationController
layout "base_shixun" layout "base_shixun"
# 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位 # 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位
# before_filter :handle_openi_request, if: -> { user_login_and_from_openi } before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index]
before_filter :check_authentication, :except => [:index] before_filter :check_authentication, :except => [:index]
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question,
:choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
@ -467,7 +467,9 @@ class ChallengesController < ApplicationController
render_404 render_404
return return
else 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 render_403
return return
end end

@ -44,31 +44,31 @@ class CollegesController < ApplicationController
def statistics def statistics
logger.info("#########################{params}") logger.info("#########################{params}")
@teachers_count = User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE @teachers_count = User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
user_extensions.`school_id` = #{@department.school_id} AND user_extensions.`identity` = 0").first.try(:teacher_count) user_extensions.`school_id` = #{@school.id} AND user_extensions.`identity` = 0").first.try(:teacher_count)
@students_count = User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE @students_count = User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
user_extensions.`school_id` = #{@department.school_id} AND user_extensions.`identity` = 1").first.try(:student_count) user_extensions.`school_id` = #{@school.id} AND user_extensions.`identity` = 1").first.try(:student_count)
# Redo这样做内存会卡死的 # Redo这样做内存会卡死的
# user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@department.school_id}").map(&:id) # user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id)
# Redo是否直接使用count会更好 # Redo是否直接使用count会更好
all_course_ids = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.school_id = #{@department.school_id}") all_course_ids = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.school_id = #{@school.id}")
@courses_count = all_course_ids.size @courses_count = all_course_ids.size
# Redo对于量比较大的尽量不使用笛卡尔积 # Redo对于量比较大的尽量不使用笛卡尔积
# @shixuns_count = Shixun.where(:status => [2, 3], :user_id => user_ids).size # @shixuns_count = Shixun.where(:status => [2, 3], :user_id => user_ids).size
@shixuns_count = Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and s.status in (2, 3) inner join user_extensions ue on @shixuns_count = Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and s.status in (2, 3) inner join user_extensions ue on
u.id=ue.user_id and ue.school_id=#{@department.school_id}").first.try(:shixun_count) u.id=ue.user_id and ue.school_id=#{@school.id}").first.try(:shixun_count)
# @shixun_time_sum = (Game.where(:user_id => user_ids).pluck(:cost_time).sum / (24*60*60.0)).ceil # @shixun_time_sum = (Game.where(:user_id => user_ids).pluck(:cost_time).sum / (24*60*60.0)).ceil
@shixun_time_sum = (Game.find_by_sql("select sum(g.cost_time) cost_time from users u RIGHT join games g on u.id=g.user_id inner join user_extensions ue on @shixun_time_sum = (Game.find_by_sql("select sum(g.cost_time) cost_time from users u RIGHT join games g on u.id=g.user_id inner join user_extensions ue on
u.id=ue.user_id and ue.school_id=#{@department.school_id}").first.try(:cost_time).to_i / (24 * 60 * 60.0)).ceil u.id=ue.user_id and ue.school_id=#{@school.id}").first.try(:cost_time).to_i / (24 * 60 * 60.0)).ceil
# select count(sw.id) from users u left join student_works sw on u.id=sw.user_id and sw.myshixun_id is not null and sw.work_status !=0 inner join user_extensions ue on u.id=ue.user_id and ue.school_id=117 ; # select count(sw.id) from users u left join student_works sw on u.id=sw.user_id and sw.myshixun_id is not null and sw.work_status !=0 inner join user_extensions ue on u.id=ue.user_id and ue.school_id=117 ;
# @shixun_report_count = StudentWork.where("work_status != 0 and user_id in (#{user_ids.join(',').strip == "" ? -1 : user_ids.join(',')}) and myshixun_id is not null").count # @shixun_report_count = StudentWork.where("work_status != 0 and user_id in (#{user_ids.join(',').strip == "" ? -1 : user_ids.join(',')}) and myshixun_id is not null").count
@shixun_report_count = StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in (SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id WHERE @shixun_report_count = StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in (SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
user_extensions.`school_id`=#{@department.school_id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count) user_extensions.`school_id`=#{@school.id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count)
@teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count, @teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count,
(SELECT count(c.id) FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=users.id AND c.is_delete = 0) as course_count (SELECT count(c.id) FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=users.id AND c.is_delete = 0) as course_count
FROM `users`, user_extensions ue where users.id=ue.user_id and ue.identity=0 and ue.school_id=#{@department.school_id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") FROM `users`, user_extensions ue where users.id=ue.user_id and ue.identity=0 and ue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10")
# ).order("publish_shixun_count desc, experience desc").limit(10) # ).order("publish_shixun_count desc, experience desc").limit(10)
@teachers = @teachers =
@teachers.map do |teacher| @teachers.map do |teacher|
@ -131,7 +131,7 @@ class CollegesController < ApplicationController
(select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count, (select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count,
c.tea_id, c.name, c.is_end, c.tea_id, c.name, c.is_end,
(SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time (SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time
FROM `courses` c WHERE (c.school_id = #{@department.school_id} and c.is_delete = 0)") FROM `courses` c WHERE (c.school_id = #{@school.id} and c.is_delete = 0)")
@courses.each do |course| @courses.each do |course|
course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join
@ -157,11 +157,11 @@ class CollegesController < ApplicationController
# 学生实训 # 学生实训
def student_shixun def student_shixun
user_ids = User.find_by_sql("SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@department.school_id}").map(&:id) user_ids = User.find_by_sql("SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@school.id}").map(&:id)
@students = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, users.grade, @students = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, users.grade,
users.experience, ue.student_id, (SELECT COUNT(myshixuns.id) FROM `myshixuns` WHERE myshixuns.user_id users.experience, ue.student_id, (SELECT COUNT(myshixuns.id) FROM `myshixuns` WHERE myshixuns.user_id
= users.id AND myshixuns.status = 1 GROUP BY users.id) AS myshixun_count FROM users join user_extensions ue on = users.id AND myshixuns.status = 1 GROUP BY users.id) AS myshixun_count FROM users join user_extensions ue on
users.id = ue.user_id where ue.school_id = #{@department.school_id} AND ue.identity = 1 AND `users`.`type` IN ('User', 'AnonymousUser') ORDER BY experience DESC, myshixun_count DESC LIMIT 10") users.id = ue.user_id where ue.school_id = #{@school.id} AND ue.identity = 1 AND `users`.`type` IN ('User', 'AnonymousUser') ORDER BY experience DESC, myshixun_count DESC LIMIT 10")
## outputs基数过大用inner join有奇效 ## outputs基数过大用inner join有奇效
@shixun_tags = TagRepertoire.find_by_sql(%Q{ @shixun_tags = TagRepertoire.find_by_sql(%Q{
@ -172,7 +172,7 @@ class CollegesController < ApplicationController
AND str.shixun_id = myshixuns.`shixun_id` AND str.shixun_id = myshixuns.`shixun_id`
AND myshixuns.id = games.`myshixun_id` AND myshixuns.id = games.`myshixun_id`
AND myshixuns.`user_id` IN ( AND myshixuns.`user_id` IN (
SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@department.school_id} SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@school.id}
) )
) a on a.id = outputs.game_id and outputs.`test_set_position` = 1 group by trid ) a on a.id = outputs.game_id and outputs.`test_set_position` = 1 group by trid
ORDER BY test_count DESC ORDER BY test_count DESC
@ -197,50 +197,50 @@ class CollegesController < ApplicationController
@eval_data = [] @eval_data = []
case @index case @index
when "day" when "day"
same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i
last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 1.day).beginning_of_day}' AND outputs.created_at < '#{(end_day - 1.day).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 1.day).beginning_of_day}' AND outputs.created_at < '#{(end_day - 1.day).end_of_day}'").first.try(:count).to_i
@time_range = "#{end_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" @time_range = "#{end_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}"
@time_data = ["2:00", "4:00", "6:00", "8:00", "10:00", "12:00", "14:00", "16:00", "18:00", "20:00", "22:00", "24:00"] @time_data = ["2:00", "4:00", "6:00", "8:00", "10:00", "12:00", "14:00", "16:00", "18:00", "20:00", "22:00", "24:00"]
for i in 0..11 for i in 0..11
@eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{end_day.beginning_of_day + (i * 2).hour}' AND outputs.created_at < '#{end_day.beginning_of_day + ((i + 1) * 2).hour}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{end_day.beginning_of_day + (i * 2).hour}' AND outputs.created_at < '#{end_day.beginning_of_day + ((i + 1) * 2).hour}'").first.try(:count).to_i
end end
when "week" when "week"
start_day = end_day - 6.days start_day = end_day - 6.days
same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i
last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 7.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 7.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 7.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 7.days).end_of_day}'").first.try(:count).to_i
@time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}"
for i in 0..6 for i in 0..6
@time_data << (start_day + i.days).strftime("%m.%d") @time_data << (start_day + i.days).strftime("%m.%d")
@eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i
end end
when "mon" when "mon"
start_day = end_day - 30.days start_day = end_day - 30.days
same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i
last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 30.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 30.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 30.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 30.days).end_of_day}'").first.try(:count).to_i
@time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}"
for i in 0..9 for i in 0..9
@time_data << (start_day + (3 * i).days).strftime("%m.%d") @time_data << (start_day + (3 * i).days).strftime("%m.%d")
@eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + (3 * i).days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (3 * (i + 1)).days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + (3 * i).days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (3 * (i + 1)).days).end_of_day}'").first.try(:count).to_i
end end
when "year" when "year"
start_day = end_day - 365.days start_day = end_day - 365.days
same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i
last_count = same_count last_count = same_count
@time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}"
for i in 0..11 for i in 0..11
@time_data << (start_day + i.month).strftime("%m.%d") @time_data << (start_day + i.month).strftime("%m.%d")
@eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i
end end
end end
@ -248,9 +248,9 @@ class CollegesController < ApplicationController
@same_rate = (@new_count == 0 || same_count == 0) ? 0 : (@new_count * 1.0 / same_count - 1).to_f @same_rate = (@new_count == 0 || same_count == 0) ? 0 : (@new_count * 1.0 / same_count - 1).to_f
@last_rate = (@new_count == 0 || last_count == 0) ? 0 : (@new_count * 1.0 / last_count - 1).to_f @last_rate = (@new_count == 0 || last_count == 0) ? 0 : (@new_count * 1.0 / last_count - 1).to_f
@total_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @total_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 ").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 ").first.try(:count).to_i
@trend_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b @trend_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{Time.now - 7.days}'").first.try(:count).to_i ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{Time.now - 7.days}'").first.try(:count).to_i
end end
@ -259,9 +259,9 @@ class CollegesController < ApplicationController
def manager_auth def manager_auth
# unless (User.current.admin? || DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?) # unless (User.current.admin? || DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?)
unless (User.current.admin? || User.current.business? || unless (User.current.admin? || User.current.business? ||
DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present? || (@department.present? && DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?) ||
(User.current.user_extensions.try(:school_id) == @department.school_id && User.current.user_extensions.try(:identity) == 0) || (User.current.user_extensions.try(:school_id) == @school.id && User.current.user_extensions.try(:identity) == 0) ||
(@department.school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@department.school.try(:customer_id)))) (@school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@school.try(:customer_id))))
render_403 render_403
end end
end end
@ -270,6 +270,8 @@ class CollegesController < ApplicationController
@department = Department.find_by_identifier(params[:id]) @department = Department.find_by_identifier(params[:id])
if @department.present? if @department.present?
@school = @department.school @school = @department.school
else
@school = School.find_by_id(params[:id])
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404

@ -9,15 +9,24 @@ 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 data_grow
@sub_type = 2 @sub_type = 2
params[:data_type] ||= 'grow'
params[:sort_by] ||= :teacher_increase_count params[:sort_by] ||= :teacher_increase_count
params[:sort_direction] ||= :desc params[:sort_direction] ||= :desc
reports = Management::SchoolYesterdayDataService.new(params).call service = Management::SchoolDataGrowService.new(params)
@reports = paginateHelper reports @grow_summary = service.grow_summary
@obj_count, @reports = service.call
@obj_pages = Paginator.new(@obj_count, Management::SchoolDataGrowService::PAGE_SIZE, params[:page])
end end
def data_contrast def data_contrast
@ -25,12 +34,25 @@ class Managements::SchoolsController < Managements::BaseController
params[:sort_direction] ||= :desc params[:sort_direction] ||= :desc
params[:sort_by] ||= :percentage params[:sort_by] ||= :percentage
# 无对比日期时直接返回无数据页面
if useless_contrast_date_parameter?
@obj_count, @reports = 0, []
return
end
@obj_count, @reports = Management::SchoolDataContrastService.new(params).call @obj_count, @reports = Management::SchoolDataContrastService.new(params).call
@obj_pages = Paginator.new(@obj_count, Management::SchoolDataContrastService::PAGE_SIZE, params[:page]) @obj_pages = Paginator.new(@obj_count, Management::SchoolDataContrastService::PAGE_SIZE, params[:page])
rescue Management::SchoolDataContrastService::ParameterError rescue Management::SchoolDataContrastService::ParameterError
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 +63,18 @@ class Managements::SchoolsController < Managements::BaseController
[I18n.t("school_daily_report.#{column}"), column] [I18n.t("school_daily_report.#{column}"), column]
end end
end end
def useless_contrast_date_parameter?
params[:begin_date].blank? && params[:end_date].blank? &&
params[:other_begin_date].blank? &&params[:other_end_date].blank?
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

@ -1416,7 +1416,8 @@ end
def update_depart_identifier def update_depart_identifier
if params[:depart] && params[:identifier] if params[:depart] && params[:identifier]
@department = Department.where(:id => params[:depart]).first @department = Department.where(:id => params[:depart]).first
@department.update_attributes(:identifier => params[:identifier]) if @department.present? identifier = params[:identifier].strip.blank? ? nil : params[:identifier].strip
@department.update_attributes(:identifier => identifier) if @department.present?
end end
end end

@ -154,9 +154,9 @@ class OauthController < ApplicationController
####--Start-- 获取Openi的授权码access_token以及用户信息。为在openi登录的用户创建相关的educoder用户 #### ####--Start-- 获取Openi的授权码access_token以及用户信息。为在openi登录的用户创建相关的educoder用户 ####
IDENTITY_SITE = Redmine::Configuration['openi_domain'] IDENTITY_SITE = Redmine::Configuration['openi_domain']
ROOT_URL = Redmine::Configuration['educoder_domain'] ROOT_URL = Redmine::Configuration['educoder_domain']
DEFAULT_PASSWORD = "a12345678" DEFAULT_PASSWORD = 'a12345678'.freeze
TOKEN_CALL_BACK = "/oauth/get_token_callback" TOKEN_CALL_BACK = '/oauth/get_token_callback'.freeze
USER_INFO = "/oauth/userinfo" USER_INFO = '/oauth/userinfo'.freeze
def get_code def get_code
# 从OpenI发过来的回调中获取授权码 # 从OpenI发过来的回调中获取授权码
@ -183,22 +183,29 @@ class OauthController < ApplicationController
openi = Openi.find_by_login(login) openi = Openi.find_by_login(login)
unless openi unless openi
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
# 如果Educoder中已存在与该OpenI用户的邮箱相同的用户则会直接跳转到登录educoder的登录页面
existing_user = User.find_by_mail(email)
break if existing_user.present?
user = User.new(lastname: name, mail: email, mail_notification: email) user = User.new(lastname: name, mail: email, mail_notification: email)
user.login = custom_openi_login(login) user.login = generate_login('m')
user.password = DEFAULT_PASSWORD user.password = DEFAULT_PASSWORD
user.certification = 1
user.save! user.save!
UserExtensions.create!(user_id: user.id, school_id: School.first.id, identity: 4, gender: 0) UserExtensions.create!(user_id: user.id, school_id: School.first.id, identity: 4, gender: 0)
UserDayCertification.create!(user_id: user.id, status: 1)
openi = Openi.create!(user_id: user.id, openi_user_id: openi_user_id, avatar_url: avatar_url, login: login, name: name, email: email) openi = Openi.create!(user_id: user.id, openi_user_id: openi_user_id, avatar_url: avatar_url, login: login, name: name, email: email)
end end
end end
self.logged_user = openi.user self.logged_user = openi.user if openi.present? && openi.user.present?
original_url = params[:original_url] original_url = params[:original_url]
if current_user.logged?
redirect_to original_url redirect_to original_url
else
redirect_to signin_path
end
end end
def get_token_callback def get_token_callback
@ -206,9 +213,10 @@ class OauthController < ApplicationController
####--End-- 获取Openi的授权码access_token以及用户信息。为在openi登录的用户创建相关的educoder用户 #### ####--End-- 获取Openi的授权码access_token以及用户信息。为在openi登录的用户创建相关的educoder用户 ####
private private
# 为了保证新创建的用户用户名不与系统中已存在的用户冲突,加上 _openi 后缀 # 为新创建的用户随机生成以m为前缀的用户名m表示该用户是用邮箱注册
def custom_openi_login(login) def generate_login(login_pre)
login + "_openi" us = UsersService.new
us.generate_user_login(login_pre)
end end
def require_login def require_login

@ -2,8 +2,6 @@
# REDO: 创建版本库权限控制 # REDO: 创建版本库权限控制
class ShixunsController < ApplicationController class ShixunsController < ApplicationController
layout 'base_shixun' layout 'base_shixun'
# 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位
# before_filter :handle_openi_request, if: -> { user_login_and_from_openi }
before_filter :require_login, :except => [:ghook, :download_file, :show, :index] before_filter :require_login, :except => [:ghook, :download_file, :show, :index]
before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index] before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index]
before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss, :shixun_migrate, :qrcode, :download_file, :departments, :get_mirror_script, :send_message_to_administrator] before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss, :shixun_migrate, :qrcode, :download_file, :departments, :get_mirror_script, :send_message_to_administrator]

@ -2,7 +2,7 @@
class SubjectsController < ApplicationController class SubjectsController < ApplicationController
layout 'base_subject' layout 'base_subject'
# 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位 # 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位
# before_filter :handle_openi_request, if: -> { user_login_and_from_openi } before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:show]
before_filter :require_login, :except => [:show, :index] before_filter :require_login, :except => [:show, :index]
before_filter :check_authentication, :except => [:show, :index] before_filter :check_authentication, :except => [:show, :index]
before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course] before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course]

@ -940,7 +940,7 @@ class UsersController < ApplicationController
@limit = 16 @limit = 16
if 1 == @index if 1 == @index
# @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc") # @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc")
@shixuns_result = Shixun.where("name like ? and hidden=0", "%#{@search}%").reorder("myshixuns_count desc") @shixuns_result = Shixun.where("name like ? and hidden=0 and status != -1", "%#{@search}%").reorder("myshixuns_count desc")
@shixuns_result_count = @shixuns_result.count @shixuns_result_count = @shixuns_result.count
@shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1 @shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1
@offset ||= @shixun_pages.offset @offset ||= @shixun_pages.offset

@ -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

@ -64,7 +64,7 @@ class School < ActiveRecord::Base
def statistic_url def statistic_url
dep = departments.where("identifier is not null").first dep = departments.where("identifier is not null").first
url = dep.present? ? "/colleges/#{dep.identifier}/statistics" : "" url = dep.present? && !dep.identifier.blank? ? "/colleges/#{dep.identifier}/statistics" : "/colleges/#{self.id}/statistics"
end end
def course_act_time def course_act_time

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

@ -17,7 +17,8 @@ class GamesService
myshixun = Myshixun.min.find(game.myshixun_id) myshixun = Myshixun.min.find(game.myshixun_id)
shixun = Shixun.min.find(myshixun.shixun_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} return{:status => 403}
end end
game_challenge = Challenge.min.find(game.challenge_id) game_challenge = Challenge.min.find(game.challenge_id)

@ -0,0 +1,81 @@
class Management::SchoolDataGrowService
include CustomSortable
PAGE_SIZE = 20
attr_reader :params
sort_columns :teacher_increase_count, :student_increase_count,
:course_increase_count, :shixun_increase_count, :active_user_count,
default_by: :teacher_increase_count, default_direction: :desc
def initialize(params)
@params = params
end
def call
reports = query_reports.group(:school_id)
count = reports.count.count
reports = reports.select(
'school_id, school_name,'\
'SUM(teacher_increase_count) teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\
'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(active_user_count) active_user_count'
)
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
reports = reports.limit(PAGE_SIZE).offset(offset)
[count, reports]
end
def grow_summary
@_grow_summary ||= begin
query_reports.select(
'SUM(teacher_increase_count) teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\
'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(active_user_count) active_user_count'
).first
end
end
private
def query_reports
reports = SchoolDailyReport.where(date: query_date)
keyword = params[:keyword].try(:to_s).try(:strip)
if keyword.present?
reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%")
end
reports
end
def query_date
if params[:grow_begin_date].present?
begin_time = Time.zone.parse(params[:grow_begin_date])
end_date = if params[:grow_end_date].present?
Time.zone.parse(params[:grow_end_date])
end
end_date.blank? || end_date == begin_time ? begin_time : begin_time..end_date
else
yesterday
end
end
def yesterday
# 每日凌晨5点为节点, 25日凌晨4点、3点、2点等等未到更新数据时间点看到的数据是23日-24日的统计数据
(Time.zone.now - 5.hours).beginning_of_day - 1.days
end
def offset
(params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * PAGE_SIZE
end
end

@ -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

@ -1,32 +0,0 @@
class Management::SchoolYesterdayDataService
include CustomSortable
attr_reader :params
sort_columns :student_increase_count, :teacher_increase_count,
:course_increase_count, :shixun_increase_count, :active_user_count,
default_by: :teacher_increase_count, default_direction: :desc
def initialize(params)
@params = params
end
def call
reports = SchoolDailyReport.where(date: yesterday)
keyword = params[:keyword].try(:to_s).try(:strip)
if keyword.present?
reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%")
end
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
reports
end
private
def yesterday
# 每日凌晨5点为节点, 25日凌晨4点、3点、2点等等未到更新数据时间点看到的数据是23日-24日的统计数据
(Time.zone.now - 5.hours).beginning_of_day - 1.days
end
end

@ -30,10 +30,10 @@
<input type="text" class="winput-240-30 edu-txt-center" value="<%= @time_range %>" id="time-condition" readonly/> <input type="text" class="winput-240-30 edu-txt-center" value="<%= @time_range %>" id="time-condition" readonly/>
</li> </li>
<li class="fr count_student_test"> <li class="fr count_student_test">
<a href="<%= student_eval_college_path(@department, :index => 'day') %>" data-remote="true" class="<%= @index == "day" ? "active" : "" %>">日</a> <a href="<%= student_eval_college_path(@school, :index => 'day') %>" data-remote="true" class="<%= @index == "day" ? "active" : "" %>">日</a>
<a href="<%= student_eval_college_path(@department, :index => 'week') %>" data-remote="true" class="<%= @index == "week" ? "active" : "" %>">周</a> <a href="<%= student_eval_college_path(@school, :index => 'week') %>" data-remote="true" class="<%= @index == "week" ? "active" : "" %>">周</a>
<a href="<%= student_eval_college_path(@department, :index => 'mon') %>" data-remote="true" class="<%= @index == "mon" ? "active" : "" %>">月</a> <a href="<%= student_eval_college_path(@school, :index => 'mon') %>" data-remote="true" class="<%= @index == "mon" ? "active" : "" %>">月</a>
<a href="<%= student_eval_college_path(@department, :index => 'year') %>" data-remote="true" class="<%= @index == "year" ? "active" : "" %>">年</a> <a href="<%= student_eval_college_path(@school, :index => 'year') %>" data-remote="true" class="<%= @index == "year" ? "active" : "" %>">年</a>
</li> </li>
</div> </div>
<div id="studentTestCount" style="width: 1200px;height: 440px;"></div> <div id="studentTestCount" style="width: 1200px;height: 440px;"></div>

@ -44,15 +44,15 @@
<li><span><%= @shixuns_count %></span>个</li> <li><span><%= @shixuns_count %></span>个</li>
<li><span><%= @shixun_report_count %></span>个</li> <li><span><%= @shixun_report_count %></span>个</li>
<li><span data-tip-down="所有学员的实训耗时之和"><span><%= @shixun_time_sum %></span>天</span></li> <li><span data-tip-down="所有学员的实训耗时之和"><span><%= @shixun_time_sum %></span>天</span></li>
<li><span><%= @department.host_count.to_i %></span>台</li> <li><span><%= @department.present? ? @department.host_count.to_i : @school.departments.first.try(:host_count).to_i %></span>台</li>
</div> </div>
</div> </div>
<div class="white-panel mb20 pl0 clearfix"> <div class="white-panel mb20 pl0 clearfix">
<li class="active" index="1"><a href="javascript:void(0);">课堂</a></li> <li class="active" index="1"><a href="javascript:void(0);">课堂</a></li>
<li index="2"><a href="<%= student_shixun_college_path(@department) %>" data-remote="true">学生实训</a></li> <li index="2"><a href="<%= student_shixun_college_path(@school) %>" data-remote="true">学生实训</a></li>
<!--<li><a href="<%#= engineering_capability_college_path(@department) %>" data-remote="true">工程能力</a></li>--> <!--<li><a href="<%#= engineering_capability_college_path(@department) %>" data-remote="true">工程能力</a></li>-->
<li index="4"><a href="<%= student_eval_college_path(@department) %>" data-remote="true">学生测评</a></li> <li index="4"><a href="<%= student_eval_college_path(@school) %>" data-remote="true">学生测评</a></li>
</div> </div>
<div class="panelContent panelContent-1"> <div class="panelContent panelContent-1">
@ -153,7 +153,7 @@
}) })
}); });
$.get('<%= course_statistics_college_path(@department) %>'); $.get('<%= course_statistics_college_path(@school) %>');
$(".count_student_test a").click(function(){ $(".count_student_test a").click(function(){
$(".count_student_test a").removeClass("active"); $(".count_student_test a").removeClass("active");

@ -35,7 +35,7 @@
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 1 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">学校+</a> <li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 1 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">学校+</a>
<ul class="edu-admin-nav-inner edu-absolute"> <ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to '统计总表', school_report_managements_path %></li> <li><%= link_to '统计总表', school_report_managements_path %></li>
<li><%= link_to '数据变化报表', school_yesterday_data_managements_path %></li> <li><%= link_to '数据变化报表', school_data_grow_managements_path %></li>
</ul> </ul>
</li> </li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 2 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">课堂+</a> <li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 2 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">课堂+</a>
@ -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>

@ -17,7 +17,7 @@
</li> </li>
<li class="clearfix mb5"> <li class="clearfix mb5">
<% if !user.try(:user_extensions).school_id.blank? && user.try(:user_extensions).try(:school) %> <% if !user.try(:user_extensions).school_id.blank? && user.try(:user_extensions).try(:school) %>
<span><%= user.try(:user_extensions).school.name %><%= user.try(:user_extensions).department ? ' - '+user.try(:user_extensions).department.name.to_s : '' %></span> <a href="<%= user.try(:user_extensions).school.statistic_url %>" target="_blank" class="color-blue"><%= user.try(:user_extensions).school.name %><%= user.try(:user_extensions).department ? ' - '+user.try(:user_extensions).department.name.to_s : '' %></a>
<% end %> <% end %>
<% if user.try(:user_extensions) && user.try(:user_extensions).identity %> <% if user.try(:user_extensions) && user.try(:user_extensions).identity %>
<span class="ml30"><%= user.identity %></span> <span class="ml30"><%= user.identity %></span>

@ -1,26 +1,37 @@
<form class="management-school-data-form"> <form class="management-school-data-form">
<div style="float: left; margin: 10px 10px 10px 25px;"> <div style="float: left; margin: 10px 10px 10px 25px;">
<!-- 数据对比 -->
<%= hidden_field_tag :contrast_column, params[:contrast_column] %> <%= hidden_field_tag :contrast_column, params[:contrast_column] %>
<%= hidden_field_tag :begin_date, params[:begin_date] %> <%= hidden_field_tag :begin_date, params[:begin_date] %>
<%= hidden_field_tag :end_date, params[:end_date] %> <%= hidden_field_tag :end_date, params[:end_date] %>
<%= hidden_field_tag :other_begin_date, params[:other_begin_date] %> <%= hidden_field_tag :other_begin_date, params[:other_begin_date] %>
<%= hidden_field_tag :other_end_date, params[:other_end_date] %> <%= hidden_field_tag :other_end_date, params[:other_end_date] %>
<!-- 新增数据 -->
<%= hidden_field_tag :grow_begin_date, params[:grow_begin_date] %>
<%= hidden_field_tag :grow_end_date, params[:grow_end_date] %>
<div class="grow-date-container" style="width: 450px;display: <%= params[:data_type] == 'grow' ? 'block' : 'none' %>">
<%= text_field_tag :grow_date_input, params[:grow_date_input],
class: 'grow-date-input winput-220-30', placeholder: '请选择时间段',
style: 'width: 400px;' %>
</div>
<div class="contrast-date-container" style="width: 450px;display: <%= params[:data_type] == 'contrast' ? 'block' : 'none' %>">
<%= text_field_tag :date_input, params[:date_input], <%= text_field_tag :date_input, params[:date_input],
class: 'date-input winput-200-30', placeholder: '请选择时间段一' %> class: 'date-input winput-200-30', placeholder: '请选择时间段一' %>
<span>VS</span> <span>VS</span>
<%= text_field_tag :other_date_input, params[:other_date_input], <%= text_field_tag :other_date_input, params[:other_date_input],
class: 'other-date-input winput-200-30', placeholder: '请选择时间段二' %> class: 'other-date-input winput-200-30', placeholder: '请选择时间段二' %>
</div> </div>
</div>
<div style="float: left;"> <div style="float: left;">
<%= hidden_field_tag :data_type, params[:data_type] || 'yesterday' %> <%= hidden_field_tag :data_type, params[:data_type] || 'grow' %>
<% if params[:data_type] == 'contrast' %> <% if params[:data_type] == 'contrast' %>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn task-btn-orange">时间对比</a> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn task-btn-orange">时间对比</a>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 yesterday-btn">日新增</a> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 grow-btn">新增数据</a>
<% else %> <% else %>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn">时间对比</a> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn">时间对比</a>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 yesterday-btn task-btn-orange">日新增</a> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 grow-btn task-btn-orange">新增数据</a>
<% end %> <% end %>
</div> </div>
@ -31,28 +42,36 @@
</form> </form>
<script> <script>
$(function(){ $(function(){
var yesterdayFormUrl = "<%= school_yesterday_data_managements_path %>"; var growFormUrl = "<%= school_data_grow_managements_path %>";
var contrastFormUrl = "<%= school_data_contrast_managements_path %>"; var contrastFormUrl = "<%= school_data_contrast_managements_path %>";
var searchForm = $(".management-school-data-form"); var searchForm = $(".management-school-data-form");
var dataTypeInput = searchForm.find("input[name='data_type']"); var dataTypeInput = searchForm.find("input[name='data_type']");
var keywordInput = searchForm.find("input[name='keyword']"); var keywordInput = searchForm.find("input[name='keyword']");
var contrastBtn = searchForm.find(".contrast-btn"); var contrastBtn = searchForm.find(".contrast-btn");
var yesterdayBtn = searchForm.find(".yesterday-btn"); var growBtn = searchForm.find(".grow-btn");
var contrastDateContainer = searchForm.find('.contrast-date-container');
var growDateContainer = searchForm.find('.grow-date-container');
// 数据对比日期输入框
var beginDateInput = searchForm.find("input[name='begin_date']"); var beginDateInput = searchForm.find("input[name='begin_date']");
var endDateInput = searchForm.find("input[name='end_date']"); var endDateInput = searchForm.find("input[name='end_date']");
var otherBeginDateInput = searchForm.find("input[name='other_begin_date']"); var otherBeginDateInput = searchForm.find("input[name='other_begin_date']");
var otherEndDateInput = searchForm.find("input[name='other_end_date']"); var otherEndDateInput = searchForm.find("input[name='other_end_date']");
// 数据展示切换: 数据对比、日新增 // 新增数据日期输入框
var growBeginDateInput = searchForm.find("input[name='grow_begin_date']");
var growEndDateInput = searchForm.find("input[name='grow_end_date']");
// 数据展示切换: 数据对比、新增数据
searchForm.on('click', ".contrast-btn", function(){ searchForm.on('click', ".contrast-btn", function(){
if(contrastBtn.hasClass("task-btn-orange")) { return } if(contrastBtn.hasClass("task-btn-orange")) { return }
changeDataType("contrast"); changeDataType("contrast");
submitForm();
}); });
searchForm.on('click', ".yesterday-btn", function(){ searchForm.on('click', ".grow-btn", function(){
if(yesterdayBtn.hasClass("task-btn-orange")) { return } if(growBtn.hasClass("task-btn-orange")) { return }
changeDataType("yesterday"); changeDataType("grow");
submitForm(); submitForm();
}); });
@ -74,7 +93,7 @@
if(!validateFrom()) { return } if(!validateFrom()) { return }
var form = searchForm; var form = searchForm;
var url = dataTypeInput.val() == "contrast" ? contrastFormUrl : yesterdayFormUrl; var url = dataTypeInput.val() == "contrast" ? contrastFormUrl : growFormUrl;
$.ajax({ $.ajax({
url: url, url: url,
@ -86,12 +105,18 @@
var validateFrom = function(){ var validateFrom = function(){
if (dataTypeInput.val() != "contrast") { return true; } if (dataTypeInput.val() != "contrast") { return true; }
if (beginDateInput.val() == "" || endDateInput.val() == "" || // 全部为空时,需要展示空数据页
otherBeginDateInput.val() == "" || otherBeginDateInput.val() == "") { if (beginDateInput.val() == "" && endDateInput.val() == "" &&
return false; otherBeginDateInput.val() == "" && otherBeginDateInput.val() == "") {
return true;
} }
if (beginDateInput.val() != "" && endDateInput.val() != "" &&
otherBeginDateInput.val() != "" && otherBeginDateInput.val() != "") {
return true; return true;
}
return false;
}; };
var changeDataType = function(dataType){ var changeDataType = function(dataType){
@ -99,17 +124,29 @@
if (dataType == "contrast") { if (dataType == "contrast") {
contrastBtn.addClass("task-btn-orange"); contrastBtn.addClass("task-btn-orange");
yesterdayBtn.removeClass("task-btn-orange"); growBtn.removeClass("task-btn-orange");
dataTypeInput.val('contrast'); dataTypeInput.val('contrast');
growDateContainer.hide();
contrastDateContainer.show();
clearGrowDateInput();
} else { } else {
contrastBtn.removeClass("task-btn-orange"); contrastBtn.removeClass("task-btn-orange");
yesterdayBtn.addClass("task-btn-orange"); growBtn.addClass("task-btn-orange");
dataTypeInput.val('yesterday'); dataTypeInput.val('grow');
growDateContainer.show();
contrastDateContainer.hide();
clearContrastDateInput(); clearContrastDateInput();
} }
}; };
var clearGrowDateInput = function() {
searchForm.find("input[name='grow_begin_date']").val('');
searchForm.find("input[name='grow_end_date']").val('');
searchForm.find("input[name='grow_date_input']").val('');
};
var clearContrastDateInput = function(){ var clearContrastDateInput = function(){
searchForm.find("input[name='begin_date']").val(''); searchForm.find("input[name='begin_date']").val('');
searchForm.find("input[name='end_date']").val(''); searchForm.find("input[name='end_date']").val('');
@ -152,10 +189,13 @@
isRTL: false isRTL: false
}; };
var options = { var baseOptions = {
dateFormat: 'yy-mm-dd', dateFormat: 'yy-mm-dd',
minDate: new Date('2017-04-01'), minDate: new Date('2017-04-01'),
maxDate: -1, maxDate: -1
}
var contrastDateOptions = {
onSelect: function(selectedDate) { onSelect: function(selectedDate) {
if(!$(this).data().datepicker.first){ if(!$(this).data().datepicker.first){
$(this).data().datepicker.inline = true; $(this).data().datepicker.inline = true;
@ -192,9 +232,6 @@
// 展示所选时间 // 展示所选时间
$(this).val(begin_date + " 至 " + end_date); $(this).val(begin_date + " 至 " + end_date);
$(this).data().datepicker.inline = false; $(this).data().datepicker.inline = false;
// 切换数据类型
changeDataType("contrast");
} }
}, },
onClose:function(){ onClose:function(){
@ -216,8 +253,53 @@
submitForm(); submitForm();
} }
}; };
options = $.extend({}, locale, options); contrastDateOptions = $.extend({}, locale, baseOptions, contrastDateOptions);
searchForm.find(".date-input").datepicker(options); searchForm.find(".date-input").datepicker(contrastDateOptions);
searchForm.find(".other-date-input").datepicker(options); searchForm.find(".other-date-input").datepicker(contrastDateOptions);
var growOptions = {
onSelect: function(selectedDate) {
if(!$(this).data().datepicker.first){
$(this).data().datepicker.inline = true;
$(this).data().datepicker.first = selectedDate;
growBeginDateInput.val("");
growEndDateInput.val("");
}else{
// 计算时间先后顺序
var begin_date = null;
var end_date = null;
if(selectedDate > $(this).data().datepicker.first){
begin_date = $(this).data().datepicker.first;
end_date = selectedDate;
}else{
begin_date = selectedDate;
end_date = $(this).data().datepicker.first;
}
growBeginDateInput.val(begin_date);
growEndDateInput.val(end_date);
// 展示所选时间
$(this).val(begin_date + " 至 " + end_date);
$(this).data().datepicker.inline = false;
}
},
onClose:function(){
var date = $(this).data().datepicker.first;
if (date && growBeginDateInput.val() == '') {
growBeginDateInput.val(date);
growEndDateInput.val(date);
}
delete $(this).data().datepicker.first;
$(this).data().datepicker.inline = false;
submitForm();
}
};
growOptions = $.extend({}, locale, baseOptions, growOptions)
searchForm.find(".grow-date-input").datepicker(growOptions);
}); });
</script> </script>

@ -6,8 +6,15 @@
options_for_select(@select_options, params[:contrast_column]), options_for_select(@select_options, params[:contrast_column]),
class: 'fl task-height-30 contrast-column-select', class: 'fl task-height-30 contrast-column-select',
style: 'position: absolute; right: 30px; top: 15px;' %> style: 'position: absolute; right: 30px; top: 15px;' %>
<% if @obj_count.nonzero? %>
<div style="position: absolute; left: 20px; bottom: 0; font-size: 12px;">
说明:新增数=时段二-时段一;新增百分比=(新增数/时段一)*100%(保留小数点后五位)
</div>
<% end %>
</div> </div>
<% if @obj_count.nonzero? %>
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed"> <table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
<thead> <thead>
<tr> <tr>
@ -35,20 +42,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 %>
@ -63,6 +70,11 @@
<div class="cl"></div> <div class="cl"></div>
</div> </div>
</div> </div>
<% else %>
<div style="padding-top: 150px; height: 250px; text-align: center; color: grey; font-size: 14px;">
暂无数据,请选择时间段对比
</div>
<% end %>
<style> <style>
.right-border::after { .right-border::after {
position: absolute; position: absolute;

@ -1,3 +1,16 @@
<div style="background-color: #fafafa;">
统计总计:
<% if params[:grow_begin_date].present? %>
<%= params[:grow_date_input] %>
<% else %>
昨日至今日,
<% end %>
新增教师<span class="color-red"><%= @grow_summary.teacher_increase_count || 0 %></span>人,
新增学生<span class="color-red"><%= @grow_summary.student_increase_count || 0 %></span>人,
新增课堂<span class="color-red"><%= @grow_summary.course_increase_count || 0 %></span>个,
新增实训<span class="color-red"><%= @grow_summary.shixun_increase_count || 0 %></span>个,
活跃用户<span class="color-red"><%= @grow_summary.active_user_count || 0 %></span>个
</div>
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed"> <table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
<thead> <thead>
<tr> <tr>
@ -5,11 +18,11 @@
<th width="10%">ID</th> <th width="10%">ID</th>
<th width="24%" class="edu-txt-left">单位名称</th> <th width="24%" class="edu-txt-left">单位名称</th>
<th width="12%"><%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_yesterday_data_managements_path) %></th> <th width="12%"><%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增学生', name: 'student_increase_count', path: school_yesterday_data_managements_path) %></th> <th width="12%"><%= sort_tag('新增学生', name: 'student_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增课堂', name: 'course_increase_count', path: school_yesterday_data_managements_path) %></th> <th width="12%"><%= sort_tag('新增课堂', name: 'course_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_yesterday_data_managements_path) %></th> <th width="12%"><%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('活跃用户', name: 'active_user_count', path: school_yesterday_data_managements_path) %></th> <th width="12%"><%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -30,8 +43,8 @@
<div style="text-align:center;" class="new_expand"> <div style="text-align:center;" class="new_expand">
<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;"> <div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">
<ul id="school_yesterday_data_ref_pages"> <ul id="school_data_grow_ref_pages">
<%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_yesterday_data_managements_path(params.except(:page)) %> <%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_data_grow_managements_path(params.except(:page)) %>
</ul> </ul>
<div class="cl"></div> <div class="cl"></div>
</div> </div>

@ -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>

@ -5,5 +5,5 @@
</div> </div>
<div class="edu-con-bg01 mt15" id="managements-school-data"> <div class="edu-con-bg01 mt15" id="managements-school-data">
<%= render 'managements/schools/yesterday_data_list'%> <%= render 'managements/schools/data_grow_list'%>
</div> </div>

@ -1,2 +1,2 @@
$("#managements-school-data").html("<%= j(render 'managements/schools/yesterday_data_list') %>") $("#managements-school-data").html("<%= j(render 'managements/schools/data_grow_list') %>")
$(".management-school-data-form-box").html("<%= j(render 'managements/schools/contrast_search_form') %>") $(".management-school-data-form-box").html("<%= j(render 'managements/schools/contrast_search_form') %>")

@ -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").split('?')[0] + "?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

@ -726,8 +726,9 @@ RedmineApp::Application.routes.draw do ## oauth相关
delete :delete_partner delete :delete_partner
get :customers_list get :customers_list
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_data_grow, controller: 'managements::schools', action: 'data_grow'
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

@ -1,24 +0,0 @@
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
# command "/usr/bin/some_great_command"
# runner "MyModel.some_method"
# rake "some:great:rake:task"
# end
#
# every 4.days do
# runner "AnotherModel.prune_old_records"
# end
# Learn more: http://github.com/javan/whenever
every 1.days, at: '5:00 am' do
runner 'StatisticSchoolDailyReportTask.new.call'
end

@ -1,6 +1,11 @@
#coding=utf-8 #coding=utf-8
namespace :school_daily_report do namespace :school_daily_report do
desc 'daily statistic school task'
task daily_statistic: :environment do
StatisticSchoolDailyReportTask.new.call
end
desc 'statistic school daily report data before now' desc 'statistic school daily report data before now'
task :statistic, [:date] => :environment do |_, args| task :statistic, [:date] => :environment do |_, args|
date = Time.zone.parse(args[:date]).beginning_of_day date = Time.zone.parse(args[:date]).beginning_of_day

Loading…
Cancel
Save