From a676383a27b097a61d8a8c942cb7bcba80809c76 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Dec 2025 14:16:37 +0330 Subject: [PATCH 1/3] change som item --- app/Console/Commands/DailyMovingMachineCommand.php | 2 +- app/Console/Kernel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index bc19cbfd..a7446e07 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -17,7 +17,7 @@ class DailyMovingMachineCommand extends Command * * @var string */ - protected $signature = 'daily_moving_machine'; + protected $signature = 'webservice:daily_moving_machine'; /** * The console command description. diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 4b9554d3..f4c047dd 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -49,7 +49,7 @@ class Kernel extends ConsoleKernel ->dailyAt('04:00') ->appendOutputTo(storage_path('logs/telescope.log')); - $schedule->command('daily_moving_machine') + $schedule->command('webservice:daily_moving_machine') ->dailyAt('02:00')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); } From dc7dc723c85b0408e4d4dd76288906d8efd82ab4 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Dec 2025 16:18:03 +0330 Subject: [PATCH 2/3] change some item in command --- .../Commands/DailyMovingMachineCommand.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index a7446e07..0282931e 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Enums\ActivityMachineType; +use App\Models\CMMSMachine; use App\Models\Mission; use App\Models\MissionViolation; use App\Services\CMMS\DailyMovingMachinesService; @@ -30,7 +31,7 @@ class DailyMovingMachineCommand extends Command * Execute the console command. * @throws Exception */ - public function handle(DailyMovingMachinesService $dailyMovingMachines): void + public function handle(DailyMovingMachinesService $dailyMovingMachines,CMMSMachine $machine): void { $vehiclesInfo = $dailyMovingMachines->run(); $response = collect($vehiclesInfo['vehiclesInfo']); @@ -39,12 +40,17 @@ class DailyMovingMachineCommand extends Command $cmms = $response->pluck('machineCode'); - $mission = Mission::query() + $missions = Mission::query() ->whereDate('start_time',$date) - ->pluck('machine_code'); + ->with('machine') + ->where('machine_id', '=',$machine->id ) + ->get(); - $cmmsOnly = $cmms->diff($mission); - $missionOnly = $mission->diff($cmms); + $missionCodes = $missions->pluck('machine.machine_code')->filter(); + + + $cmmsOnly = $cmms->diff($missionCodes); + $missionOnly = $missionCodes->diff($cmms); foreach ($cmmsOnly as $code) { $cmm = $response->firstWhere('machineCode', '=', $code); @@ -60,13 +66,9 @@ class DailyMovingMachineCommand extends Command } foreach ($missionOnly as $code) { - $missionId = Mission::query()->where('machine_code', $code) - ->whereDate('start_time', $date) - ->value('id'); - MissionViolation::query()->create([ 'machine_code' => $code, - 'mission_id' => $missionId, + 'mission_id' => $missions->id, 'type' => ActivityMachineType::ADAM_TAHAROK->value, 'request_date' => $date, ]); From ad49d7773038efe5becc6d2239d0a2e1cadc6c25 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Tue, 2 Dec 2025 11:16:23 +0330 Subject: [PATCH 3/3] improve last code --- .../Commands/DailyMovingMachineCommand.php | 17 +++++++---------- ...MachineType.php => MissionViolationType.php} | 4 +--- ...1_15_090251_add_column_to_missions_table.php | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) rename app/Enums/{ActivityMachineType.php => MissionViolationType.php} (90%) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index 0282931e..5b059dfd 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Enums\ActivityMachineType; +use App\Enums\MissionViolationType; use App\Models\CMMSMachine; use App\Models\Mission; use App\Models\MissionViolation; @@ -31,7 +31,7 @@ class DailyMovingMachineCommand extends Command * Execute the console command. * @throws Exception */ - public function handle(DailyMovingMachinesService $dailyMovingMachines,CMMSMachine $machine): void + public function handle(DailyMovingMachinesService $dailyMovingMachines): void { $vehiclesInfo = $dailyMovingMachines->run(); $response = collect($vehiclesInfo['vehiclesInfo']); @@ -41,13 +41,10 @@ class DailyMovingMachineCommand extends Command $cmms = $response->pluck('machineCode'); $missions = Mission::query() - ->whereDate('start_time',$date) - ->with('machine') - ->where('machine_id', '=',$machine->id ) + ->whereDate('start_time', $date) ->get(); - $missionCodes = $missions->pluck('machine.machine_code')->filter(); - + $missionCodes = $missions->pluck('machine_code'); $cmmsOnly = $cmms->diff($missionCodes); $missionOnly = $missionCodes->diff($cmms); @@ -57,7 +54,7 @@ class DailyMovingMachineCommand extends Command MissionViolation::query()->create([ 'machine_code' => $code, - 'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value, + 'type' => MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value, 'request_date' => $date, 'mileage' => $cmm['mileageKM'], // 'exit_time' => $cmm['exit_time'], @@ -68,8 +65,8 @@ class DailyMovingMachineCommand extends Command foreach ($missionOnly as $code) { MissionViolation::query()->create([ 'machine_code' => $code, - 'mission_id' => $missions->id, - 'type' => ActivityMachineType::ADAM_TAHAROK->value, + 'mission_id' => $missions->where('machine_code', '=', $code)->value('id'), + 'type' => MissionViolationType::ADAM_TAHAROK->value, 'request_date' => $date, ]); } diff --git a/app/Enums/ActivityMachineType.php b/app/Enums/MissionViolationType.php similarity index 90% rename from app/Enums/ActivityMachineType.php rename to app/Enums/MissionViolationType.php index 4a4d2595..e9c55b0c 100644 --- a/app/Enums/ActivityMachineType.php +++ b/app/Enums/MissionViolationType.php @@ -2,18 +2,16 @@ namespace App\Enums; -enum ActivityMachineType: int +enum MissionViolationType: int { case KHOROJ_BEDONE_MOGAVEZ = 1; case ADAM_TAHAROK = 2; - public function label(): string { return match ($this) { self::KHOROJ_BEDONE_MOGAVEZ => "خروج بدون مجوز ", self::ADAM_TAHAROK => "عدم تحرک", - }; } } \ No newline at end of file diff --git a/database/migrations/2025_11_15_090251_add_column_to_missions_table.php b/database/migrations/2025_11_15_090251_add_column_to_missions_table.php index ab13ac14..986eb8ba 100644 --- a/database/migrations/2025_11_15_090251_add_column_to_missions_table.php +++ b/database/migrations/2025_11_15_090251_add_column_to_missions_table.php @@ -13,7 +13,7 @@ return new class extends Migration { Schema::table('missions', function (Blueprint $table) { $table->foreignId('machine_id')->nullable()->constrained('cmms_machines'); - $table->string('machine_name')->nullable(); + $table->string('machine_code')->nullable(); }); } @@ -24,7 +24,7 @@ return new class extends Migration { Schema::table('missions', function (Blueprint $table) { $table->dropForeign('missions_machine_id_foreign'); - $table->dropColumn(['machine_id', 'machine_name']); + $table->dropColumn(['machine_id', 'machine_code']); }); } };