FetchBimInfo.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\BimFile;
  4. use App\Models\Enums\BimFileConvertStatus;
  5. use App\Services\File\BimService;
  6. use Illuminate\Console\Command;
  7. /**
  8. * 拉取引擎服务器的BIM信息
  9. */
  10. class FetchBimInfo extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'lpc:fetch-bim-info {scope=1}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'fetch bim info from engine';
  24. /**
  25. * Execute the console command.
  26. */
  27. public function handle()
  28. {
  29. $this->info('start to fetch bim info');
  30. $scopeDay = (int) $this->argument('scope'); //拉取最近n天
  31. if ($scopeDay == 0) {
  32. $startDateTime = '';
  33. } else {
  34. $startDateTime = date_time_str(strtotime('-' . $scopeDay . 'days'));
  35. }
  36. $bimService = new BimService;
  37. BimFile::query()->createdAtStart($startDateTime)
  38. ->chunkById(50, function ($bimFiles) use ($bimService) {
  39. foreach ($bimFiles as $bimFile) {
  40. $bimFile = $bimService->storeBimInfo($bimFile);
  41. $this->info($bimFile->id . ' extra is ' . json_encode($bimFile->extra));
  42. }
  43. });
  44. }
  45. }