| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Services;
- use App\Exceptions\ErrorException;
- use App\MaterialBox;
- use App\Station;
- use App\StationCacheShelfGrid;
- use App\StationTaskMaterialBox;
- use App\Traits\ServiceAppAop;
- use Illuminate\Support\Facades\Http;
- class CacheShelfService
- {
- use ServiceAppAop;
- protected $modelClass = Station::class;
- /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
- private $stationTaskMaterialBoxService;
- /** @var StationCacheShelfGridService $stationCacheShelfGridService */
- private $stationCacheShelfGridService;
- /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
- private $foreignHaiRoboticsService;
- /**
- * 获取现有的缓存架任务
- * @param Station $station
- */
- public function getTasks(Station $station)
- {
- $grids = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station['id'])->where('status', 1)->orderBy('grid_id')->get();
- $station->setRelation('grids', $grids);
- }
- public function lightOffTask($locCode, $PTLAction): array
- {
- $this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
- list($stationCode, $gridId, $row, $col) = StationCacheShelfGrid::getGridByCode($locCode);
- $station = Station::query()->where('code', $stationCode)->first();
- $grid = StationCacheShelfGrid::query()->where('station_id', $station['id'])->where('grid_id', $gridId)->first();
- $materialBox = MaterialBox::query()->where('id', $grid['material_box_id'])->first();
- try {
- $bool = $this->putBinToStore($station, $materialBox, $grid); // 推送任务
- if($bool)$this->stationCacheShelfGridService->lightOff($locCode, $PTLAction); // 灭灯广播
- return ['success' => $bool];
- } catch (ErrorException $e) {
- LogService::log(__FUNCTION__,'缓存架推送任务失败',json_encode($e->getMessage()));
- return ['success' => false,'errMsg' => $e->getMessage()];
- }
- }
- /**
- * 推任务
- * @param $station
- * @param $materialBox
- * @param $grid
- * @return bool
- * @throws ErrorException
- */
- public function putBinToStore($station, $materialBox, $grid): bool
- {
- $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
- $this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
- $this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService');
- /** @var StationTaskMaterialBox $stationTaskMaterialBox */
- $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station, $materialBox);
- $this->stationCacheShelfGridService->processGrid($grid, $station, $materialBox);
- $station->setRelation('grids', $grid);
- $stationTaskMaterialBox->setRelation('station', $station);
- $stationTaskMaterialBox->setRelation('materialBox', $materialBox);
- return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
- }
- // /**
- // * 入库任务完成
- // * @param $params
- // */
- // public function putBinToStoreFinish($params)
- // {
- // $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
- //
- // $locCode = $params['locCode'];
- //
- // list($stationCode, $gridId) = StationCacheShelfGrid::getGridByCode($locCode);
- // $station = Station::query()->where('code', $stationCode)->first();
- //
- // $stationCacheShelfGrid = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station)->where('grid_id', $gridId)->first();
- // $stationCacheShelfGrid->update(['status' => '0', 'material_box_id' => null]);
- //
- // $StationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $station['id'])->where('material_box_id', $stationCacheShelfGrid['$stationCacheShelfGrid'])->first();
- // $this->stationTaskMaterialBoxService->set($StationTaskMaterialBox, ['status' => '已完成']);
- // }
- // /**
- // * 取消格口任务
- // * @param Station $station
- // * @param array $girds
- // */
- // public function cancelTask(Station $station, array $girds = [])
- // {
- // $gridQuery = StationCacheShelfGrid::query()->where('station_id', $station['id']);
- // if (count($girds) > 0) $gridQuery->whereIn('grid_id', $girds);
- // $this->stationCacheShelfGridService->cancelTask($gridQuery->get());
- // }
- }
|