Browse Source

缓存架处理,优先级指定

Zhouzhendong 4 years ago
parent
commit
b414f14564

+ 13 - 6
app/Http/Controllers/TestController.php

@@ -18,7 +18,6 @@ use App\Jobs\OrderCreateWaybill;
 use App\Jobs\SettlementBillReportTask;
 use App\Jobs\StoreCreateInstantBill;
 use App\Jobs\WeightUpdateInstantBill;
-use App\Log;
 use App\MaterialBox;
 use App\MaterialBoxModel;
 use App\Order;
@@ -69,6 +68,7 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Str;
@@ -130,7 +130,14 @@ sql;
 
     public function test()
     {
-        dd();
+        TaskTransaction::query()->where("id",">=",280)->delete();
+        /*$a= new StorageService();
+        $a->clearTask(["HAIB1-01-01"]);
+        $task = StationTaskMaterialBox::query()->find(90233);
+        $station = Station::query()->find(11);
+        $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
+        $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($task, $station);
+        dd(1);*/
         /*$batchService = new BatchService();
         $batches = Batch::query()->where("id",171829)->get();
         $batchService->assignTasks($batches);
@@ -140,10 +147,10 @@ sql;
         app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");//灭灯
         app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-01");//灭灯
         dd(1);*/
-        Station::query()->find(16)->update(["status"=>1]);
+        Station::query()->where("station_type_id",5)->update(["status"=>1]);
         Cache::forget("CACHE_SHELF_AVAILABLE");
         $station = ["HAIB1-01-01","HAIB1-02-01"];
-        $material = ["IDE0001954","IDE0004030","IDE0002012"];
+        $material = ["IDE0001824","IDE0001740","IDE0002710"];
         Station::query()->whereIn("code",$station)->update(["status"=>0]);
         $stations = Station::query()->whereIn("code",$station)->get();
         $materials = MaterialBox::query()->whereIn("code",$material)->get();
@@ -214,9 +221,9 @@ sql;
         $taskMaterialBoxes = collect([$task1,$task2]);
         $foreignHaiRoboticsService->
         fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架',20,false);
-        foreach ($toLocation as $value){
+        foreach ($toLocation as $index=>$value){
             app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
-            Cache::forever("CACHE_SHELF_OCCUPANCY_11",true);
+            Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}",true);
         }
         app("StationService")->locationOccupyMulti($toLocation->toArray());
     }

+ 1 - 6
app/Http/Controllers/api/thirdPart/flux/SortingController.php

@@ -4,15 +4,11 @@ namespace App\Http\Controllers\api\thirdPart\flux;
 
 use App\Batch;
 use App\Http\Controllers\Controller;
-use App\OracleActAllocationDetails;
 use App\Order;
-use App\OrderBin;
 use App\OrderCommodity;
-use App\Owner;
-use App\Services\CommodityService;
-use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Validator;
 use Zttp\Zttp;
 
@@ -179,7 +175,6 @@ class SortingController extends Controller
                 'bin'=>$order->bin()->first()['number']
             ];
         });
-        $response=null;
         try {
             $response=Zttp::post($apiUrl,$sendingData);
         }catch (\Exception $e){

+ 7 - 5
app/Jobs/CacheShelfTaskJob.php

@@ -50,13 +50,12 @@ class CacheShelfTaskJob implements ShouldQueue
                 //等待一定时间来合并同类请求至此
                 $available = Cache::get($this->key,0);
                 Log::debug("队列事务1",["当前数量:{$this->count}","缓存数量:$available"]);
-                if ($this->count!==$available)return;
+                if ($this->count!=$available)return;
                 Cache::forget($this->key); //无论是否开始分发 都清除本次缓存架的计数器
                 //获取可用缓存架
                 $stations = app("StationService")->getCacheShelf(true);
                 Log::debug("队列事务2",["可用缓存架:{$stations->count()}"]);
                 if ($stations->count()==0)break;
-                LogService::log("海柔任务","队列事务分发",$stations->toJson());
                 //检查事务 尝试分发任务 改变下方序列来控制分发顺序 逐级分发 一次成功就终止
                 if ($this->dispatchOutTask($stations,$service))break; //首先尝试向出库事务分发 分发成功跳出
                 if ($this->dispatchInTask($stations,$service))break;  //尝试向入库事务分发
@@ -65,7 +64,7 @@ class CacheShelfTaskJob implements ShouldQueue
                 if (!Cache::has($this->key))return;
                 /** @var Collection $task */
                 list($task,$location) = Cache::get($this->key);
-                if ($this->count!==$task->count())return;
+                if ($this->count!=$task->count())return;
                 $dataToPost = $service->makeJson_move_multi($task, '缓存架入立架', $location);
                 $controlSuccess = $service->controlHaiRobot($dataToPost,$task,'缓存架入立架');
                 $tIds = [];
@@ -119,7 +118,9 @@ class CacheShelfTaskJob implements ShouldQueue
                 }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,false);
-            },"to_station_id")){DB::commit();return $stations->count()==0;} //缓存架用完 跳出,否则接着分发
+            },"to_station_id")){
+                Log::debug("队列事务4",["缓存架剩余数量:{$stations->count()}"]);
+                DB::commit();return $stations->count()==0;} //缓存架用完 跳出,否则接着分发
             DB::rollBack();
         }catch (\Exception $e){
             DB::rollBack();
@@ -151,6 +152,7 @@ class CacheShelfTaskJob implements ShouldQueue
             },function ($service,$toLocation,$task,$prefix){
                 return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架',20,false);
             },"fm_station_id")){
+                Log::debug("队列事务5",["缓存架剩余数量:{$stations->count()}"]);
                 DB::commit();return $stations->count()==0; //缓存架用完 跳出,否则接着分发
             }
             DB::rollBack();
@@ -186,7 +188,7 @@ class CacheShelfTaskJob implements ShouldQueue
         }
         app("BatchUpdateService")->batchUpdate("station_task_material_boxes",$updateTask);
         app("BatchUpdateService")->batchUpdate("task_transactions",$updateTransaction);
-        if ($execute($service,$toLocation,$task,$tasks[0]->station_task_batch_id)){
+        if ($execute($service,$toLocation,$task,$tasks[0]->station_task_batch_id ?: '')){
             foreach ($toLocation as $value){
                 app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
                 Cache::forever("CACHE_SHELF_OCCUPANCY_{$map[$value]}",true);

+ 0 - 2
app/Services/CacheShelfService.php

@@ -212,12 +212,10 @@ 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);
-        LogService::log("海柔任务","队列事务分发","队列开始处理");
         CacheShelfTaskJob::dispatch("CACHE_SHELF_AVAILABLE",$available)->delay(now()->addSeconds(config("haiRou.cacheShelf.outBinAwait",3)));
     }
 }

+ 0 - 1
app/Services/ForeignHaiRoboticsService.php

@@ -413,7 +413,6 @@ class ForeignHaiRoboticsService
             $response = Http::post(config('api.haiq.storage.moveBin'), $dataToPost);
             if(isset($response->json()['code'])&&$response->json()['code']==500)
                 throw new ErrorException('机器人500错误:'.json_encode($response->json()));
-            LogService::log('海柔请求','runMany','波次任务分配6.r5f2c1.52:');
             LogService::log(__METHOD__,'runMany','波次任务分配6.r5f2c1.53:'.json_encode($response->json()));
         }catch (\Exception $e){
             LogService::log('海柔请求','runMany','波次任务分配6.r5f2c1.54:'.json_encode($dataToPost).$e->getMessage());

+ 3 - 3
config/logging.php

@@ -54,7 +54,7 @@ return [
             'driver' => 'daily',
             'path' => storage_path('logs/error.log'),
             'level' => 'error',
-            'permission' => '0666',
+            //'permission' => '0666',
             'days' => 14,
         ],
 
@@ -63,7 +63,7 @@ return [
             'tap' => [App\Logging\DebugFormatter::class],
             'path' => storage_path('logs/debug.log'),
             'level' => 'debug',
-            'permission' => '0666',
+            //'permission' => '0666',
             'days' => 7,
         ],
         'critical'=> [
@@ -78,7 +78,7 @@ return [
             'tap' => [App\Logging\ErrorFormatter::class],
             'path' => storage_path('logs/error.log'),
             'level' => 'error',
-            'permission' => '0666',
+            //'permission' => '0666',
             'days' => 14,
             "bubble"=>false,
         ],