@fleetbase/fleetops-engine 0.6.54 → 0.6.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/components/admin/map-settings.hbs +1 -1
- package/addon/components/admin/routing-settings.hbs +2 -1
- package/addon/components/cell/attached-vehicle.hbs +10 -0
- package/addon/components/cell/attached-vehicle.js +58 -0
- package/addon/components/cell/device-identity.hbs +24 -0
- package/addon/components/cell/device-identity.js +129 -0
- package/addon/components/cell/driver-identity.hbs +33 -0
- package/addon/components/cell/driver-identity.js +143 -0
- package/addon/components/cell/equipment-identity.hbs +5 -0
- package/addon/components/cell/equipment-identity.js +48 -0
- package/addon/components/cell/part-identity.hbs +5 -0
- package/addon/components/cell/part-identity.js +63 -0
- package/addon/components/cell/telematic-device.hbs +38 -0
- package/addon/components/cell/telematic-device.js +44 -0
- package/addon/components/cell/telematic-provider.hbs +33 -16
- package/addon/components/cell/telematic-provider.js +50 -8
- package/addon/components/cell/vehicle-identity.hbs +33 -0
- package/addon/components/cell/vehicle-identity.js +138 -0
- package/addon/components/device/details.js +1 -1
- package/addon/components/device/form.hbs +2 -2
- package/addon/components/device/form.js +7 -0
- package/addon/components/device/panel-header.hbs +45 -20
- package/addon/components/device/panel-header.js +49 -1
- package/addon/components/device/panel-tabs/events.hbs +30 -0
- package/addon/components/device/panel-tabs/events.js +128 -0
- package/addon/components/device/panel-tabs/sensors.hbs +30 -0
- package/addon/components/device/panel-tabs/sensors.js +93 -0
- package/addon/components/device/panel-tabs/vehicle.hbs +68 -0
- package/addon/components/device/panel-tabs/vehicle.js +90 -0
- package/addon/components/device-event/details.hbs +192 -0
- package/addon/components/device-event/details.js +151 -0
- package/addon/components/driver/schedule.js +1 -1
- package/addon/components/equipment/form.js +8 -1
- package/addon/components/layout/fleet-ops-sidebar.hbs +1 -1
- package/addon/components/layout/fleet-ops-sidebar.js +20 -6
- package/addon/components/map/drawer/device-event-listing.js +2 -0
- package/addon/components/map/drawer/driver-listing.js +2 -0
- package/addon/components/map/drawer/place-listing.js +2 -0
- package/addon/components/map/drawer/position-listing.hbs +11 -6
- package/addon/components/map/drawer/position-listing.js +17 -4
- package/addon/components/map/drawer/vehicle-listing.js +2 -0
- package/addon/components/sensor/panel-header.hbs +47 -15
- package/addon/components/sensor/panel-header.js +59 -1
- package/addon/components/table/cell/dropdown/action-item.hbs +31 -0
- package/addon/components/table/cell/dropdown/action-item.js +62 -0
- package/addon/components/table/cell/dropdown.hbs +28 -0
- package/addon/components/table/cell/dropdown.js +91 -0
- package/addon/components/telematic/details.hbs +1 -1
- package/addon/components/telematic/form.hbs +2 -2
- package/addon/components/telematic/settings.hbs +1 -1
- package/addon/components/vendor/panel-header.hbs +82 -0
- package/addon/components/vendor/panel-header.js +48 -0
- package/addon/controllers/connectivity/devices/index/details/events.js +1 -1
- package/addon/controllers/connectivity/devices/index/details/vehicle.js +50 -2
- package/addon/controllers/connectivity/devices/index.js +144 -129
- package/addon/controllers/connectivity/events/details.js +70 -0
- package/addon/controllers/connectivity/events/index.js +187 -11
- package/addon/controllers/connectivity/sensors/index.js +160 -14
- package/addon/controllers/connectivity/telematics/details/devices.js +126 -134
- package/addon/controllers/connectivity/telematics/details/events.js +1 -1
- package/addon/controllers/connectivity/telematics/details/sensors.js +4 -0
- package/addon/controllers/maintenance/equipment/index.js +1 -2
- package/addon/controllers/maintenance/parts/index.js +1 -2
- package/addon/controllers/management/drivers/index.js +82 -42
- package/addon/controllers/management/fuel-reports/index.js +63 -4
- package/addon/controllers/management/issues/index.js +63 -4
- package/addon/controllers/management/vehicles/index.js +33 -6
- package/addon/controllers/settings/map.js +15 -0
- package/addon/instance-initializers/register-vroom-allocation.js +1 -1
- package/addon/routes/connectivity/devices/index/details/vehicle.js +24 -2
- package/addon/routes/connectivity/devices/index.js +7 -0
- package/addon/routes/connectivity/events/details.js +28 -0
- package/addon/routes/connectivity/events/index.js +6 -2
- package/addon/routes/connectivity/sensors/index.js +7 -2
- package/addon/routes/connectivity/telematics/details/devices.js +2 -0
- package/addon/routes/management/vehicles/index/details.js +3 -1
- package/addon/services/device-actions.js +30 -0
- package/addon/services/device-event-actions.js +1 -1
- package/addon/services/equipment-actions.js +1 -0
- package/addon/services/map-adapter/google.js +25 -0
- package/addon/services/map-adapter/leaflet.js +1 -1
- package/addon/services/map-adapter-interface.js +1 -1
- package/addon/services/map-manager.js +4 -1
- package/addon/services/map-settings.js +15 -0
- package/addon/services/sensor-actions.js +3 -0
- package/addon/services/service-rate-actions.js +39 -1
- package/addon/services/vehicle-actions.js +24 -12
- package/addon/services/vendor-actions.js +3 -0
- package/addon/styles/fleetops-engine.css +9 -1
- package/addon/templates/connectivity/devices/index/details/vehicle.hbs +66 -2
- package/addon/templates/connectivity/events/details.hbs +40 -0
- package/addon/templates/management/vendors/index/details.hbs +2 -2
- package/addon/templates/settings/map.hbs +38 -9
- package/addon/templates/settings/notifications.hbs +2 -1
- package/addon/templates/settings/routing.hbs +1 -0
- package/addon/utils/device-table-columns.js +288 -0
- package/addon/utils/identity-cell-resource.js +20 -0
- package/addon/utils/leaflet-plugin-loader.js +5 -5
- package/addon/utils/map-drawer-dropdown-position.js +47 -0
- package/addon/utils/route-colors.js +1 -1
- package/addon/utils/trackable-option.js +93 -0
- package/app/components/cell/attached-vehicle.js +1 -0
- package/app/components/cell/device-identity.js +1 -0
- package/app/components/cell/driver-identity.js +1 -0
- package/app/components/cell/equipment-identity.js +1 -0
- package/app/components/cell/part-identity.js +1 -0
- package/app/components/cell/telematic-device.js +1 -0
- package/app/components/cell/vehicle-identity.js +1 -0
- package/app/components/device/panel-tabs/events.hbs +30 -0
- package/app/components/device/panel-tabs/events.js +128 -0
- package/app/components/device/panel-tabs/sensors.hbs +30 -0
- package/app/components/device/panel-tabs/sensors.js +93 -0
- package/app/components/device/panel-tabs/vehicle.hbs +68 -0
- package/app/components/device/panel-tabs/vehicle.js +90 -0
- package/app/components/device-event/details.hbs +192 -0
- package/app/components/device-event/details.js +1 -0
- package/app/components/table/cell/dropdown/action-item.js +1 -0
- package/app/components/table/cell/dropdown.js +1 -0
- package/app/components/vendor/panel-header.js +1 -0
- package/app/controllers/connectivity/events/{index/details.js → details.js} +1 -1
- package/app/routes/connectivity/events/{index/details.js → details.js} +1 -1
- package/app/templates/connectivity/events/{index/details.js → details.js} +1 -1
- package/app/utils/map-drawer-dropdown-position.js +1 -0
- package/app/utils/trackable-option.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +4 -4
- package/server/migrations/2026_06_23_000001_delete_bad_afaqy_telematics_sensors.php +34 -0
- package/server/src/Console/Commands/SyncTelematics.php +4 -4
- package/server/src/Exports/ContactExport.php +12 -5
- package/server/src/Exports/DeviceExport.php +92 -0
- package/server/src/Exports/DriverExport.php +28 -3
- package/server/src/Exports/EquipmentExport.php +94 -0
- package/server/src/Exports/FleetExport.php +22 -7
- package/server/src/Exports/FuelReportExport.php +16 -1
- package/server/src/Exports/IssueExport.php +25 -3
- package/server/src/Exports/MaintenanceExport.php +106 -0
- package/server/src/Exports/MaintenanceScheduleExport.php +99 -0
- package/server/src/Exports/OrderExport.php +24 -5
- package/server/src/Exports/PartExport.php +99 -0
- package/server/src/Exports/PlaceExport.php +33 -7
- package/server/src/Exports/SensorExport.php +94 -0
- package/server/src/Exports/ServiceAreaExport.php +31 -7
- package/server/src/Exports/ServiceRateExport.php +41 -1
- package/server/src/Exports/TelematicExport.php +90 -0
- package/server/src/Exports/VehicleExport.php +274 -8
- package/server/src/Exports/VendorExport.php +15 -2
- package/server/src/Exports/WorkOrderExport.php +92 -0
- package/server/src/Http/Controllers/Api/v1/Concerns/ResolvesFleetOpsApiResources.php +176 -0
- package/server/src/Http/Controllers/Api/v1/DeviceController.php +225 -0
- package/server/src/Http/Controllers/Api/v1/EquipmentController.php +114 -0
- package/server/src/Http/Controllers/Api/v1/FuelTransactionController.php +185 -0
- package/server/src/Http/Controllers/Api/v1/PartController.php +120 -0
- package/server/src/Http/Controllers/Api/v1/SensorController.php +132 -0
- package/server/src/Http/Controllers/Api/v1/WorkOrderController.php +161 -0
- package/server/src/Http/Controllers/Internal/v1/DeviceController.php +36 -1
- package/server/src/Http/Controllers/Internal/v1/DeviceEventController.php +1 -1
- package/server/src/Http/Controllers/Internal/v1/EquipmentController.php +17 -0
- package/server/src/Http/Controllers/Internal/v1/LiveController.php +1 -1
- package/server/src/Http/Controllers/Internal/v1/MaintenanceController.php +17 -0
- package/server/src/Http/Controllers/Internal/v1/MaintenanceScheduleController.php +17 -0
- package/server/src/Http/Controllers/Internal/v1/PartController.php +17 -0
- package/server/src/Http/Controllers/Internal/v1/SensorController.php +18 -0
- package/server/src/Http/Controllers/Internal/v1/ServiceRateController.php +82 -13
- package/server/src/Http/Controllers/Internal/v1/SettingController.php +29 -5
- package/server/src/Http/Controllers/Internal/v1/TelematicController.php +18 -0
- package/server/src/Http/Controllers/Internal/v1/WorkOrderController.php +17 -0
- package/server/src/Http/Filter/DeviceEventFilter.php +21 -0
- package/server/src/Http/Filter/DeviceFilter.php +50 -4
- package/server/src/Http/Filter/EquipmentFilter.php +23 -0
- package/server/src/Http/Filter/FuelProviderTransactionFilter.php +57 -2
- package/server/src/Http/Filter/PartFilter.php +47 -0
- package/server/src/Http/Filter/SensorFilter.php +34 -6
- package/server/src/Http/Filter/WorkOrderFilter.php +23 -0
- package/server/src/Http/Requests/CreateDeviceRequest.php +51 -0
- package/server/src/Http/Requests/CreateEquipmentRequest.php +35 -0
- package/server/src/Http/Requests/CreateFuelTransactionRequest.php +50 -0
- package/server/src/Http/Requests/CreatePartRequest.php +40 -0
- package/server/src/Http/Requests/CreateSensorRequest.php +47 -0
- package/server/src/Http/Requests/CreateWorkOrderRequest.php +42 -0
- package/server/src/Http/Requests/UpdateDeviceRequest.php +7 -0
- package/server/src/Http/Requests/UpdateEquipmentRequest.php +7 -0
- package/server/src/Http/Requests/UpdateFuelTransactionRequest.php +7 -0
- package/server/src/Http/Requests/UpdatePartRequest.php +7 -0
- package/server/src/Http/Requests/UpdateSensorRequest.php +7 -0
- package/server/src/Http/Requests/UpdateWorkOrderRequest.php +7 -0
- package/server/src/Http/Resources/v1/Device.php +72 -0
- package/server/src/Http/Resources/v1/Equipment.php +57 -0
- package/server/src/Http/Resources/v1/FuelTransaction.php +69 -0
- package/server/src/Http/Resources/v1/Index/Vehicle.php +19 -0
- package/server/src/Http/Resources/v1/Part.php +64 -0
- package/server/src/Http/Resources/v1/Sensor.php +68 -0
- package/server/src/Jobs/SyncTelematicDevicesJob.php +194 -38
- package/server/src/Models/Device.php +2 -0
- package/server/src/Models/DeviceEvent.php +81 -0
- package/server/src/Models/Equipment.php +55 -0
- package/server/src/Models/Order.php +2 -1
- package/server/src/Observers/PurchaseRateObserver.php +2 -1
- package/server/src/Support/Analytics/RevenueTrend.php +3 -8
- package/server/src/Support/Metrics/ActiveRevenueQuery.php +121 -0
- package/server/src/Support/Metrics/AvgOrderValueMetric.php +1 -7
- package/server/src/Support/Metrics/EarningsMetric.php +1 -10
- package/server/src/Support/Telematics/Providers/AfaqyProvider.php +105 -5
- package/server/src/Support/Telematics/Providers/FlespiProvider.php +89 -15
- package/server/src/Support/Telematics/Providers/GeotabProvider.php +123 -35
- package/server/src/Support/Telematics/Providers/SafeeProvider.php +567 -47
- package/server/src/Support/Telematics/Providers/SamsaraProvider.php +122 -14
- package/server/src/Support/Telematics/TelematicService.php +28 -9
- package/server/src/routes.php +67 -15
- package/server/tests/DeviceFilterTest.php +9 -0
- package/server/tests/DriverVehicleStatusDefaultTest.php +19 -2
- package/server/tests/EquipmentAssignmentMorphTypeTest.php +35 -0
- package/server/tests/ExportCoverageTest.php +79 -0
- package/server/tests/MetricsRegistryTest.php +45 -5
- package/server/tests/PublicFleetOpsRestEndpointsTest.php +191 -0
- package/server/tests/ServiceRateRouteValidationTest.php +101 -0
- package/server/tests/TelematicsHardeningTest.php +873 -7
- package/addon/controllers/connectivity/events/index/details.js +0 -3
- package/addon/routes/connectivity/events/index/details.js +0 -3
- package/addon/templates/connectivity/events/index/details.hbs +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Resources\v1;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Http\Resources\FleetbaseResource;
|
|
6
|
+
use Fleetbase\Support\Http;
|
|
7
|
+
use Fleetbase\Support\Resolve;
|
|
8
|
+
|
|
9
|
+
class FuelTransaction extends FleetbaseResource
|
|
10
|
+
{
|
|
11
|
+
public function toArray($request)
|
|
12
|
+
{
|
|
13
|
+
return [
|
|
14
|
+
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
|
|
15
|
+
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
|
|
16
|
+
'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
|
|
17
|
+
'fuel_provider_connection_uuid' => $this->when(Http::isInternalRequest(), $this->fuel_provider_connection_uuid),
|
|
18
|
+
'fuel_report_uuid' => $this->when(Http::isInternalRequest(), $this->fuel_report_uuid),
|
|
19
|
+
'vehicle_uuid' => $this->when(Http::isInternalRequest(), $this->vehicle_uuid),
|
|
20
|
+
'driver_uuid' => $this->when(Http::isInternalRequest(), $this->driver_uuid),
|
|
21
|
+
'order_uuid' => $this->when(Http::isInternalRequest(), $this->order_uuid),
|
|
22
|
+
'connection' => $this->whenLoaded('connection', fn () => $this->resolveLoadedRelation($this->connection)),
|
|
23
|
+
'fuel_report' => $this->whenLoaded('fuelReport', fn () => $this->resolveLoadedRelation($this->fuelReport)),
|
|
24
|
+
'vehicle' => $this->whenLoaded('vehicle', fn () => $this->resolveLoadedRelation($this->vehicle)),
|
|
25
|
+
'driver' => $this->whenLoaded('driver', fn () => $this->resolveLoadedRelation($this->driver)),
|
|
26
|
+
'order' => $this->whenLoaded('order', fn () => $this->resolveLoadedRelation($this->order)),
|
|
27
|
+
'provider' => $this->provider,
|
|
28
|
+
'provider_transaction_id' => $this->provider_transaction_id,
|
|
29
|
+
'provider_vehicle_id' => $this->provider_vehicle_id,
|
|
30
|
+
'vehicle_card_id' => $this->vehicle_card_id,
|
|
31
|
+
'internal_number' => $this->internal_number,
|
|
32
|
+
'structure_number' => $this->structure_number,
|
|
33
|
+
'plate_number' => $this->plate_number,
|
|
34
|
+
'vin' => $this->vin,
|
|
35
|
+
'serial_number' => $this->serial_number,
|
|
36
|
+
'call_sign' => $this->call_sign,
|
|
37
|
+
'trip_number' => $this->trip_number,
|
|
38
|
+
'station_name' => $this->station_name,
|
|
39
|
+
'station_latitude' => $this->station_latitude,
|
|
40
|
+
'station_longitude' => $this->station_longitude,
|
|
41
|
+
'station_location' => $this->station_location,
|
|
42
|
+
'transaction_at' => $this->transaction_at,
|
|
43
|
+
'volume' => $this->volume,
|
|
44
|
+
'metric_unit' => $this->metric_unit,
|
|
45
|
+
'amount' => $this->amount,
|
|
46
|
+
'currency' => $this->currency,
|
|
47
|
+
'odometer' => $this->odometer,
|
|
48
|
+
'sync_status' => $this->sync_status,
|
|
49
|
+
'matched_at' => $this->matched_at,
|
|
50
|
+
'vehicle_name' => $this->vehicle_name,
|
|
51
|
+
'driver_name' => $this->driver_name,
|
|
52
|
+
'fuel_report_id' => $this->fuel_report_id,
|
|
53
|
+
'normalized_payload' => $this->when(Http::isInternalRequest(), $this->normalized_payload),
|
|
54
|
+
'raw_payload' => $this->when(Http::isInternalRequest(), $this->raw_payload),
|
|
55
|
+
'meta' => $this->when(Http::isInternalRequest(), $this->meta),
|
|
56
|
+
'updated_at' => $this->updated_at,
|
|
57
|
+
'created_at' => $this->created_at,
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected function resolveLoadedRelation($model)
|
|
62
|
+
{
|
|
63
|
+
if (!$model) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Http::isInternalRequest() ? Resolve::httpResourceForModel($model) : $model->public_id;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -46,6 +46,7 @@ class Vehicle extends FleetbaseResource
|
|
|
46
46
|
'altitude' => (int) data_get($this, 'altitude', 0),
|
|
47
47
|
'speed' => (int) data_get($this, 'speed', 0),
|
|
48
48
|
'online' => (bool) data_get($this, 'online', false),
|
|
49
|
+
'devices' => $this->whenLoaded('devices', fn () => $this->compactDevices()),
|
|
49
50
|
'assigned_orders_count' => $this->when($isInternal, $this->assignedOrdersCount()),
|
|
50
51
|
|
|
51
52
|
// Meta flag to indicate this is an index resource
|
|
@@ -65,6 +66,24 @@ class Vehicle extends FleetbaseResource
|
|
|
65
66
|
return Order::where('vehicle_assigned_uuid', $this->uuid)->count();
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
protected function compactDevices(): array
|
|
70
|
+
{
|
|
71
|
+
return $this->devices->map(
|
|
72
|
+
fn ($device) => [
|
|
73
|
+
'id' => $device->uuid,
|
|
74
|
+
'uuid' => $device->uuid,
|
|
75
|
+
'public_id' => $device->public_id,
|
|
76
|
+
'name' => $device->name,
|
|
77
|
+
'display_name' => $device->display_name,
|
|
78
|
+
'device_id' => $device->device_id,
|
|
79
|
+
'serial_number' => $device->serial_number,
|
|
80
|
+
'imei' => $device->imei,
|
|
81
|
+
'provider' => $device->provider,
|
|
82
|
+
'status' => $device->status,
|
|
83
|
+
]
|
|
84
|
+
)->values()->all();
|
|
85
|
+
}
|
|
86
|
+
|
|
68
87
|
protected function currentOrderReference(): ?string
|
|
69
88
|
{
|
|
70
89
|
$this->loadMissing('driver.currentOrder');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Resources\v1;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
6
|
+
use Fleetbase\Http\Resources\FleetbaseResource;
|
|
7
|
+
use Fleetbase\Support\Http;
|
|
8
|
+
use Fleetbase\Support\Resolve;
|
|
9
|
+
|
|
10
|
+
class Part extends FleetbaseResource
|
|
11
|
+
{
|
|
12
|
+
public function toArray($request)
|
|
13
|
+
{
|
|
14
|
+
return [
|
|
15
|
+
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
|
|
16
|
+
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
|
|
17
|
+
'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
|
|
18
|
+
'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
|
|
19
|
+
'vendor_uuid' => $this->when(Http::isInternalRequest(), $this->vendor_uuid),
|
|
20
|
+
'warranty_uuid' => $this->when(Http::isInternalRequest(), $this->warranty_uuid),
|
|
21
|
+
'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
|
|
22
|
+
'asset_uuid' => $this->when(Http::isInternalRequest(), $this->asset_uuid),
|
|
23
|
+
'asset_type' => $this->when(Http::isInternalRequest(), $this->asset_type ? Utils::toEmberResourceType($this->asset_type) : null),
|
|
24
|
+
'vendor' => $this->whenLoaded('vendor', fn () => $this->resolveLoadedRelation($this->vendor)),
|
|
25
|
+
'warranty' => $this->whenLoaded('warranty', fn () => $this->resolveLoadedRelation($this->warranty)),
|
|
26
|
+
'photo' => $this->whenLoaded('photo', fn () => $this->resolveLoadedRelation($this->photo)),
|
|
27
|
+
'asset' => $this->whenLoaded('asset', fn () => $this->resolveLoadedRelation($this->asset)),
|
|
28
|
+
'sku' => $this->sku,
|
|
29
|
+
'name' => $this->name,
|
|
30
|
+
'manufacturer' => $this->manufacturer,
|
|
31
|
+
'model' => $this->model,
|
|
32
|
+
'serial_number' => $this->serial_number,
|
|
33
|
+
'barcode' => $this->barcode,
|
|
34
|
+
'description' => $this->description,
|
|
35
|
+
'quantity_on_hand' => $this->quantity_on_hand,
|
|
36
|
+
'unit_cost' => $this->unit_cost,
|
|
37
|
+
'msrp' => $this->msrp,
|
|
38
|
+
'currency' => $this->currency,
|
|
39
|
+
'type' => $this->type,
|
|
40
|
+
'status' => $this->status,
|
|
41
|
+
'specs' => data_get($this, 'specs', Utils::createObject()),
|
|
42
|
+
'meta' => data_get($this, 'meta', Utils::createObject()),
|
|
43
|
+
'vendor_name' => $this->vendor_name,
|
|
44
|
+
'warranty_name' => $this->warranty_name,
|
|
45
|
+
'photo_url' => $this->photo_url,
|
|
46
|
+
'total_value' => $this->total_value,
|
|
47
|
+
'is_in_stock' => $this->is_in_stock,
|
|
48
|
+
'is_low_stock' => $this->is_low_stock,
|
|
49
|
+
'asset_name' => $this->asset_name,
|
|
50
|
+
'slug' => $this->slug,
|
|
51
|
+
'updated_at' => $this->updated_at,
|
|
52
|
+
'created_at' => $this->created_at,
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected function resolveLoadedRelation($model)
|
|
57
|
+
{
|
|
58
|
+
if (!$model) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Http::isInternalRequest() ? Resolve::httpResourceForModel($model) : $model->public_id;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Resources\v1;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
6
|
+
use Fleetbase\Http\Resources\FleetbaseResource;
|
|
7
|
+
use Fleetbase\Support\Http;
|
|
8
|
+
use Fleetbase\Support\Resolve;
|
|
9
|
+
|
|
10
|
+
class Sensor extends FleetbaseResource
|
|
11
|
+
{
|
|
12
|
+
public function toArray($request)
|
|
13
|
+
{
|
|
14
|
+
return $this->withCustomFields([
|
|
15
|
+
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
|
|
16
|
+
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
|
|
17
|
+
'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
|
|
18
|
+
'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
|
|
19
|
+
'device_uuid' => $this->when(Http::isInternalRequest(), $this->device_uuid),
|
|
20
|
+
'warranty_uuid' => $this->when(Http::isInternalRequest(), $this->warranty_uuid),
|
|
21
|
+
'telematic_uuid' => $this->when(Http::isInternalRequest(), $this->telematic_uuid),
|
|
22
|
+
'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
|
|
23
|
+
'sensorable_uuid' => $this->when(Http::isInternalRequest(), $this->sensorable_uuid),
|
|
24
|
+
'sensorable_type' => $this->when(Http::isInternalRequest(), $this->sensorable_type ? Utils::toEmberResourceType($this->sensorable_type) : null),
|
|
25
|
+
'device' => $this->whenLoaded('device', fn () => $this->resolveLoadedRelation($this->device)),
|
|
26
|
+
'warranty' => $this->whenLoaded('warranty', fn () => $this->resolveLoadedRelation($this->warranty)),
|
|
27
|
+
'telematic' => $this->whenLoaded('telematic', fn () => $this->resolveLoadedRelation($this->telematic)),
|
|
28
|
+
'photo' => $this->whenLoaded('photo', fn () => $this->resolveLoadedRelation($this->photo)),
|
|
29
|
+
'sensorable' => $this->whenLoaded('sensorable', fn () => $this->resolveLoadedRelation($this->sensorable)),
|
|
30
|
+
'name' => $this->name,
|
|
31
|
+
'type' => $this->type,
|
|
32
|
+
'internal_id' => $this->internal_id,
|
|
33
|
+
'imei' => $this->imei,
|
|
34
|
+
'imsi' => $this->imsi,
|
|
35
|
+
'firmware_version' => $this->firmware_version,
|
|
36
|
+
'serial_number' => $this->serial_number,
|
|
37
|
+
'last_position' => $this->last_position,
|
|
38
|
+
'unit' => $this->unit,
|
|
39
|
+
'min_threshold' => $this->min_threshold,
|
|
40
|
+
'max_threshold' => $this->max_threshold,
|
|
41
|
+
'threshold_inclusive' => $this->threshold_inclusive,
|
|
42
|
+
'last_reading_at' => $this->last_reading_at,
|
|
43
|
+
'last_value' => $this->last_value,
|
|
44
|
+
'calibration' => data_get($this, 'calibration', Utils::createObject()),
|
|
45
|
+
'report_frequency_sec' => $this->report_frequency_sec,
|
|
46
|
+
'status' => $this->status,
|
|
47
|
+
'meta' => data_get($this, 'meta', Utils::createObject()),
|
|
48
|
+
'is_active' => $this->is_active,
|
|
49
|
+
'threshold_status' => $this->threshold_status,
|
|
50
|
+
'photo_url' => $this->photo_url,
|
|
51
|
+
'device_name' => $this->device_name,
|
|
52
|
+
'warranty_name' => $this->warranty_name,
|
|
53
|
+
'attached_to_name' => $this->attached_to_name,
|
|
54
|
+
'slug' => $this->slug,
|
|
55
|
+
'updated_at' => $this->updated_at,
|
|
56
|
+
'created_at' => $this->created_at,
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected function resolveLoadedRelation($model)
|
|
61
|
+
{
|
|
62
|
+
if (!$model) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Http::isInternalRequest() ? Resolve::httpResourceForModel($model) : $model->public_id;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -28,8 +28,9 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
28
28
|
public Telematic $telematic;
|
|
29
29
|
public array $options;
|
|
30
30
|
public string $jobId;
|
|
31
|
-
public int $tries
|
|
32
|
-
public int $timeout
|
|
31
|
+
public int $tries = 1;
|
|
32
|
+
public int $timeout = 3600;
|
|
33
|
+
public bool $failOnTimeout = true;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Create a new job instance.
|
|
@@ -79,12 +80,22 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
79
80
|
$cursor = null;
|
|
80
81
|
$totalFetched = 0;
|
|
81
82
|
$totalLinked = 0;
|
|
83
|
+
$totalLinkAttempts = 0;
|
|
82
84
|
$totalEvents = 0;
|
|
83
85
|
$totalSensors = 0;
|
|
84
86
|
$totalSkipped = 0;
|
|
85
87
|
$pageCount = 0;
|
|
86
88
|
$lastProviderAllCount = null;
|
|
87
89
|
$lastProviderFiltersCount = null;
|
|
90
|
+
$providerSyncMeta = [];
|
|
91
|
+
$linkedDeviceKeys = [];
|
|
92
|
+
$inventoryPayloads = [];
|
|
93
|
+
$inventoryFetched = 0;
|
|
94
|
+
$inventoryLinked = 0;
|
|
95
|
+
$inventorySkipped = 0;
|
|
96
|
+
$totalEnrichment = 0;
|
|
97
|
+
$totalEnrichmentCompleted = 0;
|
|
98
|
+
$totalEnrichmentFailures = 0;
|
|
88
99
|
|
|
89
100
|
try {
|
|
90
101
|
$provider = $registry->resolve($this->telematic->provider);
|
|
@@ -97,10 +108,12 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
97
108
|
'filters' => $this->options['filters'] ?? [],
|
|
98
109
|
]);
|
|
99
110
|
|
|
100
|
-
$devices
|
|
101
|
-
$pagination
|
|
111
|
+
$devices = $response['devices'] ?? [];
|
|
112
|
+
$pagination = $response['pagination'] ?? [];
|
|
113
|
+
$providerSyncMeta = array_merge($providerSyncMeta, $response['sync_meta'] ?? []);
|
|
102
114
|
$pageCount++;
|
|
103
115
|
$totalFetched += count($devices);
|
|
116
|
+
$inventoryPayloads = array_merge($inventoryPayloads, $devices);
|
|
104
117
|
|
|
105
118
|
if (isset($pagination['allCount'])) {
|
|
106
119
|
$lastProviderAllCount = $pagination['allCount'];
|
|
@@ -128,10 +141,15 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
128
141
|
$normalizedDevice = $provider->normalizeDevice($devicePayload);
|
|
129
142
|
try {
|
|
130
143
|
$result = $service->ingestDeviceSnapshot($this->telematic, $provider, $devicePayload);
|
|
131
|
-
$
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
$totalLinkAttempts++;
|
|
145
|
+
$linkedDeviceKey = $this->resolveLinkedDeviceKey($result, $normalizedDevice);
|
|
146
|
+
|
|
147
|
+
if ($linkedDeviceKey && !isset($linkedDeviceKeys[$linkedDeviceKey])) {
|
|
148
|
+
$linkedDeviceKeys[$linkedDeviceKey] = true;
|
|
149
|
+
$totalLinked++;
|
|
134
150
|
}
|
|
151
|
+
|
|
152
|
+
$totalEvents += count($result['events'] ?? array_filter([$result['event'] ?? null]));
|
|
135
153
|
$totalSensors += $result['sensors'] ?? 0;
|
|
136
154
|
} catch (\Illuminate\Validation\ValidationException $e) {
|
|
137
155
|
$totalSkipped++;
|
|
@@ -152,6 +170,7 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
152
170
|
'correlation_id' => $correlationId,
|
|
153
171
|
'fetched' => $totalFetched,
|
|
154
172
|
'linked' => $totalLinked,
|
|
173
|
+
'link_attempts' => $totalLinkAttempts,
|
|
155
174
|
'events' => $totalEvents,
|
|
156
175
|
'sensors' => $totalSensors,
|
|
157
176
|
'skipped' => $totalSkipped,
|
|
@@ -161,10 +180,102 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
161
180
|
// Broadcast progress (TODO: implement WebSocket broadcasting)
|
|
162
181
|
} while (($response['has_more'] ?? false) && $cursor);
|
|
163
182
|
|
|
183
|
+
$inventoryFetched = $totalFetched;
|
|
184
|
+
$inventoryLinked = $totalLinked;
|
|
185
|
+
$inventorySkipped = $totalSkipped;
|
|
186
|
+
|
|
187
|
+
$this->telematic->status = 'synchronizing';
|
|
188
|
+
$this->telematic->meta = array_merge($this->telematic->meta ?? [], $providerSyncMeta, [
|
|
189
|
+
'last_sync_job_id' => $this->jobId,
|
|
190
|
+
'last_sync_result' => 'inventory_synced',
|
|
191
|
+
'last_sync_total' => $totalLinked,
|
|
192
|
+
'last_sync_inventory_completed_at' => now()->toDateTimeString(),
|
|
193
|
+
'last_sync_inventory_total' => $inventoryFetched,
|
|
194
|
+
'last_sync_inventory_linked_total' => $inventoryLinked,
|
|
195
|
+
'last_sync_inventory_skipped_total' => $inventorySkipped,
|
|
196
|
+
'last_sync_fetched_total' => $totalFetched,
|
|
197
|
+
'last_sync_linked_total' => $totalLinked,
|
|
198
|
+
'last_sync_link_attempts_total' => $totalLinkAttempts,
|
|
199
|
+
'last_sync_skipped_total' => $totalSkipped,
|
|
200
|
+
'last_sync_page_count' => $pageCount,
|
|
201
|
+
'last_sync_provider_total' => $lastProviderFiltersCount ?? $lastProviderAllCount,
|
|
202
|
+
'last_sync_provider_all_count' => $lastProviderAllCount,
|
|
203
|
+
'last_sync_provider_filters_count' => $lastProviderFiltersCount,
|
|
204
|
+
]);
|
|
205
|
+
$this->telematic->save();
|
|
206
|
+
|
|
207
|
+
Log::info($this->telematic->provider === 'safee' ? 'Safee inventory sync completed' : 'Telematics inventory sync completed', [
|
|
208
|
+
'correlation_id' => $correlationId,
|
|
209
|
+
'telematic_uuid' => $this->telematic->uuid,
|
|
210
|
+
'provider' => $this->telematic->provider,
|
|
211
|
+
'inventory_total' => $inventoryFetched,
|
|
212
|
+
'inventory_linked' => $inventoryLinked,
|
|
213
|
+
'skipped' => $inventorySkipped,
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
if (method_exists($provider, 'fetchDeviceTelemetrySnapshots') && !empty($inventoryPayloads)) {
|
|
217
|
+
Log::info($this->telematic->provider === 'safee' ? 'Safee telemetry enrichment started' : 'Telematics telemetry enrichment started', [
|
|
218
|
+
'correlation_id' => $correlationId,
|
|
219
|
+
'telematic_uuid' => $this->telematic->uuid,
|
|
220
|
+
'provider' => $this->telematic->provider,
|
|
221
|
+
'device_count' => count($inventoryPayloads),
|
|
222
|
+
]);
|
|
223
|
+
|
|
224
|
+
$enrichmentResponse = $provider->fetchDeviceTelemetrySnapshots($inventoryPayloads, [
|
|
225
|
+
'limit' => $this->options['limit'] ?? null,
|
|
226
|
+
'filters' => $this->options['filters'] ?? [],
|
|
227
|
+
]);
|
|
228
|
+
$providerSyncMeta = array_merge($providerSyncMeta, $enrichmentResponse['sync_meta'] ?? []);
|
|
229
|
+
$enrichedDevices = $enrichmentResponse['devices'] ?? [];
|
|
230
|
+
$totalEnrichment += count($enrichedDevices);
|
|
231
|
+
|
|
232
|
+
foreach ($enrichedDevices as $devicePayload) {
|
|
233
|
+
$normalizedDevice = $provider->normalizeDevice($devicePayload);
|
|
234
|
+
try {
|
|
235
|
+
$result = $service->ingestDeviceSnapshot($this->telematic, $provider, $devicePayload);
|
|
236
|
+
$totalLinkAttempts++;
|
|
237
|
+
$linkedDeviceKey = $this->resolveLinkedDeviceKey($result, $normalizedDevice);
|
|
238
|
+
|
|
239
|
+
if ($linkedDeviceKey && !isset($linkedDeviceKeys[$linkedDeviceKey])) {
|
|
240
|
+
$linkedDeviceKeys[$linkedDeviceKey] = true;
|
|
241
|
+
$totalLinked++;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
$totalEnrichmentCompleted++;
|
|
245
|
+
$totalEvents += count($result['events'] ?? array_filter([$result['event'] ?? null]));
|
|
246
|
+
$totalSensors += $result['sensors'] ?? 0;
|
|
247
|
+
} catch (\Illuminate\Validation\ValidationException $e) {
|
|
248
|
+
$totalSkipped++;
|
|
249
|
+
$totalEnrichmentFailures++;
|
|
250
|
+
Log::warning('Skipping telematics enrichment without provider identity', [
|
|
251
|
+
'correlation_id' => $correlationId,
|
|
252
|
+
'provider' => $this->telematic->provider,
|
|
253
|
+
'provider_unit_id' => $devicePayload['_id'] ?? $devicePayload['id'] ?? null,
|
|
254
|
+
'device_id' => $normalizedDevice['device_id'] ?? null,
|
|
255
|
+
'name' => $normalizedDevice['name'] ?? $devicePayload['name'] ?? null,
|
|
256
|
+
'imei' => $devicePayload['imei'] ?? null,
|
|
257
|
+
]);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
Log::info($this->telematic->provider === 'safee' ? 'Safee telemetry enrichment completed' : 'Telematics telemetry enrichment completed', [
|
|
262
|
+
'correlation_id' => $correlationId,
|
|
263
|
+
'telematic_uuid' => $this->telematic->uuid,
|
|
264
|
+
'provider' => $this->telematic->provider,
|
|
265
|
+
'total' => $totalEnrichment,
|
|
266
|
+
'completed' => $totalEnrichmentCompleted,
|
|
267
|
+
'failures' => $totalEnrichmentFailures,
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
|
|
164
271
|
Log::info('Device discovery completed', [
|
|
165
272
|
'correlation_id' => $correlationId,
|
|
166
273
|
'total_fetched' => $totalFetched,
|
|
167
274
|
'total_linked' => $totalLinked,
|
|
275
|
+
'total_link_attempts' => $totalLinkAttempts,
|
|
276
|
+
'total_enrichment' => $totalEnrichment,
|
|
277
|
+
'enrichment_completed' => $totalEnrichmentCompleted,
|
|
278
|
+
'enrichment_failures' => $totalEnrichmentFailures,
|
|
168
279
|
'total_events' => $totalEvents,
|
|
169
280
|
'total_sensors' => $totalSensors,
|
|
170
281
|
'total_skipped' => $totalSkipped,
|
|
@@ -174,22 +285,29 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
174
285
|
]);
|
|
175
286
|
|
|
176
287
|
$this->telematic->status = 'active';
|
|
177
|
-
$this->telematic->meta = array_merge($this->telematic->meta ?? [], [
|
|
178
|
-
'last_sync_job_id'
|
|
179
|
-
'last_sync_completed_at'
|
|
180
|
-
'last_sync_result'
|
|
181
|
-
'last_sync_total'
|
|
182
|
-
'last_sync_fetched_total'
|
|
183
|
-
'last_sync_linked_total'
|
|
184
|
-
'
|
|
185
|
-
'
|
|
186
|
-
'
|
|
187
|
-
'
|
|
188
|
-
'
|
|
189
|
-
'
|
|
190
|
-
'
|
|
191
|
-
'
|
|
192
|
-
'
|
|
288
|
+
$this->telematic->meta = array_merge($this->telematic->meta ?? [], $providerSyncMeta, [
|
|
289
|
+
'last_sync_job_id' => $this->jobId,
|
|
290
|
+
'last_sync_completed_at' => now()->toDateTimeString(),
|
|
291
|
+
'last_sync_result' => 'success',
|
|
292
|
+
'last_sync_total' => $totalLinked,
|
|
293
|
+
'last_sync_fetched_total' => $totalFetched,
|
|
294
|
+
'last_sync_linked_total' => $totalLinked,
|
|
295
|
+
'last_sync_link_attempts_total' => $totalLinkAttempts,
|
|
296
|
+
'last_sync_inventory_total' => $inventoryFetched,
|
|
297
|
+
'last_sync_inventory_linked_total' => $inventoryLinked,
|
|
298
|
+
'last_sync_inventory_skipped_total' => $inventorySkipped,
|
|
299
|
+
'last_sync_enrichment_total' => $totalEnrichment,
|
|
300
|
+
'last_sync_enrichment_completed' => $totalEnrichmentCompleted,
|
|
301
|
+
'last_sync_enrichment_failures' => $totalEnrichmentFailures,
|
|
302
|
+
'last_sync_events_total' => $totalEvents,
|
|
303
|
+
'last_sync_sensors_total' => $totalSensors,
|
|
304
|
+
'last_sync_skipped_total' => $totalSkipped,
|
|
305
|
+
'last_sync_page_count' => $pageCount,
|
|
306
|
+
'last_sync_provider_total' => $lastProviderFiltersCount ?? $lastProviderAllCount,
|
|
307
|
+
'last_sync_provider_all_count' => $lastProviderAllCount,
|
|
308
|
+
'last_sync_provider_filters_count' => $lastProviderFiltersCount,
|
|
309
|
+
'last_sync_error' => null,
|
|
310
|
+
'last_sync_error_context' => null,
|
|
193
311
|
]);
|
|
194
312
|
$this->telematic->save();
|
|
195
313
|
} catch (\Exception $e) {
|
|
@@ -205,21 +323,28 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
205
323
|
|
|
206
324
|
$this->telematic->status = 'error';
|
|
207
325
|
$this->telematic->meta = array_merge($this->telematic->meta ?? [], [
|
|
208
|
-
'last_sync_job_id'
|
|
209
|
-
'last_sync_result'
|
|
210
|
-
'last_sync_fetched_total'
|
|
211
|
-
'last_sync_linked_total'
|
|
212
|
-
'
|
|
213
|
-
'
|
|
214
|
-
'
|
|
215
|
-
'
|
|
216
|
-
'
|
|
217
|
-
'
|
|
218
|
-
'
|
|
219
|
-
'
|
|
220
|
-
'
|
|
221
|
-
'
|
|
222
|
-
'
|
|
326
|
+
'last_sync_job_id' => $this->jobId,
|
|
327
|
+
'last_sync_result' => 'failed',
|
|
328
|
+
'last_sync_fetched_total' => $totalFetched,
|
|
329
|
+
'last_sync_linked_total' => $totalLinked,
|
|
330
|
+
'last_sync_link_attempts_total' => $totalLinkAttempts,
|
|
331
|
+
'last_sync_inventory_total' => $inventoryFetched,
|
|
332
|
+
'last_sync_inventory_linked_total' => $inventoryLinked,
|
|
333
|
+
'last_sync_inventory_skipped_total' => $inventorySkipped,
|
|
334
|
+
'last_sync_enrichment_total' => $totalEnrichment,
|
|
335
|
+
'last_sync_enrichment_completed' => $totalEnrichmentCompleted,
|
|
336
|
+
'last_sync_enrichment_failures' => $totalEnrichmentFailures,
|
|
337
|
+
'last_sync_events_total' => $totalEvents,
|
|
338
|
+
'last_sync_sensors_total' => $totalSensors,
|
|
339
|
+
'last_sync_skipped_total' => $totalSkipped,
|
|
340
|
+
'last_sync_page_count' => $pageCount,
|
|
341
|
+
'last_sync_provider_total' => $lastProviderFiltersCount ?? $lastProviderAllCount,
|
|
342
|
+
'last_sync_provider_all_count' => $lastProviderAllCount,
|
|
343
|
+
'last_sync_provider_filters_count' => $lastProviderFiltersCount,
|
|
344
|
+
'last_sync_error' => $failureMessage,
|
|
345
|
+
'last_sync_error_type' => class_basename($e),
|
|
346
|
+
'last_sync_error_context' => $failureContext,
|
|
347
|
+
'last_sync_failed_at' => now()->toDateTimeString(),
|
|
223
348
|
]);
|
|
224
349
|
$this->telematic->save();
|
|
225
350
|
|
|
@@ -238,6 +363,37 @@ class SyncTelematicDevicesJob implements ShouldQueue
|
|
|
238
363
|
return $this->jobId;
|
|
239
364
|
}
|
|
240
365
|
|
|
366
|
+
public function failed(\Throwable $e): void
|
|
367
|
+
{
|
|
368
|
+
$this->telematic->refresh();
|
|
369
|
+
$this->telematic->status = 'error';
|
|
370
|
+
$this->telematic->meta = array_merge($this->telematic->meta ?? [], [
|
|
371
|
+
'last_sync_job_id' => $this->jobId,
|
|
372
|
+
'last_sync_result' => 'failed',
|
|
373
|
+
'last_sync_error' => $this->safeSyncErrorMessage($e),
|
|
374
|
+
'last_sync_error_type' => class_basename($e),
|
|
375
|
+
'last_sync_failed_at' => now()->toDateTimeString(),
|
|
376
|
+
'last_sync_failed_reason' => $e instanceof \Illuminate\Queue\TimeoutExceededException ? 'job_timeout' : null,
|
|
377
|
+
]);
|
|
378
|
+
$this->telematic->save();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
protected function resolveLinkedDeviceKey(array $result, array $normalizedDevice): ?string
|
|
382
|
+
{
|
|
383
|
+
$device = $result['device'] ?? null;
|
|
384
|
+
$value = null;
|
|
385
|
+
|
|
386
|
+
if (is_object($device)) {
|
|
387
|
+
$value = $device->uuid ?? $device->device_id ?? null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
$value ??= $normalizedDevice['device_id']
|
|
391
|
+
?? $normalizedDevice['external_id']
|
|
392
|
+
?? null;
|
|
393
|
+
|
|
394
|
+
return $value === null || $value === '' ? null : (string) $value;
|
|
395
|
+
}
|
|
396
|
+
|
|
241
397
|
protected function safeSyncErrorMessage(\Throwable $e): string
|
|
242
398
|
{
|
|
243
399
|
$message = $e->getMessage();
|
|
@@ -103,6 +103,15 @@ class DeviceEvent extends Model
|
|
|
103
103
|
*/
|
|
104
104
|
protected $appends = [
|
|
105
105
|
'device_name',
|
|
106
|
+
'device_id',
|
|
107
|
+
'device_imei',
|
|
108
|
+
'device_serial_number',
|
|
109
|
+
'device_connection_status',
|
|
110
|
+
'device_status',
|
|
111
|
+
'device_photo_url',
|
|
112
|
+
'telematic_uuid',
|
|
113
|
+
'telematic_name',
|
|
114
|
+
'provider_descriptor',
|
|
106
115
|
'is_processed',
|
|
107
116
|
'age_minutes',
|
|
108
117
|
'processing_delay_minutes',
|
|
@@ -208,6 +217,78 @@ class DeviceEvent extends Model
|
|
|
208
217
|
return $this->device?->name;
|
|
209
218
|
}
|
|
210
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Get the provider device identifier.
|
|
222
|
+
*/
|
|
223
|
+
public function getDeviceIdAttribute(): ?string
|
|
224
|
+
{
|
|
225
|
+
return $this->device?->device_id ?? $this->ident;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Get the device IMEI.
|
|
230
|
+
*/
|
|
231
|
+
public function getDeviceImeiAttribute(): ?string
|
|
232
|
+
{
|
|
233
|
+
return $this->device?->imei;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get the device serial number.
|
|
238
|
+
*/
|
|
239
|
+
public function getDeviceSerialNumberAttribute(): ?string
|
|
240
|
+
{
|
|
241
|
+
return $this->device?->serial_number;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get the device connection status.
|
|
246
|
+
*/
|
|
247
|
+
public function getDeviceConnectionStatusAttribute(): ?string
|
|
248
|
+
{
|
|
249
|
+
return $this->device?->connection_status;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get the device operational status.
|
|
254
|
+
*/
|
|
255
|
+
public function getDeviceStatusAttribute(): ?string
|
|
256
|
+
{
|
|
257
|
+
return $this->device?->status;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Get the device photo URL.
|
|
262
|
+
*/
|
|
263
|
+
public function getDevicePhotoUrlAttribute(): ?string
|
|
264
|
+
{
|
|
265
|
+
return $this->device?->photo_url;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get the related telematic UUID.
|
|
270
|
+
*/
|
|
271
|
+
public function getTelematicUuidAttribute(): ?string
|
|
272
|
+
{
|
|
273
|
+
return $this->device?->telematic_uuid;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Get the related telematic name.
|
|
278
|
+
*/
|
|
279
|
+
public function getTelematicNameAttribute(): ?string
|
|
280
|
+
{
|
|
281
|
+
return $this->device?->telematic?->name;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Get the related telematic provider descriptor.
|
|
286
|
+
*/
|
|
287
|
+
public function getProviderDescriptorAttribute(): array
|
|
288
|
+
{
|
|
289
|
+
return $this->device?->telematic?->provider_descriptor ?? [];
|
|
290
|
+
}
|
|
291
|
+
|
|
211
292
|
/**
|
|
212
293
|
* Check if the event has been processed.
|
|
213
294
|
*/
|