CacheShelfService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Services;
  3. use App\Exceptions\ErrorException;
  4. use App\MaterialBox;
  5. use App\Station;
  6. use App\StationCacheShelfGrid;
  7. use App\StationTaskMaterialBox;
  8. use App\Traits\ServiceAppAop;
  9. use Illuminate\Support\Facades\Http;
  10. class CacheShelfService
  11. {
  12. use ServiceAppAop;
  13. protected $modelClass = Station::class;
  14. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  15. private $stationTaskMaterialBoxService;
  16. /** @var StationCacheShelfGridService $stationCacheShelfGridService */
  17. private $stationCacheShelfGridService;
  18. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  19. private $foreignHaiRoboticsService;
  20. /**
  21. * 获取现有的缓存架任务
  22. * @param Station $station
  23. */
  24. public function getTasks(Station $station)
  25. {
  26. $grids = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station['id'])->where('status', 1)->orderBy('grid_id')->get();
  27. $station->setRelation('grids', $grids);
  28. }
  29. public function lightOffTask($locCode, $PTLAction): array
  30. {
  31. $this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
  32. list($stationCode, $gridId, $row, $col) = StationCacheShelfGrid::getGridByCode($locCode);
  33. $station = Station::query()->where('code', $stationCode)->first();
  34. $grid = StationCacheShelfGrid::query()->where('station_id', $station['id'])->where('grid_id', $gridId)->first();
  35. $materialBox = MaterialBox::query()->where('id', $grid['material_box_id'])->first();
  36. try {
  37. $bool = $this->putBinToStore($station, $materialBox, $grid); // 推送任务
  38. if($bool)$this->stationCacheShelfGridService->lightOff($locCode, $PTLAction); // 灭灯广播
  39. return ['success' => $bool];
  40. } catch (ErrorException $e) {
  41. LogService::log(__FUNCTION__,'缓存架推送任务失败',json_encode($e->getMessage()));
  42. return ['success' => false,'errMsg' => $e->getMessage()];
  43. }
  44. }
  45. /**
  46. * 推任务
  47. * @param $station
  48. * @param $materialBox
  49. * @param $grid
  50. * @return bool
  51. * @throws ErrorException
  52. */
  53. public function putBinToStore($station, $materialBox, $grid): bool
  54. {
  55. $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
  56. $this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
  57. $this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService');
  58. /** @var StationTaskMaterialBox $stationTaskMaterialBox */
  59. $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station, $materialBox);
  60. $this->stationCacheShelfGridService->processGrid($grid, $station, $materialBox);
  61. $station->setRelation('grids', $grid);
  62. $stationTaskMaterialBox->setRelation('station', $station);
  63. $stationTaskMaterialBox->setRelation('materialBox', $materialBox);
  64. return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
  65. }
  66. // /**
  67. // * 入库任务完成
  68. // * @param $params
  69. // */
  70. // public function putBinToStoreFinish($params)
  71. // {
  72. // $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
  73. //
  74. // $locCode = $params['locCode'];
  75. //
  76. // list($stationCode, $gridId) = StationCacheShelfGrid::getGridByCode($locCode);
  77. // $station = Station::query()->where('code', $stationCode)->first();
  78. //
  79. // $stationCacheShelfGrid = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station)->where('grid_id', $gridId)->first();
  80. // $stationCacheShelfGrid->update(['status' => '0', 'material_box_id' => null]);
  81. //
  82. // $StationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $station['id'])->where('material_box_id', $stationCacheShelfGrid['$stationCacheShelfGrid'])->first();
  83. // $this->stationTaskMaterialBoxService->set($StationTaskMaterialBox, ['status' => '已完成']);
  84. // }
  85. // /**
  86. // * 取消格口任务
  87. // * @param Station $station
  88. // * @param array $girds
  89. // */
  90. // public function cancelTask(Station $station, array $girds = [])
  91. // {
  92. // $gridQuery = StationCacheShelfGrid::query()->where('station_id', $station['id']);
  93. // if (count($girds) > 0) $gridQuery->whereIn('grid_id', $girds);
  94. // $this->stationCacheShelfGridService->cancelTask($gridQuery->get());
  95. // }
  96. }