Browse Source

修改测试文件

haozi 5 years ago
parent
commit
b8173de51f

+ 11 - 33
app/Http/Controllers/TestController.php

@@ -14,6 +14,7 @@ use App\Console\Commands\CreateOwnerBillReport;
 use App\Console\Commands\CreateOwnerReport;
 use App\Console\Commands\SyncWmsCommoditiesInformation;
 use App\Console\Commands\SyncWMSOrderTask;
+use App\Console\Commands\WasSyncWmsAsnInformation;
 use App\Events\CancelOrder;
 use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
 use App\Http\Requests\TestAaRequest;
@@ -1244,10 +1245,16 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
 
     public function testSyncAsn()
     {
-        dump('start' . (string)Carbon::now());
-        app(StoreService::class)->storeCreateByWms();
-        app(StoreService::class)->storeUpdateByWms();
-        dump('end' . (string)Carbon::now());
+//        dump('hendle...');
+        dump((string)Carbon::now());
+//        dump(memory_get_usage() / 1024 / 1024);
+        $task=new WasSyncWmsAsnInformation();
+        $task->handle();
+        dump((string)Carbon::now());
+//        dump('hendle...end');
+//        dump(memory_get_usage() / 1024 / 1024);
+//        dump(memory_get_peak_usage() / 1024 / 1024);
+//        return view('test');
     }
 
     public function testSyncCommodity()
@@ -1258,24 +1265,6 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         dump('end' . (string)Carbon::now());
     }
 
-    public function testSyncCommodityByMaps()
-    {
-        dump('get_start' . (string)Carbon::now());
-        $bas_skus = OracleBasSKU::query()->where('addTime', '>=', '2020-12-14 00:00:00')->select('customerid', 'sku')->get();
-
-        $ownerIds = Owner::query()->whereIn('code', data_get($bas_skus, '*.customerid'))->get()->map(function ($owner) {
-            return $owner->id;
-        })->toArray();
-        $ownerIds = array_unique($ownerIds);
-        $skus = array_unique(data_get($bas_skus, '*.sku'));
-        dump('get_end' . (string)Carbon::now());
-        /**@var  CommodityService $commodityService */
-        $commodityService = app(CommodityService::class);
-        dump('start' . (string)Carbon::now());
-        $commodities = $commodityService->get_($ownerIds, $skus, [], true);
-        dump('end' . (string)Carbon::now());
-    }
-
     public function editOrderSyncAt()
     {
         ValueStore::query()->where('name','order_last_created_sync_at')->update(['value'=>'2020-12-22 09:00:00']);
@@ -1426,15 +1415,4 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
             }
         }
     }
-
-    public function testHz(){
-        dump('start'.Carbon::now()->toDateTimeString());
-        $ownerAreaReportTask=new CreateOwnerAreaReport();
-        $ownerAreaReportTask->handle();
-        $ownerBillReportTask= new CreateOwnerBillReport();
-        $ownerBillReportTask->handle();
-        $ownerReportTask= new CreateOwnerReport();
-        $ownerReportTask->handle();
-        dump('end'.Carbon::now()->toDateTimeString());
-    }
 }

+ 1 - 1
app/Services/RejectedBillService.php

@@ -84,7 +84,7 @@ Class RejectedBillService
         if ($updateCollect->isEmpty()) return null;
         $logisticNumberReturn = $this->getLogisticNumberReturn($updateCollect);
         $rejectedBills = $this->getRejectedBills($logisticNumberReturn);
-        if ($rejectedBills->isEmpty()) return null;
+        if (!$rejectedBills) return null;
         $updateParams = [[
             'logistic_number_return', 'is_loaded', 'updated_at'
         ]];

+ 4 - 2
app/Services/StoreService.php

@@ -51,9 +51,9 @@ Class StoreService
         $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
         $last_time = $this->getAsnLastSyncAt($created_at, 'create');
         $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateCreate($last_time);
+        if (!$asnHerders) return;
         $last_time = $asnHerders->first()['addtime'];
         $last_records = $asnHerders->where('addtime', $last_time);
-        if (!$asnHerders) return;
         $this->createStore($asnHerders);
         $this->deleteCacheKey($create_set, $create_keys);
         $this->setLastRecordsByRedis($create_key, $create_set, $create_keys, $last_records);
@@ -71,9 +71,9 @@ Class StoreService
         $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
         $last_time = $this->getAsnLastSyncAt($updated_at, 'update');
         $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateEdit($last_time);
+        if (!$asnHerders) return;
         $last_time = $asnHerders->first()['edittime'];
         $last_records = $asnHerders->where('edittime', $last_time);
-        if (!$asnHerders) return;
         $this->createStore($asnHerders);
         $this->updateStore($asnHerders);
         $this->deleteCacheKey($update_set, $update_keys);
@@ -100,9 +100,11 @@ Class StoreService
         }
         $owners = $ownerService->getOwnerByCodes($owner_codes);
         $warehouses = $wareHouseService->getWareHouseByCodes($warehouse_codes);
+        $owners_code_map=[];
         foreach ($owners as $owner) {
             $owners_code_map[$owner->code] = $owner;
         }
+        $warehouses_code_map=[];
         foreach ($warehouses as $warehouse) {
             $warehouses_code_map[$warehouse->code] = $warehouse;
         }

+ 23 - 22
tests/Services/CommodityService/GetParamsByBasSkusTest.php

@@ -5,41 +5,42 @@ namespace Tests\Services\CommodityService;
 
 
 use App\OracleBasSKU;
+use App\Owner;
 use App\Services\CommodityService;
-use App\Services\OwnerService;
-use App\Store;
 use Tests\TestCase;
 
 class GetParamsByBasSkusTest extends TestCase
 {
-    /**
-     * @var CommodityService $service
-     * @var OwnerService $ownerService
-     *
-     */
+    /** @var CommodityService $service */
     public $service;
     public $bas_skus;
-    public $ownerService;
+    private $data = [];
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        cache()->flush();
+        $owner =  factory(Owner::class)->create();
+        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code]);
+        $this->data['owner'] = $owner;
+        $this->data['basSKU'] = $basSKU;
+        $this->bas_skus=collect($this->data['basSKU']);
         $this->service=app(CommodityService::class);
-        $this->ownerService=app(OwnerService::class);
-        $this->bas_skus=OracleBasSKU::query()
-            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
-            ->where('addTime', '>=', $startDate)
-            ->orderByDesc('addtime')
-            ->get();
+
     }
     public function testGetParamsByBasSkus(){
-        if ($this->bas_skus->isEmpty()) {
-            $this->assertEmpty($this->bas_skus);
-            $insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
-            $this->assertNull($insert_params);
-        }else{
+
             $insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
-            $this->assertNotNull($insert_params);
-        }
+            if ($insert_params){
+                $this->assertNotNull($insert_params);
+            }else{
+                $this->assertNull($insert_params);
+            }
+
+    }
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 2 - 6
tests/Services/StoreItemService/GetAsnDetailsByAsnHerderTest.php

@@ -30,15 +30,11 @@ class GetAsnDetailsByAsnHerderTest extends TestCase
         $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
         $this->service=app(StoreItemService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('addTime', '>=', $startDate)
             ->get();
         $this->asnHeadersEdit=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('EditTime', '>=',  $startDate)
             ->whereColumn('EditTime', '<>', 'addTime')
             ->get();

+ 2 - 4
tests/Services/StoreItemService/GetByWmsTest.php

@@ -26,12 +26,10 @@ class GetByWmsTest extends TestCase
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
         $this->service=app(StoreItemService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('addTime', '>=',$startDate)
             ->get();
     }

+ 2 - 4
tests/Services/StoreItemService/GetParamsByAsnDetailsTest.php

@@ -27,11 +27,9 @@ class GetParamsByAsnDetailsTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service=app(StoreItemService::class);
-        $startDate = \Illuminate\Support\Carbon::now()->setSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->setSeconds(30);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('addTime', '>=', $startDate)
             ->get();
     }

+ 21 - 4
tests/Services/StoreService/CreateStoreTest.php

@@ -4,7 +4,9 @@
 namespace Tests\Services\StoreService;
 
 
+use App\OracleDOCASNDetail;
 use App\OracleDOCASNHeader;
+use App\Services\CommodityService;
 use App\Services\StoreService;
 use Carbon\Carbon;
 use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -21,12 +23,10 @@ class CreateStoreTest extends TestCase
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
         $this->service=app(StoreService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('addTime', '>=', $startDate)
             ->get();
     }
@@ -43,6 +43,23 @@ class CreateStoreTest extends TestCase
         foreach ($this->stores as $store){
             array_push($storeIds,$store->id);
         }
+        $asnDetails=OracleDOCASNDetail::query()->whereIn('asnno',data_get($this->asnHeaders,'*.asnno'))->get();
+        $maps = [];
+        foreach ($asnDetails as $asnDetail) {
+            $value = [
+                'owner_code' => $asnDetail->customerid,
+                'sku' => $asnDetail->sku,
+            ];
+            $maps[json_encode($value)] = $value;
+        }
+        /** CommodityService $commodityService */
+        $commodityService=app(CommodityService::class);
+        $commodities=$commodityService->getCommoditiesByMaps($maps);
+        $commodity_ids=[];
+        foreach ($commodities as $commodity){
+            array_push($commodity_ids,$commodity->id);
+        }
+        DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
         DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
         DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
         cache()->flush();

+ 16 - 8
tests/Services/StoreService/GetParamsByAsnHeaderTest.php

@@ -27,28 +27,36 @@ class GetParamsByAsnHeaderTest extends TestCase
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(60);
         $this->service=app(StoreService::class);
         $this->ownerService=app(OwnerService::class);
         $this->warehouseService=app(WarehouseService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('addTime', '>=', $startDate)
             ->get();
     }
     public function testGetParamsByAsnHeader(){
         if (empty($this->asnHeaders))return null;
         $stores = Store::query()->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->get();
-        $owners=$this->ownerService->getByWmsOrders($this->asnHeaders);
-        $warehouses=$this->warehouseService->getByWmsOrders($this->asnHeaders);
+        $owner_codes = [];
+        $warehouse_codes = [];
+        foreach ($this->asnHeaders as $asnHerder) {
+            if (!empty($asnHerder['customerid']))
+                $owner_codes[$asnHerder['customerid']] = $asnHerder['customerid'];
+            if (!empty($asnHerder['warehouseid']))
+                $warehouse_codes[$asnHerder['warehouseid']] = $asnHerder['warehouseid'];
+        }
+        $owners = $this->ownerService->getOwnerByCodes($owner_codes);
+        $warehouses = $this->warehouseService->getWareHouseByCodes($warehouse_codes);
         $this->assertNotEmpty($this->asnHeaders);
-        $this->assertNotEmpty($owners);
-        $this->assertNotEmpty($warehouses);
+//        $this->assertNotEmpty($owners);
+//        $this->assertNotEmpty($warehouses);
+        $owners_code_map=[];
         foreach ($owners as $owner) {
             $owners_code_map[$owner->code] = $owner;
         }
+        $warehouses_code_map=[];
         foreach ($warehouses as $warehouse) {
             $warehouses_code_map[$warehouse->code] = $warehouse;
         }

+ 9 - 4
tests/Services/StoreService/SyncStoreCreateByWmsTest.php

@@ -15,6 +15,7 @@ use App\Services\ShopService;
 use App\Services\StoreService;
 use App\Services\WarehouseService;
 use App\Shop;
+use App\StoreItems;
 use App\ValueStore;
 use App\Warehouse;
 use Carbon\Carbon;
@@ -46,11 +47,9 @@ class SyncStoreCreateByWmsTest extends TestCase
     {
         $this->created_at = config('sync.asn_sync.created_at');
         $this->last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
-        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(30);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
             ->where('addTime', '>=',  $this->last_time??$time)
             ->orderByDesc('addtime')
@@ -73,8 +72,14 @@ class SyncStoreCreateByWmsTest extends TestCase
         foreach ($this->stores as $store){
             array_push($storeIds,$store->id);
         }
+        $storeItems=StoreItems::query()->whereIn('store_id',$storeIds)->get();
+        $commodity_ids=[];
+        foreach ($storeItems as $storeItem){
+            array_push($commodity_ids,$storeItem->commodity_id);
+        }
         DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
         DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
+        DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
         cache()->flush();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }

+ 9 - 4
tests/Services/StoreService/SyncStoreUpdateByWmsTest.php

@@ -15,6 +15,7 @@ use App\Services\ShopService;
 use App\Services\StoreService;
 use App\Services\WarehouseService;
 use App\Shop;
+use App\StoreItems;
 use App\ValueStore;
 use App\Warehouse;
 use Carbon\Carbon;
@@ -46,11 +47,9 @@ class SyncStoreUpdateByWmsTest extends TestCase
     {
         $this->update_at = config('sync.asn_sync.updated_at');
         $this->last_time = ValueStore::query()->where('name',$this->update_at)->value('value');
-        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(30);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
             ->where('EditTime', '>=', $this->last_time ?? $time)
             ->whereColumn('EditTime', '<>', 'addTime')
@@ -74,8 +73,14 @@ class SyncStoreUpdateByWmsTest extends TestCase
         foreach ($this->stores as $store){
             array_push($storeIds,$store->id);
         }
+        $storeItems=StoreItems::query()->whereIn('store_id',$storeIds)->get();
+        $commodity_ids=[];
+        foreach ($storeItems as $storeItem){
+            array_push($commodity_ids,$storeItem->commodity_id);
+        }
         DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
         DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
+        DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
         cache()->flush();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }

+ 21 - 5
tests/Services/StoreService/UpdateStoreTest.php

@@ -4,9 +4,10 @@
 namespace Tests\Services\StoreService;
 
 
+use App\OracleDOCASNDetail;
 use App\OracleDOCASNHeader;
+use App\Services\CommodityService;
 use App\Services\StoreService;
-use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 use Tests\TestCase;
 
@@ -19,12 +20,10 @@ class UpdateStoreTest extends TestCase
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
         $this->service=app(StoreService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
-                $query->with(['lineStatus', 'qualityStatus','basSku']);
-            }])
+            ->with(['asnType', 'asnStatus'])
             ->where('EditTime', '>=', $startDate)
             ->whereColumn('EditTime', '<>', 'addTime')
             ->get();
@@ -44,7 +43,24 @@ class UpdateStoreTest extends TestCase
         foreach ($this->stores as $store){
             array_push($storeIds,$store->id);
         }
+        $asnDetails=OracleDOCASNDetail::query()->whereIn('asnno',data_get($this->asnHeaders,'*.asnno'))->get();
+        $maps = [];
+        foreach ($asnDetails as $asnDetail) {
+            $value = [
+                'owner_code' => $asnDetail->customerid,
+                'sku' => $asnDetail->sku,
+            ];
+            $maps[json_encode($value)] = $value;
+        }
+        /** CommodityService $commodityService */
+        $commodityService=app(CommodityService::class);
+        $commodities=$commodityService->getCommoditiesByMaps($maps);
+        $commodity_ids=[];
+        foreach ($commodities as $commodity){
+            array_push($commodity_ids,$commodity->id);
+        }
         DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
+        DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
         DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
         cache()->flush();
         parent::tearDown(); // TODO: Change the autogenerated stub