Merge branch 'feature/FastReactJob' into 'develop'
create job for road observed problems See merge request witelgroup/rms_v2!67
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\SendRoadObservationToNikarayan;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SendRoadObservationToNikarayanCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'road-observation:send-to-nikarayan';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'send road observation to nikarayan from 1 farvardin 1403 to 14 mehr 1403';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$count = 0;
|
||||
$this->info("Dispatching jobs with a delay between each...");
|
||||
|
||||
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) {
|
||||
foreach ($roads as $road) {
|
||||
$road->update(['rms_status' => 1]);
|
||||
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addMinutes(10)->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;
|
||||
$count +=1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$this->info("{$count} item's sent successfully");
|
||||
}
|
||||
}
|
||||
131
app/Http/Controllers/V3/Dashboard/ReceiptController.php
Normal file
131
app/Http/Controllers/V3/Dashboard/ReceiptController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Accident;
|
||||
use App\Models\City;
|
||||
use App\Models\DailyAccidentSettings;
|
||||
use App\Models\Damage;
|
||||
use App\Models\Province;
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReceiptController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function show(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array('id', 'province_fa','city_fa', 'axis_name', 'accident_type_fa', 'accident_date', 'id',
|
||||
'damage_picture1', 'damage_picture2', 'plaque', 'created_at', 'sum', 'deposit_date', 'status',
|
||||
'police_file_date','deposit_insurance_image','deposit_daghi_image','deposit_insurance_amount',
|
||||
'deposit_daghi_amount','status_fa','final_amount','province_id','accident_time','accident_type',
|
||||
'city_id','driver_name','driver_national_code','driver_phone_number','police_file','lat','lng',
|
||||
'police_serial','report_base'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-receipt')) {
|
||||
$query = Accident::with('damages');
|
||||
} else {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = Accident::with('damages')->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings
|
||||
);
|
||||
|
||||
|
||||
$user->addActivityComplete(1122);
|
||||
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function store(Request $request, NominatimService $nominatimService)
|
||||
{
|
||||
DB::transaction(function () use ($request, $nominatimService) {
|
||||
|
||||
$province = Province::query()->where('id', '=', $request->province_id)->first();
|
||||
$city = City::query()->where('id', '=', $request->city_id)->first();
|
||||
|
||||
$accident = [
|
||||
'province_id' => $province->id,
|
||||
'province_fa' => $province->name_fa,
|
||||
'city_id' => $city->id,
|
||||
'city_fa' => $city->name_fa,
|
||||
'axis_name' => $request->axis_name,
|
||||
'driver_name' => $request->driver_name,
|
||||
'plaque' => $request->plaque,
|
||||
'driver_national_code' => $request->driver_national_code,
|
||||
'driver_phone_number' => $request->driver_phone_number,
|
||||
'user_id' => auth()->user()->id,
|
||||
'lat' => $request->lat,
|
||||
'lng' => $request->lng,
|
||||
'accident_type' => $request->accident_type,
|
||||
'accident_date' => $request->accident_date,
|
||||
'accident_time' => $request->accident_time,
|
||||
'accident_type_fa' => DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value,
|
||||
'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng),
|
||||
];
|
||||
|
||||
if ($request->report_base) {
|
||||
$accident['report_base'] = 1;
|
||||
} else {
|
||||
$accident['police_file'] = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public');
|
||||
$accident['police_serial'] = $request->police_serial;
|
||||
$accident['police_file_date'] = $request->police_file_date;
|
||||
$accident['report_base'] = 0;
|
||||
}
|
||||
|
||||
if ($request->has('damage_picture1')) {
|
||||
$new_accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture1_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public');
|
||||
}
|
||||
|
||||
if ($request->has('damage_picture2')) {
|
||||
$new_accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture2_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public');
|
||||
}
|
||||
|
||||
$new_accident->save();
|
||||
$sum = 0;
|
||||
foreach (json_decode($request->items_damge) as $key => $item) {
|
||||
$damage = Damage::find($item->id);
|
||||
$new_accident->damages()->attach($item->id, [
|
||||
'value' => $item->value,
|
||||
'unit' => $damage->unit,
|
||||
'amount' => $item->amount,
|
||||
]);
|
||||
$sum += $item->amount;
|
||||
}
|
||||
|
||||
$ojrate_nasb = $sum/100*20;
|
||||
$new_accident->ojrate_nasb = $ojrate_nasb;
|
||||
|
||||
$sum += $ojrate_nasb;
|
||||
$new_accident->sum = $sum;
|
||||
$new_accident->withoutAction();
|
||||
$new_accident->save();
|
||||
$msg = "درخواست شما بابت پرداخت خسارت وارده به ابنیه فنی و تاسیسات راه با کد یکتا ".$new_accident->id." ثبت شد.\n".verta()->now()->format('Y/m/d H:i') ;
|
||||
Sms::sendSms($request->phone_number, $msg);
|
||||
auth()->user()->addActivityComplete(1123);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,13 @@ class RoadPatrolProjectController extends Controller
|
||||
|
||||
$item_end_coordinates = null;
|
||||
if ($item['instant_action'] == 0) {
|
||||
$priority = [
|
||||
1 => 'عادی',
|
||||
2 => 'فوری',
|
||||
3 => 'آنی',
|
||||
];
|
||||
$observed_item->priority = $item['priority'];
|
||||
$observed_item->priority_fa = $item['priority_fa'];
|
||||
$observed_item->priority_fa = $priority[$item['priority']];
|
||||
$observed_item->save();
|
||||
} elseif ($item['instant_action'] == 1) {
|
||||
if ($info_item->needs_end_point) {
|
||||
|
||||
@@ -49,7 +49,6 @@ class StoreRequest extends FormRequest
|
||||
'observed_items.*.before_image' => 'image|max:4096',
|
||||
'observed_items.*.after_image' => 'image|max:4096',
|
||||
'observed_items.*.priority' => 'integer|in:1,2,3|required_if:observed_items.*.instant_action,0',
|
||||
'observed_items.*.priority_fa' => 'string|required_if:observed_items.*.instant_action,0',
|
||||
'description' => 'string',
|
||||
|
||||
'observed_items.*.road_item_machines_id' => 'required_if:observed_items.*.instant_action,1|array',
|
||||
|
||||
50
app/Jobs/SendRoadObservationToNikarayan.php
Normal file
50
app/Jobs/SendRoadObservationToNikarayan.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use SoapClient;
|
||||
|
||||
class SendRoadObservationToNikarayan implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(private RoadObserved $roadObserved){}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
|
||||
|
||||
$array = array(
|
||||
'strUserName' => 'vaytelrop',
|
||||
'strPassword' => 'VaYtelROP*2024',
|
||||
'strAutoID' => $this->roadObserved->fk_RegisteredEventMessage,
|
||||
'strStateID' => '2',
|
||||
'strDescription' => 'گزارشات تایید شده از تاریخ 1 فروردین 1403 تا 14 مهر 1403',
|
||||
'strRMSDateAndTime' => $this->roadObserved->updated_at
|
||||
);
|
||||
|
||||
$soapClient = new SoapClient($url);
|
||||
|
||||
$soapClient->UpdateInfo_RoadObservedProblems($array);
|
||||
}
|
||||
catch (\Exception $exception){
|
||||
Log::channel('road_observation_problem')->error($exception->getMessage(), [
|
||||
'roadObserved' => $this->roadObserved,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,12 @@ return [
|
||||
'path' => storage_path('logs/fms/vehicle_activity_service.log'),
|
||||
'level' => 'info',
|
||||
],
|
||||
|
||||
'road_observation_problem' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/road_observation_problem.log'),
|
||||
'level' => 'info',
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
32
database/migrations/2025_02_16_111413_create_jobs_table.php
Normal file
32
database/migrations/2025_02_16_111413_create_jobs_table.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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::table('edarate_ostani', function (Blueprint $table) {
|
||||
$table->text('sub_items_for_confirm')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('edarate_ostani', function (Blueprint $table) {
|
||||
$table->dropColumn('sub_items_for_confirm');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user