create fms service
This commit is contained in:
@@ -8,6 +8,8 @@ use App\Http\Traits\ApiResponse;
|
|||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class CMMSMachinesController extends Controller
|
class CMMSMachinesController extends Controller
|
||||||
{
|
{
|
||||||
@@ -39,4 +41,11 @@ class CMMSMachinesController extends Controller
|
|||||||
|
|
||||||
return $this->successResponse($matchedSearchedMachines);
|
return $this->successResponse($matchedSearchedMachines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function carTypes(): Collection
|
||||||
|
{
|
||||||
|
return DB::table('cmms_machines')
|
||||||
|
->distinct()
|
||||||
|
->pluck('car_type');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
app/Services/FMS/GetErrorRateService.php
Normal file
71
app/Services/FMS/GetErrorRateService.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\FMS;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class GetErrorRateService
|
||||||
|
{
|
||||||
|
protected string $url;
|
||||||
|
protected string $channelName;
|
||||||
|
protected string $password;
|
||||||
|
protected string $username;
|
||||||
|
protected array $inputParameters;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->url = config('fms_web_services.Vehicle_Activity.url');
|
||||||
|
$this->password = config('fms_web_services.Vehicle_Activity.password');
|
||||||
|
$this->username = config('fms_web_services.Vehicle_Activity.username');
|
||||||
|
$this->channelName = 'fms_vehicle_activity';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInputParameters(array $inputs): void
|
||||||
|
{
|
||||||
|
$this->inputParameters = $inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function run(): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->sendRequest();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Log::channel($this->channelName)
|
||||||
|
->error(get_class($this),
|
||||||
|
[
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendRequest(): array
|
||||||
|
{
|
||||||
|
$inputData = $this->makeInputParameters();
|
||||||
|
|
||||||
|
return Http::withBody($inputData)
|
||||||
|
->throw()
|
||||||
|
->withoutVerifying()
|
||||||
|
->post($this->url)
|
||||||
|
->json();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeInputParameters(): string
|
||||||
|
{
|
||||||
|
$inputData = $this->inputParameters + array(
|
||||||
|
"username" => $this->username,
|
||||||
|
"password" => $this->password,
|
||||||
|
"minStopDuration" => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
return json_encode($inputData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -180,6 +180,7 @@ Route::prefix('cmms_machines')
|
|||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
Route::get('/list', 'list')->name('list');
|
Route::get('/list', 'list')->name('list');
|
||||||
Route::get('/search', 'search')->name('search');
|
Route::get('/search', 'search')->name('search');
|
||||||
|
Route::get('/car_types', 'carTypes')->name('carTypes');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('rahdaran')
|
Route::prefix('rahdaran')
|
||||||
|
|||||||
Reference in New Issue
Block a user