Jing Li 2022-10-19 16:15:59 +08:00
parent 13e6b05ef3
commit e9d8b6c341
1 changed files with 15 additions and 5 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Exceptions\BizException;
use App\Models\LinkosDeviceLog;
use App\Services\LinkosService;
use Illuminate\Console\Command;
@ -36,7 +37,7 @@ class LinkosDeviceLogSyncCommand extends Command
*/
public function handle()
{
$time = now();
$now = now();
$device = $this->argument('device');
@ -45,16 +46,21 @@ class LinkosDeviceLogSyncCommand extends Command
do {
if ($lastDate === null) {
$lastDate = Carbon::parse('2022-06-01');
$lastDate = Carbon::parse('2022-10-18');
} else {
$lastDate->addDay();
}
$start = $lastDate->copy()->startOfDay();
if ($start->gt($now)) {
throw new BizException('开始时间大约当前时间');
}
$end = $lastDate->copy()->endOfDay();
if ($end->gt($time)) {
$end = $time;
if ($end->gt($now)) {
$end = $now;
}
$this->info('----------------------------------');
@ -67,8 +73,12 @@ class LinkosDeviceLogSyncCommand extends Command
$this->info('Done!');
$this->info('----------------------------------');
if ($now->isSameDay($lastDate)) {
break;
}
$this->setLastDate($device, $lastDate);
} while (! $lastDate->isToday());
} while (true);
return Command::SUCCESS;
}