diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index bc19cbfd..5b059dfd 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -2,7 +2,8 @@ namespace App\Console\Commands; -use App\Enums\ActivityMachineType; +use App\Enums\MissionViolationType; +use App\Models\CMMSMachine; use App\Models\Mission; use App\Models\MissionViolation; use App\Services\CMMS\DailyMovingMachinesService; @@ -17,7 +18,7 @@ class DailyMovingMachineCommand extends Command * * @var string */ - protected $signature = 'daily_moving_machine'; + protected $signature = 'webservice:daily_moving_machine'; /** * The console command description. @@ -39,19 +40,21 @@ class DailyMovingMachineCommand extends Command $cmms = $response->pluck('machineCode'); - $mission = Mission::query() - ->whereDate('start_time',$date) - ->pluck('machine_code'); + $missions = Mission::query() + ->whereDate('start_time', $date) + ->get(); - $cmmsOnly = $cmms->diff($mission); - $missionOnly = $mission->diff($cmms); + $missionCodes = $missions->pluck('machine_code'); + + $cmmsOnly = $cmms->diff($missionCodes); + $missionOnly = $missionCodes->diff($cmms); foreach ($cmmsOnly as $code) { $cmm = $response->firstWhere('machineCode', '=', $code); 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'], @@ -60,14 +63,10 @@ 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, - '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/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')); } 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']); }); } };