From 69430cf7bc796d23e9a5f5b0aefcc7f547448168 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Wed, 12 Nov 2025 21:52:41 +0330 Subject: [PATCH 1/4] Create prosess for check moving machine in mission --- .env.example | 4 + .../Commands/DailyMovingMachineCommand.php | 93 +++++++++++++++++++ app/Console/Kernel.php | 4 + app/Enums/ActivityMachineType.php | 21 +++++ .../Dashboard/Mission/SendDataToFMSEvent.php | 1 - .../V3/Dashboard/Mission/DetailController.php | 9 ++ app/Models/DailyMoveMachine.php | 17 ++++ .../CMMS/DailyMovingMachinesService.php | 68 ++++++++++++++ .../Mission/DailyMoveMachineService.php | 25 +++++ config/cmms_web_services.php | 6 ++ config/logging.php | 5 + ...55435_create_daily_move_machines_table.php | 35 +++++++ 12 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/DailyMovingMachineCommand.php create mode 100644 app/Enums/ActivityMachineType.php create mode 100644 app/Models/DailyMoveMachine.php create mode 100644 app/Services/CMMS/DailyMovingMachinesService.php create mode 100644 app/Services/Cartables/Mission/DailyMoveMachineService.php create mode 100644 database/migrations/2025_11_12_155435_create_daily_move_machines_table.php diff --git a/.env.example b/.env.example index 5a6b45c4..5ce02157 100644 --- a/.env.example +++ b/.env.example @@ -98,3 +98,7 @@ BACKUP_PASSWORD= HARIM_ENCRYPTION_KEY="TestKey" HARIM_ENCRYPTION_IV="1111000011110101" + +CHECKE_LIST_MACHINES_ACTIVITY_URL='fms.141.ir:7030/api/RMS/GetMovingVehicles', +CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD= +CHECKE_LIST_MACHINES_ACTIVITY_USERNAME= \ No newline at end of file diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php new file mode 100644 index 00000000..e315e194 --- /dev/null +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -0,0 +1,93 @@ +run(); + + $date = now()->toDateString(); + + $cmms = $response + ->pluck('machineCode'); + + $mission = Mission::query() + ->whereDate('start_time',today()) + ->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); + + DailyMoveMachine::query()->create([ + 'machine_code' => $code, + 'type' => ActivityMachineType::TEDADE_MACHINES_BISHTAR_AS_MISSION->label(), + 'request_date' => $date, + 'mileage' => $cmm->mileage, + 'exit_time' => $cmm->exit_time, + 'enter_time' => $cmm->enter_time, + ]); + } + + foreach ($missionOnly as $code) { + DailyMoveMachine::create([ + 'machine_code' => $code, + 'mission_id' => $mission->id, + 'type' => ActivityMachineType::TEDADE_MISSIONS_BISHTAR_AS_MACHINES->label(), + 'request_date' => $date, + ]); + } + + + $this->info('Diffs saved.'); + } + +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 281693b9..7fd4011a 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel protected $commands = [ 'App\Console\Commands\RoadObservationProblems', //// road observed webservice from 141 sawaneh 'App\Console\Commands\SendContractSmsNotification', //// road observed webservice from 141 sawaneh + 'App\Console\Commands\DailyMovingMachineCommand', ]; /** @@ -48,6 +49,9 @@ class Kernel extends ConsoleKernel ->dailyAt('04:00') ->appendOutputTo(storage_path('logs/telescope.log')); + $schedule->command('daily_moving_machine') + ->dailyAt('23:59')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); + } /** diff --git a/app/Enums/ActivityMachineType.php b/app/Enums/ActivityMachineType.php new file mode 100644 index 00000000..23cd3879 --- /dev/null +++ b/app/Enums/ActivityMachineType.php @@ -0,0 +1,21 @@ + "مطابقت ", + self::TEDADE_MACHINES_BISHTAR_AS_MISSION => " تعداد ماشین ها بیشتر از ماموریت ها", + self::TEDADE_MISSIONS_BISHTAR_AS_MACHINES => "تغداد ماموریت ها بیشتر از ماشین ها ", + + }; + } +} \ No newline at end of file diff --git a/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php index f25abfb1..72dde81f 100644 --- a/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php +++ b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php @@ -2,7 +2,6 @@ namespace App\Events\V3\Dashboard\Mission; -use App\Models\Harim; use App\Models\Mission; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php index cf1b2dd1..1c361ff1 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php @@ -5,7 +5,9 @@ namespace App\Http\Controllers\V3\Dashboard\Mission; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\Mission; +use App\Services\Cartables\Mission\DailyMoveMachineService; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class DetailController extends Controller { @@ -31,4 +33,11 @@ class DetailController extends Controller return $this->successResponse($rahdaran); } + + public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse + { + $data = $dailyMoveMachineService->dataTable($request); + + return response()->json($data); + } } diff --git a/app/Models/DailyMoveMachine.php b/app/Models/DailyMoveMachine.php new file mode 100644 index 00000000..033f8681 --- /dev/null +++ b/app/Models/DailyMoveMachine.php @@ -0,0 +1,17 @@ +belongsTo(Mission::class); + } +} diff --git a/app/Services/CMMS/DailyMovingMachinesService.php b/app/Services/CMMS/DailyMovingMachinesService.php new file mode 100644 index 00000000..828a83fd --- /dev/null +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -0,0 +1,68 @@ +url = config('cmms_web_services.CHECK_ACTIVITY.url'); + $this->password = config('cmms_web_services.CHECK_ACTIVITY.password'); + $this->username = config('cmms_web_services.CHECK_ACTIVITY.username'); + $this->channelName = 'daily_moving_machine'; + } + + /** + * @throws Exception + */ + public function run(): array + { + try { + return $this->sendRequest(); + } + catch (Exception $e) { + Log::channel($this->channelName) + ->error(get_class($this), + [ + 'message' => $e->getMessage(), + ] + ); + + throw $e; + } + } + + public function sendRequest(): array + { + $inputData = $this->makeInputParameters(); + + return Http::withBody($inputData) + ->throw() + ->withoutVerifying() + ->post($this->url) + ->json(); + } + + private function makeInputParameters(): string + { + $inputData = array( + "username" => $this->username, + "password" => $this->password, + "day" => today(), + "minMileage" => 10, + ); + + return json_encode($inputData); + } +} diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php new file mode 100644 index 00000000..1a63ed8a --- /dev/null +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -0,0 +1,25 @@ + env('CMMS_MACHINE_INFO_PASSWORD'), 'ViewName' => env('CMMS_MACHINE_INFO_VIEW_NAME'), ], + + 'CHECK_ACTIVITY' => [ + 'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'), + 'password' => env('CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD'), + 'username' => env('CHECKE_LIST_MACHINES_ACTIVITY_USERNAME'), + ], ]; \ No newline at end of file diff --git a/config/logging.php b/config/logging.php index 972f7be3..14edc387 100644 --- a/config/logging.php +++ b/config/logging.php @@ -147,5 +147,10 @@ return [ 'path' => storage_path('logs/telescope.log'), 'level' => 'info', ], + 'daily_moving_machine' => [ + 'driver' => 'single', + 'path' => storage_path('logs/cmms/daily_moving_machine_service.log'), + 'level' => 'info', + ], ], ]; diff --git a/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php b/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php new file mode 100644 index 00000000..7af2c25b --- /dev/null +++ b/database/migrations/2025_11_12_155435_create_daily_move_machines_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('mission_id')->index()->nullable(); + $table->string('machine_code')->index(); + $table->date('request_date')->index(); + $table->string('type')->nullable(); + $table->unsignedInteger('mileage')->nullable(); + $table->dateTime('exit_time')->nullable(); + $table->dateTime('enter_time')->nullable(); + $table->timestamps(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('report_mission_and_machines'); + } +}; From a54345983d0617e22b40ca0e87ef85b26d4e62a8 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 15 Nov 2025 16:08:06 +0330 Subject: [PATCH 2/4] change some part of code --- .../Commands/DailyMovingMachineCommand.php | 52 +++++++------------ app/Enums/ActivityMachineType.php | 10 ++-- ...ilyMoveMachine.php => AssignmentFails.php} | 2 +- .../CMMS/DailyMovingMachinesService.php | 24 ++++----- .../Mission/DailyMoveMachineService.php | 8 +-- config/cmms_web_services.php | 2 +- database/factories/AssignmentFailsFactory.php | 18 +++++++ ..._155435_create_assignment_fails_table.php} | 12 ++--- 8 files changed, 60 insertions(+), 68 deletions(-) rename app/Models/{DailyMoveMachine.php => AssignmentFails.php} (87%) create mode 100644 database/factories/AssignmentFailsFactory.php rename database/migrations/{2025_11_12_155435_create_daily_move_machines_table.php => 2025_11_12_155435_create_assignment_fails_table.php} (61%) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index e315e194..96bdf9d6 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -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()); } - } diff --git a/app/Enums/ActivityMachineType.php b/app/Enums/ActivityMachineType.php index 23cd3879..4a4d2595 100644 --- a/app/Enums/ActivityMachineType.php +++ b/app/Enums/ActivityMachineType.php @@ -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 => "عدم تحرک", }; } diff --git a/app/Models/DailyMoveMachine.php b/app/Models/AssignmentFails.php similarity index 87% rename from app/Models/DailyMoveMachine.php rename to app/Models/AssignmentFails.php index 033f8681..ea33b98c 100644 --- a/app/Models/DailyMoveMachine.php +++ b/app/Models/AssignmentFails.php @@ -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 =[]; diff --git a/app/Services/CMMS/DailyMovingMachinesService.php b/app/Services/CMMS/DailyMovingMachinesService.php index 828a83fd..6383eb10 100644 --- a/app/Services/CMMS/DailyMovingMachinesService.php +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -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( - "username" => $this->username, - "password" => $this->password, - "day" => today(), - "minMileage" => 10, - ); - - return json_encode($inputData); + return json_encode([ + "username" => $this->username, + "password" => $this->password, + "day" => today(), + "minMileage" => 10, + ]); } } diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php index 1a63ed8a..b3d08ac1 100644 --- a/app/Services/Cartables/Mission/DailyMoveMachineService.php +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -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: ['*'], diff --git a/config/cmms_web_services.php b/config/cmms_web_services.php index 25be6244..2541aa46 100644 --- a/config/cmms_web_services.php +++ b/config/cmms_web_services.php @@ -8,7 +8,7 @@ return [ ], 'CHECK_ACTIVITY' => [ - 'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'), + 'url' => env('CHECKE_LIST_MACHINES_ACTIVITY_URL'), 'password' => env('CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD'), 'username' => env('CHECKE_LIST_MACHINES_ACTIVITY_USERNAME'), ], diff --git a/database/factories/AssignmentFailsFactory.php b/database/factories/AssignmentFailsFactory.php new file mode 100644 index 00000000..1f5144f5 --- /dev/null +++ b/database/factories/AssignmentFailsFactory.php @@ -0,0 +1,18 @@ +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'); } }; From 068b6037c75178bb1bf181caaa3f8055056fb6b0 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 15 Nov 2025 17:41:32 +0330 Subject: [PATCH 3/4] fix code --- app/Console/Commands/DailyMovingMachineCommand.php | 12 ++++++------ .../V3/Dashboard/Mission/DetailController.php | 2 +- app/Services/CMMS/DailyMovingMachinesService.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index 96bdf9d6..0b0bacbe 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -32,12 +32,11 @@ class DailyMovingMachineCommand extends Command public function handle(DailyMovingMachinesService $dailyMovingMachines): void { $vehiclesInfo = $dailyMovingMachines->run(); - $response =$vehiclesInfo->get('vehiclesInfo', collect()); + $response = collect($vehiclesInfo['vehiclesInfo']); $date = now()->toDateString(); - $cmms = $response - ->pluck('machineCode'); + $cmms = $response->pluck('machineCode'); $mission = Mission::query() ->whereDate('start_time',$date) @@ -60,12 +59,13 @@ class DailyMovingMachineCommand extends Command } foreach ($missionOnly as $code) { - $missionRecord = Mission::query()->where('machine_code', $code) + $missionId = Mission::query()->where('machine_code', $code) ->whereDate('start_time', today()) - ->get(); + ->value('id'); + AssignmentFails::query()->create([ 'machine_code' => $code, - 'mission_id' => $missionRecord->id, + 'mission_id' => $missionId, 'type' => ActivityMachineType::ADAM_TAHAROK->label(), 'request_date' => $date, ]); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php index 1c361ff1..4a99af4f 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php @@ -15,7 +15,7 @@ class DetailController extends Controller public function machines(Mission $mission): JsonResponse { - return $this->successResponse($mission->machines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); + return $this->successResponse($mission->machine()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); } public function rahdaran(Mission $mission): JsonResponse diff --git a/app/Services/CMMS/DailyMovingMachinesService.php b/app/Services/CMMS/DailyMovingMachinesService.php index 6383eb10..1facb4e8 100644 --- a/app/Services/CMMS/DailyMovingMachinesService.php +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -25,10 +25,10 @@ class DailyMovingMachinesService /** * @throws Exception */ - public function run(): Collection + public function run(): array { try { - return collect( $this->sendRequest()); + return $this->sendRequest(); } catch (Exception $e) { Log::channel($this->channelName) ->error(get_class($this), From 6c41296f22de0e243f7916712ca2efa8a5638b6d Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 16 Nov 2025 10:45:41 +0330 Subject: [PATCH 4/4] fix code --- .../Commands/DailyMovingMachineCommand.php | 21 ++--- app/Console/Kernel.php | 2 +- .../V3/Dashboard/Mission/DetailController.php | 11 +-- .../Mission/ViolationManagementController.php | 79 +++++++++++++++++++ ...signmentFails.php => MissionViolation.php} | 2 +- .../CMMS/DailyMovingMachinesService.php | 6 +- .../Mission/DailyMoveMachineService.php | 4 +- database/factories/AssignmentFailsFactory.php | 4 +- ...55435_create_mission_violations_table.php} | 8 +- 9 files changed, 105 insertions(+), 32 deletions(-) create mode 100644 app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php rename app/Models/{AssignmentFails.php => MissionViolation.php} (87%) rename database/migrations/{2025_11_12_155435_create_assignment_fails_table.php => 2025_11_12_155435_create_mission_violations_table.php} (73%) diff --git a/app/Console/Commands/DailyMovingMachineCommand.php b/app/Console/Commands/DailyMovingMachineCommand.php index 0b0bacbe..bc19cbfd 100644 --- a/app/Console/Commands/DailyMovingMachineCommand.php +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -4,10 +4,11 @@ namespace App\Console\Commands; use App\Enums\ActivityMachineType; use App\Models\Mission; -use App\Models\AssignmentFails; +use App\Models\MissionViolation; use App\Services\CMMS\DailyMovingMachinesService; use Exception; use Illuminate\Console\Command; +use Illuminate\Support\Carbon; class DailyMovingMachineCommand extends Command { @@ -34,7 +35,7 @@ class DailyMovingMachineCommand extends Command $vehiclesInfo = $dailyMovingMachines->run(); $response = collect($vehiclesInfo['vehiclesInfo']); - $date = now()->toDateString(); + $date = Carbon::yesterday()->toDateString(); $cmms = $response->pluck('machineCode'); @@ -46,27 +47,27 @@ class DailyMovingMachineCommand extends Command $missionOnly = $mission->diff($cmms); foreach ($cmmsOnly as $code) { - $cmm = $response->firstWhere('machineCode', $code); + $cmm = $response->firstWhere('machineCode', '=', $code); - AssignmentFails::query()->create([ + MissionViolation::query()->create([ 'machine_code' => $code, - 'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(), + 'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value, 'request_date' => $date, 'mileage' => $cmm['mileageKM'], - 'exit_time' => $cmm['exit_time'], - 'enter_time' => $cmm['enter_time'], +// 'exit_time' => $cmm['exit_time'], +// 'enter_time' => $cmm['enter_time'], ]); } foreach ($missionOnly as $code) { $missionId = Mission::query()->where('machine_code', $code) - ->whereDate('start_time', today()) + ->whereDate('start_time', $date) ->value('id'); - AssignmentFails::query()->create([ + MissionViolation::query()->create([ 'machine_code' => $code, 'mission_id' => $missionId, - 'type' => ActivityMachineType::ADAM_TAHAROK->label(), + 'type' => ActivityMachineType::ADAM_TAHAROK->value, 'request_date' => $date, ]); } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7fd4011a..4b9554d3 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -50,7 +50,7 @@ class Kernel extends ConsoleKernel ->appendOutputTo(storage_path('logs/telescope.log')); $schedule->command('daily_moving_machine') - ->dailyAt('23:59')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); + ->dailyAt('02:00')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php index 4a99af4f..cf1b2dd1 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/DetailController.php @@ -5,9 +5,7 @@ namespace App\Http\Controllers\V3\Dashboard\Mission; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\Mission; -use App\Services\Cartables\Mission\DailyMoveMachineService; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; class DetailController extends Controller { @@ -15,7 +13,7 @@ class DetailController extends Controller public function machines(Mission $mission): JsonResponse { - return $this->successResponse($mission->machine()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); + return $this->successResponse($mission->machines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); } public function rahdaran(Mission $mission): JsonResponse @@ -33,11 +31,4 @@ class DetailController extends Controller return $this->successResponse($rahdaran); } - - public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse - { - $data = $dailyMoveMachineService->dataTable($request); - - return response()->json($data); - } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php new file mode 100644 index 00000000..4e6e95ad --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -0,0 +1,79 @@ +dataTable($request); + + return response()->json($data); + } + + public function noProcess(NoProcessRequest $request): JsonResponse + { + DB::transaction(function () use ($request) { + + $start = Carbon::parse($request->start_date); + $end = Carbon::parse($request->end_date); + $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; + $user = auth()->user(); + $zone = $request->zone; + $state = MissionStates::END_MISSION->value; + + $mission = Mission::query()->create([ + 'user_id' => $user->id, + 'username' => $user->username, + 'province_id' => $user->province_id, + 'province_name' => $user->province_fa, + 'edare_shahri_id' => $user->edarate_shahri_id ?? null, + 'edare_shahri_name' => $user->edarate_shahri_name ?? null, + 'zone' => $zone, + 'zone_fa' => MissionZones::name($zone), + 'type' => $type, + 'type_fa' => MissionTypes::name($type), + 'start_date' => $request->start_date, + 'end_date' => $request->end_date, + 'end_point' => $request->end_point, + 'area' => json_encode($request->area), + 'category_id' => $request->category_id, + 'category_name' => MissionCategory::name($request->category_id), + 'start_time' => $request->start_date, + 'finish_time' => $request->end_date, + 'state_id' => $state, + 'state_name' => MissionStates::name($state), + 'explanation' => $request->explanation, + 'request_date' => now(), + ]); + + $mission->rahdaran()->sync($request->rahdaran); + $mission->machines()->attach($request->machines); + $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); + + if ($mission->category_id == 2) { + $rpc = new OperatorController; + $rpc->store($mission); + } + }); + + return $this->successResponse(); + } +} diff --git a/app/Models/AssignmentFails.php b/app/Models/MissionViolation.php similarity index 87% rename from app/Models/AssignmentFails.php rename to app/Models/MissionViolation.php index ea33b98c..b1ff3be1 100644 --- a/app/Models/AssignmentFails.php +++ b/app/Models/MissionViolation.php @@ -5,7 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class AssignmentFails extends Model +class MissionViolation extends Model { use HasFactory; protected $guarded =[]; diff --git a/app/Services/CMMS/DailyMovingMachinesService.php b/app/Services/CMMS/DailyMovingMachinesService.php index 1facb4e8..3f891221 100644 --- a/app/Services/CMMS/DailyMovingMachinesService.php +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -3,7 +3,7 @@ namespace App\Services\CMMS; use Exception; -use Illuminate\Support\Collection; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -54,10 +54,12 @@ class DailyMovingMachinesService private function makeInputParameters(): string { + $day = Carbon::yesterday()->toDateString(); + return json_encode([ "username" => $this->username, "password" => $this->password, - "day" => today(), + "day" => $day, "minMileage" => 10, ]); } diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php index b3d08ac1..c074fba6 100644 --- a/app/Services/Cartables/Mission/DailyMoveMachineService.php +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -3,7 +3,7 @@ namespace App\Services\Cartables\Mission; use App\Facades\DataTable\DataTableFacade; -use App\Models\AssignmentFails; +use App\Models\MissionViolation; use Illuminate\Http\Request; class DailyMoveMachineService @@ -11,7 +11,7 @@ class DailyMoveMachineService public function dataTable(Request $request) { return DataTableFacade::run( - AssignmentFails::query(), + MissionViolation::query(), $request, allowedFilters: ['*'], allowedSortings: ['*'], diff --git a/database/factories/AssignmentFailsFactory.php b/database/factories/AssignmentFailsFactory.php index 1f5144f5..27e8e5f4 100644 --- a/database/factories/AssignmentFailsFactory.php +++ b/database/factories/AssignmentFailsFactory.php @@ -2,12 +2,12 @@ namespace Database\Factories; -use App\Models\AssignmentFails; +use App\Models\MissionViolation; use Illuminate\Database\Eloquent\Factories\Factory; class AssignmentFailsFactory extends Factory { - protected $model = AssignmentFails::class; + protected $model = MissionViolation::class; public function definition(): array { diff --git a/database/migrations/2025_11_12_155435_create_assignment_fails_table.php b/database/migrations/2025_11_12_155435_create_mission_violations_table.php similarity index 73% rename from database/migrations/2025_11_12_155435_create_assignment_fails_table.php rename to database/migrations/2025_11_12_155435_create_mission_violations_table.php index b59d5f16..c741572f 100644 --- a/database/migrations/2025_11_12_155435_create_assignment_fails_table.php +++ b/database/migrations/2025_11_12_155435_create_mission_violations_table.php @@ -11,12 +11,12 @@ return new class extends Migration */ public function up(): void { - Schema::create('assignment_fails', function (Blueprint $table) { + Schema::create('mission_violations', function (Blueprint $table) { $table->id(); - $table->foreignId('mission_id')->constrained('missions')->nullable(); + $table->foreignId('mission_id')->nullable()->constrained('missions'); $table->string('machine_code')->nullable(); $table->date('request_date')->nullable(); - $table->string('type')->nullable(); + $table->tinyInteger('type')->nullable(); $table->bigInteger('mileage')->nullable(); $table->dateTime('exit_time')->nullable(); $table->dateTime('enter_time')->nullable(); @@ -30,6 +30,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('assignment_fails'); + Schema::dropIfExists('mission_violations'); } };