stationService=null; $this->stationTypeService=null; $this->stationTaskService=null; $this->materialBoxService=null; $this->stationTaskBatchService=null; $this->stationTaskCommodityService=null; } function createByBatches(Collection $batches,Collection $stationTasks_toAttach): Collection { $this->instant($this->stationTaskService,'StationTaskService'); $stationTaskMaterialBoxes_byBatch = (function () use ($batches) { $stationTaskMaterialBoxes_listByBatch = new Collection(); foreach ($batches as $batch) { $stationTaskMaterialBoxes_listByBatch->push( $this->createByBatch($batch) ); } return $stationTaskMaterialBoxes_listByBatch; })(); $this->stationTaskService ->registerSubTasks( $stationTasks_toAttach, $stationTaskMaterialBoxes_byBatch); return collect(data_get($stationTaskMaterialBoxes_byBatch,'*.*')); } function createByBatch(Batch $batch): ?Collection { $this->instant($this->materialBoxService,'MaterialBoxService'); $this->instant($this->stationTypeService,'StationTypeService'); $this->instant($this->stationService,'StationService'); $stationMaterialBoxes_toCreate=new Collection(); $order_ids=data_get($batch['orders'],'*.id'); $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get(); if($orderCommodities->isEmpty())return $stationMaterialBoxes_toCreate; $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess(); foreach ($orderCommodities as $orderCommodity){ $station=$this->stationService->getStation_byType($stationType['name']); $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]); $stationMaterialBoxes_toCreate->push([ 'station_id'=>$station['id'], 'material_box_id'=>$materialBox['id'], 'station_task_batch_id'=>$batch['id'], 'status'=>'待处理' ]); } return $this->insert($stationMaterialBoxes_toCreate->toArray(),true); } function get(array $kvPairs, $with=null){ ksort($kvPairs); return Cache::remember('StationTaskMaterialBox'.md5(json_encode($kvPairs).json_encode([$with])), config('cache.expirations.fastChange'), function ()use($kvPairs,$with) { $query = StationTaskMaterialBox::query(); if($with){ $query->with($with); } foreach ($kvPairs as $column => $value){ if (is_array($value))$query->whereIn($column,$value); else $query->where($column,$value); } return $query->get(); }); } function markHasTaken(StationTaskMaterialBox $stationTaskMaterialBox){ $this->instant($this->stationTaskBatchService,'StationTaskBatchService'); $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService'); try{ $taskType=$this->getServingTaskType($stationTaskMaterialBox); switch ($taskType){ case '分波次': $this->markProcessing($stationTaskMaterialBox); $this->stationTaskBatchService->markProcessing_byIds($stationTaskMaterialBox['station_task_batch_id']); $this->stationTaskCommodityService->markProcessing($stationTaskMaterialBox['stationTaskCommodities']); $this->stationTaskService->markProcessing_byIds(data_get($stationTaskMaterialBox['stationTaskCommodities'],'*.station_task_id')); break; case '入立库': break; case '入库':break; } }catch (\Exception $e){ throw new ErrorException('放置料箱出错'); } } function markPutStored($stationTaskMaterialBox){ //TODO: 标记 料箱位置(需要其字段存在)$stationTaskMaterialBox['materialBox']['position'] } function markProcessed(StationTaskMaterialBox $stationTaskMaterialBox){ $stationTaskMaterialBox['status'] = '完成'; $stationTaskMaterialBox->save(); } function markProcessing($stationTaskMaterialBox_orBoxes) { $this->instant($this->stationTaskService,'StationTaskService'); if (get_class($stationTaskMaterialBox_orBoxes)==StationTaskMaterialBox::class){ $stationTaskMaterialBox_orBoxes = collect([$stationTaskMaterialBox_orBoxes]); } StationTaskMaterialBox::query() ->whereIn('id', data_get($stationTaskMaterialBox_orBoxes, '*.id')) ->update(['status'=>'处理中']); $this->stationTaskService ->markProcessing_byIds( data_get($stationTaskMaterialBox_orBoxes, '*.station_id') ); } function excepted($stationTaskMaterialBoxes_orBox){ if (get_class($stationTaskMaterialBoxes_orBox)==StationTaskMaterialBox::class){ $stationTaskMaterialBoxes_orBox = collect([$stationTaskMaterialBoxes_orBox]); } StationTaskMaterialBox::query()->whereIn('id',data_get($stationTaskMaterialBoxes_orBox,'*.id')) ->update(['status'=>'异常']); switch (get_class($stationTaskMaterialBoxes_orBox)){ case MaterialBox::class: case StationTaskMaterialBox::class: throw new ErrorException('料箱异常'.json_encode($stationTaskMaterialBoxes_orBox->toJson())); } } function getServingTaskType(StationTaskMaterialBox $stationTaskMaterialBox): string { $stationTaskMaterialBox->load('station.stationType'); if($isBatching=( $stationTaskMaterialBox['station_task_batch_id'] && $stationTaskMaterialBox['station']['stationType']['name'] == '料箱监视器') ){ return '分波次'; } if($isPuttingBack=( !$stationTaskMaterialBox && $stationTaskMaterialBox['station']['stationType'] == '立库') ){ return '入立库'; } // if($isStoring=false){ // return '入库'; // } throw new ErrorException('当前类型找不到'); } }