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\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());
}
}

View File

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

View File

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

View File

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

View File

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

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