Selaa lähdekoodia

海柔完成任务后状态变化

LD 5 vuotta sitten
vanhempi
commit
31f4b19e75

+ 3 - 0
app/Http/Controllers/TestController.php

@@ -351,6 +351,9 @@ class TestController extends Controller
 
     function packageT(Request $request)
     {
+        $taskBox=StationTaskMaterialBox::query()->find(270);
+        $taskBox->loadMissing('stationTaskBatch');
+        dd($taskBox['stationTaskBatch'],$taskBox);
     }
 
     function injectJS(Request $request)

+ 8 - 0
app/Services/ForeignHaiRoboticsService.php

@@ -17,6 +17,8 @@ class ForeignHaiRoboticsService
     use ServiceAppAop;
 //    protected $modelClass=ForeignHaiRobotics::class;
 
+    /** @var  $stationTaskBatchService StationTaskBatchService */
+    private $stationTaskBatchService;
     /** @var  $stationTaskMaterialBoxService StationTaskMaterialBoxService */
     private $stationTaskMaterialBoxService;
     /** @var  $stationTaskCommoditiesService StationTaskCommodityService */
@@ -170,6 +172,12 @@ class ForeignHaiRoboticsService
                     ->markProcessing($stationTaskMaterialBox_next['stationTaskCommodities']);//因为上边商品任务被标记完成了,所以这里要将队列中找出正在处理的料箱对应的标记为“处理中”
             if(!$stationTaskMaterialBox_next){
                 $this->instant($this->stationTaskService,'StationTaskService');
+                $stationTaskMaterialBox->loadMissing('stationTaskBatch');
+                LogService::log('海柔请求','markBinProcessed1.81',
+                    json_encode($stationTaskMaterialBox['stationTaskBatch']));
+                $this->stationTaskBatchService->markProcessed($stationTaskMaterialBox['stationTaskBatch']);
+                LogService::log('海柔请求','markBinProcessed1.82',
+                    json_encode($stationTaskMaterialBox['stationTaskBatch']));
                 $this->stationTaskService->markProcessed($stationTaskMaterialBox['stationTask']);
             }
             LogService::log('海柔请求','markBinProcessed1.9',

+ 10 - 3
app/Services/StationRuleBatchService.php

@@ -23,7 +23,6 @@ class StationRuleBatchService
         LogService::log(__METHOD__,'getByBatch','波次任务分配1.21:'.json_encode($batch));
         $batchType = $batch['type'] ?? 'null';
         $ownerId = $batch['owner_id'] ?? 'null';
-        if(!$this->isLocationOfRobot($batch))return null;
         LogService::log(__METHOD__,'getByBatch','波次任务分配1.22:'.($this->isLocationOfRobot($batch)));
         $batch->loadMissing('stationTaskBatch');
 //        if($batch['stationTaskBatch'])return null;//? 这行有啥用?
@@ -40,10 +39,16 @@ class StationRuleBatchService
     }
     function isLocationOfRobot(?Batch $batch): bool
     {
+        LogService::log(__METHOD__,'getByBatch','波次任务分配1.21I1:'.json_encode($batch));
         if(!$batch)return false;
+        LogService::log(__METHOD__,'getByBatch','波次任务分配1.22I2:'.json_encode($batch));
         $sql = "select count(*) as count from order_commodities where location like 'IDE%' and order_id in (select id from orders where batch_id in (select id from batches where id = ?))";
+
+        LogService::log(__METHOD__,'getByBatch','波次任务分配1.22I3:');
+        LogService::log(__METHOD__,'getByBatch','波次任务分配1.22I3.2:'.$sql);
         $billDetails = DB::select(DB::raw($sql),[$batch['id']]);
-        return $billDetails[0]->count>0;
+        LogService::log(__METHOD__,'getByBatch','波次任务分配1.22I4:'.json_encode($batch).json_encode($billDetails).($billDetails[0]->count > 0));
+        return $billDetails[0]->count > 0;
     }
 
     function getStationType_toBeTask(Batch $batch): ?StationType{
@@ -65,8 +70,10 @@ class StationRuleBatchService
         $batches=$batches->whereNotIn('id',data_get($batches_inTask,'*.id')??[]);
         foreach ($batches as $batch){
             $stationRuleBatch=$this->getByBatch($batch);
-            if($stationRuleBatch)
+            if($stationRuleBatch){
+//                if(!$this->isLocationOfRobot($batch))continue;
                 $batches_toProcess->push($batch);
+            }
         }
         LogService::log(__METHOD__,'shouldProcess','波次任务分配1.3:'.json_encode($batches_inTask));
         return $batches_toProcess;

+ 15 - 0
app/Services/StationTaskBatchService.php

@@ -208,6 +208,13 @@ class StationTaskBatchService
         return $isFetchedFromRobotics;
     }
 
+    function markProcessed($stationTaskBatch_orCollection)
+    {
+        if (get_class($stationTaskBatch_orCollection)==StationTaskBatch::class){
+            $stationTaskBatch_orCollection = collect([$stationTaskBatch_orCollection]);
+        }
+        $this->markProcessed_byIds(data_get($stationTaskBatch_orCollection, '*.id'));
+    }
     function markProcessing($stationTaskBatch_orCollection)
     {
         if (get_class($stationTaskBatch_orCollection)==StationTaskBatch::class){
@@ -223,6 +230,14 @@ class StationTaskBatchService
             ->whereIn('id', $ids)
             ->update(['status'=>'处理中']);
     }
+    function markProcessed_byIds($ids)
+    {
+        if(!$ids)$ids=[];
+        if(!is_array($ids))$ids=[$ids];
+        StationTaskBatch::query()
+            ->whereIn('id', $ids)
+            ->update(['status'=>'完成']);
+    }
 
 //    function markFinished($stationTaskBatches)
 //    {

+ 3 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -68,18 +68,20 @@ class StationTaskMaterialBoxService
         $this->instant($this->materialBoxService,'MaterialBoxService');
         $this->instant($this->stationTypeService,'StationTypeService');
         $this->instant($this->stationService,'StationService');
+        $this->instant($this->stationTaskBatchService,'StationTaskBatchService');
         $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();
+        $stationTaskBatch=$this->stationTaskBatchService->get(['batch_id',$batch['id']]);
         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'],
+                'station_task_batch_id'=>$stationTaskBatch['id'],
                 'status'=>'待处理'
             ]);
         }