From 69430cf7bc796d23e9a5f5b0aefcc7f547448168 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Wed, 12 Nov 2025 21:52:41 +0330 Subject: [PATCH] Create prosess for check moving machine in mission --- .env.example | 4 + .../Commands/DailyMovingMachineCommand.php | 93 +++++++++++++++++++ app/Console/Kernel.php | 4 + app/Enums/ActivityMachineType.php | 21 +++++ .../Dashboard/Mission/SendDataToFMSEvent.php | 1 - .../V3/Dashboard/Mission/DetailController.php | 9 ++ app/Models/DailyMoveMachine.php | 17 ++++ .../CMMS/DailyMovingMachinesService.php | 68 ++++++++++++++ .../Mission/DailyMoveMachineService.php | 25 +++++ config/cmms_web_services.php | 6 ++ config/logging.php | 5 + ...55435_create_daily_move_machines_table.php | 35 +++++++ 12 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/DailyMovingMachineCommand.php create mode 100644 app/Enums/ActivityMachineType.php create mode 100644 app/Models/DailyMoveMachine.php create mode 100644 app/Services/CMMS/DailyMovingMachinesService.php create mode 100644 app/Services/Cartables/Mission/DailyMoveMachineService.php create mode 100644 database/migrations/2025_11_12_155435_create_daily_move_machines_table.php diff --git a/.env.example b/.env.example index 5a6b45c4..5ce02157 100644 --- a/.env.example +++ b/.env.example @@ -98,3 +98,7 @@ BACKUP_PASSWORD= HARIM_ENCRYPTION_KEY="TestKey" HARIM_ENCRYPTION_IV="1111000011110101" + +CHECKE_LIST_MACHINES_ACTIVITY_URL='fms.141.ir:7030/api/RMS/GetMovingVehicles', +CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD= +CHECKE_LIST_MACHINES_ACTIVITY_USERNAME= \ No newline at end of file diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php new file mode 100644 index 00000000..e315e194 --- /dev/null +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -0,0 +1,93 @@ +run(); + + $date = now()->toDateString(); + + $cmms = $response + ->pluck('machineCode'); + + $mission = Mission::query() + ->whereDate('start_time',today()) + ->pluck('machine_code'); + + + $cmmsOnly = $cmms->diff($mission); + $missionOnly = $mission->diff($cmms); + $matching = $cmms->intersect($mission); + + foreach ($matching as $code) { + $cmm = (object) $response->firstWhere('machineCode', $code); + $missionRecord = Mission::where('machine_code', $code) + ->whereDate('start_time', today()) + ->first(); + + DailyMoveMachine::query()->create([ + 'machine_code' => $code, + 'mission_id' => $missionRecord->id , + 'type' => ActivityMachineType::MOTABEGAT->label(), + 'request_date' => $date, + 'mileage' => $cmm->mileage, + 'exit_time' => $cmm->exit_time, + 'enter_time' => $cmm->enter_time, + ]); + } + + foreach ($cmmsOnly as $code) { + $cmm = (object) $response->firstWhere('machineCode', $code); + + DailyMoveMachine::query()->create([ + 'machine_code' => $code, + 'type' => ActivityMachineType::TEDADE_MACHINES_BISHTAR_AS_MISSION->label(), + 'request_date' => $date, + 'mileage' => $cmm->mileage, + 'exit_time' => $cmm->exit_time, + 'enter_time' => $cmm->enter_time, + ]); + } + + foreach ($missionOnly as $code) { + DailyMoveMachine::create([ + 'machine_code' => $code, + 'mission_id' => $mission->id, + 'type' => ActivityMachineType::TEDADE_MISSIONS_BISHTAR_AS_MACHINES->label(), + 'request_date' => $date, + ]); + } + + + $this->info('Diffs saved.'); + } + +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 281693b9..7fd4011a 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel protected $commands = [ 'App\Console\Commands\RoadObservationProblems', //// road observed webservice from 141 sawaneh 'App\Console\Commands\SendContractSmsNotification', //// road observed webservice from 141 sawaneh + 'App\Console\Commands\DailyMovingMachineCommand', ]; /** @@ -48,6 +49,9 @@ class Kernel extends ConsoleKernel ->dailyAt('04:00') ->appendOutputTo(storage_path('logs/telescope.log')); + $schedule->command('daily_moving_machine') + ->dailyAt('23:59')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); + } /** diff --git a/app/Enums/ActivityMachineType.php b/app/Enums/ActivityMachineType.php new file mode 100644 index 00000000..23cd3879 --- /dev/null +++ b/app/Enums/ActivityMachineType.php @@ -0,0 +1,21 @@ + "مطابقت ", + self::TEDADE_MACHINES_BISHTAR_AS_MISSION => " تعداد ماشین ها بیشتر از ماموریت ها", + self::TEDADE_MISSIONS_BISHTAR_AS_MACHINES => "تغداد ماموریت ها بیشتر از ماشین ها ", + + }; + } +} \ No newline at end of file diff --git a/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php index f25abfb1..72dde81f 100644 --- a/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php +++ b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php @@ -2,7 +2,6 @@ namespace App\Events\V3\Dashboard\Mission; -use App\Models\Harim; use App\Models\Mission; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php index cf1b2dd1..1c361ff1 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php @@ -5,7 +5,9 @@ namespace App\Http\Controllers\V3\Dashboard\Mission; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\Mission; +use App\Services\Cartables\Mission\DailyMoveMachineService; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class DetailController extends Controller { @@ -31,4 +33,11 @@ class DetailController extends Controller return $this->successResponse($rahdaran); } + + public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse + { + $data = $dailyMoveMachineService->dataTable($request); + + return response()->json($data); + } } diff --git a/app/Models/DailyMoveMachine.php b/app/Models/DailyMoveMachine.php new file mode 100644 index 00000000..033f8681 --- /dev/null +++ b/app/Models/DailyMoveMachine.php @@ -0,0 +1,17 @@ +belongsTo(Mission::class); + } +} diff --git a/app/Services/CMMS/DailyMovingMachinesService.php b/app/Services/CMMS/DailyMovingMachinesService.php new file mode 100644 index 00000000..828a83fd --- /dev/null +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -0,0 +1,68 @@ +url = config('cmms_web_services.CHECK_ACTIVITY.url'); + $this->password = config('cmms_web_services.CHECK_ACTIVITY.password'); + $this->username = config('cmms_web_services.CHECK_ACTIVITY.username'); + $this->channelName = 'daily_moving_machine'; + } + + /** + * @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 = array( + "username" => $this->username, + "password" => $this->password, + "day" => today(), + "minMileage" => 10, + ); + + return json_encode($inputData); + } +} diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php new file mode 100644 index 00000000..1a63ed8a --- /dev/null +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -0,0 +1,25 @@ + env('CMMS_MACHINE_INFO_PASSWORD'), 'ViewName' => env('CMMS_MACHINE_INFO_VIEW_NAME'), ], + + 'CHECK_ACTIVITY' => [ + 'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'), + 'password' => env('CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD'), + 'username' => env('CHECKE_LIST_MACHINES_ACTIVITY_USERNAME'), + ], ]; \ No newline at end of file diff --git a/config/logging.php b/config/logging.php index 972f7be3..14edc387 100644 --- a/config/logging.php +++ b/config/logging.php @@ -147,5 +147,10 @@ return [ 'path' => storage_path('logs/telescope.log'), 'level' => 'info', ], + 'daily_moving_machine' => [ + 'driver' => 'single', + 'path' => storage_path('logs/cmms/daily_moving_machine_service.log'), + 'level' => 'info', + ], ], ]; diff --git a/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php b/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php new file mode 100644 index 00000000..7af2c25b --- /dev/null +++ b/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('mission_id')->index()->nullable(); + $table->string('machine_code')->index(); + $table->date('request_date')->index(); + $table->string('type')->nullable(); + $table->unsignedInteger('mileage')->nullable(); + $table->dateTime('exit_time')->nullable(); + $table->dateTime('enter_time')->nullable(); + $table->timestamps(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('report_mission_and_machines'); + } +};