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

Merge branch 'master' into zengjun

ajun 5 лет назад
Родитель
Сommit
310cdaf2a2

+ 1 - 0
app/Services/BatchService.php

@@ -48,6 +48,7 @@ Class BatchService
         //注册料箱任务
         //注册商品任务
         //注册总任务
+        //执行总任务
     }
 
     public function getBatchByCodes($codes)

+ 7 - 1
app/Services/OwnerService.php

@@ -122,7 +122,7 @@ Class OwnerService
         $customerIds = array_diff($customerIds,[null,'','*']);
         $owners = Owner::query()->whereIn('code',$customerIds)->get();
 
-         if($owners->count() < count($customerIds)){
+        if($owners->count() < count($customerIds)){
             $customerIds = array_diff($customerIds,data_get($owners,'*.code'));
             $owner_list = $this->createByWmsCustomerIds($customerIds);
             $owners=$owners->concat($owner_list);
@@ -237,4 +237,10 @@ Class OwnerService
             return Owner::query()->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
         });
     }
+    public function codeGetOwner($code)
+    {
+        return app(CacheService::class)->getOrExecute("owner_".$code,function ()use($code){
+            return Owner::query()->firstOrCreate(["code"=>$code],["code"=>$code,"name"=>$code]);
+        });
+    }
 }

+ 46 - 0
app/Services/StationRuleBatchService.php

@@ -0,0 +1,46 @@
+<?php
+
+
+namespace App\Services;
+
+
+use App\Batch;
+use App\StationRuleBatch;
+use App\StationType;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
+
+class StationRuleBatchService
+{
+    function getByBatch(Batch $batch): StationRuleBatch
+    {
+        $batchType = $batch['type'] ?? 'null';
+        $ownerId = $batch['owner_id'] ?? 'null';
+        return Cache::remember('stationType_type_'.$batchType.'_ownerId_'.$ownerId, config('cache.expirations.rarelyChange'),function($batch){
+            return StationRuleBatch::query()->with('stationType')->where('batch_type',$batch['type'])
+                ->where('owner_id',$batch['owner_id'])
+                ->first();
+        });
+    }
+
+    function getStationType_toBeTask(Batch $batch): ?StationType{
+        $stationRuleBatch=$this->getByBatch($batch);
+        if(!$stationRuleBatch)return null;
+        return $stationRuleBatch['stationType'];
+    }
+
+    /**
+     * @param Batch[] $batches
+     * @return Collection
+     */
+    function getBatches_canProcess(array $batches): Collection
+    {
+        $batches_toProcess=collect();
+        foreach ($batches as $batch){
+            $stationRuleBatch=$this->getByBatch($batch);
+            if($stationRuleBatch)
+            $batches_toProcess->push($batch);
+        }
+        return $batches_toProcess;
+    }
+}