91 lines
2.9 KiB
PHP
91 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\MissionViolationType;
|
|
use App\Models\CMMSMachine;
|
|
use App\Models\Mission;
|
|
use App\Models\MissionViolation;
|
|
use App\Services\CMMS\DailyMovingMachinesService;
|
|
use Exception;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class DailyMovingMachineCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'webservice: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 = collect($vehiclesInfo['vehiclesInfo']);
|
|
|
|
$date = Carbon::yesterday()->toDateString();
|
|
|
|
$cmms = $response->pluck('machineCode');
|
|
|
|
$missions = Mission::query()
|
|
->whereDate('start_time', $date)
|
|
->get();
|
|
|
|
$missionCodes = $missions->pluck('machine_code');
|
|
|
|
$cmmsOnly = $cmms->diff($missionCodes);
|
|
// $missionOnly = $missionCodes->diff($cmms);
|
|
|
|
$violationMachineCodes = MissionViolation::query()->whereDate('request_date', $date)->pluck('machine_code');
|
|
|
|
foreach ($cmmsOnly as $code) {
|
|
$cmm = $response->firstWhere('machineCode', '=', $code);
|
|
|
|
if ($violationMachineCodes->contains($cmm->machine_code)) {
|
|
break;
|
|
}
|
|
|
|
$machine = CMMSMachine::query()->firstWhere('machine_code', '=', $code);
|
|
|
|
MissionViolation::query()->create([
|
|
'machine_code' => $code,
|
|
'machine_id' => $machine->id,
|
|
'type' => MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
|
'request_date' => $date,
|
|
'mileage' => $cmm['mileageKM'],
|
|
// 'exit_time' => $cmm['exit_time'],
|
|
// 'enter_time' => $cmm['enter_time'],
|
|
'province_id' => $machine->province_id,
|
|
// 'province_name' => $machine->province_fa,
|
|
'city_id' => $machine->city_id,
|
|
// 'city_name' => $machine->city_fa,
|
|
]);
|
|
}
|
|
|
|
// foreach ($missionOnly as $code) {
|
|
// MissionViolation::query()->create([
|
|
// 'machine_code' => $code,
|
|
// 'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
|
// 'type' => MissionViolationType::ADAM_TAHAROK->value,
|
|
// 'request_date' => $date,
|
|
// ]);
|
|
// }
|
|
|
|
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
|
// $this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
|
}
|
|
}
|