SyncDrugReportCommand.php 1.4 KB

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