diff --git a/app/tasks/statistic_school_daily_report_task.rb b/app/tasks/statistic_school_daily_report_task.rb index 8e5103a3..8a038718 100644 --- a/app/tasks/statistic_school_daily_report_task.rb +++ b/app/tasks/statistic_school_daily_report_task.rb @@ -41,9 +41,12 @@ class StatisticSchoolDailyReportTask shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date } report = SchoolDailyReport.create!(create_params) - values = '(' + active_user_ids.join(", #{report.id}),(") + ", #{report.id})" - user_sql = "INSERT INTO school_daily_active_users(user_id, school_daily_report_id) VALUES#{values}" - SchoolDailyActiveUser.connection.execute(user_sql) + + if active_user_ids.present? + values = '(' + active_user_ids.join(", #{report.id}),(") + ", #{report.id})" + user_sql = "INSERT INTO school_daily_active_users(user_id, school_daily_report_id) VALUES#{values}" + SchoolDailyActiveUser.connection.execute(user_sql) + end end end