| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace App\Services;
- use App\Events\BroadcastToStation;
- use App\Station;
- use App\StationTask;
- use App\StationType;
- use Exception;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Cache;
- use App\Traits\ServiceAppAop;
- class StationService
- {
- use ServiceAppAop;
- protected $modelClass=Station::class;
- /** @var $stationTaskService StationTaskService */
- protected $stationTaskService;
- /**
- * @param string $typeName
- * @return Station
- * @throws Exception
- */
- function getStation_byType(string $typeName):Station{
- $station= Cache::remember('Station_typeName_'.$typeName,
- config('cache.expirations.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 getULineEntrance(Station $station):?Station{
- $station->loadMissing(['stationType','child']);
- if (($station['stationType']['name']??'')=='料箱出货口'){
- return $station;
- }
- if (($station['child']['stationType']['name']??'')=='料箱出货口'){
- return $station['child'];
- }
- return null;
- }
- function getULineExit(Station $station):?Station{
- $station->loadMissing(['stationType','child']);
- if ($station['stationType']['name']??''=='料箱入货口'){
- return $station;
- }
- if ($station['child']['stationType']['name']??''=='料箱入货口'){
- return $station['child'];
- }
- return null;
- }
- function broadcast($station_id, ?StationTask $stationTask){
- LogService::log('海柔请求in2','broadcast',
- $station_id.'|'.json_encode($stationTask));
- if($stationTask)
- $json = $stationTask->toJson();
- else
- $json =[];
- LogService::log('海柔请求done2','broadcast',
- $station_id.'|'.$json);
- broadcast(new BroadcastToStation($station_id, $json));
- }
- function broadcastBinMonitor($station_id, ?StationTask $stationTask){
- LogService::log('海柔请求in1','broadcastBinMonitor',
- $station_id.'|'.json_encode($stationTask));
- if(!$stationTask)return;
- $this->instant($this->stationTaskService,'StationTaskService');
- if($stationTask['status']=='完成')
- $stationTask=$this->stationTaskService->getCurrent_shouldProcess_ByStationId($stationTask['station_id']);
- if($stationTask)
- $stationTask->loadMissing([
- "stationTaskCommodities.commodity.barcodes",
- "stationTaskCommodities.stationTaskMaterialBox",
- "stationTaskBatches.batch",
- "stationTaskMaterialBoxes.materialBox",
- ]);
- LogService::log('海柔请求done1','broadcastBinMonitor',
- $station_id.'|'.json_encode($stationTask));
- $this->broadcast($station_id, $stationTask);
- }
- /**
- * 获取镜像映射库位
- *
- * @param string $mirrorLocation
- *
- * @return Model|null
- */
- public function getMirrorMappingLocation($mirrorLocation)
- {
- if (!$mirrorLocation)return null;
- return Station::query()->where("code",substr($mirrorLocation,2))->first();
- }
- /**
- * 是否为半箱缓存架位置
- *
- * @param Station|null|\stdClass $station
- * @return bool
- */
- public function isHalfBoxLocation(?Station $station):bool
- {
- if (!$station)return false;
- return $station->parent_id==7;
- }
- /**
- * 是否为缓存架位置
- *
- * @param Station|\stdClass $station
- *
- * @return bool
- */
- public function isCacheShelfLocation(Station $station):bool
- {
- return $station->station_type_id == 5;
- }
- }
|