SyncSealDrugReportCommand.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\SyncSealDrugReportService;
  4. use Carbon\Carbon;
  5. use Illuminate\Console\Command;
  6. class SyncSealDrugReportCommand extends Command
  7. {
  8. protected $signature = 'sync:drug-report {--source= : 来源} {--full : 全量模式} {--start-time= : 开始时间} {--end-time= : 结束时间} {--page=1 : 当前页码} {--page-size=20 : 每页大小}';
  9. protected $description = '同步药检报告数据';
  10. public function handle(SyncSealDrugReportService $service): int
  11. {
  12. $source = $this->option('source');
  13. $isFull = (bool)$this->option('full');
  14. $startTime = $this->option('start-time') ?? Carbon::today()->startOfDay();
  15. $endTime = $this->option('end-time') ?? ''; // Carbon::now()
  16. $page = $this->option('page') ?? 1;
  17. $pageSize = $this->option('page-size') ?? 20;
  18. if (empty($source)) {
  19. echo "参数错误,未指定来源[source]", PHP_EOL;
  20. return Command::FAILURE;
  21. }
  22. echo $isFull ? "全量同步开始" : "增量同步开始", sprintf('[%d, %s, %s, %d, %d]……', $isFull, $startTime, $endTime, $page, $pageSize), PHP_EOL;
  23. $count = $service->syncDrugReport($source, $isFull, $startTime, $endTime, $page, $pageSize);
  24. echo $isFull ? "全量同步结束" : "增量同步结束", ",共处理 {$count} 条记录!", PHP_EOL;
  25. return Command::SUCCESS;
  26. }
  27. }