Merge branch 'feature/NewMission' into 'develop'
Feature/NewMission See merge request witelgroup/rms_v2!164
This commit is contained in:
@@ -6,12 +6,14 @@ enum MissionTypes: int
|
||||
{
|
||||
case SAATY= 1;
|
||||
case ROZANE = 2;
|
||||
case NO_PROCESS = 3;
|
||||
|
||||
public static function name(int $state): string
|
||||
{
|
||||
$mapArray = [
|
||||
1 => 'ساعتی',
|
||||
2 => 'روزانه',
|
||||
3 => 'بدون فرآیند',
|
||||
];
|
||||
|
||||
return $mapArray[$state];
|
||||
|
||||
19
app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php
Normal file
19
app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\V3\Dashboard\Mission;
|
||||
|
||||
use App\Models\Harim;
|
||||
use App\Models\Mission;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendDataToFMSEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(public Mission $mission){}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ use App\Http\Traits\ApiResponse;
|
||||
use App\Models\CMMSMachine;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CMMSMachinesController extends Controller
|
||||
{
|
||||
@@ -39,4 +41,11 @@ class CMMSMachinesController extends Controller
|
||||
|
||||
return $this->successResponse($matchedSearchedMachines);
|
||||
}
|
||||
|
||||
public function carTypes(): Collection
|
||||
{
|
||||
return DB::table('cmms_machines')
|
||||
->distinct()
|
||||
->pluck('car_type');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Mission;
|
||||
|
||||
use App\Enums\MissionCategory;
|
||||
use App\Enums\MissionStates;
|
||||
use App\Enums\MissionTypes;
|
||||
use App\Enums\MissionZones;
|
||||
use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\Mission\ControlUnit\FinishRequest;
|
||||
use App\Http\Requests\V3\Mission\ControlUnit\NoProcessRequest;
|
||||
use App\Http\Requests\V3\Mission\ControlUnit\StartRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Mission;
|
||||
@@ -51,6 +56,7 @@ class ControlUnitController extends Controller
|
||||
]);
|
||||
|
||||
$state = MissionStates::END_MISSION->value;
|
||||
|
||||
$mission->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => MissionStates::name($state),
|
||||
@@ -58,6 +64,45 @@ class ControlUnitController extends Controller
|
||||
]);
|
||||
});
|
||||
|
||||
SendDataToFMSEvent::dispatch($mission);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
|
||||
public function noProcess(NoProcessRequest $request): JsonResponse
|
||||
{
|
||||
|
||||
DB::transaction(function () use ($request) {
|
||||
$user = auth()->user();
|
||||
$zone= $request->zone;
|
||||
$type= MissionTypes::NO_PROCESS->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,
|
||||
]);
|
||||
|
||||
$mission->rahdaran()->sync($request->rahdaran);
|
||||
$mission->machines()->attach($request->machines);
|
||||
$mission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
||||
});
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Mission\ControlUnit;
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class NoProcessRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'rahdaran' => 'array',
|
||||
'rahdaran.*' => 'exists:rahdaran,id',
|
||||
'machines' => 'required|array',
|
||||
'machines.*' => 'required|integer|exists:cmms_machines,id',
|
||||
'driver' => 'required|integer|exists:rahdaran,id',
|
||||
'zone' => 'required|in:1,2,3',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'end_point' => 'required|string',
|
||||
'area' => 'required|array',
|
||||
'area.type' => 'required|string',
|
||||
'area.coordinates' => 'required|array',
|
||||
'category_id' => 'required|in:1,2,3',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$start = Carbon::parse($this->start_date);
|
||||
$end = Carbon::parse($this->end_date);
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($end->diffInMinutes($now) > 0 || $start->diffInMinutes($now) > 0) {
|
||||
$validator->errors()->add(
|
||||
'end_date',
|
||||
'امکان ثبت ماموریت بدون فرایند با توجه به زمان انتخابی مقدور نمی باشد.'
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,19 @@
|
||||
namespace App\Listeners\V3\Dashboard\Harim;
|
||||
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ConfirmGuaranteeLetterNeedListener
|
||||
class ConfirmGuaranteeLetterNeedListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'harim';
|
||||
|
||||
protected string $url;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
@@ -17,6 +26,10 @@ class ConfirmGuaranteeLetterNeedListener
|
||||
$this->username = config('harim_web_services.reject.username');
|
||||
$this->password = config('harim_web_services.reject.password');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function handle(ConfirmGuaranteeLetterNeedEvent $event): void
|
||||
{
|
||||
Http::post($this->url,
|
||||
@@ -27,7 +40,7 @@ class ConfirmGuaranteeLetterNeedListener
|
||||
'' => $event->harim->id,
|
||||
'' => $event->harim->id,
|
||||
'' => $event->harim->id,
|
||||
' ' => $event->harim->id,
|
||||
'' => $event->harim->id,
|
||||
))->throw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,19 @@
|
||||
namespace App\Listeners\V3\Dashboard\Harim;
|
||||
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ConfirmNoRoadAccessNeedListener
|
||||
class ConfirmNoRoadAccessNeedListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'harim';
|
||||
|
||||
protected string $url;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
@@ -18,6 +27,9 @@ class ConfirmNoRoadAccessNeedListener
|
||||
$this->password = config('harim_web_services.reject.password');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function handle(ConfirmNoRoadAccessNeedEvent $event): void
|
||||
{
|
||||
Http::post($this->url,
|
||||
|
||||
@@ -3,10 +3,19 @@
|
||||
namespace App\Listeners\V3\Dashboard\Harim;
|
||||
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ConfirmRoadAccessEditNeedListener
|
||||
class ConfirmRoadAccessEditNeedListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'harim';
|
||||
|
||||
protected string $url;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
@@ -18,6 +27,9 @@ class ConfirmRoadAccessEditNeedListener
|
||||
$this->password = config('harim_web_services.reject.password');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function handle(ConfirmRoadAccessEditNeedEvent $event): void
|
||||
{
|
||||
Http::post($this->url,
|
||||
|
||||
@@ -3,10 +3,19 @@
|
||||
namespace App\Listeners\V3\Dashboard\Harim;
|
||||
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ConfirmRoadAccessNeedListener
|
||||
class ConfirmRoadAccessNeedListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'harim';
|
||||
|
||||
protected string $url;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
@@ -20,6 +29,7 @@ class ConfirmRoadAccessNeedListener
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function handle(ConfirmRoadAccessNeedEvent $event): void
|
||||
{
|
||||
|
||||
@@ -3,11 +3,19 @@
|
||||
namespace App\Listeners\V3\Dashboard\Harim;
|
||||
|
||||
use App\Events\V3\Dashboard\Harim\RejectRequestEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class RejectRequestListener
|
||||
class RejectRequestListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'harim';
|
||||
|
||||
protected string $url;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
|
||||
28
app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php
Normal file
28
app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\V3\Dashboard\Mission;
|
||||
|
||||
use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent;
|
||||
use App\Services\FMS\GetErrorRateService;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
|
||||
class SendDataToFMSListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* The name of the queue the job should be sent to.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $queue = 'fms';
|
||||
|
||||
/**
|
||||
* @throws RequestException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(SendDataToFMSEvent $event, GetErrorRateService $getErrorRateService): void
|
||||
{
|
||||
$getErrorRateService->run($event->mission);
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent;
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent;
|
||||
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent;
|
||||
use App\Events\V3\Dashboard\Harim\RejectRequestEvent;
|
||||
use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent;
|
||||
use App\Listeners\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedListener;
|
||||
use App\Listeners\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedListener;
|
||||
use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedListener;
|
||||
use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessNeedListener;
|
||||
use App\Listeners\V3\Dashboard\Harim\RejectRequestListener;
|
||||
use App\Listeners\V3\Dashboard\Mission\SendDataToFMSListener;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
@@ -50,6 +52,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
ConfirmGuaranteeLetterNeedEvent::class => [
|
||||
ConfirmGuaranteeLetterNeedListener::class
|
||||
],
|
||||
SendDataToFMSEvent::class => [
|
||||
SendDataToFMSListener::class
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
71
app/Services/FMS/GetErrorRateService.php
Normal file
71
app/Services/FMS/GetErrorRateService.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\FMS;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GetErrorRateService
|
||||
{
|
||||
protected string $url;
|
||||
protected string $channelName;
|
||||
protected string $password;
|
||||
protected string $username;
|
||||
protected array $inputParameters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->url = config('fms_web_services.Vehicle_Activity.url');
|
||||
$this->password = config('fms_web_services.Vehicle_Activity.password');
|
||||
$this->username = config('fms_web_services.Vehicle_Activity.username');
|
||||
$this->channelName = 'fms_vehicle_activity';
|
||||
}
|
||||
|
||||
public function setInputParameters(array $inputs): void
|
||||
{
|
||||
$this->inputParameters = $inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = $this->inputParameters + array(
|
||||
"username" => $this->username,
|
||||
"password" => $this->password,
|
||||
"minStopDuration" => 1,
|
||||
);
|
||||
|
||||
return json_encode($inputData);
|
||||
}
|
||||
}
|
||||
@@ -180,6 +180,7 @@ Route::prefix('cmms_machines')
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/list', 'list')->name('list');
|
||||
Route::get('/search', 'search')->name('search');
|
||||
Route::get('/car_types', 'carTypes')->name('carTypes');
|
||||
});
|
||||
|
||||
Route::prefix('rahdaran')
|
||||
@@ -499,6 +500,7 @@ Route::prefix('missions')
|
||||
->controller(ControlUnitController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/no_process','noProcess')->name('noProcess');
|
||||
Route::post('/start/{mission}', 'start')->name('start');
|
||||
Route::post('/finish/{mission}', 'finish')->name('finish');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user