change some part of code

This commit is contained in:
2025-11-15 16:08:06 +03:30
parent 69430cf7bc
commit a54345983d
8 changed files with 60 additions and 68 deletions

View File

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

View File

@@ -4,17 +4,15 @@ namespace App\Enums;
enum ActivityMachineType: int enum ActivityMachineType: int
{ {
case MOTABEGAT = 1; case KHOROJ_BEDONE_MOGAVEZ = 1;
case TEDADE_MACHINES_BISHTAR_AS_MISSION = 2; case ADAM_TAHAROK = 2;
case TEDADE_MISSIONS_BISHTAR_AS_MACHINES = 3;
public function label(): string public function label(): string
{ {
return match ($this) { return match ($this) {
self::MOTABEGAT => "مطابقت ", self::KHOROJ_BEDONE_MOGAVEZ => "خروج بدون مجوز ",
self::TEDADE_MACHINES_BISHTAR_AS_MISSION => " تعداد ماشین ها بیشتر از ماموریت ها", self::ADAM_TAHAROK => "عدم تحرک",
self::TEDADE_MISSIONS_BISHTAR_AS_MACHINES => "تغداد ماموریت ها بیشتر از ماشین ها ",
}; };
} }

View File

@@ -5,7 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class DailyMoveMachine extends Model class AssignmentFails extends Model
{ {
use HasFactory; use HasFactory;
protected $guarded =[]; protected $guarded =[];

View File

@@ -3,6 +3,7 @@
namespace App\Services\CMMS; namespace App\Services\CMMS;
use Exception; use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -13,8 +14,6 @@ class DailyMovingMachinesService
protected string $password; protected string $password;
protected string $channelName; protected string $channelName;
public function __construct() public function __construct()
{ {
$this->url = config('cmms_web_services.CHECK_ACTIVITY.url'); $this->url = config('cmms_web_services.CHECK_ACTIVITY.url');
@@ -26,12 +25,11 @@ class DailyMovingMachinesService
/** /**
* @throws Exception * @throws Exception
*/ */
public function run(): array public function run(): Collection
{ {
try { try {
return $this->sendRequest(); return collect( $this->sendRequest());
} } catch (Exception $e) {
catch (Exception $e) {
Log::channel($this->channelName) Log::channel($this->channelName)
->error(get_class($this), ->error(get_class($this),
[ [
@@ -56,13 +54,11 @@ class DailyMovingMachinesService
private function makeInputParameters(): string private function makeInputParameters(): string
{ {
$inputData = array( return json_encode([
"username" => $this->username, "username" => $this->username,
"password" => $this->password, "password" => $this->password,
"day" => today(), "day" => today(),
"minMileage" => 10, "minMileage" => 10,
); ]);
return json_encode($inputData);
} }
} }

View File

@@ -2,20 +2,16 @@
namespace App\Services\Cartables\Mission; namespace App\Services\Cartables\Mission;
use App\Exceptions\ProhibitedAction;
use App\Facades\DataTable\DataTableFacade; use App\Facades\DataTable\DataTableFacade;
use App\Models\DailyMoveMachine; use App\Models\AssignmentFails;
use App\Models\Damage;
use App\Models\SafetyAndPrivacy;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class DailyMoveMachineService class DailyMoveMachineService
{ {
public function dataTable(Request $request) public function dataTable(Request $request)
{ {
return DataTableFacade::run( return DataTableFacade::run(
DailyMoveMachine::query(), AssignmentFails::query(),
$request, $request,
allowedFilters: ['*'], allowedFilters: ['*'],
allowedSortings: ['*'], allowedSortings: ['*'],

View File

@@ -8,7 +8,7 @@ return [
], ],
'CHECK_ACTIVITY' => [ 'CHECK_ACTIVITY' => [
'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'), 'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'),
'password' => env('CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD'), 'password' => env('CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD'),
'username' => env('CHECKE_LIST_MACHINES_ACTIVITY_USERNAME'), 'username' => env('CHECKE_LIST_MACHINES_ACTIVITY_USERNAME'),
], ],

View File

@@ -0,0 +1,18 @@
<?php
namespace Database\Factories;
use App\Models\AssignmentFails;
use Illuminate\Database\Eloquent\Factories\Factory;
class AssignmentFailsFactory extends Factory
{
protected $model = AssignmentFails::class;
public function definition(): array
{
return [
];
}
}

View File

@@ -11,13 +11,13 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::create('report_mission_and_machines', function (Blueprint $table) { Schema::create('assignment_fails', function (Blueprint $table) {
$table->id(); $table->id();
$table->unsignedBigInteger('mission_id')->index()->nullable(); $table->foreignId('mission_id')->constrained('missions')->nullable();
$table->string('machine_code')->index(); $table->string('machine_code')->nullable();
$table->date('request_date')->index(); $table->date('request_date')->nullable();
$table->string('type')->nullable(); $table->string('type')->nullable();
$table->unsignedInteger('mileage')->nullable(); $table->bigInteger('mileage')->nullable();
$table->dateTime('exit_time')->nullable(); $table->dateTime('exit_time')->nullable();
$table->dateTime('enter_time')->nullable(); $table->dateTime('enter_time')->nullable();
$table->timestamps(); $table->timestamps();
@@ -30,6 +30,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('report_mission_and_machines'); Schema::dropIfExists('assignment_fails');
} }
}; };