LD vor 5 Jahren
Ursprung
Commit
9da49f926d

+ 8 - 8
app/Services/StationTaskBatchService.php

@@ -77,7 +77,7 @@ class StationTaskBatchService
         }
         $this->batchService->updateWhereIn('id', data_get($batches_handled, '*.id'), ['status' => '处理中']);
         $this->insert($stationTaskBatches_toCreate->toArray());
-        $stationTaskBatches_toCreate=$this->getWithIds($stationTaskBatches_toCreate);
+        $stationTaskBatches_toCreate=$this->getAndAttachIds($stationTaskBatches_toCreate);
         $this->stationTaskService->registerSubTasks(
             $stationTasks_toAttach,
             $stationTaskBatches_toCreate->map(function($taskBatch){
@@ -88,18 +88,18 @@ class StationTaskBatchService
         return $stationTaskBatches_toCreate;
     }
 
-    function getWithIds($stationMissionBatches): Collection
+    function getAndAttachIds($stationTaskBatches): Collection
     {
-        $md5=is_array($stationMissionBatches)
-            ?$md5=md5(json_encode($stationMissionBatches)):null;
+        $md5=is_array($stationTaskBatches)
+            ?$md5=md5(json_encode($stationTaskBatches)):null;
 
         return Cache::remember(
-            $md5??md5(json_encode($stationMissionBatches->toArray()))
+            'StationTaskBatch_'.$md5??md5(json_encode($stationTaskBatches->toArray()))
             ,config('cache.expirations.rarelyChange')
-            ,function()use($stationMissionBatches){
+            ,function()use($stationTaskBatches){
             return StationTaskBatch::query()
-                ->whereIn('status',data_get($stationMissionBatches,'*.status'))
-                ->whereIn('batch_id',data_get($stationMissionBatches,'*.batch_id'))
+                ->whereIn('status',data_get($stationTaskBatches,'*.status'))
+                ->whereIn('batch_id',data_get($stationTaskBatches,'*.batch_id'))
                 ->get();
         });
     }

+ 20 - 0
app/Services/StationTaskCommodityService.php

@@ -7,6 +7,7 @@ namespace App\Services;
 use App\Batch;
 use App\OrderCommodity;
 use App\StationTask;
+use App\StationTaskBatch;
 use App\StationTaskCommodity;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
@@ -47,12 +48,31 @@ class StationTaskCommodityService
                 $this->createByBatch($batch)
             );
         }
+        $stationTaskCommodities_listByBatch=$this->getAndAttachIds($stationTaskCommodities_listByBatch);
         $this->stationTaskService->registerSubTasks(
             $stationTasks_toAttach,
             $stationTaskCommodities_listByBatch);
+        return $stationTaskCommodities_listByBatch;
 
     }
 
+    function getAndAttachIds($taskCommodities): Collection
+    {
+        $md5=is_array($taskCommodities)
+            ?$md5=md5(json_encode($taskCommodities)):null;
+
+        return Cache::remember(
+            'StationTaskCommodity_'.$md5??md5(json_encode($taskCommodities->toArray()))
+            ,config('cache.expirations.rarelyChange')
+            ,function()use($taskCommodities){
+            return StationTaskCommodity::query()
+                ->whereIn('status',data_get($taskCommodities,'*.status'))
+                ->whereIn('station_task_batch_id',data_get($taskCommodities,'*.station_task_batch_id'))
+                ->whereIn('commodity_id',data_get($taskCommodities,'*.commodity_id'))
+                ->get();
+        });
+    }
+
     function createByBatch(Batch $batch): Collection
     {
         $this->stationTypeService=app('StationTypeService');

+ 27 - 0
tests/Services/StationTaskCommodityService/CreateByBatchesTest.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace Tests\Services\StationTaskCommodityService;
+use App\Services\StationTaskCommodityService;
+use Tests\TestCase;
+
+class CreateByBatchesTest extends TestCase
+{
+
+    /** @var StationTaskCommodityService $service */
+    public $service;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('StationTaskCommodityService');
+    }
+
+    public function testReturned()
+    {
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        parent::tearDown();
+    }
+}