Commit fc1c2275 by Phạm Văn Đoan

cập nhật task report

parent 8cd0fa51
<?php
namespace App\Console\Commands;
use App\Models\Crontjob;
use App\Repositories\TrackRepository;
use Carbon\Carbon;
use Illuminate\Console\Command;
class CalculateWeeklyReportCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'calculate:weekly-report';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Tính toán số liệu báo cáo tuần';
protected $trackRepository;
/**
* Create a new command instance.
*
* CalculateWeeklyReportCommand constructor.
* @param TrackRepository $trackRepository
*/
public function __construct(TrackRepository $trackRepository)
{
parent::__construct();
ini_set('max_execution_time', -1);
$this->trackRepository = $trackRepository;
}
public function handle()
{
// Ghi log xem có gọi không
Crontjob::create(['message' => 'CalculateWeeklyReportCommand is called']);
// Xử lý di chuyển
echo "\n Bắt đầu xử lý tính toán báo cáo tuần";
echo "\n Kết thúc xử lý tính toán báo cáo tuần";
}
}
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace App\Console; namespace App\Console;
use App\Console\Commands\CalculateDailyListenCommand; use App\Console\Commands\CalculateDailyListenCommand;
use App\Console\Commands\CalculateWeeklyReportCommand; use App\Console\Commands\CalculateReportCommand;
use App\Console\Commands\CrawlerTrackListenCommand; use App\Console\Commands\CrawlerTrackListenCommand;
use App\Console\Commands\CrontjobCommand; use App\Console\Commands\CrontjobCommand;
use App\Console\Commands\Keeng\KeengCrawlerByCateCommand; use App\Console\Commands\Keeng\KeengCrawlerByCateCommand;
...@@ -40,7 +40,7 @@ class Kernel extends ConsoleKernel ...@@ -40,7 +40,7 @@ class Kernel extends ConsoleKernel
CalculateDailyListenCommand::class, CalculateDailyListenCommand::class,
CalculateWeeklyReportCommand::class, CalculateReportCommand::class,
]; ];
...@@ -87,6 +87,10 @@ class Kernel extends ConsoleKernel ...@@ -87,6 +87,10 @@ class Kernel extends ConsoleKernel
$schedule->command('calculate:daily-listen')->dailyAt('1:00'); $schedule->command('calculate:daily-listen')->dailyAt('1:00');
$schedule->command('calculate:daily-listen')->dailyAt('1:10'); $schedule->command('calculate:daily-listen')->dailyAt('1:10');
$schedule->command('php artisan calculate:report daily')->dailyAt('8:00');
$schedule->command('php artisan calculate:report weekly')->sundays();
$schedule->command('php artisan calculate:report monthly')->monthlyOn(21, '6:10');
$schedule->command('queue:work --once --timeout=120')->everyMinute()->withoutOverlapping(); $schedule->command('queue:work --once --timeout=120')->everyMinute()->withoutOverlapping();
} }
......
...@@ -37,6 +37,10 @@ class Constants ...@@ -37,6 +37,10 @@ class Constants
const TABLE_USER_LOGS = 'user_logs'; const TABLE_USER_LOGS = 'user_logs';
const TABLE_USERS = 'users'; const TABLE_USERS = 'users';
const VIEW_TABLE_DAILY_REPORT_VIEW = 'daily_report_view';
const VIEW_TABLE_WEEKLY_REPORT_VIEW = 'weekly_report_view';
const VIEW_TABLE_MONTHLY_REPORT_VIEW = 'monthly_report_view';
const USER_STATUS_INACTIVE = 0; const USER_STATUS_INACTIVE = 0;
const USER_STATUS_ACTIVE = 1; const USER_STATUS_ACTIVE = 1;
const USER_STATUS_LOCKED = 2; const USER_STATUS_LOCKED = 2;
......
...@@ -293,3 +293,38 @@ if (!function_exists('convertViews')) { ...@@ -293,3 +293,38 @@ if (!function_exists('convertViews')) {
return $point; return $point;
} }
} }
if (!function_exists('saveLogFile')) {
/**
* Hàm lưu file log txt trong storage
*
* @param $file_name
* @param $data
* @param string $type
*
* @return bool
*/
function saveLogFile($file_name, $data, $type='daily') {
switch ($type) {
case 'daily': $new_path = 'storage/app/public/daily_report/'; break;
case 'weekly': $new_path = 'storage/app/public/weekly_report/'; break;
case 'monthly': $new_path = 'storage/app/public/monthly_report/'; break;
default: return false;
}
// Kiểm tra tồn tại thư mục, ko tồn tại thì tạo mới
if (!file_exists($new_path)) {
@mkdir($new_path, 0777, true);
}
// Ghi dữ liệu ra file
$new_file_path = $new_path . $file_name;
@copy('storage/app/public/report_template.txt', $new_file_path);
$my_file = fopen($new_file_path, "w");
@fwrite($my_file, $data);
@fclose($my_file);
//
return true;
}
}
...@@ -16,6 +16,7 @@ class CrawlerListenHistory extends Model ...@@ -16,6 +16,7 @@ class CrawlerListenHistory extends Model
'zing_count', 'zing_count',
'nct_count', 'nct_count',
'nhacvn_count', 'nhacvn_count',
'keeng_count' 'keeng_count',
'total_listen'
]; ];
} }
<?php <?php
namespace App\Models; namespace App\Models\Report;
use App\Helpers\Constants; use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
...@@ -12,11 +12,11 @@ class DailyReport extends Model ...@@ -12,11 +12,11 @@ class DailyReport extends Model
public $timestamps = true; public $timestamps = true;
protected $fillable = [ protected $fillable = [
'date', 'day', 'month', 'year', 'date',
'track_id', 'track_id',
'views_zing', 'views_nct', 'views_keeng', 'views_zing', 'views_nct', 'views_keeng',
'point_zing', 'point_keeng', 'total_point', 'point_zing', 'point_nct', 'point_keeng', 'total_point',
'order' 'ranking'
]; ];
} }
<?php <?php
namespace App\Models; namespace App\Models\Report;
use App\Helpers\Constants; use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
...@@ -12,10 +12,10 @@ class MonthlyReport extends Model ...@@ -12,10 +12,10 @@ class MonthlyReport extends Model
public $timestamps = true; public $timestamps = true;
protected $fillable = [ protected $fillable = [
'date', 'day', 'month', 'year', 'month', 'year',
'track_id', 'track_id',
'views_zing', 'views_nct', 'views_keeng', 'views_zing', 'views_nct', 'views_keeng',
'point_zing', 'point_keeng', 'total_point', 'point_zing', 'point_nct', 'point_keeng', 'total_point',
'order' 'order'
]; ];
......
<?php <?php
namespace App\Models; namespace App\Models\Report;
use App\Helpers\Constants; use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
...@@ -12,10 +12,10 @@ class WeeklyReport extends Model ...@@ -12,10 +12,10 @@ class WeeklyReport extends Model
public $timestamps = true; public $timestamps = true;
protected $fillable = [ protected $fillable = [
'date', 'day', 'month', 'year', 'week', 'month', 'year',
'track_id', 'track_id',
'views_zing', 'views_nct', 'views_keeng', 'views_zing', 'views_nct', 'views_keeng',
'point_zing', 'point_keeng', 'total_point', 'point_zing', 'point_nct', 'point_keeng', 'total_point',
'order' 'order'
]; ];
......
<?php
namespace App\Models\View;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class DailyReportView extends Model
{
protected $table = Constants::VIEW_TABLE_DAILY_REPORT_VIEW;
public $timestamps = false;
protected $fillable = [
'track_id',
'date_zing', 'date_nct', 'date_keeng', 'total_listen',
'point_zing', 'point_nct', 'point_keeng', 'total_point'
];
}
<?php
namespace App\Models\View;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class MonthlyReportView extends Model
{
protected $table = Constants::VIEW_TABLE_MONTHLY_REPORT_VIEW;
public $timestamps = false;
protected $fillable = [
'track_id',
'month_zing', 'month_nct', 'month_keeng', 'total_listen',
'point_zing', 'point_nct', 'point_keeng', 'total_point'
];
}
<?php
namespace App\Models\View;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class WeeklyReportView extends Model
{
protected $table = Constants::VIEW_TABLE_WEEKLY_REPORT_VIEW;
public $timestamps = false;
protected $fillable = [
'track_id',
'week_zing', 'week_nct', 'week_keeng', 'total_listen',
'point_zing', 'point_nct', 'point_keeng', 'total_point'
];
}
...@@ -52,6 +52,9 @@ return [ ...@@ -52,6 +52,9 @@ return [
'prefix' => '', 'prefix' => '',
'strict' => false, 'strict' => false,
'engine' => null, 'engine' => null,
'options' => [
\PDO::ATTR_EMULATE_PREPARES => true
]
], ],
'pgsql' => [ 'pgsql' => [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment