From 439527306c6db2d2ddb24bebb133f246c6e108d7 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 12 May 2025 16:23:39 +0330 Subject: [PATCH] add daily mode to nikarayan command --- app/Console/Commands/RoadObservationProblems.php | 12 +++++++----- app/Console/Kernel.php | 5 +++-- app/Services/NikarayanService.php | 9 ++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/RoadObservationProblems.php b/app/Console/Commands/RoadObservationProblems.php index c778d66c..3706103e 100755 --- a/app/Console/Commands/RoadObservationProblems.php +++ b/app/Console/Commands/RoadObservationProblems.php @@ -24,7 +24,7 @@ class RoadObservationProblems extends Command * * @var string */ - protected $signature = 'webservice:roadobserved'; + protected $signature = 'webservice:roadobserved {--daily-mode}'; /** * The console command description. @@ -63,7 +63,9 @@ class RoadObservationProblems extends Command // return 0; // } - $result = $nikarayanService->getRoadObservedProblemsByDate(); + $time = $this->option('daily-mode') ? verta()->subDay() : verta(); + + $result = $nikarayanService->getRoadObservedProblemsByDate($time); $result = serialize($result); $x = strpos($result, 'fk_FeatureType >= 1 && $value->fk_FeatureType <= 18) { + if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 24) { $mobile = null; if ($value->MobileForSendEventSms && (strlen($value->MobileForSendEventSms) == 11)) { @@ -89,7 +91,7 @@ class RoadObservationProblems extends Command } $city = findCityFromGeoJson($value->YGeo, $value->XGeo); - $cityModel = $city ? City::find($city['city_id']) : null; + $cityModel = $city ? City::query()->find($city['city_id']) : City::query()->find(NikarayanComplaints::mapCities((int) $value->fk_Town)); $rop = RoadObserved::query()->updateOrCreate( ['fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage], [ @@ -130,7 +132,7 @@ class RoadObservationProblems extends Command 'province_id' => $city ? $city['province_id'] : null, 'city_id' => $city ? $city['city_id'] : null, // 'handler_type' => EdarateShahri::class, - 'edarate_shahri_id' => $cityModel ? ($cityModel->edarateShahri()->where('is_primary', 1)->exists() ? $cityModel->edarateShahri()->where('is_primary', 1)->first()->id : null) : null, + 'edarate_shahri_id' => $cityModel->edarateShahri()->first()->id, 'province_fa' => (isset($city['province_id']) ? Province::find($city['province_id'])->name_fa : null), 'city_fa' => $cityModel ? $cityModel->name_fa : null, ] diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7a38c610..6a2033c1 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -26,7 +26,7 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->command('webservice:roadobserved') - ->everyFiveMinutes()->appendOutputTo(storage_path('logs/roadobser.log')); + ->everyFiveMinutes()->appendOutputTo(storage_path('logs/nikarayan.log')); $schedule->command('command:sendcontractsmsnotification') // ->everyMinute()->appendOutputTo(storage_path('logs/contractSms.log')); @@ -35,7 +35,8 @@ class Kernel extends ConsoleKernel $schedule->command('reports:rms-summary') ->dailyAt('00:00')->appendOutputTo(storage_path('logs/report_summary.log')); - + $schedule->command("webservice:roadobserved --daily-mode") + ->dailyAt('00:15')->appendOutputTo(storage_path('logs/nikarayan.log')); } /** diff --git a/app/Services/NikarayanService.php b/app/Services/NikarayanService.php index 2d229668..702ab1d4 100644 --- a/app/Services/NikarayanService.php +++ b/app/Services/NikarayanService.php @@ -49,15 +49,14 @@ class NikarayanService /** * @throws SoapFault */ - public function getRoadObservedProblemsByDate() + public function getRoadObservedProblemsByDate($time) { try { $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl"; - $v = verta(); - $month = $v->month < 10 ? '0' . $v->month : $v->month; - $day = $v->day < 10 ? '0' . $v->day : $v->day; - $date = $v->year . $month . $day; + $month = $time->month < 10 ? '0' . $time->month : $time->month; + $day = $time->day < 10 ? '0' . $time->day : $time->day; + $date = $time->year . $month . $day; $soap_client = new SoapClient($url); return $soap_client->Get_RoadObservedProblems_ByDate(array(