فهرست منبع

海柔修正,回立库新建料箱任务

LD 5 سال پیش
والد
کامیت
ad0aa94aff

+ 7 - 8
app/Http/Controllers/TestController.php

@@ -125,6 +125,7 @@ use App\StoreCheckingReceiveItem;
 use App\StoreItem;
 use App\StoreItems;
 use App\Supplier;
+use App\Traits\ModelLogChanging;
 use App\Unit;
 use App\User;
 use App\UserDetail;
@@ -398,14 +399,12 @@ class TestController extends Controller
     public function tj2(Request $request)
     {
 
-        Cache::tags(['aa','bb'])->put('xxx','yy',60);
-        var_dump(
-            Cache::get('xxx'),
-            Cache::tags(['aa'])->get('xxx'),
-            Cache::tags(['aa','bb'])->get('xxx')
-        );
-
-
+        $a=new StationTaskMaterialBox([
+            'id'=>333,
+            'station_id'=>'444'
+        ]);
+        $a['id']=22;
+        dd($a);
 
     }
 

+ 2 - 26
app/Http/Controllers/api/thirdPart/haiq/StorageController.php

@@ -43,22 +43,10 @@ class StorageController
             "taskMode"      => 1,
             "bins"=>[
                 [
-                    "binCode"   => "IDE0004954",
+                    "binCode"   => "IDE0000159",
                     "taskCode"  =>'t1'.microtime(true),
                     "fromLocCode" => "BIN-IN1",
                 "toLocCode" => "",
-            ],
-                [
-                    "binCode"   => "IDE0005262",
-                    "taskCode"  =>'t2'.microtime(true),
-                    "fromLocCode" => "BIN-IN1",
-                "toLocCode" => "",
-            ],
-                [
-                    "binCode"   => "IDE0004968",
-                    "taskCode"  =>'t3'.microtime(true),
-                    "fromLocCode" => "BIN-IN1",
-                "toLocCode" => "",
             ],
                 ],
             "groupCode"     => 'g'.microtime(true),
@@ -71,19 +59,7 @@ class StorageController
 
                 [
                 "taskCode"  =>'t1'.microtime(true),
-                "binCode"   => "IDE0004954",
-                "fromLocCode" => "",
-                "toLocCode" => "BIN-OUT1",
-            ],
-                [
-                "taskCode"  =>'t2'.microtime(true),
-                "binCode"   => "IDE0005262",
-                "fromLocCode" => "",
-                "toLocCode" => "BIN-OUT1",
-            ],
-                [
-                "taskCode"  =>'t3'.microtime(true),
-                "binCode"   => "IDE0004968",
+                "binCode"   => "IDE0004952",
                 "fromLocCode" => "",
                 "toLocCode" => "BIN-OUT1",
             ],

+ 4 - 4
app/Services/BatchService.php

@@ -73,9 +73,9 @@ class BatchService
             $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
 
             $stationTaskBatches=null;
-            DB::transaction(function ()use($batches,&$stationTaskBatches){
-                $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
-                if($batches_shouldProcess->isEmpty()) return;
+            $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
+            if($batches_shouldProcess->isEmpty()) return;
+            DB::transaction(function ()use($batches,&$stationTaskBatches,&$batches_shouldProcess){
                 LogService::log(__METHOD__,'assignTasks','波次任务分配2:'.json_encode($batches));
 //                $batches_shouldProcess = $this->stationTaskMaterialBoxService->getInOccupied_byBatches($batches); //按规则过滤需要的波次
 
@@ -95,7 +95,7 @@ class BatchService
             foreach ($batches as $batch){
                 Cache::tags(['波次防重叠'.$batch['id']])->flush();
             }
-            throw new ErrorException('注册任务失败: '.json_encode($batches). $e->getMessage());
+            throw new ErrorException('注册任务失败: '.json_encode($batches). $e->getMessage().$e->getTrace());
         }
     }
 

+ 1 - 1
app/Services/CacheShelfService.php

@@ -64,7 +64,7 @@ class CacheShelfService
         $this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService');
 
         /** @var StationTaskMaterialBox $stationTaskMaterialBox */
-        $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationMaterialBox($station, $materialBox);
+        $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station, $materialBox);
         $this->stationCacheShelfGridService->processGrid($grid, $station, $materialBox);
 
         $station->setRelation('grids', $grid);

+ 64 - 39
app/Services/ForeignHaiRoboticsService.php

@@ -9,6 +9,7 @@ use App\MaterialBox;
 use App\StationCacheShelfGrid;
 use App\StationTaskMaterialBox;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
 use App\Traits\ServiceAppAop;
 
@@ -153,44 +154,66 @@ class ForeignHaiRoboticsService
             LogService::log('海柔请求','markBinProcessed1.6',
                 json_encode($stationTaskMaterialBox));
             if(!$stationTaskMaterialBox){
-                throw new ErrorException('该料箱没有安排在处理队列中.');
+                throw new ErrorException($binCode.'该料箱没有安排在处理队列中.');
             }
-            $this->putBinToStore($stationTaskMaterialBox)
-                ?true
-                :(function(){throw new ErrorException('呼叫机器人回收U型线料箱失败');})();
             LogService::log('海柔请求','markBinProcessed1.7',
                 json_encode($stationTaskMaterialBox));
-            $stationTaskMaterialBox_next=
-                $this->stationTaskMaterialBoxService
-                    ->processNextQueued($stationTaskMaterialBox); //找到队列中下一个料箱,并标记为处理中
-            $this->stationTaskCommoditiesService
-                ->markProcessed($stationTaskMaterialBox['stationTaskCommodities']);
-            LogService::log('海柔请求','markBinProcessed1.8',
-                json_encode($stationTaskMaterialBox));
-            if($stationTaskMaterialBox_next)
+
+            DB::transaction(function ()use($stationTaskMaterialBox){
+                $stationTaskMaterialBox_next=
+                    $this->stationTaskMaterialBoxService
+                        ->processNextQueued($stationTaskMaterialBox); //找到队列中下一个料箱,并标记为处理中
                 $this->stationTaskCommoditiesService
-                    ->markProcessing($stationTaskMaterialBox_next['stationTaskCommodities']);//因为上边商品任务被标记完成了,所以这里要将队列中找出正在处理的料箱对应的标记为“处理中”
-
-            $notFinishedBoxTasks = $this->stationTaskMaterialBoxService->getNotFinishedSiblings($stationTaskMaterialBox);
-            if($notFinishedBoxTasks->isEmpty()){
-                $this->instant($this->stationTaskService,'StationTaskService');
-                LogService::log('海柔请求','markBinProcessed1.81',
-                    json_encode($stationTaskMaterialBox['stationTaskBatch']));
-                $stationTaskMaterialBox->loadMissing('stationTaskBatch');
-                $this->stationTaskBatchService->markProcessed($stationTaskMaterialBox['stationTaskBatch']);
-                LogService::log('海柔请求','markBinProcessed1.82',
-                    json_encode($stationTaskMaterialBox['stationTaskBatch']));
-                $this->stationTaskService->markProcessed($stationTaskMaterialBox['stationTask']);
-            }
-            LogService::log('海柔请求','markBinProcessed1.9',
-                json_encode($stationTaskMaterialBox));
-            $this->stationService->broadcastBinMonitor($stationTaskMaterialBox['station_id'],$stationTaskMaterialBox['stationTask']);
-            $this->stationTaskMaterialBoxService
-                ->markProcessed($stationTaskMaterialBox);
-            LogService::log('海柔请求','markBinProcessed1.99',
-                json_encode($stationTaskMaterialBox));
+                    ->markProcessed($stationTaskMaterialBox['stationTaskCommodities']);
+                LogService::log('海柔请求','markBinProcessed1.8',
+                    json_encode($stationTaskMaterialBox));
+                if($stationTaskMaterialBox_next)
+                    $this->stationTaskCommoditiesService
+                        ->markProcessing($stationTaskMaterialBox_next['stationTaskCommodities']);//因为上边商品任务被标记完成了,所以这里要将队列中找出正在处理的料箱对应的标记为“处理中”
+
+                $this->stationTaskMaterialBoxService
+                    ->markProcessed($stationTaskMaterialBox);
+                $notProcessedBoxTasks = $this->stationTaskMaterialBoxService->getNotProcessedSiblings($stationTaskMaterialBox);
+                if($notProcessedBoxTasks->isEmpty()){
+                    $this->instant($this->stationTaskService,'StationTaskService');
+                    LogService::log('海柔请求','markBinProcessed1.81',
+                        json_encode($stationTaskMaterialBox['stationTaskBatch']));
+                    $stationTaskMaterialBox->loadMissing('stationTaskBatch');
+                    $this->stationTaskBatchService->markProcessed($stationTaskMaterialBox['stationTaskBatch']);
+                    LogService::log('海柔请求','markBinProcessed1.82',
+                        json_encode($stationTaskMaterialBox['stationTaskBatch']));
+                    $this->stationTaskService->markProcessed($stationTaskMaterialBox['stationTask']);
+                }
+                $this->storeBox($stationTaskMaterialBox)
+                    ?true
+                    :(function(){throw new ErrorException('呼叫机器人回收U型线料箱失败');})();
+                LogService::log('海柔请求','markBinProcessed1.9',
+                    json_encode($stationTaskMaterialBox));
+                $this->stationService->broadcastBinMonitor($stationTaskMaterialBox['station_id'],$stationTaskMaterialBox['stationTask']);
+                LogService::log('海柔请求','markBinProcessed1.99',
+                    json_encode($stationTaskMaterialBox));
+            });
+
             return true;
         }catch (\Exception $e){
+
+            $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
+            $stationTaskMaterialBox_toStore=
+                $this->stationTaskMaterialBoxService->create([
+                    'station_id' => $this->stationService->getStation_byType('立库')['id'],
+                    'material_box_id' => $stationTaskMaterialBox['materialBox']['id'],
+                    'status' => '处理中'
+                ] );
+
+            $dataToPost=$this->makeJson_move(
+                collect([$stationTaskMaterialBox_toStore]),
+                '输送线入立架',
+                'BIN-IN1',//TODO:这里应该是动态取得,参考出立架getULineExit()方法,不然不能从站获得对应的出口,而且要改Station的child为children
+                '',
+                $stationTaskMaterialBox['stationTaskBatch']['id']
+            );
+            $this->controlHaiRobot($dataToPost);
+
             $stationTaskMaterialBox = $stationTaskMaterialBox??$materialBox??null;
             if($stationTaskMaterialBox && get_class($stationTaskMaterialBox)==MaterialBox::class){
                 $stationTaskMaterialBox = StationTaskMaterialBox::query()
@@ -206,15 +229,22 @@ class ForeignHaiRoboticsService
         }
     }
 
-    public function putBinToStore(?StationTaskMaterialBox $stationTaskMaterialBox): bool
+    public function storeBox(?StationTaskMaterialBox $stationTaskMaterialBox): bool
     {
         LogService::log('海柔请求','putBinToStore1',
             '');
         LogService::log('海柔请求','putBinToStore2',
             json_encode($stationTaskMaterialBox));
         $this->instant($this->stationService,'StationService');
+        $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
+        $stationTaskMaterialBox_toStore=
+            $this->stationTaskMaterialBoxService->create([
+                'station_id' => $this->stationService->getStation_byType('立库')['id'],
+                'material_box_id' => $stationTaskMaterialBox['materialBox']['id'],
+                'status' => '处理中'
+            ] );
         $dataToPost=$this->makeJson_move(
-            collect([$stationTaskMaterialBox]),
+            collect([$stationTaskMaterialBox_toStore]),
             '输送线入立架',
             'BIN-IN1',//TODO:这里应该是动态取得,参考出立架getULineExit()方法,不然不能从站获得对应的出口,而且要改Station的child为children
             '',
@@ -224,11 +254,6 @@ class ForeignHaiRoboticsService
             json_encode($dataToPost));
         $controlSuccess = $this->controlHaiRobot($dataToPost);
         if($controlSuccess){
-            $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
-            $this->stationTaskMaterialBoxService->set($stationTaskMaterialBox,[
-                'id' => $stationTaskMaterialBox['id'],
-                'status' => $stationTaskMaterialBox['status']='处理中',
-            ]);
         }
         return $controlSuccess;
     }

+ 3 - 2
app/Services/StationTaskBatchService.php

@@ -126,10 +126,11 @@ class StationTaskBatchService
     }
 
     /**
-     * @param Collection $stationTaskBatches
+     * @param Collection|null $stationTaskBatches
      * @return Collection|\Tightenco\Collect\Support\Collection|null 返回执行失败的记录
+     * @throws ErrorException
      */
-    function runMany(Collection $stationTaskBatches):?Collection
+    function runMany(?Collection $stationTaskBatches):?Collection
     {
         LogService::log(__METHOD__,'runMany','波次任务分配6.1:'.json_encode($stationTaskBatches));
         $stationTaskBatches_failed = null;

+ 7 - 4
app/Services/StationTaskMaterialBoxService.php

@@ -48,7 +48,11 @@ class StationTaskMaterialBoxService
         $this->stationTaskCommodityService=null;
     }
 
-    function createByStationMaterialBox($station,$materialBox)
+    function create($kvPairs)
+    {
+        return StationTaskMaterialBox::query()->create($kvPairs);
+    }
+    function createByStationAndMaterialBox($station, $materialBox)
     {
         return StationTaskMaterialBox::query()->create([
             'station_id' => $station['id'],
@@ -194,11 +198,10 @@ class StationTaskMaterialBoxService
     }
 
     function markProcessed(StationTaskMaterialBox $stationTaskMaterialBox){
-        $stationTaskMaterialBox['status'] = '完成';
-        $stationTaskMaterialBox['station_id'] = 4;
+        $stationTaskMaterialBox['status'] = '处理完';
         $stationTaskMaterialBox->update();
     }
-    function getNotFinishedSiblings($stationTaskMaterialBox){
+    function getNotProcessedSiblings($stationTaskMaterialBox){
         return StationTaskMaterialBox::query()
             ->whereNotIn('status',['完成'])
             ->where('station_task_id',$stationTaskMaterialBox['station_task_id'])