improve last code
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Enums\ActivityMachineType;
|
use App\Enums\MissionViolationType;
|
||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
use App\Models\MissionViolation;
|
use App\Models\MissionViolation;
|
||||||
@@ -31,7 +31,7 @@ class DailyMovingMachineCommand extends Command
|
|||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function handle(DailyMovingMachinesService $dailyMovingMachines,CMMSMachine $machine): void
|
public function handle(DailyMovingMachinesService $dailyMovingMachines): void
|
||||||
{
|
{
|
||||||
$vehiclesInfo = $dailyMovingMachines->run();
|
$vehiclesInfo = $dailyMovingMachines->run();
|
||||||
$response = collect($vehiclesInfo['vehiclesInfo']);
|
$response = collect($vehiclesInfo['vehiclesInfo']);
|
||||||
@@ -41,13 +41,10 @@ class DailyMovingMachineCommand extends Command
|
|||||||
$cmms = $response->pluck('machineCode');
|
$cmms = $response->pluck('machineCode');
|
||||||
|
|
||||||
$missions = Mission::query()
|
$missions = Mission::query()
|
||||||
->whereDate('start_time',$date)
|
->whereDate('start_time', $date)
|
||||||
->with('machine')
|
|
||||||
->where('machine_id', '=',$machine->id )
|
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$missionCodes = $missions->pluck('machine.machine_code')->filter();
|
$missionCodes = $missions->pluck('machine_code');
|
||||||
|
|
||||||
|
|
||||||
$cmmsOnly = $cmms->diff($missionCodes);
|
$cmmsOnly = $cmms->diff($missionCodes);
|
||||||
$missionOnly = $missionCodes->diff($cmms);
|
$missionOnly = $missionCodes->diff($cmms);
|
||||||
@@ -57,7 +54,7 @@ class DailyMovingMachineCommand extends Command
|
|||||||
|
|
||||||
MissionViolation::query()->create([
|
MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
'machine_code' => $code,
|
||||||
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value,
|
'type' => MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
||||||
'request_date' => $date,
|
'request_date' => $date,
|
||||||
'mileage' => $cmm['mileageKM'],
|
'mileage' => $cmm['mileageKM'],
|
||||||
// 'exit_time' => $cmm['exit_time'],
|
// 'exit_time' => $cmm['exit_time'],
|
||||||
@@ -68,8 +65,8 @@ class DailyMovingMachineCommand extends Command
|
|||||||
foreach ($missionOnly as $code) {
|
foreach ($missionOnly as $code) {
|
||||||
MissionViolation::query()->create([
|
MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
'machine_code' => $code,
|
||||||
'mission_id' => $missions->id,
|
'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
||||||
'type' => ActivityMachineType::ADAM_TAHAROK->value,
|
'type' => MissionViolationType::ADAM_TAHAROK->value,
|
||||||
'request_date' => $date,
|
'request_date' => $date,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
enum ActivityMachineType: int
|
enum MissionViolationType: int
|
||||||
{
|
{
|
||||||
case KHOROJ_BEDONE_MOGAVEZ = 1;
|
case KHOROJ_BEDONE_MOGAVEZ = 1;
|
||||||
case ADAM_TAHAROK = 2;
|
case ADAM_TAHAROK = 2;
|
||||||
|
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
self::KHOROJ_BEDONE_MOGAVEZ => "خروج بدون مجوز ",
|
self::KHOROJ_BEDONE_MOGAVEZ => "خروج بدون مجوز ",
|
||||||
self::ADAM_TAHAROK => "عدم تحرک",
|
self::ADAM_TAHAROK => "عدم تحرک",
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::table('missions', function (Blueprint $table) {
|
Schema::table('missions', function (Blueprint $table) {
|
||||||
$table->foreignId('machine_id')->nullable()->constrained('cmms_machines');
|
$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) {
|
Schema::table('missions', function (Blueprint $table) {
|
||||||
$table->dropForeign('missions_machine_id_foreign');
|
$table->dropForeign('missions_machine_id_foreign');
|
||||||
$table->dropColumn(['machine_id', 'machine_name']);
|
$table->dropColumn(['machine_id', 'machine_code']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user