StationService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Services;
  3. use App\Station;
  4. use App\StationTask;
  5. use App\StationTaskCommodity;
  6. use App\StationType;
  7. use Exception;
  8. use Illuminate\Support\Facades\Cache;
  9. class StationService
  10. {
  11. /**
  12. * @param string $typeName
  13. * @return Station
  14. * @throws Exception
  15. */
  16. function getDefaultStation(string $typeName):Station{
  17. $station= Cache::remember('StationType_default_name_'.$typeName,config('rarelyChange'), function ()use($typeName) {
  18. $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
  19. if(!$stationType) throw new Exception('指定站类型获取不到');
  20. return Station::query()->where('station_type_id',$stationType['id'])->first();
  21. });
  22. if(!$station)throw new Exception('默认站获取不到');
  23. return $station;
  24. }
  25. function broadcast($station_id, $json_data){
  26. //...
  27. //event(new BroadcastToStation($station_id,$json_data))
  28. }
  29. function broadcastBinMonitor($station_id, StationTask $stationTask,StationTaskCommodity $stationTaskCommodity){
  30. //...
  31. //$stationTask->stationTaskBatch
  32. //$stationTask->stationTaskMaterialBox
  33. //$stationTask->stationCommodities
  34. //$batch= $stationTask->stationTaskBatch->batch
  35. //$orders= $batch->....
  36. //.....
  37. //$json_data=['batch','stationCommodities','stationMaterialBin']
  38. //$this->broadcast($station_id, $json_data)
  39. }
  40. function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
  41. //...
  42. //...
  43. //$json_data=['warn']
  44. //$this->broadcast($station_id, $json_data)
  45. }
  46. }