CacheShelfTaskJob.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\ForeignHaiRoboticsService;
  4. use App\StationTaskMaterialBox;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Support\Collection;
  10. use Illuminate\Support\Facades\Cache;
  11. class CacheShelfTaskJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable;
  14. protected string $key;
  15. protected int $count;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(string $key,int $count)
  22. {
  23. $this->count = $count;
  24. $this->key = $key;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. /** @var ForeignHaiRoboticsService $service */
  34. $service = app("ForeignHaiRoboticsService");
  35. if (!Cache::has($this->key))return;
  36. /** @var Collection $task */
  37. list($task,$location) = Cache::get($this->key);
  38. if ($this->count!==$task->count())return;
  39. $dataToPost = $service->makeJson_move_multi($task, '缓存架入立架', $location);
  40. $controlSuccess = $service->controlHaiRobot($dataToPost,$task,'缓存架入立架');
  41. $tIds = [];
  42. $task->each(function ($t)use(&$tIds){$tIds[] = $t->id;});
  43. StationTaskMaterialBox::query()->where("id",$tIds)
  44. ->where("status","待处理")->update(['status' => $controlSuccess ? '处理中' : '异常']);
  45. Cache::forget($this->key);
  46. }
  47. }