StationService.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Services;
  3. use App\Station;
  4. use App\StationType;
  5. use Exception;
  6. use Illuminate\Support\Facades\Cache;
  7. class StationService
  8. {
  9. /**
  10. * @param string $typeName
  11. * @return Station
  12. * @throws Exception
  13. */
  14. function getDefaultStation(string $typeName):Station{
  15. $station= Cache::remember('StationType_default_name_'.$typeName,config('rarelyChange'), function ()use($typeName) {
  16. $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
  17. if(!$stationType) throw new Exception('指定站类型获取不到');
  18. return Station::query()->where('station_type_id',$stationType['id'])->first();
  19. });
  20. if(!$station)throw new Exception('默认站获取不到');
  21. return $station;
  22. }
  23. function broadcast($station_id, $json_data){
  24. //...
  25. //event(new BroadcastToStation($station_id,$json_data))
  26. }
  27. function broadcastBinMonitor($station_id, ){
  28. //...
  29. //$this->broadcast($station_id, $json_data)
  30. }
  31. }