StationService.php 3.3 KB

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