change some part of code
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\ActivityMachineType;
|
||||
use App\Models\Mission;
|
||||
use App\Models\DailyMoveMachine;
|
||||
use App\Models\AssignmentFails;
|
||||
use App\Services\CMMS\DailyMovingMachinesService;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -31,7 +31,8 @@ class DailyMovingMachineCommand extends Command
|
||||
*/
|
||||
public function handle(DailyMovingMachinesService $dailyMovingMachines): void
|
||||
{
|
||||
$response = $dailyMovingMachines->run();
|
||||
$vehiclesInfo = $dailyMovingMachines->run();
|
||||
$response =$vehiclesInfo->get('vehiclesInfo', collect());
|
||||
|
||||
$date = now()->toDateString();
|
||||
|
||||
@@ -39,55 +40,38 @@ class DailyMovingMachineCommand extends Command
|
||||
->pluck('machineCode');
|
||||
|
||||
$mission = Mission::query()
|
||||
->whereDate('start_time',today())
|
||||
->whereDate('start_time',$date)
|
||||
->pluck('machine_code');
|
||||
|
||||
|
||||
$cmmsOnly = $cmms->diff($mission);
|
||||
$missionOnly = $mission->diff($cmms);
|
||||
$matching = $cmms->intersect($mission);
|
||||
|
||||
foreach ($matching as $code) {
|
||||
$cmm = (object) $response->firstWhere('machineCode', $code);
|
||||
$missionRecord = Mission::where('machine_code', $code)
|
||||
->whereDate('start_time', today())
|
||||
->first();
|
||||
|
||||
DailyMoveMachine::query()->create([
|
||||
'machine_code' => $code,
|
||||
'mission_id' => $missionRecord->id ,
|
||||
'type' => ActivityMachineType::MOTABEGAT->label(),
|
||||
'request_date' => $date,
|
||||
'mileage' => $cmm->mileage,
|
||||
'exit_time' => $cmm->exit_time,
|
||||
'enter_time' => $cmm->enter_time,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($cmmsOnly as $code) {
|
||||
$cmm = (object) $response->firstWhere('machineCode', $code);
|
||||
$cmm = $response->firstWhere('machineCode', $code);
|
||||
|
||||
DailyMoveMachine::query()->create([
|
||||
AssignmentFails::query()->create([
|
||||
'machine_code' => $code,
|
||||
'type' => ActivityMachineType::TEDADE_MACHINES_BISHTAR_AS_MISSION->label(),
|
||||
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(),
|
||||
'request_date' => $date,
|
||||
'mileage' => $cmm->mileage,
|
||||
'exit_time' => $cmm->exit_time,
|
||||
'enter_time' => $cmm->enter_time,
|
||||
'mileage' => $cmm['mileageKM'],
|
||||
'exit_time' => $cmm['exit_time'],
|
||||
'enter_time' => $cmm['enter_time'],
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($missionOnly as $code) {
|
||||
DailyMoveMachine::create([
|
||||
$missionRecord = Mission::query()->where('machine_code', $code)
|
||||
->whereDate('start_time', today())
|
||||
->get();
|
||||
AssignmentFails::query()->create([
|
||||
'machine_code' => $code,
|
||||
'mission_id' => $mission->id,
|
||||
'type' => ActivityMachineType::TEDADE_MISSIONS_BISHTAR_AS_MACHINES->label(),
|
||||
'mission_id' => $missionRecord->id,
|
||||
'type' => ActivityMachineType::ADAM_TAHAROK->label(),
|
||||
'request_date' => $date,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$this->info('Diffs saved.');
|
||||
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
||||
$this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user