| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Jobs;
- use App\Services\ForeignHaiRoboticsService;
- use App\StationTaskMaterialBox;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- class CacheShelfTaskJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable;
- protected string $key;
- protected int $count;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(string $key,int $count)
- {
- $this->count = $count;
- $this->key = $key;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- /** @var ForeignHaiRoboticsService $service */
- $service = app("ForeignHaiRoboticsService");
- if (!Cache::has($this->key))return;
- /** @var Collection $task */
- list($task,$location) = Cache::get($this->key);
- if ($this->count!==$task->count())return;
- $dataToPost = $service->makeJson_move_multi($task, '缓存架入立架', $location);
- $controlSuccess = $service->controlHaiRobot($dataToPost,$task,'缓存架入立架');
- $tIds = [];
- $task->each(function ($t)use(&$tIds){$tIds[] = $t->id;});
- StationTaskMaterialBox::query()->where("id",$tIds)
- ->where("status","待处理")->update(['status' => $controlSuccess ? '处理中' : '异常']);
- Cache::forget($this->key);
- }
- }
|