From dc7dc723c85b0408e4d4dd76288906d8efd82ab4 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Dec 2025 16:18:03 +0330 Subject: [PATCH] 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, ]);