ajun 5 роки тому
батько
коміт
f7b2952397

+ 1 - 1
app/Services/LogisticService.php

@@ -101,7 +101,7 @@ Class LogisticService
     }
 
     public function getLogisticByCode($code){
-        return Cache::remember("getLogisticByCode_{$code}", config('database.cache.expirations.rand'), function()use($code){
+        return Cache::remember("getLogisticByCode_{$code}", config('database.cache.expirations.logistic'), function()use($code){
             $logistic = Logistic::query()->where('code',$code)->first();
             if($logistic)return $logistic;
             $baseCustomers = app('OracleBasCustomerService')->first(['Customer_Type'=>'CA','CustomerID'=>'$code']);

+ 1 - 1
app/Services/OrderService.php

@@ -820,7 +820,7 @@ class OrderService
         $owners = $ownerService->getOwnerByCodes($owner_codes);
         $logistics = $logisticService->getLogisticByCodes($logistic_codes);
         $shops = $shopService->getShopByCodeMap($shop_names);
-        $warehouses = $warehouseService->getWareHouseByCode($warehouse_codes);
+        $warehouses = $warehouseService->getWareHouseByCodes($warehouse_codes);
 
         $orders = $this->getByWmsOrders($orderHeaders);
 

+ 1 - 1
app/Services/OwnerService.php

@@ -229,7 +229,7 @@ Class OwnerService
     }
 
     public function getOwnerByCode($code){
-        return Cache::remember("getOwnerByCode_{$code}", config('database.cache.expirations.rand'), function ()use($code){
+        return Cache::remember("getOwnerByCode_{$code}", config('database.cache.expirations.owner'), function ()use($code){
             $owner = Owner::query()->where('code',$code)->first();
             if($owner) return $owner;
             $basCustomer = app('OracleBasCustomerService')->first(['Customer_Type'=>'OW','CustomerID'=>$code]);

+ 12 - 8
app/Services/WarehouseService.php

@@ -105,20 +105,24 @@ Class WarehouseService
         return Warehouse::query()->insert($fillables);
     }
 
-    public function getWareHouseByCode($codes)
+    public function getWareHouseByCodes($codes)
     {
         $collect = collect();
         if(count($codes)==0)return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("WareHouse_{$code}",config('database.cache.expirations.rand'),function()use($code){
-                $wareHouse =  Warehouse::query()->where('code',$code)->first();
-                if($wareHouse)return $wareHouse;
-                $bas_customer = OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('CustomerId',$code)->where('Customer_Type','WH')->first();
-                if(!$bas_customer) return null;
-                return Warehouse::query()->create(['name'=>$bas_customer['descr_c'],'code'=>$bas_customer['customerid']]);
-            }));
+            $collect->push($this->getWareHouseByCode($code));
         }
         return $collect;
     }
+
+    public function getWareHouseByCode($code){
+        return Cache::remember("WareHouse_{$code}",config('database.cache.expirations.warehouse'),function()use($code){
+            $wareHouse =  Warehouse::query()->where('code',$code)->first();
+            if($wareHouse)return $wareHouse;
+            $bas_customer = app('OracleBasCustomerService')->first(['CustomerId'=>$code,'Customer_Type'=>'WH']);
+            if(!$bas_customer) return null;
+            return Warehouse::query()->create(['name'=>$bas_customer['descr_c'],'code'=>$bas_customer['customerid']]);
+        });
+    }
 }
 

+ 2 - 0
config/cache.php

@@ -10,6 +10,8 @@ return [
         'rarelyChange'=>60,     //几乎不变
         'commonFrequent'=>20,  //一般频率
         'owners'=>20,           //模型Owner
+        'logistic'=>40,           //模型Logistic
+        'warehouse'=>60,           //模型WareHouse
     ],
     /*
     |--------------------------------------------------------------------------

+ 0 - 2
tests/Services/WarehouseService/GetByWmsOrderTest.php

@@ -3,10 +3,8 @@
 namespace Tests\Services\WarehouseService\GetByWmsOrdersTest;
 
 use App\OracleBasCustomer;
-use App\OracleDOCOrderHeader;
 use App\Services\WarehouseService;
 use App\Warehouse;
-use Carbon\Carbon;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Tests\TestCase;
 

+ 12 - 17
tests/Services/WarehouseService/GetWareHouseByCodeTest.php

@@ -3,11 +3,10 @@
 namespace Tests\Services\WarehouseService;
 
 use App\OracleBasCustomer;
-use App\Services\OwnerService;
+use App\Services\OracleBasCustomerService;
 use App\Services\WarehouseService;
 use App\Warehouse;
 use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
 use Tests\TestCase;
 
 class GetWareHouseByCodeTest extends TestCase
@@ -22,10 +21,13 @@ class GetWareHouseByCodeTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service = app('WarehouseService');
-        $basCustomers = OracleBasCustomer::query()->selectRaw('CustomerId,Descr_C')->where('Customer_Type','WH')->get();
-        $this->data['basCustomers'] = $basCustomers;
-        $this->data['codes'] = $basCustomers->map(function ($basCustomer){
-            return $basCustomer->customerid;
+        $warehouse = factory(Warehouse::class)->create();
+        $basCustomer = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse->code,'descr_c'=>$warehouse->name]);
+        $this->data['warehouse'] = $warehouse;
+        $this->data['code'] = $warehouse->code;
+        $this->data['basCustomer'] = $basCustomer;
+        $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
         });
     }
 
@@ -34,21 +36,14 @@ class GetWareHouseByCodeTest extends TestCase
      */
     public function getWareHouseByCodeTest()
     {
-        $wareHouses =  $this->service->getWareHouseByCode($this->data['codes']);
-        $this->assertNotEmpty($wareHouses);
-        foreach ($wareHouses as $wareHouse) {
-            $basCustomer = $this->data['basCustomers']->where('customerid',$wareHouse->code)->where('descr_c',$wareHouse->name);
-            $this->assertNotEmpty($basCustomer);
-        }
-        foreach ($this->data['basCustomers'] as $basCustomer) {
-            $wareHouse = $wareHouses->where('name',$basCustomer['descr_c'])->where('code',$basCustomer['customerid']);
-            $this->assertNotEmpty($wareHouse);
-        }
+        $warehouse = $this->service->getWareHouseByCode($this->data['code']);
+        $this->assertEquals($warehouse->toArray(),$this->data['warehouse']->toArray());
     }
 
+
     public function tearDown(): void
     {
-        cache()->flush();
+        $this->data['warehouse']->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 37 - 0
tests/Services/WarehouseService/GetWareHouseByCodesTest.php

@@ -0,0 +1,37 @@
+<?php
+
+
+namespace Tests\Services\WarehouseService;
+
+
+use App\Services\WarehouseService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class GetWareHouseByCodesTest extends TestCase
+{
+    use RefreshDatabase;
+    /** @var WarehouseService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('WarehouseService');
+    }
+
+    /**
+     * @test
+     */
+    public function getWareHouseCodes(){
+        $this->assertNotNull(11);
+    }
+
+    public function tearDown(): void
+    {
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+
+
+}