management export school report xlsx add column

dev_trainings
p31729568 6 years ago
parent b76f158df1
commit e1a8372b2b

@ -49,10 +49,10 @@ class Management::SchoolReportService
active_course_map = courses.where(is_end: false).count
shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids })
.group('school_id').count
.where(fork_from: nil).group('school_id').count
evaluate_count_map = Game.joins(challenge: { shixun: { creator: :user_extensions } })
.where(user_extensions: { identity: User::TEACHER, school_id: ids })
.group('school_id').sum(:evaluate_count)
.group('school_id').reorder(nil).sum(:evaluate_count)
schools.map do |school|
{
@ -88,7 +88,7 @@ class Management::SchoolReportService
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
.select("#{base_query_column}, COUNT(*) course_count")
when 'shixun_count' then
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id')
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id AND sx.fork_from IS NULL')
.select("#{base_query_column}, COUNT(*) shixun_count")
when 'shixun_evaluate_count' then
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id')

@ -1,11 +1,12 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: '统计总表') do |sheet|
sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 实训作业总数 其它作业总数 动态时间)
sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 总实训数 实训评测总数 实训作业总数 其它作业总数 动态时间)
@schools.each do |school|
sheet.add_row([
school[:id].to_s, school[:name].to_s, (school[:teacher_count] || 0).to_s, (school[:student_count] || 0).to_s,
(school[:course_count] || 0).to_s, (school[:active_course_count] || 0).to_s, (school[:homework_count] || 0).to_s,
(school[:course_count] || 0).to_s, (school[:active_course_count] || 0).to_s,
(school[:shixun_count] || 0).to_s,(school[:shixun_evaluate_count] || 0).to_s, (school[:homework_count] || 0).to_s,
(school[:other_homework_count] || 0).to_s, format_time(school[:nearly_course_time])
])
end

Loading…
Cancel
Save