LD пре 5 година
родитељ
комит
d6ba212b81

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

@@ -283,9 +283,8 @@ sql;
 
     function t1(Request $request)
     {
-        $c1=collect([1,3,5]);
-        $c2=$c1->merge(collect([333,444]));
-        var_dump($c1,$c2);
+        DB::connection('oracle')->update(DB::raw("update BAS_SKU set HAZARD_FLAG= 'N' where SKU= '13564151055'"));
+//        DB::connection('oracle')->update(DB::raw("UPDATE DOC_ORDER_HEADER SET notes = CASE WHEN notes IS NULL THEN '停运' ELSE  notes||',停运' END where ORDERNO in ('','SO190628000050','SO190628000001')"));
     }
 
     function packageT(Request $request)

+ 1 - 0
app/Services/BatchService.php

@@ -100,6 +100,7 @@ Class BatchService
                     ];
                 }
             }
+            return null;
         });
 
         $json= [

+ 1 - 1
app/Services/StationTaskMaterialBoxService.php

@@ -55,7 +55,7 @@ class StationTaskMaterialBoxService
          $this->stationTaskService
             ->registerSubTasks(
                 $stationTasks_toAttach,
-                $stationTaskMaterialBoxes);
+                [$stationTaskMaterialBoxes]);
         return $stationTaskMaterialBoxes;
 
     }

+ 1 - 1
app/Services/StationTaskService.php

@@ -38,7 +38,7 @@ class StationTaskService
      * @param Collection $tasks
      * @param Collection $subTaskLists 二维数组,第一维是对应注册的任务
      */
-    function registerSubTasks(Collection $tasks, Collection $subTaskLists)
+    function registerSubTasks(Collection $tasks, iterable $subTaskLists)
     {
         $this->instant($this->stationTaskChildService,'StationTaskChildService');
         $taskChildren_toInsert=collect();

+ 27 - 3
app/StationTask.php

@@ -19,14 +19,38 @@ class StationTask extends Model
 
     public function stationTaskCommodities()
     {   //任务商品列表
-        return $this->morphTo()->where("station_task_table_type","station_task_commodities");
+        return $this->morphToMany(
+            StationTaskCommodity::class,
+            'station_taskable',
+            'station_task_children',
+            'station_task_id',
+            'station_taskable_id',
+            'id',
+            'id',
+            true);
     }
     public function stationTaskBatches()
     {   //任务波次 目前为单个,取值时应取第一个即可
-        return $this->morphTo()->where("station_task_table_type","station_task_batches");
+        return $this->morphToMany(
+            StationTaskBatch::class,
+            'station_taskable',
+            'station_task_children',
+            'station_task_id',
+            'station_taskable_id',
+            'id',
+            'id',
+            true);
     }
     public function stationTaskMaterialBoxes()
     {   //任务料箱
-        return $this->morphTo()->where("station_task_table_type","station_task_material_boxes");
+        return $this->morphToMany(
+            StationTaskMaterialBox::class,
+            'station_taskable',
+            'station_task_children',
+            'station_task_id',
+            'station_taskable_id',
+            'id',
+            'id',
+        true);
     }
 }

+ 16 - 0
app/Traits/TestMockSubServices.php

@@ -55,4 +55,20 @@ trait TestMockSubServices{
         $this->data[$iName]++;
         return $this->data[$iName];
     }
+    function makeArray($amount,$array)
+    {
+        $resultArrays=[];
+        for($i=0;$i<$amount;$i++){
+            $newArr=[];
+            foreach ($array as $key=>$item){
+                if(gettype($item)=='object'){
+                    $newArr[$key]=$item;
+                }else{
+                    $newArr[$key]=$item();
+                }
+            }
+            $resultArrays[]= $newArr;
+        }
+        return $resultArrays;
+    }
 }

+ 2 - 2
public/t.php

@@ -1,4 +1,4 @@
 <?php
 
-$s = '434211kjk';
-var_dump(preg_match('/434/',$s));
+$s = function (){};
+var_dump();

+ 37 - 0
tests/Services/StationTaskBatch/RunManyTest.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Tests\Services\StationTaskBatch;
+use App\Services\StationTaskBatch;
+use Tests\TestCase;
+use App\StationTaskBatch;
+use App\Traits\TestMockSubServices;
+
+class RunManyTest extends TestCase
+{
+    use TestMockSubServices;
+    /** @var StationTaskBatch $service */
+    public $service;
+    private $data;
+    private $amount=2;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('StationTaskBatch');
+        $this->data['StationTaskBatses']
+            = factory(StationTaskBatch::class, $this->amount)
+            ->create();
+    }
+
+    public function testReturned()
+    {
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        StationTaskBatch::query()
+            ->whereIn('id',data_get($this->data['StationTaskBatses'],'*.id')??[])
+            ->delete();
+        parent::tearDown();
+    }
+}

+ 12 - 15
tests/Services/StationTaskCommodityService/CreateByBatchTest.php

@@ -34,25 +34,22 @@ class CreateByBatchTest extends TestCase
                     'status'=>'未处理',
                 ]);
         $this->data['orders'] =
-            factory(Order::class,
-                $this->orderAmount)
-                ->create([
+            factory(Order::class)
+                ->createMany($this->makeArray($this->orderAmount,[
                     'status'=>'未处理',
-                    'batch_id'=>$this->getTargetIdCirculately($this->data['batches']),
-                ]);
+                    'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
+                ]));
         $this->data['orderBins'] =
-            factory(OrderBin::class,
-                $this->orderAmount)
-                ->create([
-                    'order_id'=>$this->getTargetIdCirculately($this->data['orders']),
+            factory(OrderBin::class)
+                ->createMany($this->makeArray($this->orderAmount,[
+                    'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);},
                     'number'=>$this->getIntegerIncreasely('orderBins_number'),
-                ]);
+                ]));
         $this->data['orderCommodities'] =
-            factory(OrderCommodity::class,
-                $this->orderCommodityAmount)
-                ->create([
-                    'order_id'=>$this->getTargetIdCirculately($this->data['orders']),
-                ]);
+            factory(OrderCommodity::class)
+                ->createMany($this->makeArray($this->orderCommodityAmount,[
+                    'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);},
+                ]));
     }
 
     public function testReturned()

+ 4 - 4
tests/Services/StationTaskCommodityService/CreateByBatchesTest.php

@@ -37,14 +37,14 @@ class CreateByBatchesTest extends TestCase
                 ]);
         $this->data['orders'] =
             factory(Order::class)
-                ->createMany(array_fill(0, $this->orderAmount, [
+                ->createMany($this->makeArray($this->orderAmount,[
                     'status'=>'未处理',
-                    'batch_id'=>$this->getTargetIdCirculately($this->data['batches']),
+                    'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
                 ]));
         $this->data['orderCommodities'] =
             factory(OrderCommodity::class)
-                ->createMany(array_fill(0, $this->orderCommodityAmount, [
-                    'order_id'=>$this->getTargetIdCirculately($this->data['orders']),
+                ->createMany($this->makeArray($this->orderAmount,[
+                    'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);}
                 ]));
     }
 

+ 14 - 6
tests/Services/StationTaskMaterialBoxService/CreateByBatchesTest.php

@@ -29,17 +29,17 @@ class CreateByBatchesTest extends TestCase
             ->create();
         $this->data['orders']
             = factory(Order::class)
-            ->createMany(array_fill(0, $this->orderAmount, [
-                'batch_id' => $this->getTargetIdCirculately($this->data['batches'])
+            ->createMany($this->makeArray($this->orderAmount,[
+                'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
             ]));
         $this->data['materialBoxes']
             = factory(MaterialBox::class, $this->materialBoxAmount)
             ->create();
         $this->data['orderCommodities']
             = factory(OrderCommodity::class)
-            ->createMany(array_fill(0, $this->orderAmount, [
-                'order_id'=>$this->getTargetIdCirculately($this->data['orders']),
-                'location'=>$this->getTargetIdCirculately($this->data['materialBoxes'],'','code'),
+            ->createMany($this->makeArray($this->materialBoxAmount,[
+                'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);},
+                'location' => function(){return $this->getTargetIdCirculately($this->data['materialBoxes'],'','code');},
             ]));
         $this->data['stationTasks']
             = factory(StationTask::class, $this->batchAmount)
@@ -50,8 +50,16 @@ class CreateByBatchesTest extends TestCase
     {
         $this->data['stationTaskMaterialBoxes']=$this->service->createByBatches($this->data['batches'],$this->data['stationTasks'] );
         $this->assertTrue($this->data['stationTaskMaterialBoxes']->isNotEmpty());
-        $this->assertEquals(StationTaskMaterialBox::class, $this->data['stationTaskMaterialBoxes']->first());
+        $this->assertEquals(StationTaskMaterialBox::class, get_class($this->data['stationTaskMaterialBoxes']->first()));
         $this->assertEquals($this->materialBoxAmount, $this->data['stationTaskMaterialBoxes']->count());
+        $this->assertEquals($this->materialBoxAmount, (function(){
+            $taskBoxes=collect();
+            foreach ($this->data['stationTasks'] as $stationTask){
+                $stationTask->loadMissing('stationTaskMaterialBoxes');
+                $taskBoxes=$taskBoxes->merge($stationTask['stationTaskMaterialBoxes']);
+            }
+            return $taskBoxes->count();
+        })());
     }
 
     function tearDown(): void