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..bc19cbfd --- /dev/null +++ b/app/Console/Commands/DailyMovingMachineCommand.php @@ -0,0 +1,78 @@ +run(); + $response = collect($vehiclesInfo['vehiclesInfo']); + + $date = Carbon::yesterday()->toDateString(); + + $cmms = $response->pluck('machineCode'); + + $mission = Mission::query() + ->whereDate('start_time',$date) + ->pluck('machine_code'); + + $cmmsOnly = $cmms->diff($mission); + $missionOnly = $mission->diff($cmms); + + foreach ($cmmsOnly as $code) { + $cmm = $response->firstWhere('machineCode', '=', $code); + + MissionViolation::query()->create([ + 'machine_code' => $code, + 'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value, + 'request_date' => $date, + 'mileage' => $cmm['mileageKM'], +// 'exit_time' => $cmm['exit_time'], +// 'enter_time' => $cmm['enter_time'], + ]); + } + + foreach ($missionOnly as $code) { + $missionId = Mission::query()->where('machine_code', $code) + ->whereDate('start_time', $date) + ->value('id'); + + MissionViolation::query()->create([ + 'machine_code' => $code, + 'mission_id' => $missionId, + 'type' => ActivityMachineType::ADAM_TAHAROK->value, + 'request_date' => $date, + ]); + } + + $this->info("ماشین‌های متحرک بدون مأموریت: " . $cmmsOnly->count()); + $this->info("مأموریت‌های بدون حرکت در CMMS: " . $missionOnly->count()); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 281693b9..4b9554d3 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('02:00')->appendOutputTo(storage_path('logs/dailymovingmachine.log')); + } /** diff --git a/app/Enums/ActivityMachineType.php b/app/Enums/ActivityMachineType.php new file mode 100644 index 00000000..4a4d2595 --- /dev/null +++ b/app/Enums/ActivityMachineType.php @@ -0,0 +1,19 @@ + "خروج بدون مجوز ", + self::ADAM_TAHAROK => "عدم تحرک", + + }; + } +} \ 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/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/MissionViolation.php b/app/Models/MissionViolation.php new file mode 100644 index 00000000..b1ff3be1 --- /dev/null +++ b/app/Models/MissionViolation.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..3f891221 --- /dev/null +++ b/app/Services/CMMS/DailyMovingMachinesService.php @@ -0,0 +1,66 @@ +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 + { + $day = Carbon::yesterday()->toDateString(); + + return json_encode([ + "username" => $this->username, + "password" => $this->password, + "day" => $day, + "minMileage" => 10, + ]); + } +} diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php new file mode 100644 index 00000000..c074fba6 --- /dev/null +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -0,0 +1,21 @@ + 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/factories/AssignmentFailsFactory.php b/database/factories/AssignmentFailsFactory.php new file mode 100644 index 00000000..27e8e5f4 --- /dev/null +++ b/database/factories/AssignmentFailsFactory.php @@ -0,0 +1,18 @@ +id(); + $table->foreignId('mission_id')->nullable()->constrained('missions'); + $table->string('machine_code')->nullable(); + $table->date('request_date')->nullable(); + $table->tinyInteger('type')->nullable(); + $table->bigInteger('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('mission_violations'); + } +};