| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Services;
- use App\Station;
- use App\StationType;
- use Exception;
- use Illuminate\Support\Facades\Cache;
- class StationService
- {
- /**
- * @param string $typeName
- * @return Station
- * @throws Exception
- */
- function getDefaultStation(string $typeName):Station{
- $station= Cache::remember('StationType_default_name_'.$typeName,config('rarelyChange'), function ()use($typeName) {
- $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
- if(!$stationType) throw new Exception('指定站类型获取不到');
- return Station::query()->where('station_type_id',$stationType['id'])->first();
- });
- if(!$station)throw new Exception('默认站获取不到');
- return $station;
- }
- function broadcast($station_id, $json_data){
- //...
- //event(new BroadcastToStation($station_id,$json_data))
- }
- function broadcastBinMonitor($station_id, ){
- //...
- //$this->broadcast($station_id, $json_data)
- }
- }
|