|
|
@ -31,11 +31,11 @@ namespace :school_daily_report do
|
|
|
|
|
|
|
|
|
|
|
|
data = reports.map do |report|
|
|
|
|
data = reports.map do |report|
|
|
|
|
# 无效数据不记录
|
|
|
|
# 无效数据不记录
|
|
|
|
next if %w(teacher_count student_count course_count shixun_count shixun_homework_count shixun_evaluate_count active_user_count).all? { |key| report[key].zero? }
|
|
|
|
next if %w(teacher_count student_count professional_count course_count shixun_count shixun_homework_count shixun_evaluate_count active_user_count).all? { |key| report[key].zero? }
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
[
|
|
|
|
report['id'], report['name'], report['teacher_count'], report['student_count'], report['course_count'],
|
|
|
|
report['id'], report['name'], report['teacher_count'], report['student_count'], report['professional_count'],
|
|
|
|
report['shixun_count'], report['shixun_homework_count'], report['shixun_evaluate_count'],
|
|
|
|
report['course_count'], report['shixun_count'], report['shixun_homework_count'], report['shixun_evaluate_count'],
|
|
|
|
report['active_user_count'], date_str, current_datetime, current_datetime
|
|
|
|
report['active_user_count'], date_str, current_datetime, current_datetime
|
|
|
|
]
|
|
|
|
]
|
|
|
|
end.compact
|
|
|
|
end.compact
|
|
|
@ -195,7 +195,7 @@ namespace :school_daily_report do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def build_insert_report_sql(arr)
|
|
|
|
def build_insert_report_sql(arr)
|
|
|
|
prefix = 'INSERT INTO school_daily_reports(school_id, school_name, teacher_increase_count, student_increase_count, '\
|
|
|
|
prefix = 'INSERT INTO school_daily_reports(school_id, school_name, teacher_increase_count, student_increase_count, professional_increase_count, '\
|
|
|
|
'course_increase_count, shixun_increase_count, shixun_homework_count, shixun_evaluate_count, active_user_count, date, created_at, updated_at) VALUES'
|
|
|
|
'course_increase_count, shixun_increase_count, shixun_homework_count, shixun_evaluate_count, active_user_count, date, created_at, updated_at) VALUES'
|
|
|
|
# [[1,2], [3,4]] => ['"1", "2"', '"3", "4"'] => '("1", "2"),("3", "4")'
|
|
|
|
# [[1,2], [3,4]] => ['"1", "2"', '"3", "4"'] => '("1", "2"),("3", "4")'
|
|
|
|
values = '(' + arr.map { |item| '"' + item.join('","') + '"' }.join('),(') + ')'
|
|
|
|
values = '(' + arr.map { |item| '"' + item.join('","') + '"' }.join('),(') + ')'
|
|
|
@ -223,6 +223,11 @@ namespace :school_daily_report do
|
|
|
|
WHERE cs.school_id = schools.id
|
|
|
|
WHERE cs.school_id = schools.id
|
|
|
|
AND cs.created_at BETWEEN "#{begin_date}" AND "#{end_date}"
|
|
|
|
AND cs.created_at BETWEEN "#{begin_date}" AND "#{end_date}"
|
|
|
|
) course_count, (
|
|
|
|
) course_count, (
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM users u
|
|
|
|
|
|
|
|
LEFT JOIN user_extensions ue ON ue.user_id = u.id
|
|
|
|
|
|
|
|
WHERE ue.school_id = schools.id AND ue.identity = #{User::ENTERPRISE}
|
|
|
|
|
|
|
|
AND u.created_on BETWEEN "#{begin_date}" AND "#{end_date}"
|
|
|
|
|
|
|
|
) professional_count, (
|
|
|
|
SELECT COUNT(*) FROM shixuns sx
|
|
|
|
SELECT COUNT(*) FROM shixuns sx
|
|
|
|
LEFT JOIN users u ON sx.user_id = u.id
|
|
|
|
LEFT JOIN users u ON sx.user_id = u.id
|
|
|
|
LEFT JOIN user_extensions ue ON ue.user_id = u.id
|
|
|
|
LEFT JOIN user_extensions ue ON ue.user_id = u.id
|
|
|
|