From a3cdae6815d214eb3ccb21d78256198289efa329 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 23 Aug 2021 09:35:37 +0800 Subject: [PATCH] update packinglists from vt portal jobs and schedule --- app/Classes/Jobs/CurlWarehouseListJob.php | 94 ------------------- ...hContainersStatusUpdateFromVTPortalJob.php | 40 ++++++++ .../Jobs/FetchDeliveryListFromVTPortalJob.php | 40 ++++++++ .../FetchLoadedContainersFromVTPortalJob.php | 46 +++++++++ .../Jobs/FetchPackingListFromVTPortalJob.php | 40 ++++++++ ...tchWarehouseReceiveListFromVTPortalJob.php | 45 +++++++++ app/Console/Kernel.php | 11 ++- database/seeders/OrdersTableSeeder.php | 34 +++++++ 8 files changed, 255 insertions(+), 95 deletions(-) delete mode 100644 app/Classes/Jobs/CurlWarehouseListJob.php create mode 100644 app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php create mode 100644 app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php create mode 100644 app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php create mode 100644 app/Classes/Jobs/FetchPackingListFromVTPortalJob.php create mode 100644 app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php create mode 100644 database/seeders/OrdersTableSeeder.php diff --git a/app/Classes/Jobs/CurlWarehouseListJob.php b/app/Classes/Jobs/CurlWarehouseListJob.php deleted file mode 100644 index 6d8703c5..00000000 --- a/app/Classes/Jobs/CurlWarehouseListJob.php +++ /dev/null @@ -1,94 +0,0 @@ -page = $page; - } - - /** - * Execute the job. - * - * @return void - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function handle() - { - $cookies = $this->getCookie(); - - $headers = [ - 'Content-Type' => 'application/json', - 'Cookie' => $cookies, - ]; - - $yesterday = Carbon::now()->subDays(1)->format('Y-m-d'); - - $client = new \GuzzleHttp\Client(['headers' => $headers]); - $res = $client->post('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', [\GuzzleHttp\RequestOptions::JSON => json_decode('{"controller":"WarehouseList","view":"grid1","request":{"PageIndex":' . $this->page . ',"PageSize":100,"PageOffset":0,"SortExpression":"ParcelDate DESC,FullMarking DESC","GroupExpression":"","Filter":["ParcelDate:=%js%\"' . $yesterday . 'T00:00:00.000\"\u0000"],"ContextKey":"view1","FilterIsExternal":false,"LookupContextFieldName":null,"LookupContextController":null,"LookupContextView":null,"LookupContext":null,"Inserting":false,"LastCommandName":null,"ExternalFilter":[],"DoesNotRequireData":false,"LastView":"grid1","Tag":null,"RequiresFirstLetters":false,"ViewType":"Grid","SupportsCaching":true,"SystemFilter":null,"RequiresRowCount":true,"QuickFindHint":null,"RequiresPivot":false,"PivotDefinitions":null,"RequiresMetaData":true}}')]); - - $data = json_decode($res->getBody()->getContents()); - - if (!empty($data->d->Row)) { - // insert data here - - // next page - $this->page = $this->page > 0 ? $this->page + 1 : 1; - CurlWarehouseListJob::dispatch($this->page + 1) - ->delay(Carbon::now()->addSeconds(10)); - } - } - - public function getCookie() - { - // get latest cookies - $client = new \GuzzleHttp\Client(['cookies' => true]); - $r = $client->request('GET', 'https://portalvt.azurewebsites.net'); - $call_cookie = $client->getConfig('cookies'); - $call_cookie = $call_cookie->toArray(); - $latest_cookie = []; - - foreach ($call_cookie as $key => $row) { - $latest_cookie[] = $row['Name'] . '=' . $row['Value']; - } - $latest_cookie = implode(';', $latest_cookie); - - // get access token - $headers = [ - 'Content-Type' => 'application/json', - 'Cookie' => $latest_cookie, - ]; - $client = new \GuzzleHttp\Client(['headers' => $headers]); - $res = $client->post('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login', [\GuzzleHttp\RequestOptions::JSON => [ - "username" => "CIEF", - "password" => "0122120880", - "createPersistentCookie" => true, - ]]); - - $token = json_decode($res->getBody()->getContents()); - $token = $token->d->AccessToken; - - $latest_cookie = $latest_cookie . ';AppVTCC=' . $token; - return $latest_cookie; - } -} diff --git a/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php b/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php new file mode 100644 index 00000000..66ed254d --- /dev/null +++ b/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php @@ -0,0 +1,40 @@ +fetchContainersStatusUpdateFromVTPortalProcessor = $fetchContainersStatusUpdateFromVTPortalProcessor; + } + + + /** + * Execute the job. + * + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function handle() + { + $this->fetchContainersStatusUpdateFromVTPortalProcessor->execute(); + } +} diff --git a/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php b/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php new file mode 100644 index 00000000..2be16a09 --- /dev/null +++ b/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php @@ -0,0 +1,40 @@ +fetchDeliveryListFromVTPortalProcessor = $fetchDeliveryListFromVTPortalProcessor; + } + + + /** + * Execute the job. + * + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function handle() + { + $this->fetchDeliveryListFromVTPortalProcessor->execute(); + } +} diff --git a/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php b/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php new file mode 100644 index 00000000..eb31b715 --- /dev/null +++ b/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php @@ -0,0 +1,46 @@ +fetchLoadedContainersFromVTPortalProcessor = $fetchLoadedContainersFromVTPortalProcessor; + } + + + /** + * Execute the job. + * + * @param Carbon|null $start + * @param Carbon|null $end + * @return void + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function handle(?Carbon $start = null, ?Carbon $end = null) + { + $this->fetchLoadedContainersFromVTPortalProcessor->execute($start, $end); + } +} diff --git a/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php b/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php new file mode 100644 index 00000000..917955d6 --- /dev/null +++ b/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php @@ -0,0 +1,40 @@ +fetchPackingListFromVTPortalProcessor = $fetchPackingListFromVTPortalProcessor; + } + + /** + * Execute the job. + * + * @return void + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function handle() + { + $this->fetchPackingListFromVTPortalProcessor->execute(); + } +} diff --git a/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php b/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php new file mode 100644 index 00000000..4e812a34 --- /dev/null +++ b/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php @@ -0,0 +1,45 @@ +fetchWarehouseReceiveListFromVTPortalProcessor = $fetchWarehouseReceiveListFromVTPortalProcessor; + } + + /** + * Execute the job. + * + * @param Carbon|null $start + * @param Carbon|null $end + * @return void + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function handle(?Carbon $start = null, ?Carbon $end = null) + { + $this->fetchWarehouseReceiveListFromVTPortalProcessor->execute($start, $end); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 69914e99..bec96f83 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,11 @@ namespace App\Console; +use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob; +use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob; +use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob; +use App\Classes\Jobs\FetchPackingListFromVTPortalJob; +use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -24,7 +29,11 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - // $schedule->command('inspire')->hourly(); + $schedule->job(FetchWarehouseReceiveListFromVTPortalJob::class)->dailyAt('21:00'); + $schedule->job(FetchLoadedContainersFromVTPortalJob::class)->dailyAt('21:15'); + $schedule->job(FetchPackingListFromVTPortalJob::class)->dailyAt('21:30'); + $schedule->job(FetchContainersStatusUpdateFromVTPortalJob::class)->dailyAt('21:45'); + $schedule->job(FetchDeliveryListFromVTPortalJob::class)->dailyAt('22:00'); } /** diff --git a/database/seeders/OrdersTableSeeder.php b/database/seeders/OrdersTableSeeder.php new file mode 100644 index 00000000..bce0b3f9 --- /dev/null +++ b/database/seeders/OrdersTableSeeder.php @@ -0,0 +1,34 @@ +chain([ + FetchLoadedContainersFromVTPortalJob::class, + FetchPackingListFromVTPortalJob::class, + FetchContainersStatusUpdateFromVTPortalProcessor::class, + FetchDeliveryListFromVTPortalJob::class, + + ]); + + } + +}