improve last code
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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 => "عدم تحرک",
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user