parent
c90f648219
commit
4ebe247633
@ -0,0 +1,3 @@
|
|||||||
|
class SchoolReport < ActiveRecord::Base
|
||||||
|
belongs_to :school
|
||||||
|
end
|
@ -0,0 +1,20 @@
|
|||||||
|
class StatisticSchoolReportTask
|
||||||
|
def call
|
||||||
|
School.find_each do |school|
|
||||||
|
evaluate_count = Game.joins(:challenge)
|
||||||
|
.joins('LEFT JOIN members ON members.user_id = games.user_id')
|
||||||
|
.joins('LEFT JOIN homework_commons_shixuns hcs ON hcs.shixun_id = challenges.shixun_id')
|
||||||
|
.joins('LEFT JOIN homework_commons hc ON hcs.homework_common_id = hc.id AND hc.homework_type = 4')
|
||||||
|
.joins('LEFT JOIN courses ON hc.course_id = courses.id AND members.course_id = courses.id')
|
||||||
|
.where(courses: { school_id: school.id })
|
||||||
|
.sum(:evaluate_count)
|
||||||
|
|
||||||
|
report = SchoolReport.find_or_initialize_by_school_id(school.id)
|
||||||
|
|
||||||
|
report.school_name = school.name
|
||||||
|
report.shixun_evaluate_count = evaluate_count
|
||||||
|
|
||||||
|
report.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,14 @@
|
|||||||
|
class CreateSchoolReports < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :school_reports do |t|
|
||||||
|
t.integer :school_id
|
||||||
|
t.string :school_name
|
||||||
|
t.integer :shixun_evaluate_count
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :school_reports, :school_id
|
||||||
|
add_index :school_reports, :shixun_evaluate_count
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
namespace :school_report do
|
||||||
|
desc 'statistic school report task'
|
||||||
|
task statistic: :environment do
|
||||||
|
StatisticSchoolReportTask.new.call
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue