StationService.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Services;
  3. use App\Events\BroadcastToStation;
  4. use App\Station;
  5. use App\StationTask;
  6. use App\StationType;
  7. use Exception;
  8. use Illuminate\Support\Facades\Cache;
  9. use App\Traits\ServiceAppAop;
  10. class StationService
  11. {
  12. use ServiceAppAop;
  13. protected $modelClass=Station::class;
  14. /**
  15. * @param string $typeName
  16. * @return Station
  17. * @throws Exception
  18. */
  19. function getStation_byType(string $typeName):Station{
  20. $station= Cache::remember('Station_typeName_'.$typeName,
  21. config('cache.expirations.rarelyChange'),
  22. function ()use($typeName) {
  23. $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
  24. if(!$stationType) throw new Exception('指定站类型获取不到');
  25. return Station::query()->where('station_type_id',$stationType['id'])->first();
  26. });
  27. if(!$station)throw new Exception('默认站获取不到');
  28. return $station;
  29. }
  30. function getULineEntrance(Station $station):?Station{
  31. $station->loadMissing(['stationType','child']);
  32. if ($station['stationType']['name']??''=='料箱出货口'){
  33. return $station;
  34. }
  35. if ($station['child']['stationType']['name']??''=='料箱出货口'){
  36. return $station['child'];
  37. }
  38. return null;
  39. }
  40. function getULineExit(Station $station):?Station{
  41. $station->loadMissing(['stationType','child']);
  42. if ($station['stationType']['name']??''=='料箱入货口'){
  43. return $station;
  44. }
  45. if ($station['child']['stationType']['name']??''=='料箱入货口'){
  46. return $station['child'];
  47. }
  48. return null;
  49. }
  50. function broadcast($station_id, $json_data){
  51. broadcast(new BroadcastToStation($station_id,$json_data));
  52. }
  53. function broadcastBinMonitor($station_id, ?StationTask $stationTask){
  54. $stationTask->loadMissing(["taskCommodities.commodity.barcodes","taskCommodities.materialBox","taskBatches.batch"/*,"taskMaterialBoxes.box"*/]);
  55. $stationTask->toJson();
  56. $this->broadcast($station_id, $stationTask->toJson());
  57. //...
  58. //$stationTask->stationTaskBatch
  59. //$stationTask->stationTaskMaterialBox
  60. //$stationTask->stationTaskCommodities //'待处理', '处理中' blue,'完成',green
  61. //$batch= $stationTask->stationTaskBatch->batch
  62. //$orders= $batch->....
  63. //.....
  64. //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
  65. //$this->broadcast($station_id, $json_data)
  66. }
  67. function broadcastBinChange($station_id, StationTask $stationTask, int $currentStationTaskCommodity_id){
  68. //...
  69. //$stationTask->stationTaskBatch
  70. //$stationTask->stationTaskMaterialBox
  71. //$stationTask->stationTaskCommodities //'待处理', '处理中' blue,'完成',green
  72. //$batch= $stationTask->stationTaskBatch->batch
  73. //$orders= $batch->....
  74. //.....
  75. //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
  76. //$this->broadcast($station_id, $json_data)
  77. }
  78. function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
  79. //...
  80. //...
  81. //$json_data=['warn']
  82. //$this->broadcast($station_id, $json_data)
  83. }
  84. }