LD 4 жил өмнө
parent
commit
f15d31361b

+ 2 - 0
app/Events/BroadcastToStation.php

@@ -19,6 +19,7 @@ class BroadcastToStation implements ShouldBroadcastNow
      */
     public function __construct(int $id, string $json)
     {
+        app('LogService')->log('海柔','broadcast1',$id.$json);
         $this->id = $id;// 0意味着通用站,所有站都需要收发的意思
         $this->json = $json;
     }
@@ -30,6 +31,7 @@ class BroadcastToStation implements ShouldBroadcastNow
      */
     public function broadcastOn()
     {
+        app('LogService')->log('海柔','broadcast2',$this->id.$this->json);
         return new Channel('station-'.$this->id);
     }
 }

+ 8 - 0
app/Services/BatchService.php

@@ -65,6 +65,7 @@ class BatchService
      */
     public function assignTasks($batches)
     {
+        app('LogService')->log('海柔','assignTasks1',json_encode($batches));
         try{
             $batches = collect($batches);
 
@@ -76,6 +77,7 @@ class BatchService
 
             $stationTaskBatches=null;
             $stationTasks=null;
+            app('LogService')->log('海柔','assignTasks2',json_encode($batches));
             $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
             if($batches_shouldProcess->isEmpty()) return;
             $stationTaskMaterialBoxes_occupied = $this->stationTaskMaterialBoxService->getOccupied_byBatches($batches_shouldProcess); //按规则过滤需要的波次
@@ -87,11 +89,13 @@ class BatchService
                     ->delay(now()->addMinutes(1));    //因为料箱被占用了,所以将任务推迟1分钟后尝试
                 return;
             }
+            app('LogService')->log('海柔','assignTasks3',json_encode($batches_shouldProcess));
             DB::transaction(function ()use($batches,&$stationTaskBatches,&$batches_shouldProcess,&$stationTasks){
                 $stationTasks =  $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
                 $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
                 $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
                 $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
+                app('LogService')->log('海柔','assignTasks4',json_encode($batches_shouldProcess));
             });
             foreach ($stationTasks as &$stationTask){
                 $stationTask->loadMissing([
@@ -101,15 +105,19 @@ class BatchService
                     "stationTaskMaterialBoxes.materialBox",
                 ]);
             }
+            app('LogService')->log('海柔','assignTasks5',json_encode($stationTask).json_encode($batches_shouldProcess));
             $jsonStationTasks=json_encode($stationTasks);
             broadcast(new BroadcastToStation(BroadcastToStation::ALL_STATION, $jsonStationTasks));
+            app('LogService')->log('海柔','assignTasks6',$jsonStationTasks.json_encode($batches_shouldProcess));
 //            $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
         }catch(Exception $e){
+            app('LogService')->log('海柔','assignTasks7',json_encode($batches));
             $batchesJson='';
             foreach ($batches as $batch){
                 $batchesJson.=json_encode($batch);
                 Cache::tags(['波次防重叠'.$batch['id']])->flush();
             }
+            app('LogService')->log('海柔','assignTasks8',json_encode($batches));
             throw new ErrorException('注册任务失败: '. $batchesJson . $e->getMessage().json_encode($e->getTrace()));
         }
     }