Create prosess for check moving machine in mission
This commit is contained in:
@@ -98,3 +98,7 @@ BACKUP_PASSWORD=
|
|||||||
|
|
||||||
HARIM_ENCRYPTION_KEY="TestKey"
|
HARIM_ENCRYPTION_KEY="TestKey"
|
||||||
HARIM_ENCRYPTION_IV="1111000011110101"
|
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=
|
||||||
93
app/Console/Commands/DailyMovingMachineCommand.php
Normal file
93
app/Console/Commands/DailyMovingMachineCommand.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Enums\ActivityMachineType;
|
||||||
|
use App\Models\Mission;
|
||||||
|
use App\Models\DailyMoveMachine;
|
||||||
|
use App\Services\CMMS\DailyMovingMachinesService;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class DailyMovingMachineCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'daily_moving_machine';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'receive cmms cars information and compare my information';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function handle(DailyMovingMachinesService $dailyMovingMachines): void
|
||||||
|
{
|
||||||
|
$response = $dailyMovingMachines->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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
|
|||||||
protected $commands = [
|
protected $commands = [
|
||||||
'App\Console\Commands\RoadObservationProblems', //// road observed webservice from 141 sawaneh
|
'App\Console\Commands\RoadObservationProblems', //// road observed webservice from 141 sawaneh
|
||||||
'App\Console\Commands\SendContractSmsNotification', //// 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')
|
->dailyAt('04:00')
|
||||||
->appendOutputTo(storage_path('logs/telescope.log'));
|
->appendOutputTo(storage_path('logs/telescope.log'));
|
||||||
|
|
||||||
|
$schedule->command('daily_moving_machine')
|
||||||
|
->dailyAt('23:59')->appendOutputTo(storage_path('logs/dailymovingmachine.log'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
21
app/Enums/ActivityMachineType.php
Normal file
21
app/Enums/ActivityMachineType.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum ActivityMachineType: int
|
||||||
|
{
|
||||||
|
case MOTABEGAT = 1;
|
||||||
|
case TEDADE_MACHINES_BISHTAR_AS_MISSION = 2;
|
||||||
|
case TEDADE_MISSIONS_BISHTAR_AS_MACHINES = 3;
|
||||||
|
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::MOTABEGAT => "مطابقت ",
|
||||||
|
self::TEDADE_MACHINES_BISHTAR_AS_MISSION => " تعداد ماشین ها بیشتر از ماموریت ها",
|
||||||
|
self::TEDADE_MISSIONS_BISHTAR_AS_MACHINES => "تغداد ماموریت ها بیشتر از ماشین ها ",
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Events\V3\Dashboard\Mission;
|
namespace App\Events\V3\Dashboard\Mission;
|
||||||
|
|
||||||
use App\Models\Harim;
|
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ namespace App\Http\Controllers\V3\Dashboard\Mission;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
|
use App\Services\Cartables\Mission\DailyMoveMachineService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class DetailController extends Controller
|
class DetailController extends Controller
|
||||||
{
|
{
|
||||||
@@ -31,4 +33,11 @@ class DetailController extends Controller
|
|||||||
|
|
||||||
return $this->successResponse($rahdaran);
|
return $this->successResponse($rahdaran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $dailyMoveMachineService->dataTable($request);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
app/Models/DailyMoveMachine.php
Normal file
17
app/Models/DailyMoveMachine.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class DailyMoveMachine extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
protected $guarded =[];
|
||||||
|
|
||||||
|
public function mission()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Mission::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
68
app/Services/CMMS/DailyMovingMachinesService.php
Normal file
68
app/Services/CMMS/DailyMovingMachinesService.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\CMMS;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class DailyMovingMachinesService
|
||||||
|
{
|
||||||
|
protected string $url;
|
||||||
|
protected string $username;
|
||||||
|
protected string $password;
|
||||||
|
protected string $channelName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Services/Cartables/Mission/DailyMoveMachineService.php
Normal file
25
app/Services/Cartables/Mission/DailyMoveMachineService.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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 Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DailyMoveMachineService
|
||||||
|
{
|
||||||
|
public function dataTable(Request $request)
|
||||||
|
{
|
||||||
|
return DataTableFacade::run(
|
||||||
|
DailyMoveMachine::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: ['id', 'mission_id', 'machine_code', 'request_date', 'type', 'exit_time', 'enter_time']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,4 +6,10 @@ return [
|
|||||||
'password' => env('CMMS_MACHINE_INFO_PASSWORD'),
|
'password' => env('CMMS_MACHINE_INFO_PASSWORD'),
|
||||||
'ViewName' => env('CMMS_MACHINE_INFO_VIEW_NAME'),
|
'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'),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
@@ -147,5 +147,10 @@ return [
|
|||||||
'path' => storage_path('logs/telescope.log'),
|
'path' => storage_path('logs/telescope.log'),
|
||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
],
|
],
|
||||||
|
'daily_moving_machine' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/cmms/daily_moving_machine_service.log'),
|
||||||
|
'level' => 'info',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('report_mission_and_machines', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user