瀏覽代碼

波次任务BUG

LD 5 年之前
父節點
當前提交
9c1dff685f

+ 2 - 2
app/Console/Commands/SyncBatchTask.php

@@ -36,7 +36,7 @@ class SyncBatchTask extends Command
 
     public function handle()
     {
-        sleep(100+rand(0,10));
+        sleep(10+rand(0,10));
         $this->disposeHeader();
         sleep(rand(0,10));
         $this->disposeDetail();
@@ -213,6 +213,7 @@ sql;
             }
         }
         $batches = $this->batchService->get(["code"=>$nos]);
+        BatchTaskJob::dispatch($batches);    //在这里为波次注册队列任务!
         $batchDiff = array_keys(array_flip(array_diff($nos,array_column($batches->toArray(),"code"))));
         if (count($batchDiff)>0){
             $sql = <<<sql
@@ -262,7 +263,6 @@ sql;
                 foreach ($batches as $batch){
                     app("OrderService")->update(["code"=>$map[$batch->code]],["batch_id"=>$batch->id]);
                 }
-                BatchTaskJob::dispatch($batches);    //在这里为波次注册队列任务!
             }
         }
         ValueStore::query()->where("name","wave_detail_last_sync_date")->update(["value"=>$details[count($details)-1]->edittime]);

+ 23 - 1
app/Http/Controllers/TestController.php

@@ -27,6 +27,7 @@ use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
 use App\Http\Requests\TestAaRequest;
 use App\Imports\OrderTrackingImport;
 use App\InventoryAccount;
+use App\Jobs\BatchTaskJob;
 use App\Jobs\OrderCreateInstantBill;
 use App\Jobs\OrderFreeze;
 use App\LaborReport;
@@ -103,6 +104,7 @@ use App\Services\StoreService;
 use App\Services\WarehouseService;
 use App\StationRuleBatch;
 use App\StationTask;
+use App\StationTaskMaterialBox;
 use App\Store;
 use App\StationTaskBatch;
 use App\StoreCheckingReceiveItem;
@@ -167,7 +169,27 @@ class TestController extends Controller
         dd(Region::query()->where("id", ">=", 404)->where("id", "<=", 432)->delete());
     }
     public function tt1(){
-       return view("store.deliveryAppointment.success");
+        $stationTaskMaterialBoxId=StationTaskMaterialBox::query()->where('station_task_batch_id',87255)->where('material_box_id',$materialBox['id'])->get('id');
+    }
+    public function assignBatch(){
+        $batches = collect([
+  [
+    "id"=> 87255,
+    "code"=> "W210312000317",
+    "status"=> "\u672a\u5904\u7406",
+    "type"=> null,
+    "wms_type"=> "09.[BAOSHI]\u622a\u5355\u6ce2\u6b21\u3010\u65e0\u5907\u6ce8\u3011",
+    "wms_status"=> "\u90e8\u5206\u6536\u8d27",
+    "wms_created_at"=> "0000-00-00 00=>00=>00",
+    "created_at"=> "2021-03-12T09=>10=>44.000000Z",
+    "updated_at"=> "2021-03-12T09=>10=>44.000000Z",
+    "remark"=> null,
+    "owner_id"=> "42",
+    "station_task_batch"=> null
+  ]
+]);
+        $batches=Batch::query()->where('id',data_get($batches,'*.id'))->get();
+        app('BatchService')->assignTasks($batches);
     }
 
     public function zzd()

+ 1 - 0
app/Jobs/BatchTaskJob.php

@@ -3,6 +3,7 @@
 namespace App\Jobs;
 
 use App\Services\BatchService;
+use App\Services\LogService;
 use App\Traits\TestableInstant;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;

+ 2 - 2
app/Services/BatchService.php

@@ -68,16 +68,16 @@ class BatchService
             $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
             $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
 
-
             $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
             if($batches_shouldProcess->isEmpty()) return;
 
             $stationTasks =  $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
             $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
-            $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
             $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
+            $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
 
             $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
+            LogService::log('batchservice',__FUNCTION__,'8'.$ran->toJson());
         }catch(Exception $e){
             throw new ErrorException('注册任务失败: '.json_encode($batches). $e->getMessage());
         }

+ 4 - 1
app/Services/StationRuleBatchService.php

@@ -6,6 +6,7 @@ namespace App\Services;
 
 use App\Batch;
 use App\StationRuleBatch;
+use App\StationTaskBatch;
 use App\StationType;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
@@ -46,10 +47,12 @@ class StationRuleBatchService
     function getBatches_shouldProcess(Collection $batches): Collection
     {
         $batches_toProcess=collect();
+        $batches_inTask=StationTaskBatch::query()->whereIn('batch_id',data_get($batches,'*.id'))->get();
+        $batches=$batches->whereNotIn('id',data_get($batches_inTask,'*.id')??[]);
         foreach ($batches as $batch){
             $stationRuleBatch=$this->getByBatch($batch);
             if($stationRuleBatch)
-            $batches_toProcess->push($batch);
+                $batches_toProcess->push($batch);
         }
         return $batches_toProcess;
     }

+ 2 - 1
app/Services/StationTaskBatchService.php

@@ -59,7 +59,7 @@ class StationTaskBatchService
 
         $batches_handled = collect();
         foreach ($batches as $batch) {
-            if ($batch['status'] == '未处理') {
+            if ($batch['status'] != '已处理') {
                 $stationType = $this->stationTypeService->getByBatch($batch);
                 $station = $this->stationService->getStation_byType($stationType['name']);
                 $stationTaskBatches_toCreate->push(
@@ -75,6 +75,7 @@ class StationTaskBatchService
         }
         $this->batchService->updateWhereIn('id', data_get($batches_handled, '*.id'), ['status' => '处理中']);
         $this->insert($stationTaskBatches_toCreate->toArray());
+
         $stationTaskBatches_toCreate=$this->getAndAttachIds($stationTaskBatches_toCreate);
         $this->stationTaskService->registerSubTasks(
             $stationTasks_toAttach,

+ 7 - 1
app/Services/StationTaskService.php

@@ -4,6 +4,7 @@
 namespace App\Services;
 
 
+use App\Batch;
 use App\StationTask;
 use App\StationTaskBatch;
 use App\StationTaskChild;
@@ -21,6 +22,8 @@ class StationTaskService
     private $stationTaskChildService;
     /** @var StationService $stationService  */
     private $stationService;
+    /** @var BatchService $batchService  */
+    private $batchService;
     public function __construct()
     {
         $this->stationTaskChildService=null;
@@ -109,9 +112,12 @@ class StationTaskService
         if (get_class($stationTask_orCollection)==StationTask::class){
             $stationTask_orCollection = collect([$stationTask_orCollection]);
         }
+        $ids_stationTasks = data_get($stationTask_orCollection, '*.id')??[];
         $this->markProcessed_byIds(
-            data_get($stationTask_orCollection, '*.id')
+            $ids_stationTasks
         );
+        $stationTaskBatches=StationTaskBatch::query()->whereIn('station_task_id',$ids_stationTasks);
+        $this->batchService->updateWhereIn('id', data_get($stationTaskBatches, '*.batch_id'), ['status' => '已处理']);
     }
 
 

+ 1 - 1
app/StationTaskBatch.php

@@ -46,7 +46,7 @@ class StationTaskBatch extends Model
             'station_task_batch_id',
             'id',
             'id',
-            'material_box_id',
+            'material_box_id'
         );
     }