StationService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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([
  55. "stationTaskCommodities.commodity.barcodes",
  56. "stationTaskCommodities.materialBox",
  57. "stationTaskBatches.batch"
  58. /*,"taskMaterialBoxes.box"*/
  59. ]);
  60. $this->broadcast($station_id, $stationTask->toJson());
  61. //...
  62. //$stationTask->stationTaskBatch
  63. //$stationTask->stationTaskMaterialBox
  64. //$stationTask->stationTaskCommodities //'待处理', '处理中' blue,'完成',green
  65. //$batch= $stationTask->stationTaskBatch->batch
  66. //$orders= $batch->....
  67. //.....
  68. //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
  69. //$this->broadcast($station_id, $json_data)
  70. }
  71. function broadcastBinChange($station_id, StationTask $stationTask, int $currentStationTaskCommodity_id){
  72. //...
  73. //$stationTask->stationTaskBatch
  74. //$stationTask->stationTaskMaterialBox
  75. //$stationTask->stationTaskCommodities //'待处理', '处理中' blue,'完成',green
  76. //$batch= $stationTask->stationTaskBatch->batch
  77. //$orders= $batch->....
  78. //.....
  79. //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
  80. //$this->broadcast($station_id, $json_data)
  81. }
  82. function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
  83. //...
  84. //...
  85. //$json_data=['warn']
  86. //$this->broadcast($station_id, $json_data)
  87. }
  88. }