Просмотр исходного кода

海柔放置料箱逻辑重叠

LD 5 лет назад
Родитель
Сommit
bfaff8222c

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

@@ -352,8 +352,6 @@ class TestController extends Controller
 
     function packageT(Request $request)
     {
-        $package = Package::where('created_at', '<', '2020-07-08')->whereNotNull('logistic_number')->first();
-        $package->fetchLogistic();
     }
 
     function injectJS(Request $request)

+ 11 - 1
app/Http/Controllers/api/thirdPart/haiq/StorageController.php

@@ -43,7 +43,17 @@ class StorageController
             "taskMode"      => 1,
             "bins"=>[[
                 "taskCode"  =>'t'.microtime(true),
-                "binCode"   => "IDE0005713",
+                "binCode"   => "IDE0005665",
+                "fromLocCode" => "BIN-IN1",
+                "toLocCode" => "",
+            ],[
+                "taskCode"  =>'t1'.microtime(true),
+                "binCode"   => "IDE0005656",
+                "fromLocCode" => "BIN-IN1",
+                "toLocCode" => "",
+            ],[
+                "taskCode"  =>'t2'.microtime(true),
+                "binCode"   => "IDE0005657",
                 "fromLocCode" => "BIN-IN1",
                 "toLocCode" => "",
             ],],

+ 18 - 7
app/Services/ForeignHaiRoboticsService.php

@@ -210,7 +210,16 @@ class ForeignHaiRoboticsService
         );
         LogService::log('海柔请求','putBinToStore3',
             json_encode($dataToPost));
-        return $this->controlHaiRobot($dataToPost);
+        $controlSuccess = $this->controlHaiRobot($dataToPost);
+        if($controlSuccess){
+            $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
+            $this->stationTaskMaterialBoxService->set($stationTaskMaterialBox,[
+                'id' => $stationTaskMaterialBox['id'],
+                'status' => $stationTaskMaterialBox['status']='处理中',
+                'station_id' => 4,
+            ]);
+        }
+        return $controlSuccess;
     }
 
     public function taskUpdate(
@@ -247,18 +256,20 @@ class ForeignHaiRoboticsService
                         ->get()
                         ->toJson());
             }
-            ($标记已放置在库外=
+            if(($标记已放置=
                 function()use($updateEventType,$stationTaskMaterialBox){
                     if(($isPut
                             =$updateEventType)==1){
-                        $this->stationTaskMaterialBoxService->markHasTaken($stationTaskMaterialBox);
-                    }
-                })();
-            ($标记已入立架=
+                        $this->stationTaskMaterialBoxService->markHasPut($stationTaskMaterialBox);
+                        return true;
+                    }return false;
+                })())
+                    return true;
+            ($标记已取出=
                 function()use($updateEventType,$stationTaskMaterialBox){
                     if(($isGet
                             =$updateEventType)==0){
-                        $this->stationTaskMaterialBoxService->markPutStored($stationTaskMaterialBox);
+                        $this->stationTaskMaterialBoxService->markHasTaken($stationTaskMaterialBox);
                     }
                 })();
         }catch (\Exception $e){

+ 15 - 0
app/Services/StationRuleBatchService.php

@@ -11,6 +11,7 @@ use App\StationType;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
 use App\Traits\ServiceAppAop;
+use Illuminate\Support\Facades\DB;
 
 
 class StationRuleBatchService
@@ -19,8 +20,11 @@ class StationRuleBatchService
     protected $modelClass=StationRuleBatch::class;
     function getByBatch(?Batch $batch): ?StationRuleBatch
     {
+        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;//? 这行有啥用?
         return Cache::remember('stationRuleBatch_batchType_'.$batchType.'_ownerId_'.$ownerId, config('cache.expirations.rarelyChange'),function()use($batch){
@@ -30,9 +34,17 @@ class StationRuleBatchService
                 && $batch['type']!='无'){
                 $builder=$builder->where('batch_type',$batch['type']);
             }
+            LogService::log(__METHOD__,'getByBatch','波次任务分配1.23:');
             return $builder->first();
         });
     }
+    function isLocationOfRobot(?Batch $batch): bool
+    {
+        if(!$batch)return false;
+        $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 = ?))";
+        $billDetails = DB::select(DB::raw($sql),[$batch['id']]);
+        return $billDetails[0]->count>0;
+    }
 
     function getStationType_toBeTask(Batch $batch): ?StationType{
         $stationRuleBatch=$this->getByBatch($batch);
@@ -46,14 +58,17 @@ class StationRuleBatchService
      */
     function getBatches_shouldProcess(Collection $batches): Collection
     {
+        LogService::log(__METHOD__,'shouldProcess','波次任务分配1.1:'.json_encode($batches));
         $batches_toProcess=collect();
         $batches_inTask=StationTaskBatch::query()->whereIn('batch_id',data_get($batches,'*.id'))->get();
+        LogService::log(__METHOD__,'shouldProcess','波次任务分配1.2:'.json_encode($batches_inTask));
         $batches=$batches->whereNotIn('id',data_get($batches_inTask,'*.id')??[]);
         foreach ($batches as $batch){
             $stationRuleBatch=$this->getByBatch($batch);
             if($stationRuleBatch)
                 $batches_toProcess->push($batch);
         }
+        LogService::log(__METHOD__,'shouldProcess','波次任务分配1.3:'.json_encode($batches_inTask));
         return $batches_toProcess;
     }
 }

+ 10 - 7
app/Services/StationTaskMaterialBoxService.php

@@ -102,7 +102,7 @@ class StationTaskMaterialBoxService
     }
 
 
-    function markHasTaken(StationTaskMaterialBox $stationTaskMaterialBox){
+    function markHasPut(StationTaskMaterialBox $stationTaskMaterialBox){
         $this->instant($this->stationTaskBatchService,'StationTaskBatchService');
         $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
         $this->instant($this->stationTaskService,'StationTaskService');
@@ -121,16 +121,20 @@ class StationTaskMaterialBoxService
                     $this->stationService->broadcastBinMonitor($stationTaskMaterialBox['station_id'],$stationTaskMaterialBox['stationTask']);
                     break;
                 case '入立库':
-
+                    $this->set($stationTaskMaterialBox,[
+                        'id' => $stationTaskMaterialBox['station_id'],
+                        'status' => '完成',
+                    ]);
                     break;
-                case '入库':break;
+                case '入缓存架':break;
+                default:;
             }
         }catch (\Exception $e){
             throw new ErrorException('放置料箱出错');
         }
     }
 
-    function markPutStored($stationTaskMaterialBox){
+    function markHasTaken($stationTaskMaterialBox){
         //TODO: 标记 料箱位置(需要其字段存在)$stationTaskMaterialBox['materialBox']['position']
     }
     function processNextQueued(StationTaskMaterialBox $stationTaskMaterialBox_lastProcessed){
@@ -235,13 +239,12 @@ class StationTaskMaterialBoxService
         $stationTaskMaterialBox->load('station.stationType');
         if($isBatching=(
             $stationTaskMaterialBox['station_task_batch_id'] &&
-            $stationTaskMaterialBox['station']['stationType']['name'] == '料箱监视器')
+                $stationTaskMaterialBox['station']['stationType']['name'] == '料箱监视器')
         ){
             return '分波次';
         }
         if($isPuttingBack=(
-            !$stationTaskMaterialBox &&
-            $stationTaskMaterialBox['station']['stationType'] == '立库')
+            $stationTaskMaterialBox['station']['stationType']['name'] == '立库')
         ){
             return '入立库';
         }

+ 8 - 0
app/Traits/ServiceAppAop.php

@@ -28,6 +28,14 @@ trait ServiceAppAop
             return $query->get();
         });
     }
+    function set($target,array $kvPairs){
+        $update = $target->update($kvPairs);
+        Cache::forget($this->cachingKey($kvPairs));
+        if(isset($kvPairs['id'])){
+            Cache::forget($this->cachingKey(['id'=>$kvPairs['id']]));
+        }
+        return $update;
+    }
 
     protected function cachingKey(array $kvPairs): string
     {