Ver Fonte

缓存架DEBUG记录,与亮灯信息更改

Zhouzhendong há 4 anos atrás
pai
commit
06150643b6

+ 123 - 14
app/Http/Controllers/TestController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\Authority;
+use App\Batch;
 use App\Commodity;
 use App\CommodityMaterialBoxModel;
 use App\Components\AsyncResponse;
@@ -34,6 +35,7 @@ use App\OwnerPriceOperation;
 use App\OrderPackageCountingRecord;
 use App\ProcurementCheckSheet;
 use App\RejectedBill;
+use App\Services\BatchService;
 use App\Services\CacheShelfService;
 use App\Services\ForeignHaiRoboticsService;
 use App\Services\OrderPackageReceivedSyncService;
@@ -128,21 +130,128 @@ sql;
 
     public function test()
     {
-        TaskTransaction::query()->where("id",">=","265")->delete();
-        StationTaskMaterialBox::query()->whereIn("id",[85010,85011])->get();
-        app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");
-        Station::query()->where("station_type_id",5)
-            ->whereNotNull("parent_id")->where("id","!=",11)->update(["status"=>1]);
-        TaskTransaction::query()->find(265)->update(["status"=>0,"material_box_id"=>4562]);
-        StationTaskMaterialBox::query()->find(85010)->update(["status"=>"待处理","material_box_id"=>4562]);
         Cache::forget("CACHE_SHELF_AVAILABLE");
-        $task = StationTaskMaterialBox::query()->find(85010);
-        //11 HAIB1-01-01
-        $a = new ForeignHaiRoboticsService();
-        $toLocation = collect(["HAIB1-01-01"]);
-        $taskMaterialBoxes= collect([$task]);
-        $a->
-        fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架',20);
+        $station = ["HAIB1-01-01"];
+        $material = ["IDE0000751"];
+        Station::query()->whereIn("code",$station)->update(["status"=>0]);
+        $stations = Station::query()->whereIn("code",$station)->get();
+        $materials = MaterialBox::query()->whereIn("code",$material)->get();
+        $dateTime = date("Y-m-d H:i:s");
+        $task1 = StationTaskMaterialBox::query()->create([
+            'station_id'=>$stations[0]->id,
+            'material_box_id'=>$materials[0]->id,
+            'station_task_batch_id'=>1,
+            'status'=>'待处理'
+        ]);
+        TaskTransaction::query()->insert([[
+            "doc_code" => "test",
+            "bar_code" => "test",
+            "to_station_id" => $stations[0]->id,
+            "material_box_id" => $materials[0]->id,
+            "task_id" => $task1->id,
+            "commodity_id" => 505012,//XUNI03
+            "amount" => 1,
+            "type" => "出库",
+            "status" => 0,
+            "mark" => 2,
+            "bin_number"=>1,
+            "created_at"=>$dateTime,
+            "updated_at"=>$dateTime,
+        ]]);
+        $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
+        $toLocation = collect($station);
+        $taskMaterialBoxes = collect([$task1]);
+        $foreignHaiRoboticsService->
+        fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架',20,false);
+        foreach ($toLocation as $value){
+            app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
+            Cache::forever("CACHE_SHELF_OCCUPANCY_11",true);
+        }
+        app("StationService")->locationOccupyMulti($toLocation->toArray());
+        dd(1);
+        /*$batchService = new BatchService();
+        $batches = Batch::query()->where("id",171829)->get();
+        $batchService->assignTasks($batches);
+        dd();*/
+        /*TaskTransaction::query()->where("id",">=",277)->delete();
+        StationTaskMaterialBox::query()->whereIn("id",[89685,89686,89687])->delete();
+        app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");//灭灯
+        app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-01");//灭灯
+        dd(1);*/
+        Station::query()->find(16)->update(["status"=>1]);
+        Cache::forget("CACHE_SHELF_AVAILABLE");
+        $station = ["HAIB1-01-01","HAIB1-02-01"];
+        $material = ["IDE0001954","IDE0004030","IDE0002012"];
+        Station::query()->whereIn("code",$station)->update(["status"=>0]);
+        $stations = Station::query()->whereIn("code",$station)->get();
+        $materials = MaterialBox::query()->whereIn("code",$material)->get();
+        $dateTime = date("Y-m-d H:i:s");
+        $task1 = StationTaskMaterialBox::query()->create([
+            'station_id'=>$stations[0]->id,
+            'material_box_id'=>$materials[0]->id,
+            'station_task_batch_id'=>1,
+            'status'=>'待处理'
+        ]);
+        $task2=StationTaskMaterialBox::query()->create([
+            'station_id'=>$stations[1]->id,
+            'material_box_id'=>$materials[1]->id,
+            'station_task_batch_id'=>1,
+            'status'=>'待处理'
+        ]);
+        $task3=StationTaskMaterialBox::query()->create([
+            'station_id'=>6,
+            'material_box_id'=>$materials[2]->id,
+            'station_task_batch_id'=>1,
+            'status'=>'待处理'
+        ]);
+        TaskTransaction::query()->insert([[
+            "doc_code" => "test",
+            "bar_code" => "test",
+            "to_station_id" => $stations[0]->id,
+            "material_box_id" => $materials[0]->id,
+            "task_id" => $task1->id,
+            "commodity_id" => 505012,//XUNI03
+            "amount" => 1,
+            "type" => "出库",
+            "status" => 0,
+            "mark" => 2,
+            "bin_number"=>1,
+            "created_at"=>$dateTime,
+            "updated_at"=>$dateTime,
+        ],[
+            "doc_code" => "test",
+            "bar_code" => "test",
+            "to_station_id" => $stations[1]->id,
+            "material_box_id" => $materials[1]->id,
+            "task_id" => $task2->id,
+            "commodity_id" => 505012,//XUNI03
+            "amount" => 1,
+            "type" => "出库",
+            "status" => 0,
+            "mark" => 2,
+            "bin_number"=>1,
+            "created_at"=>$dateTime,
+            "updated_at"=>$dateTime,
+        ],[
+            "doc_code" => "test",
+            "bar_code" => "test",
+            "to_station_id" => 6,
+            "material_box_id" => $materials[2]->id,
+            "task_id" => $task3->id,
+            "commodity_id" => 505012,//XUNI03
+            "amount" => 1,
+            "type" => "出库",
+            "status" => 3,
+            "mark" => 2,
+            "bin_number"=>1,
+            "created_at"=>$dateTime,
+            "updated_at"=>$dateTime,
+        ]]);
+        $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
+        $toLocation = collect($station);
+        $taskMaterialBoxes = collect([$task1,$task2]);
+        $foreignHaiRoboticsService->
+        fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架',20,false);
         foreach ($toLocation as $value){
             app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
             Cache::forever("CACHE_SHELF_OCCUPANCY_11",true);

+ 5 - 2
app/Jobs/CacheShelfTaskJob.php

@@ -4,6 +4,7 @@ namespace App\Jobs;
 
 use App\Components\ErrorPush;
 use App\Services\ForeignHaiRoboticsService;
+use App\Services\LogService;
 use App\Station;
 use App\StationTaskMaterialBox;
 use App\TaskTransaction;
@@ -47,11 +48,13 @@ class CacheShelfTaskJob implements ShouldQueue
             case "CACHE_SHELF_AVAILABLE"://缓存架释放呼叫
                 //等待一定时间来合并同类请求至此
                 $available = Cache::get($this->key,0);
+                LogService::log("海柔任务","队列事务分发","当前数量:".$this->count.",总量:".$available);
                 if ($this->count!==$available)return;
                 Cache::forget($this->key); //无论是否开始分发 都清除本次缓存架的计数器
                 //获取可用缓存架
                 $stations = app("StationService")->getCacheShelf(true);
                 if ($stations->count()==0)break;
+                LogService::log("海柔任务","队列事务分发",$stations->toJson());
                 //检查事务 尝试分发任务 改变下方序列来控制分发顺序 逐级分发 一次成功就终止
                 if ($this->dispatchOutTask($stations,$service))break; //首先尝试向出库事务分发 分发成功跳出
                 if ($this->dispatchInTask($stations,$service))break;  //尝试向入库事务分发
@@ -111,7 +114,7 @@ class CacheShelfTaskJob implements ShouldQueue
                     foreach ($ids as $id)$updateTransaction[] = ["id"=>$id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
                 }else $updateTransaction[] = ["id"=>$obj->id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
             },function ($service,$toLocation,$task,$prefix){
-                return $service->fetchGroup_multiLocation($toLocation,$task,$prefix,'立架出至缓存架',20);
+                return $service->fetchGroup_multiLocation($toLocation,$task,$prefix,'立架出至缓存架',20,false);
             },"to_station_id")){DB::commit();return $stations->count()==0;} //缓存架用完 跳出,否则接着分发
             DB::rollBack();
         }catch (\Exception $e){
@@ -141,7 +144,7 @@ class CacheShelfTaskJob implements ShouldQueue
             if ($this->dispatchTask($tasks,$stations,$service,function ($obj,$stationId,$time,&$updateTransaction){
                 $updateTransaction[] = ["id"=>$obj->id,"fm_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
             },function ($service,$toLocation,$task,$prefix){
-                return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架');
+                return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架',20,false);
             },"fm_station_id")){
                 DB::commit();return $stations->count()==0; //缓存架用完 跳出,否则接着分发
             }

+ 1 - 4
app/Logging/CriticalFormatter.php

@@ -18,9 +18,6 @@ class CriticalFormatter
     {
         /** @var Logger $logger */
         //$logger->popHandler();
-        $logger->pushProcessor(function (){
-            dump("一些前置后置操作");
-        });
 
         //也可以在前置或后置设置一些通知渠道
         //$logger->setHandlers([new EmailHandler()]); //TODO 这里设置处理器
@@ -30,7 +27,7 @@ class CriticalFormatter
             //用switch捕获各种写入失败场景
             //普通日志也应做此处理,记录应该分级分块
             //logs表考虑下是否启用
-            dd($e);//写入失败时,会再此处处理下
+            //写入失败时,会再此处处理下
         });
     }
 

+ 5 - 2
app/Services/CacheShelfService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Components\ErrorPush;
 use App\Events\BroadcastToStation;
 use App\Exceptions\ErrorException;
 use App\Jobs\CacheShelfTaskJob;
@@ -15,7 +16,7 @@ use Illuminate\Database\Eloquent\Collection;
 
 class   CacheShelfService
 {
-    use ServiceAppAop;
+    use ServiceAppAop,ErrorPush;
 
     protected $modelClass = Station::class;
 
@@ -211,10 +212,12 @@ class   CacheShelfService
      */
     public function boxHasBeenTaken($station)
     {
+        $this->push("1","取出料箱通知","位置:".$station->code);
         app("StationService")->locationFreed($station->code); //释放库位,解除绑定料箱
         $available=Cache::get("CACHE_SHELF_AVAILABLE",0)+1;//获取可用缓存架数量 plus当前
         Cache::forever("CACHE_SHELF_AVAILABLE",$available);
         $this->_stationCacheLightOff($station->code);
-        CacheShelfTaskJob::dispatch("CACHE_SHELF_AVAILABLE",$available)->delay(now()->addSeconds(config("haiRou.cacheShelf.outBinAwait")));
+        LogService::log("海柔任务","队列事务分发","队列开始处理");
+        CacheShelfTaskJob::dispatch("CACHE_SHELF_AVAILABLE",$available)->delay(now()->addSeconds(config("haiRou.cacheShelf.outBinAwait",3)));
     }
 }

+ 7 - 2
app/Services/ForeignHaiRoboticsService.php

@@ -8,6 +8,7 @@ use App\Components\ErrorPush;
 use App\Exceptions\ErrorException;
 use App\Exceptions\Exception;
 use App\Jobs\CacheShelfTaskJob;
+use App\Log;
 use App\MaterialBox;
 use App\Station;
 use App\StationTask;
@@ -141,10 +142,13 @@ class ForeignHaiRoboticsService
      * @param Collection $taskMaterialBoxes
      * @param string $groupIdPrefix
      * @param string $mode
+     * @param int $priority
+     * @param bool $isSequenced
      * @return bool
      * @throws ErrorException|Exception
      */
-    public function fetchGroup_multiLocation(Collection $toLocations, Collection $taskMaterialBoxes, $groupIdPrefix='', $mode='立架出至输送线', int $priority = 10): bool
+    public function fetchGroup_multiLocation(Collection $toLocations, Collection $taskMaterialBoxes,string $groupIdPrefix='',string
+        $mode='立架出至输送线', int $priority = 10, bool $isSequenced = true): bool
     {
         $dataToPost=$this->makeJson_move_multi(
             $taskMaterialBoxes,
@@ -152,7 +156,8 @@ class ForeignHaiRoboticsService
             null,
             $toLocations,
             $groupIdPrefix,
-            $priority
+            $priority,
+            $isSequenced ? 1 : 0
         );
         return $this->controlHaiRobot($dataToPost,$taskMaterialBoxes,$mode);
     }

+ 1 - 1
app/Services/StationTaskBatchService.php

@@ -197,7 +197,7 @@ class StationTaskBatchService
                     list($toLocation, $taskMaterialBoxes, $map) = $this->apportionLocation($taskMaterialBoxes);
                     if ($toLocation->count()>0){
                         $isFetchedFromRobotics = $this->foreignHaiRoboticsService->
-                        fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, $groupPrefix, '立架出至缓存架',20);
+                        fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, $groupPrefix, '立架出至缓存架',20,false);
                         foreach ($toLocation as $value){
                             app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
                             Cache::forever("CACHE_SHELF_OCCUPANCY_{$map[$value]}",true);

+ 1 - 3
app/Services/StationTaskMaterialBoxService.php

@@ -155,10 +155,9 @@ class StationTaskMaterialBoxService
         $this->instant($this->cacheShelfService,'CacheShelfService');
         $this->instant($this->storageService,'StorageService');
         try{
-            LogService::log('海柔请求','markHasTaken1','');
             $taskType=$this->getServingTaskType($stationTaskMaterialBox);
             LogService::log('海柔请求','markHasTaken2',
-                json_encode($taskType));
+                json_encode($stationTaskMaterialBox));
             switch ($taskType){
                 case '分波次':
                     $this->markProcessing($stationTaskMaterialBox);
@@ -213,7 +212,6 @@ class StationTaskMaterialBoxService
     {
         $this->instant($this->cacheShelfService,'CacheShelfService');
         //$stationTaskMaterialBox->loadMissing("station");
-        $this->push("1","取出料箱通知","任务信息:".$stationTaskMaterialBox->toJson());
 
         //判断取出料箱是否是在缓存架
         $station = Station::query()->where("material_box_id",$stationTaskMaterialBox->material_box_id)