improve last code

This commit is contained in:
2025-12-02 11:16:23 +03:30
parent dc7dc723c8
commit ad49d77730
3 changed files with 10 additions and 15 deletions

View File

@@ -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,
]);
}

View File

@@ -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 => "عدم تحرک",
};
}
}

View File

@@ -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']);
});
}
};