refactor the web services

This commit is contained in:
2025-03-08 14:48:03 +03:30
parent 03e2bcfdf9
commit 5f2cbf5f12
5 changed files with 99 additions and 48 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Console\Commands;
use Illuminate\Support\Facades\Log;
use SoapFault;
use SoapClient;
use Illuminate\Console\Command;
@@ -84,6 +85,7 @@ class RoadObservationProblems extends Command
$msg .= $e->getMessage();
// self::sms_sender('09398586633', $msg);
// self::sms_sender('09367487107', $msg);
Log::channel('nikarayan')->error($e->getMessage());
return 0;
}
$result = serialize($result);
@@ -2723,6 +2725,7 @@ class RoadObservationProblems extends Command
]
];
$affectedRows = 0;
$cities = [];
foreach ($xml as $value) {
// if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 6) { //// code ghabli
@@ -2781,6 +2784,7 @@ class RoadObservationProblems extends Command
'city_fa' => $cityModel ? $cityModel->name_fa : null,
]
);
$affectedRows += 1;
}
}
} else {
@@ -2788,9 +2792,11 @@ class RoadObservationProblems extends Command
$msg = 'rms: error in get data roadobserved babe!!!!' . "\n";
// self::sms_sender('09398586633', $msg);
// self::sms_sender('09367487107', $msg);
$this->info('the received body is empty');
return $result;
}
echo 'done at: ' . date("Y-m-d H:i:s") . "\n";
$this->info("{$affectedRows} row's affected");
return 0;
}
public function sms_sender($mobile, $msg)

View File

@@ -5,29 +5,42 @@ namespace App\Services;
use App\Models\RoadObserved;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use SoapClient;
use SoapFault;
class NikarayanService
{
/**
* @throws SoapFault
*/
public function updateRoadObservedInfoByNikarayan(Request $request, RoadObserved $roadObserved, $files)
{
if (App::isProduction())
{
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
try {
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$soapClient = new SoapClient($url);
$soapClient = new SoapClient($url);
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
Log::channel('nikarayan')->info($result);
return $soapClient->UpdateInfo_RoadObservedProblems($array);
return $result;
}
catch (\Exception $e) {
Log::channel('nikarayan')->error($e->getMessage());
throw $e;
}
}
return 0;

View File

@@ -2,62 +2,82 @@
namespace App\Services;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
class NominatimService
{
/**
* @throws Exception
*/
public function get_way_id_from_nominatim($lat = null, $lng = null)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
try {
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
}
}
return 0;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
return 0;
}
return 0;
}
/**
* @throws Exception
*/
function getIDFromNominatim($s_lng, $s_lat, $d_lng, $d_lat)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
try {
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
}
}
}
return $ids;
return $ids;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
}
return [1, 2, 3];

View File

@@ -117,6 +117,18 @@ return [
'path' => storage_path('logs/road_observation_problem.log'),
'level' => 'info',
],
'nominatim' => [
'driver' => 'single',
'path' => storage_path('logs/nominatim.log'),
'level' => 'info',
],
'nikarayan' => [
'driver' => 'single',
'path' => storage_path('logs/nikarayan.log'),
'level' => 'info',
],
],
];

View File

@@ -262,6 +262,7 @@ Route::prefix('receipts')
Route::get('/', 'index')->name('index');
Route::get('/excel_report', 'excelReport')->name('excelReport');
Route::post('/', 'store')->name('store');
Route::get('/accident_types', 'accidentTypes')->name('accidentTypes');
Route::get('/{accident}', 'show')->name('show');
Route::post('/{accident}', 'update')->name('update');
Route::delete('/{accident}', 'destroy')->name('destroy');
@@ -271,7 +272,6 @@ Route::prefix('receipts')
Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus');
Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument');
Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain');
Route::get('/accident_types', 'accidentTypes')->name('accidentTypes');
});
Route::prefix('receipt_reports')
@@ -333,9 +333,9 @@ Route::prefix('safety_and_privacy')
Route::get('/', 'index')->name('index')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
Route::get('/excel_report', 'excelReport')->name('excelReport')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy');
Route::get('/sub_items', 'subItems')->name('subItems');
Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy');
Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy');
Route::get('/sub_items', 'subItems')->name('subItems');
Route::get('/{safetyAndPrivacy}', 'show')->name('show');
Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy');
Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize');