Merge pull request #100 from witelgroup/feature/GiveDriverInCmms

Feature/give driver in cmms
This commit is contained in:
Amir Ghasempoor
2025-12-13 14:41:44 +03:30
committed by GitHub
4 changed files with 17 additions and 20 deletions

View File

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

View File

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

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