Merge branch 'dev_aliyun' into educoder

dev_local_lzdx
daiao 5 years ago
commit 430a00c90c

@ -7,6 +7,7 @@ class StatisticSchoolDailyReportTask
teacher_count = users.where(created_on: yesterday, user_extensions: { identity: User::TEACHER }).count teacher_count = users.where(created_on: yesterday, user_extensions: { identity: User::TEACHER }).count
student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count
professional_count = users.where(created_on: yesterday, user_extensions: { identity: User::ENTERPRISE }).count
# 活跃用户 # 活跃用户
active_user_ids = users.where(last_login_on: yesterday).pluck(:id) active_user_ids = users.where(last_login_on: yesterday).pluck(:id)
@ -33,13 +34,13 @@ class StatisticSchoolDailyReportTask
.where(created_at: yesterday).reorder(nil).count .where(created_at: yesterday).reorder(nil).count
# 无有效数据时不记录 # 无有效数据时不记录
data = [teacher_count, student_count, course_count, shixun_count, active_user_count, data = [teacher_count, student_count, professional_count, course_count, shixun_count, active_user_count,
shixun_homework_count, shixun_evaluate_count] shixun_homework_count, shixun_evaluate_count]
next if data.all?(&:zero?) next if data.all?(&:zero?)
create_params = { create_params = {
school_id: school.id, school_name: school.name, teacher_increase_count: teacher_count, school_id: school.id, school_name: school.name, teacher_increase_count: teacher_count,
student_increase_count: student_count, course_increase_count: course_count, student_increase_count: student_count, professional_increase_count: professional_count, course_increase_count: course_count,
shixun_homework_count: shixun_homework_count, shixun_evaluate_count: shixun_evaluate_count, shixun_homework_count: shixun_homework_count, shixun_evaluate_count: shixun_evaluate_count,
shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date
} }

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

Loading…
Cancel
Save