| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Console\Commands;
- use App\Models\DrugReportInfo;
- use App\Services\SyncDrugReportService;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- class SyncDrugReportCommand extends Command
- {
- protected $signature = 'sync:drug-report {--source= : 来源} {--full : 全量模式} {--start-time= : 开始时间} {--end-time= : 结束时间} {--page=1 : 当前页码} {--page-size=20 : 每页大小}';
- protected $description = '同步药检报告数据';
- public function handle(SyncDrugReportService $service): int
- {
- $source = $this->option('source');
- $isFull = (bool)$this->option('full');
- $startTime = $this->option('start-time') ?? Carbon::today()->startOfDay();
- $endTime = $this->option('end-time') ?? ''; // Carbon::now()
- $page = $this->option('page') ?? 1;
- $pageSize = $this->option('page-size') ?? 20;
- if (empty($source)) {
- echo "参数错误,未指定来源[source]", PHP_EOL;
- return Command::FAILURE;
- }
- echo $isFull ? "全量同步开始" : "增量同步开始", sprintf('[%d, %s, %s, %d, %d]……', $isFull, $startTime, $endTime, $page, $pageSize), PHP_EOL;
- $count = $service->syncDrugReport($source, $isFull, $startTime, $endTime, $page, $pageSize);
- echo $isFull ? "全量同步结束" : "增量同步结束", ",共处理 {$count} 条记录!", PHP_EOL;
- return Command::SUCCESS;
- }
- }
|