From e30b19ab7925653608b65b5d5355ae5697fcda36 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 25 Aug 2025 13:22:11 +0330 Subject: [PATCH 1/3] create fms service --- .../Controllers/V3/CMMSMachinesController.php | 9 +++ app/Services/FMS/GetErrorRateService.php | 71 +++++++++++++++++++ routes/v3.php | 1 + 3 files changed, 81 insertions(+) create mode 100644 app/Services/FMS/GetErrorRateService.php diff --git a/app/Http/Controllers/V3/CMMSMachinesController.php b/app/Http/Controllers/V3/CMMSMachinesController.php index b25ca2a7..fcef7b57 100644 --- a/app/Http/Controllers/V3/CMMSMachinesController.php +++ b/app/Http/Controllers/V3/CMMSMachinesController.php @@ -8,6 +8,8 @@ use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\DB; class CMMSMachinesController extends Controller { @@ -39,4 +41,11 @@ class CMMSMachinesController extends Controller return $this->successResponse($matchedSearchedMachines); } + + public function carTypes(): Collection + { + return DB::table('cmms_machines') + ->distinct() + ->pluck('car_type'); + } } diff --git a/app/Services/FMS/GetErrorRateService.php b/app/Services/FMS/GetErrorRateService.php new file mode 100644 index 00000000..bcf02c4e --- /dev/null +++ b/app/Services/FMS/GetErrorRateService.php @@ -0,0 +1,71 @@ +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); + } +} diff --git a/routes/v3.php b/routes/v3.php index 50eb8330..717202a6 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -180,6 +180,7 @@ Route::prefix('cmms_machines') Route::get('/', 'index')->name('index'); Route::get('/list', 'list')->name('list'); Route::get('/search', 'search')->name('search'); + Route::get('/car_types', 'carTypes')->name('carTypes'); }); Route::prefix('rahdaran') From e3cf21ac277ff73ce62d8dc8ec3c2f4a038579e4 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 25 Aug 2025 13:25:49 +0330 Subject: [PATCH 2/3] create new thing --- app/Enums/MissionTypes.php | 2 + .../Dashboard/Mission/FinishRequestEvent.php | 19 ++++++ .../Mission/ControlUnitController.php | 42 +++++++++++++ .../Mission/ControlUnit/NoProcessRequest.php | 62 +++++++++++++++++++ .../Mission/FinishRequestListener.php | 35 +++++++++++ 5 files changed, 160 insertions(+) create mode 100644 app/Events/V3/Dashboard/Mission/FinishRequestEvent.php create mode 100644 app/Http/Requests/V3/Mission/ControlUnit/NoProcessRequest.php create mode 100644 app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php diff --git a/app/Enums/MissionTypes.php b/app/Enums/MissionTypes.php index e19472cf..356fbd33 100644 --- a/app/Enums/MissionTypes.php +++ b/app/Enums/MissionTypes.php @@ -6,12 +6,14 @@ enum MissionTypes: int { case SAATY= 1; case ROZANE = 2; + case NO_PROCESS = 3; public static function name(int $state): string { $mapArray = [ 1 => 'ساعتی', 2 => 'روزانه', + 3 => 'بدون فرآیند', ]; return $mapArray[$state]; diff --git a/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php b/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php new file mode 100644 index 00000000..3569c2b3 --- /dev/null +++ b/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php @@ -0,0 +1,19 @@ +value; + $mission->update([ 'state_id' => $state, 'state_name' => MissionStates::name($state), @@ -60,4 +65,41 @@ class ControlUnitController extends Controller return $this->successResponse(); } + + + public function noProcess(NoProcessRequest $request): JsonResponse + { + + DB::transaction(function () use ($request) { + $user = auth()->user(); + $zone= $request->zone; + $type= MissionTypes::NO_PROCESS->value; + + $mission = Mission::query()->create([ + 'user_id' => $user->id, + 'username' => $user->username, + 'province_id' => $user->province_id, + 'province_name' => $user->province_fa, + 'edare_shahri_id' => $user->edarate_shahri_id ?? null, + 'edare_shahri_name' => $user->edarate_shahri_name ?? null, + 'zone' => $zone, + 'zone_fa' => MissionZones::name($zone), + 'type' => $type, + 'type_fa' => MissionTypes::name($type), + 'start_date' => $request->start_date, + 'end_date' => $request->end_date, + 'end_point' => $request->end_point, + 'area' => json_encode($request->area), + 'category_id' => $request->category_id, + 'category_name' => MissionCategory::name($request->category_id), + 'start_time' => $request->start_date, + 'finish_time' => $request->end_date, + ]); + + $mission->rahdaran()->sync($request->rahdaran); + $mission->machines()->attach($request->machines); + $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); + }); + return $this->successResponse(); + } } diff --git a/app/Http/Requests/V3/Mission/ControlUnit/NoProcessRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/NoProcessRequest.php new file mode 100644 index 00000000..bbcf30b9 --- /dev/null +++ b/app/Http/Requests/V3/Mission/ControlUnit/NoProcessRequest.php @@ -0,0 +1,62 @@ + + */ + public function rules(): array + { + return [ + 'rahdaran' => 'array', + 'rahdaran.*' => 'exists:rahdaran,id', + 'machines' => 'required|array', + 'machines.*' => 'required|integer|exists:cmms_machines,id', + 'driver' => 'required|integer|exists:rahdaran,id', + 'zone' => 'required|in:1,2,3', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'end_point' => 'required|string', + 'area' => 'required|array', + 'area.type' => 'required|string', + 'area.coordinates' => 'required|array', + 'category_id' => 'required|in:1,2,3', + ]; + } + + public function after(): array + { + return [ + function (Validator $validator) { + $start = Carbon::parse($this->start_date); + $end = Carbon::parse($this->end_date); + $now = Carbon::now(); + + if ($end->diffInMinutes($now) > 0 || $start->diffInMinutes($now) > 0) { + $validator->errors()->add( + 'end_date', + 'امکان ثبت ماموریت بدون فرایند با توجه به زمان انتخابی مقدور نمی باشد.' + ); + } + } + ]; + } +} diff --git a/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php b/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php new file mode 100644 index 00000000..be6e1d49 --- /dev/null +++ b/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php @@ -0,0 +1,35 @@ +url = config('App\Services\FMSService.url'); + $this->username = config('App\Services\FMSService.username'); + $this->password = config('App\Services\FMSService.password'); + } + + /** + * @throws RequestException + */ + public function handle(FinishRequestEvent $event): void + { + Http::post($this->url, + array( + 'area' => $event->mission->area, + 'machine_code' => $event->mission->machines()->pluck('machines.machine_code'), + 'start_date' => $event->mission->start_date, + 'end_date' => $event->mission->end_date, + ))->throw(); + } +} From 2589787f3a20ef4e09d5176197d96c87a3015841 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 25 Aug 2025 13:55:21 +0330 Subject: [PATCH 3/3] create new thing for mission acsses and event and listener --- ...equestEvent.php => SendDataToFMSEvent.php} | 2 +- .../Mission/ControlUnitController.php | 3 ++ .../ConfirmGuaranteeLetterNeedListener.php | 17 +++++++-- .../Harim/ConfirmNoRoadAccessNeedListener.php | 14 +++++++- .../ConfirmRoadAccessEditNeedListener.php | 14 +++++++- .../Harim/ConfirmRoadAccessNeedListener.php | 12 ++++++- .../Dashboard/Harim/RejectRequestListener.php | 10 +++++- .../Mission/FinishRequestListener.php | 35 ------------------- .../Mission/SendDataToFMSListener.php | 28 +++++++++++++++ app/Providers/EventServiceProvider.php | 5 +++ routes/v3.php | 1 + 11 files changed, 99 insertions(+), 42 deletions(-) rename app/Events/V3/Dashboard/Mission/{FinishRequestEvent.php => SendDataToFMSEvent.php} (94%) delete mode 100644 app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php create mode 100644 app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php diff --git a/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php similarity index 94% rename from app/Events/V3/Dashboard/Mission/FinishRequestEvent.php rename to app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php index 3569c2b3..f25abfb1 100644 --- a/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php +++ b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php @@ -8,7 +8,7 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class FinishRequestEvent +class SendDataToFMSEvent { use Dispatchable, InteractsWithSockets, SerializesModels; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php index e919baff..c13d77f0 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php @@ -6,6 +6,7 @@ use App\Enums\MissionCategory; use App\Enums\MissionStates; use App\Enums\MissionTypes; use App\Enums\MissionZones; +use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent; use App\Http\Controllers\Controller; use App\Http\Requests\V3\Mission\ControlUnit\FinishRequest; use App\Http\Requests\V3\Mission\ControlUnit\NoProcessRequest; @@ -63,6 +64,8 @@ class ControlUnitController extends Controller ]); }); + SendDataToFMSEvent::dispatch($mission); + return $this->successResponse(); } diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php index 6f9839b8..8dd0eeca 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmGuaranteeLetterNeedListener +class ConfirmGuaranteeLetterNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -17,6 +26,10 @@ class ConfirmGuaranteeLetterNeedListener $this->username = config('harim_web_services.reject.username'); $this->password = config('harim_web_services.reject.password'); } + + /** + * @throws RequestException + */ public function handle(ConfirmGuaranteeLetterNeedEvent $event): void { Http::post($this->url, @@ -27,7 +40,7 @@ class ConfirmGuaranteeLetterNeedListener '' => $event->harim->id, '' => $event->harim->id, '' => $event->harim->id, - ' ' => $event->harim->id, + '' => $event->harim->id, ))->throw(); } } diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php index ce5bc75e..e4a2600c 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmNoRoadAccessNeedListener +class ConfirmNoRoadAccessNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -18,6 +27,9 @@ class ConfirmNoRoadAccessNeedListener $this->password = config('harim_web_services.reject.password'); } + /** + * @throws RequestException + */ public function handle(ConfirmNoRoadAccessNeedEvent $event): void { Http::post($this->url, diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php index b0a84311..7ad2e903 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmRoadAccessEditNeedListener +class ConfirmRoadAccessEditNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -18,6 +27,9 @@ class ConfirmRoadAccessEditNeedListener $this->password = config('harim_web_services.reject.password'); } + /** + * @throws RequestException + */ public function handle(ConfirmRoadAccessEditNeedEvent $event): void { Http::post($this->url, diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php index eb07807e..c94bc368 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmRoadAccessNeedListener +class ConfirmRoadAccessNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -20,6 +29,7 @@ class ConfirmRoadAccessNeedListener /** * Handle the event. + * @throws RequestException */ public function handle(ConfirmRoadAccessNeedEvent $event): void { diff --git a/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php b/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php index ce50d817..6ccc698c 100644 --- a/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php +++ b/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php @@ -3,11 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\RejectRequestEvent; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class RejectRequestListener +class RejectRequestListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; diff --git a/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php b/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php deleted file mode 100644 index be6e1d49..00000000 --- a/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php +++ /dev/null @@ -1,35 +0,0 @@ -url = config('App\Services\FMSService.url'); - $this->username = config('App\Services\FMSService.username'); - $this->password = config('App\Services\FMSService.password'); - } - - /** - * @throws RequestException - */ - public function handle(FinishRequestEvent $event): void - { - Http::post($this->url, - array( - 'area' => $event->mission->area, - 'machine_code' => $event->mission->machines()->pluck('machines.machine_code'), - 'start_date' => $event->mission->start_date, - 'end_date' => $event->mission->end_date, - ))->throw(); - } -} diff --git a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php new file mode 100644 index 00000000..26c98a2c --- /dev/null +++ b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php @@ -0,0 +1,28 @@ +run($event->mission); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3686d436..16c73d00 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -7,11 +7,13 @@ use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent; use App\Events\V3\Dashboard\Harim\RejectRequestEvent; +use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent; use App\Listeners\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessNeedListener; use App\Listeners\V3\Dashboard\Harim\RejectRequestListener; +use App\Listeners\V3\Dashboard\Mission\SendDataToFMSListener; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -50,6 +52,9 @@ class EventServiceProvider extends ServiceProvider ], ConfirmGuaranteeLetterNeedEvent::class => [ ConfirmGuaranteeLetterNeedListener::class + ], + SendDataToFMSEvent::class => [ + SendDataToFMSListener::class ] ]; diff --git a/routes/v3.php b/routes/v3.php index 717202a6..f211be1a 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -500,6 +500,7 @@ Route::prefix('missions') ->controller(ControlUnitController::class) ->group(function () { Route::get('/', 'index')->name('index'); + Route::post('/no_process','noProcess')->name('noProcess'); Route::post('/start/{mission}', 'start')->name('start'); Route::post('/finish/{mission}', 'finish')->name('finish'); });