create FMS service with test

This commit is contained in:
2024-04-22 11:28:19 +03:30
parent 5f839385f8
commit acd7c496b5
15 changed files with 701 additions and 67 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace App\Services;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class FMSService
{
public function getVehicleActivity(Request $request)
{
if (App::isProduction()) {
$r = $request->machineCode;
$s = $request->startDT;
$e = $request->endDT;
$d = $request->minStopDuration;
$url = 'http://fms.141.ir/api/RMS/GetVehicleActivity?';
$query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}";
$full_url = $url . $query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $full_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
return json_encode([
'ResultCode' => 0
]);
}
public function getVehicleData(Request $request)
{
if (App::isProduction()) {
$r = $request->machine;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://fms.141.ir/api/RMS/GetVehicleLastPoints?username=RMS&password=XSW@1qaz&machineCodes={$r}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"username=RMS&password=XSW@1qaz&machineCodes={$r}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
$output = (object)['ResultCode' => 0];
return json_encode([
[$output]
]);
}
public function getVehicleLastPoints(Request $request)
{
if (App::isProduction()) {
$r = $request->machineCode;
$url = 'http://fms.141.ir/api/RMS/GetVehicleLastPoints?';
$query = "username=RMS&password=XSW@1qaz&machineCodes={$r}";
$full_url = $url . $query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $full_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"username=RMS&password=XSW@1qaz&machineCode={$r}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
return json_encode([
'ResultCode' => 0
]);
}
public function getVehicleActivitySummary(Request $request)
{
if (App::isProduction()) {
$r = $request->machineCode;
$s = $request->startDT;
$e = $request->endDT;
$url = 'http://fms.141.ir/api/RMS/GetVehicleActivitySummary?';
$query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}";
$full_url = $url . $query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $full_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
return json_encode([
'ResultCode' => 0
]);
}
}

View File

@@ -30,4 +30,36 @@ class NominatimService
return 0;
}
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;
}
}
return $ids;
}
return [1, 2, 3];
}
}