78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\ActivityMachineType;
|
|
use App\Models\Mission;
|
|
use App\Models\AssignmentFails;
|
|
use App\Services\CMMS\DailyMovingMachinesService;
|
|
use Exception;
|
|
use Illuminate\Console\Command;
|
|
|
|
class DailyMovingMachineCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'daily_moving_machine';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'receive cmms cars information and compare my information';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
* @throws Exception
|
|
*/
|
|
public function handle(DailyMovingMachinesService $dailyMovingMachines): void
|
|
{
|
|
$vehiclesInfo = $dailyMovingMachines->run();
|
|
$response =$vehiclesInfo->get('vehiclesInfo', collect());
|
|
|
|
$date = now()->toDateString();
|
|
|
|
$cmms = $response
|
|
->pluck('machineCode');
|
|
|
|
$mission = Mission::query()
|
|
->whereDate('start_time',$date)
|
|
->pluck('machine_code');
|
|
|
|
$cmmsOnly = $cmms->diff($mission);
|
|
$missionOnly = $mission->diff($cmms);
|
|
|
|
foreach ($cmmsOnly as $code) {
|
|
$cmm = $response->firstWhere('machineCode', $code);
|
|
|
|
AssignmentFails::query()->create([
|
|
'machine_code' => $code,
|
|
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(),
|
|
'request_date' => $date,
|
|
'mileage' => $cmm['mileageKM'],
|
|
'exit_time' => $cmm['exit_time'],
|
|
'enter_time' => $cmm['enter_time'],
|
|
]);
|
|
}
|
|
|
|
foreach ($missionOnly as $code) {
|
|
$missionRecord = Mission::query()->where('machine_code', $code)
|
|
->whereDate('start_time', today())
|
|
->get();
|
|
AssignmentFails::query()->create([
|
|
'machine_code' => $code,
|
|
'mission_id' => $missionRecord->id,
|
|
'type' => ActivityMachineType::ADAM_TAHAROK->label(),
|
|
'request_date' => $date,
|
|
]);
|
|
}
|
|
|
|
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
|
$this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
|
}
|
|
}
|