where('parent_id',$id)->with('parent','pendingStationTask.stationTaskMaterialBoxes.materialBox')->get(); } /** * 拍灯触发任务 * @param $locCode * @param $PTLAction * @return array|bool[] */ public function lightOffTask($locCode, $PTLAction): array { $station = Station::query()->where('code', $locCode)->first(); try { $bool = $this->putBinToStore($station); // 推送任务 if($bool){ $this->_stationCacheLightOff($locCode); // 格口灭灯 $this->_stationCacheBroadCast($locCode,$PTLAction); // 灭灯广播 return ['success' => true]; }else{ return ['success' => false,'errMsg' => '机器人推送失败']; } } catch (ErrorException $e) { LogService::log(__FUNCTION__,'缓存架推送任务失败',json_encode($e->getMessage())); return ['success' => false,'errMsg' => $e->getMessage()]; } } /** * 推任务至海柔机器人 * @param $station * @return bool * @throws ErrorException */ public function putBinToStore($station): bool { $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService'); $this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService'); /** @var StationTaskMaterialBox $stationTaskMaterialBox */ $stationTaskMaterialBox = $station['pendingStationTask']['stationTaskMaterialBoxes']->first(); return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox); } /** * 创建站任务和料箱任务 * @param $stationCode * @param $materialBoxCode * @return array */ public function createStationTask($stationCode,$materialBoxCode): array { $this->instant($this->stationTaskService, 'StationTaskService'); $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService'); $this->instant($this->stationTaskChildService,'StationTaskChildService'); $station = Station::query()->where('code' , $stationCode)->first(); if(!$station){ $arr = []; preg_match('/^HAI([\w]+)/',$stationCode,$arr); $parentCode = $arr[1] ?? ''; $stationType = StationType::query()->where('name','缓存架')->first(); $parentStation = Station::query()->firstOrCreate(['code'=>$parentCode],['station_type_id'=>$stationType['id']]); $station = Station::query()->firstOrCreate(['code' => $stationCode,'parent_id'=>$parentStation['id']],['name'=>$stationCode,'station_type_id' => $stationType['id']]); } $materialBox = MaterialBox::query()->firstOrCreate(['code' => $materialBoxCode]); if($station['pendingStationTask'] ?? false){ return ['success' => false,'message' => '当前已有未完成的站任务']; } $stationTask = $this->stationTaskService->create(1); // 生成站任务 $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station,$materialBox); // 创建料箱任务 $this->stationTaskService->registerStations($stationTask,[$station['id']]); // 注册站任务站 $stationTaskMaterialBox->update(['station_task_id'=>$stationTask['id']]); $params = [[ 'station_task_id'=>$stationTask->first()['id'], 'station_taskable_type'=>StationTaskMaterialBox::class, 'station_taskable_id'=>$stationTaskMaterialBox['id'] ]]; $this->stationTaskChildService->insert($params); // 任务任务注册 $body = $this->_stationCacheLightOn($stationCode,$materialBoxCode); if($body->code == 200)['success'=>true]; return ['success' => false,'message' => '机器人亮灯异常']; } /** * 控制格口亮灯 * @param $locCode * @param string $title * @param null $materialCode * @return mixed */ public function _stationCacheLightOn($locCode,$materialCode = null,$title = 'title') { $params = [ "areaCode" => "1004", 'locCode' => $locCode, 'PTLAction' => 1, 'PTLSettings' => [ 'color'=> 1, 'frequency' =>1 ], "displayInfo" => [ "detail01" => $materialCode, "detail02" => "detail02", "detail03" => "detail03", "qrCode" => "qrCode", "qty00" => "11", "qty01" => 1, "qty02" => 2, "title" => $title, "uomDesc01" => "uo", "uomDesc02" => "uo" ], ]; $response = Http::post(config('api.haiq.storage.light'), $params); return json_decode($response->body()); } /** * 控制格口灭灯 * @param $locCode * @return mixed */ public function _stationCacheLightOff($locCode){ $params = [ "areaCode" => "1004", 'locCode' => $locCode, 'PTLAction' => 0, ]; $response = Http::post(config('api.haiq.storage.light'), $params); return json_decode($response->body()); } /** * 广播 通知货物被取走 * @param $locCode * @param $PTLAction */ public function _stationCacheBroadCast($locCode,$PTLAction) { if($PTLAction == 0){ $station = Station::query()->with('parent')->where('code',$locCode)->first(); $json = json_encode( [ 'station_id' => $station['parent']['id'], 'code' => $station['parent']['code'], 'gird_id' => $station['id'], 'grid_code' => $station['code'], ]); broadcast(new BroadcastToStation($station['parent_id'],$json)); } } }