Merge branch 'feature/ActivityStatistic' into 'develop'

Feature/activity statistic

See merge request witelgroup/rms_v2!90
This commit is contained in:
2025-03-10 07:56:09 +00:00
13 changed files with 3036 additions and 2774 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,15 +32,14 @@ class SendRoadObservationToNikarayanCommand extends Command
$count = 0;
$this->info("Dispatching jobs with a delay between each...");
DB::transaction(function () use ($count) {
DB::transaction(function () use (&$count) {
$delay = 0;
RoadObserved::query()
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59'])
->where('rms_status', '=', 0)
->chunkById(50, function ($roads) use ($delay, $count) {
->chunkById(50, function ($roads) use (&$delay, &$count) {
foreach ($roads as $road) {
$road->update(['rms_status' => 1]);
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addMinutes(10)->addSeconds($delay));
$road->update(['status' => 1]);
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds($delay));
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with a {$delay} seconds delay.");
$this->info("Scheduled job for Road ID: {$road->id} {$delay}s");
$delay += 3;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Exceptions;
use App\Http\Traits\ApiResponse;
use Exception;
use Illuminate\Http\JsonResponse;
use Throwable;
class ProhibitedAction extends Exception
{
use ApiResponse;
public function __construct(public $message = "", int $code = 422, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* Render the exception into an HTTP response.
*/
public function render(): JsonResponse
{
return $this->errorResponse($this->message);
}
}

View File

@@ -11,7 +11,7 @@ use App\Models\LogList;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class LogListController extends Controller
class LogListManagementController extends Controller
{
use ApiResponse;
@@ -47,7 +47,7 @@ class LogListController extends Controller
public function update(UpdateRequest $request, LogList $logList): JsonResponse
{
LogList::query()->update([
$logList->update([
'description' => $request->description,
'log_unique_code' => $request->log_unique_code,
'action_type' => $request->action_type,

View File

@@ -0,0 +1,197 @@
<?php
namespace App\Http\Controllers\V3;
use App\Exceptions\ProhibitedAction;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\EdarateOstani;
use App\Models\RoadItemsProject;
use App\Models\RoadObserved;
use App\Models\SafetyAndPrivacy;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Throwable;
class NotificationController extends Controller
{
use ApiResponse;
/**
* Handle the incoming request.
* @throws Throwable
*/
public function __invoke(Request $request): JsonResponse
{
return $this->successResponse([
'roadItem' => $this->roadItemNotifications(),
'safetyAndPrivacy' => $this->safetyAndPrivacyNotifications(),
'roadObserved' => $this->roadObservedNotifications(),
]);
}
/**
* @throws Throwable
*/
private function roadItemNotifications(): JsonResponse|array
{
$user = auth()->user();
$road_items = [
'total' => 0
];
if ($user->hasPermissionTo('create-road-item')) {
$road_items['operation_cnt'] = RoadItemsProject::query()
->where('is_new', '=', 1)
->where('user_id', '=', $user->id)
->where('status', '=', 2)
->count();
$road_items['total'] += $road_items['operation_cnt'];
}
if ($user->hasPermissionTo('supervise-road-item')) {
$road_items['supervise_cnt'] = RoadItemsProject::query()
->where('is_new', '=', 1)
->where('status', '=', 0)
->count();
$road_items['total'] += $road_items['supervise_cnt'];
}
elseif ($user->hasPermissionTo('supervise-road-item-province')) {
throw_if(is_null($user->province_id) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
$road_items['supervise_cnt'] = RoadItemsProject::query()
->where('is_new', '=', 1)
->where('province_id', '=', $user->province_id)
->where('status', '=', 0)
->count();
$road_items['total'] += $road_items['supervise_cnt'];
}
elseif ($user->hasPermissionTo('supervise-road-item-by-edareostani')) {
throw_if(is_null($user->edarate_ostani_id) || !$user->edarate_ostani_id, new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
$confirmableItems = EdarateOstani::query()->where('id', '=', $user->edarate_ostani_id)->value('items_for_confirm');
$road_items['supervise_cnt'] = RoadItemsProject::query()
->where('is_new', '=', 1)
->where('province_id', '=', $user->province_id)
->whereIn('item', explode(",", $confirmableItems))
->where('status', '=', 0)
->count();
$road_items['total'] += $road_items['supervise_cnt'];
}
return $road_items;
}
/**
* @throws Throwable
*/
private function safetyAndPrivacyNotifications(): JsonResponse|array
{
$user = auth()->user();
$safety_and_privacy = array();
if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
$activity = SafetyAndPrivacy::query()
->selectRaw('count(*) as cnt, step')
->groupby('step')
->orderBy('step')
->get();
}
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
$activity = SafetyAndPrivacy::query()
->where('province_id', '=', $user->province_id)
->selectRaw('count(*) as cnt, step')
->groupby('step')
->orderBy('step')
->get();
}
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
$activity = SafetyAndPrivacy::query()
->where('edare_shahri_id', '=', $user->edarate_shahri_id)
->selectRaw('count(*) as cnt, step')
->groupby('step')
->orderBy('step')
->get();
}
$safety_and_privacy['step_one'] = isset($activity[0]) ? $activity[0]->cnt : 0;
$safety_and_privacy['step_two'] = isset($activity[1]) ? $activity[1]->cnt : 0;
return $safety_and_privacy;
}
/**
* @throws Throwable
*/
private function roadObservedNotifications(): JsonResponse|array
{
$user = auth()->user();
$road_observations = [
'total' => 0,
'operation_cnt' => 0,
'complaint_cnt' => 0,
'supervise_cnt' => 0
];
$conditions = [];
$complaintConditions = [
['rms_status', '=', 0],
['edarate_shahri_id', '!=', null]
];
if ($user->hasPermissionTo('show-fast-react')) {
$conditions[] = ['status', '=', 2];
}
elseif ($user->hasPermissionTo('show-fast-react-province')) {
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
$conditions = [
['status', '=', 2],
['rms_province_id', '=', $user->province_id]
];
$complaintConditions[] = ['province_id', '=', $user->province_id];
}
elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
$conditions = [
['status', '=', 2],
['edarate_shahri_id', '=', $user->edarate_shahri_id]
];
$complaintConditions[] = ['edarate_shahri_id', '=', $user->edarate_shahri_id];
}
if (!empty($conditions)) {
$road_observations['operation_cnt'] = RoadObserved::query()->where($conditions)->count();
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
$road_observations['total'] += $road_observations['operation_cnt'] + $road_observations['complaint_cnt'];
}
$superviseConditions = [
['status', '=', 0]
];
if ($user->hasPermissionTo('supervise-fast-react')) {
$road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count();
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
$road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt'];
}
elseif ($user->hasPermissionTo('supervise-fast-react-province')) {
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
$superviseConditions[] = ['province_id', '=', $user->province_id];
$complaintConditions[] = ['province_id', '=', $user->province_id];
$road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count();
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
$road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt'];
}
return $road_observations;
}
}

View File

@@ -24,7 +24,7 @@ class StoreRequest extends FormRequest
return [
'name' => 'required|string|unique:permissions,name',
'name_fa' => 'required|string',
'description' => 'required|string',
'description' => 'string',
'type' => 'required|string',
'type_fa' => 'required|string',
'need_province' => 'required|in:0,1',

View File

@@ -24,7 +24,7 @@ class UpdateRequest extends FormRequest
return [
'name' => "required|string|unique:permissions,name,{$this->permission->id}",
'name_fa' => 'required|string',
'description' => 'required|string',
'description' => 'string',
'type' => 'required|string',
'type_fa' => 'required|string',
'need_province' => 'required|in:0,1',

View File

@@ -15,6 +15,13 @@ class SendRoadObservationToNikarayan implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public int $tries = 2;
/**
* Create a new job instance.
*/

View File

@@ -5,31 +5,71 @@ namespace App\Services;
use App\Models\RoadObserved;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use SoapClient;
use SoapFault;
class NikarayanService
{
/**
* @throws SoapFault
*/
public function updateRoadObservedInfoByNikarayan(Request $request, RoadObserved $roadObserved, $files)
{
if (App::isProduction())
{
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
try {
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$soapClient = new SoapClient($url);
$soapClient = new SoapClient($url);
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
Log::channel('nikarayan')->info($result);
return $soapClient->UpdateInfo_RoadObservedProblems($array);
return $result;
}
catch (\Exception $e) {
Log::channel('nikarayan')->error($e->getMessage());
throw $e;
}
}
return 0;
}
/**
* @throws SoapFault
*/
public function getRoadObservedProblemsByDate()
{
try {
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
$v = verta();
$month = $v->month < 10 ? '0' . $v->month : $v->month;
$day = $v->day < 10 ? '0' . $v->day : $v->day;
$date = $v->year . $month . $day;
$soap_client = new SoapClient($url);
return $soap_client->Get_RoadObservedProblems_ByDate(array(
'strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strStartDate' => $date,
'strEndDate' => $date
));
}
catch (\Exception $e) {
Log::channel('nikarayan')->error($e->getMessage());
throw $e;
}
}
}

View File

@@ -2,62 +2,82 @@
namespace App\Services;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
class NominatimService
{
/**
* @throws Exception
*/
public function get_way_id_from_nominatim($lat = null, $lng = null)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
try {
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
}
}
return 0;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
return 0;
}
return 0;
}
/**
* @throws Exception
*/
function getIDFromNominatim($s_lng, $s_lat, $d_lng, $d_lat)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
try {
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
}
}
}
return $ids;
return $ids;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
}
return [1, 2, 3];

View File

@@ -117,6 +117,18 @@ return [
'path' => storage_path('logs/road_observation_problem.log'),
'level' => 'info',
],
'nominatim' => [
'driver' => 'single',
'path' => storage_path('logs/nominatim.log'),
'level' => 'info',
],
'nikarayan' => [
'driver' => 'single',
'path' => storage_path('logs/nikarayan.log'),
'level' => 'info',
],
],
];

View File

@@ -20,7 +20,8 @@ use App\Http\Controllers\V3\Dashboard\RoadPatrolProjectController;
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacyController;
use App\Http\Controllers\V3\FMSVehicleManagementController;
use App\Http\Controllers\V3\Harim\DivarkeshiController;
use App\Http\Controllers\V3\LogListController;
use App\Http\Controllers\V3\LogListManagementController;
use App\Http\Controllers\V3\NotificationController;
use App\Http\Controllers\V3\PermissionManagementController;
use App\Http\Controllers\V3\ProfileController;
use App\Http\Controllers\V3\RahdaranController;
@@ -261,6 +262,7 @@ Route::prefix('receipts')
Route::get('/', 'index')->name('index');
Route::get('/excel_report', 'excelReport')->name('excelReport');
Route::post('/', 'store')->name('store');
Route::get('/accident_types', 'accidentTypes')->name('accidentTypes');
Route::get('/{accident}', 'show')->name('show');
Route::post('/{accident}', 'update')->name('update');
Route::delete('/{accident}', 'destroy')->name('destroy');
@@ -270,7 +272,6 @@ Route::prefix('receipts')
Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus');
Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument');
Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain');
Route::get('/accident_types', 'accidentTypes')->name('accidentTypes');
});
Route::prefix('receipt_reports')
@@ -320,7 +321,7 @@ Route::prefix('road_observations')
Route::prefix('log_list')
->name('logList.')
->controller(LogListController::class)
->controller(LogListManagementController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/list', 'list')->name('list');
@@ -337,9 +338,9 @@ Route::prefix('safety_and_privacy')
Route::get('/', 'index')->name('index')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
Route::get('/excel_report', 'excelReport')->name('excelReport')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy');
Route::get('/sub_items', 'subItems')->name('subItems');
Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy');
Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy');
Route::get('/sub_items', 'subItems')->name('subItems');
Route::get('/{safetyAndPrivacy}', 'show')->name('show');
Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy');
Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize');
@@ -379,3 +380,5 @@ Route::prefix('permissions')
Route::post('/{permission}', 'update')->name('update');
Route::delete('/{permission}', 'destroy')->name('destroy');
});
Route::get('/notifications', NotificationController::class)->name('notifications');