Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9732a06d1e | |||
| e388c268b8 | |||
| 2e40b31a6c | |||
| 9e9412190b | |||
| 79911eaf2c | |||
| 47fa13be34 | |||
| fe29aef33f | |||
| ba097b2c5e | |||
| 0791fa976f | |||
| 01b081b8ef | |||
| 7c6eedd457 | |||
| df03f20502 | |||
| a17ed2133d | |||
| 29aeae0fd9 | |||
| 14a9a076b8 | |||
| 545817fd1a | |||
| 760289805d | |||
| b6c5149c28 | |||
| 029a19e214 | |||
| ea3ff7a45d | |||
| cc321aebe8 | |||
| 1e2043aeac | |||
| abe7dfeb4e | |||
| 7f9cd70529 | |||
| 65b0069ee4 | |||
| 5698432fec | |||
| df23cc4a40 | |||
| 1c985ccd47 | |||
| bbf19cef81 | |||
| 7f5e527758 | |||
| 8ac1220797 | |||
| 37e7eb7dc6 | |||
| 833881c6b6 | |||
| f7928ed3c9 | |||
| cc8e20383b | |||
| 5f2b70bc78 | |||
| a008a7114c | |||
| ef353a48b3 | |||
| fb37a3ac6e | |||
| a89948fa8a | |||
| 5f6f83f519 | |||
| 976b7a14a1 | |||
| b8f01d7c47 |
1908
IOT Custom API's.postman_collection.json
Normal file
1908
IOT Custom API's.postman_collection.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,17 +7,20 @@ use App\Models\Asset;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Device;
|
||||
use App\Services\AdminService;
|
||||
use App\Services\CustomerInfoService;
|
||||
use Illuminate\Container\Attributes\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\UserAssetLink;
|
||||
|
||||
class AdminDashboardController extends Controller
|
||||
{
|
||||
protected $adminService;
|
||||
|
||||
public function __construct(AdminService $adminService)
|
||||
public function __construct(AdminService $adminService, CustomerInfoService $customerInfoService)
|
||||
{
|
||||
$this->adminService = $adminService;
|
||||
$this->customerInfoService = $customerInfoService;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +28,19 @@ class AdminDashboardController extends Controller
|
||||
public function adminDashboard()
|
||||
{
|
||||
try {
|
||||
$token = $this->adminService->getToken();
|
||||
$totalCustomers = Customer::count();
|
||||
$totalAssets = Asset::count();
|
||||
$totalDevices = Device::count();
|
||||
// $totalDevices = Device::count();
|
||||
$deviceIds = Device::where(['active' => 1])->get()
|
||||
->pluck('id')
|
||||
->flatten()
|
||||
->toArray();
|
||||
|
||||
|
||||
|
||||
$customers = Customer::select('name', 'country', 'state', 'city')->get();
|
||||
|
||||
$token = $this->adminService->getToken();
|
||||
$activeDevices = 0;
|
||||
$inactiveDevices = 0;
|
||||
$activeAlarmsCount = 0;
|
||||
@@ -40,37 +49,26 @@ class AdminDashboardController extends Controller
|
||||
|
||||
if ($token) {
|
||||
$baseUrl = env('THINGSBOARD_URL');
|
||||
$deviceIds = Device::pluck('id')->toArray();
|
||||
|
||||
foreach ($deviceIds as $deviceId) {
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->get("{$baseUrl}api/device/info/{$deviceId}");
|
||||
$totalDevices = $this->customerInfoService->getDevicesCount($deviceIds);
|
||||
$alarmsResponse = $this->customerInfoService->fetchDeviceAlarms($deviceIds);
|
||||
|
||||
if ($response->successful()) {
|
||||
$deviceInfo = $response->json();
|
||||
$deviceInfo['active'] ? $activeDevices++ : $inactiveDevices++;
|
||||
} else {
|
||||
$inactiveDevices++;
|
||||
}
|
||||
}
|
||||
// $alarmsResponse = Http::withHeaders([
|
||||
// 'Authorization' => "Bearer $token",
|
||||
// 'Accept' => 'application/json',
|
||||
// ])->get("{$baseUrl}api/v2/alarms", [
|
||||
// 'pageSize' => 1000,
|
||||
// 'page' => 0,
|
||||
// 'status' => 'ACTIVE'
|
||||
// ]);
|
||||
|
||||
$alarmsResponse = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->get("{$baseUrl}api/v2/alarms", [
|
||||
'pageSize' => 1000,
|
||||
'page' => 0,
|
||||
'status' => 'ACTIVE'
|
||||
]);
|
||||
// if ($alarmsResponse->successful()) {
|
||||
// $alarmsData = $alarmsResponse->json();
|
||||
|
||||
if ($alarmsResponse->successful()) {
|
||||
$alarmsData = $alarmsResponse->json();
|
||||
$activeAlarmsCount = $alarmsData['totalElements'] ?? 0;
|
||||
$activeAlarmsCount = $alarmsResponse['count'] ?? 0;
|
||||
|
||||
if (isset($alarmsData['data'])) {
|
||||
foreach ($alarmsData['data'] as $alarm) {
|
||||
if (isset($alarmsResponse['data'])) {
|
||||
foreach ($alarmsResponse['data'] as $alarm) {
|
||||
$severity = strtoupper($alarm['severity'] ?? '');
|
||||
if ($severity === 'CRITICAL') {
|
||||
$criticalAlarmsCount++;
|
||||
@@ -79,7 +77,7 @@ class AdminDashboardController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
@@ -87,9 +85,9 @@ class AdminDashboardController extends Controller
|
||||
'total_customers' => $totalCustomers,
|
||||
'total_assets' => $totalAssets,
|
||||
'devices' => [
|
||||
'total_devices' => $totalDevices,
|
||||
'active_devices' => $activeDevices,
|
||||
'inactive_devices' => $inactiveDevices,
|
||||
'total_devices' => $totalDevices['totalDevices'],
|
||||
'active_devices' => $totalDevices['activeDevices'],
|
||||
'inactive_devices' => $totalDevices['totalDevices'] - $totalDevices['activeDevices'],
|
||||
],
|
||||
'alarms' => [
|
||||
'total_active' => $activeAlarmsCount,
|
||||
@@ -109,4 +107,41 @@ class AdminDashboardController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdminActiveDevicesList(){
|
||||
try {
|
||||
// $token = readHeaderToken();
|
||||
$deviceIds = Device::where(['active' => 1])->get()
|
||||
->pluck('id')
|
||||
->flatten()
|
||||
->toArray();
|
||||
|
||||
|
||||
$activeDevices = $this->customerInfoService->getActiveDevicesList($deviceIds);
|
||||
$deviceCount = $this->customerInfoService->getDevicesCount($deviceIds);
|
||||
|
||||
$activeDeviceIds = collect($activeDevices['activeDevices'])->pluck('entityId')->pluck('id')->toArray();
|
||||
|
||||
$getDevices = Device::with('asset')->whereIn('id', $activeDeviceIds)->get(['id', 'name', 'label', 'asset_id', 'customer_id', 'type', 'created_at']);
|
||||
|
||||
$liveDevices = $getDevices->map(function($device){
|
||||
|
||||
$assetName = Asset::where('id', $device->asset_id)->first()->name;
|
||||
|
||||
return [
|
||||
'deviceId' => $device->id,
|
||||
'assetName' => $assetName,
|
||||
'deviceName' => $device->label,
|
||||
'deviceType' => $device->type,
|
||||
'deviceCustomer' => $device->customer->title,
|
||||
'deviceCreatedAt' => $device->created_at ?? 'N/A'
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return response()->json(['success' => true, 'totalDevices' => $deviceCount['totalDevices'] ?? 0, 'activeDevices' => $deviceCount['activeDevices'] ?? 0, 'data' => $liveDevices]);
|
||||
} catch(Exception $e){
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,11 +103,10 @@ class AssetadmintController extends Controller
|
||||
throw new \Exception('Asset not found');
|
||||
}
|
||||
|
||||
// Update asset via admin service
|
||||
// $response = $this->adminService->updateAsset($request->id, $assetData);
|
||||
// if (!$response) {
|
||||
// throw new \Exception('Failed to update asset via admin service');
|
||||
// }
|
||||
$assetNameExists = Asset::where('name', $request->name)->where('id','!=',$request->id)->first();
|
||||
if ($assetNameExists) {
|
||||
return jsonResponseWithErrorMessage('Asset name already exists', 400);
|
||||
}
|
||||
|
||||
// Update local database record
|
||||
$asset->name = $assetData['name'];
|
||||
@@ -155,6 +154,7 @@ class AssetadmintController extends Controller
|
||||
$customerName = \App\Models\Customer::where('id', $assetData['customerId'])->value('name');
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 200,
|
||||
'message' => $message,
|
||||
'data' => $asset,
|
||||
'customer_name' => $customerName,
|
||||
|
||||
@@ -26,9 +26,22 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
|
||||
public function createOrUpdateCustomer(CreateCustomerRequest $request)
|
||||
public function createOrUpdateCustomer(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$customerEmailExist = Customer::where('email', $request->email)->first();
|
||||
if ($customerEmailExist) {
|
||||
// return response()->json(['status' => 'error','message' => 'Email already exists'],200);
|
||||
return jsonResponseWithErrorMessage('Email already exists', 400);
|
||||
}
|
||||
|
||||
$customerNameExist = Customer::where('title', $request->title)->first();
|
||||
if ($customerNameExist) {
|
||||
// return response()->json(['status' => 'error','message' => 'Name already exists'],200);
|
||||
return jsonResponseWithErrorMessage('Name already exists', 400);
|
||||
}
|
||||
|
||||
$userData = [
|
||||
'title' => $request->title,
|
||||
'email' => $request->email,
|
||||
@@ -36,7 +49,7 @@ class CustomerController extends Controller
|
||||
'state' => $request->state,
|
||||
'city' => $request->city,
|
||||
'zip' => $request->zip,
|
||||
'name' => $request->name,
|
||||
'name' => $request->title,
|
||||
'phone' => $request->phone,
|
||||
'address' => $request->address,
|
||||
'address2' => $request->address2,
|
||||
@@ -78,17 +91,15 @@ class CustomerController extends Controller
|
||||
$externalId = $apiData['externalId'] ?? null;
|
||||
$tenantId = is_array($apiData['tenantId']) ? ($apiData['tenantId']['id'] ?? null) : $apiData['tenantId'];
|
||||
|
||||
|
||||
|
||||
// Store customer in database
|
||||
$customer = Customer::updateOrCreate(
|
||||
['id' => $apiData['id']['id'] ?? Str::uuid()->toString()],
|
||||
[
|
||||
'entity_type' => $apiData['id']['entityType'] ?? 'CUSTOMER',
|
||||
'created_time' => $apiData['createdTime'] ?? now()->timestamp,
|
||||
'country_xid' => $apiData['country'] ?? null,
|
||||
'state_xid' => $apiData['state'] ?? null,
|
||||
'city_xid' => $apiData['city'] ?? null,
|
||||
'country' => $apiData['country'] ?? null,
|
||||
'state' => $apiData['state'] ?? null,
|
||||
'city' => $apiData['city'] ?? null,
|
||||
'address' => $apiData['address'] ?? null,
|
||||
'address2' => $apiData['address2'] ?? null,
|
||||
'zip' => $apiData['zip'] ?? null,
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\APIS\AdminApi;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CreateDeviceRequest;
|
||||
use App\Models\Device;
|
||||
use App\Models\Asset;
|
||||
use App\Models\DeviceProfileMaster;
|
||||
use App\Services\DeviceService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -32,13 +33,21 @@ class DeviceController extends Controller
|
||||
|
||||
$deviceNameExists = Device::where('name', $request->name)->first();
|
||||
if (empty($request->id) && $deviceNameExists) {
|
||||
// return response()->json(['status' => 'error','message' => 'Device name already exists'],400);
|
||||
return jsonResponseWithErrorMessage('Device name already exists', 400);
|
||||
}
|
||||
|
||||
$assetNameExists = Asset::where('name', $request->name)->first();
|
||||
if ($assetNameExists) {
|
||||
return jsonResponseWithErrorMessage('Name already exists', 400);
|
||||
}
|
||||
|
||||
$deviceProfileName = DeviceProfileMaster::where('id',$request->deviceProfileId)->first();
|
||||
|
||||
$deviceData = [
|
||||
'id' => $request->id ?? null,
|
||||
'name' => $request->name ?? null,
|
||||
'type' => $request->type ?? null,
|
||||
'type' => $deviceProfileName['name'] ?? null,
|
||||
'label' => $request->label ?? null,
|
||||
'version' => $request->version ?? 1,
|
||||
'customerId' => $request->customerId ?? 1,
|
||||
@@ -62,8 +71,13 @@ class DeviceController extends Controller
|
||||
|
||||
// dd($request->id);
|
||||
// Handle updating existing devices
|
||||
if (empty($request->id)) {
|
||||
if (!empty($request->id)) {
|
||||
$deviceData['id'] = $request->id;
|
||||
|
||||
$deviceNameExists = Device::where('name', $request->name)->where('id','!=',$request->id)->first();
|
||||
if ($deviceNameExists) {
|
||||
return response()->json(['status' => 'error','message' => 'Device name already exists'],400);
|
||||
}
|
||||
}
|
||||
if (!empty($request->firmwareId)) {
|
||||
$deviceData['firmwareId'] = $request->firmwareId;
|
||||
@@ -72,7 +86,7 @@ class DeviceController extends Controller
|
||||
$deviceData['softwareId'] = $request->softwareId;
|
||||
}
|
||||
|
||||
|
||||
// dd($request->all());
|
||||
// Call Service to create/update device
|
||||
if (empty($request->id)) {
|
||||
$apiResponse = $this->deviceService->createOrUpdateDevice($deviceData);
|
||||
@@ -200,6 +214,7 @@ class DeviceController extends Controller
|
||||
try {
|
||||
$devices = Device::with('deviceProfile:id,name', 'customer:id,name')
|
||||
->where('customer_id', $customerId)
|
||||
->orderBy('created_at','desc')
|
||||
->get()
|
||||
->map(function ($device) {
|
||||
$deviceArray = $device->toArray();
|
||||
|
||||
@@ -213,29 +213,12 @@ class UsersController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
// Validation rules (include all fields)
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email' => 'required|email|unique:users,email',
|
||||
// 'authority' => 'required|string|in:CUSTOMER_USER,TENANT_ADMIN,SYS_ADMIN',
|
||||
// 'tenant_id' => 'required|uuid',
|
||||
// 'customer_id' => 'nullable|uuid',
|
||||
'first_name' => 'required|string|max:255',
|
||||
'last_name' => 'required|string|max:255',
|
||||
// 'phone' => 'nullable|string|max:20',
|
||||
// 'name' => 'nullable|string|max:255',
|
||||
// 'description' => 'nullable|string',
|
||||
// 'default_dashboard_id' => 'nullable',
|
||||
// 'home_dashboard_id' => 'nullable',
|
||||
// 'version' => 'nullable|integer',
|
||||
// Add validation for other fields as needed
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
$userEmailExist = User::where('email', $request->email)->first();
|
||||
if ($userEmailExist) {
|
||||
// return response()->json(['status' => 'error','message' => 'Email already exists'],400);
|
||||
return jsonResponseWithErrorMessage('Email already exists', 400);
|
||||
|
||||
}
|
||||
|
||||
// Generate UUID for the user
|
||||
@@ -302,6 +285,7 @@ class UsersController extends Controller
|
||||
$mail = Mail::to($user->email)->send(new UserCreatedMail($user, $newActivationLink));
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 200,
|
||||
'success' => true,
|
||||
'message' => 'User created successfully',
|
||||
'data' => [
|
||||
|
||||
@@ -952,8 +952,9 @@ class TelemetryController extends Controller
|
||||
foreach ($deviceIds as $deviceId) {
|
||||
$device = Device::find($deviceId);
|
||||
if ($device) {
|
||||
$deviceType = $device->type;
|
||||
$telemetryValues = $this->getHealthConditionTelemetry($device);
|
||||
$deviceHealth = $this->telemetryService->getDeviceHealth($telemetryValues);
|
||||
$deviceHealth = $deviceType == 'Torque' ? 'green' : $this->telemetryService->getDeviceHealth($telemetryValues);
|
||||
|
||||
match ($deviceHealth) {
|
||||
'green' => $good++,
|
||||
@@ -985,39 +986,71 @@ class TelemetryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveDevicesList(){
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
$devices = UserAssetLink::with('asset.devices')
|
||||
->where(['user_id' => $token['sub'], 'active' => 1])
|
||||
->get()
|
||||
->pluck('asset.devices')
|
||||
->flatten()
|
||||
->unique('id');
|
||||
$deviceIds = $devices->pluck('id')->toArray();
|
||||
$activeDevices = $this->customerInfoService->getActiveDevicesList($deviceIds);
|
||||
$deviceCount = $this->customerInfoService->getDevicesCount($deviceIds);
|
||||
public function getActiveDevicesList() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
$userId = $token['sub'];
|
||||
|
||||
$activeDeviceIds = collect($activeDevices['activeDevices'])->pluck('entityId')->pluck('id')->toArray();
|
||||
$assetDeviceLinks = UserAssetLink::with('asset.devices')
|
||||
->where(['user_id' => $userId, 'active' => 1])
|
||||
->get();
|
||||
|
||||
$getDevices = Device::with('customer:id,title')->whereIn('id', $activeDeviceIds)->get(['id', 'name', 'customer_id', 'type', 'created_at']);
|
||||
// Maintain order as per userAssetsNew
|
||||
$orderedDeviceIds = [];
|
||||
|
||||
$liveDevices = $getDevices->map(function($device){
|
||||
return [
|
||||
'deviceId' => $device->id,
|
||||
'deviceName' => $device->name,
|
||||
'deviceType' => $device->type,
|
||||
'deviceCustomer' => $device->customer->title,
|
||||
'deviceCreatedAt' => $device->created_at ?? 'N/A'
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return response()->json(['success' => true, 'totalDevices' => $deviceCount['totalDevices'] ?? 0, 'activeDevices' => $deviceCount['activeDevices'] ?? 0, 'data' => $liveDevices]);
|
||||
} catch(Exception $e){
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
foreach ($assetDeviceLinks as $link) {
|
||||
foreach ($link->asset->devices as $device) {
|
||||
$orderedDeviceIds[] = $device->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicates while keeping order
|
||||
$orderedDeviceIds = array_values(array_unique($orderedDeviceIds));
|
||||
|
||||
// Fetch only active devices
|
||||
$activeDevices = $this->customerInfoService->getActiveDevicesList($orderedDeviceIds);
|
||||
$activeDeviceIds = collect($activeDevices['activeDevices'])->pluck('entityId')->pluck('id')->toArray();
|
||||
|
||||
// Intersect ordered list with active IDs while preserving order
|
||||
$orderedActiveDeviceIds = array_values(array_filter($orderedDeviceIds, function ($id) use ($activeDeviceIds) {
|
||||
return in_array($id, $activeDeviceIds);
|
||||
}));
|
||||
|
||||
// Fetch device details
|
||||
$getDevices = Device::with(['asset', 'customer'])
|
||||
->whereIn('id', $orderedActiveDeviceIds)
|
||||
->get(['id', 'name', 'label', 'asset_id', 'customer_id', 'type', 'created_at']);
|
||||
|
||||
// Maintain order
|
||||
$deviceMap = $getDevices->keyBy('id');
|
||||
$liveDevices = collect($orderedActiveDeviceIds)->map(function ($id) use ($deviceMap) {
|
||||
$device = $deviceMap[$id] ?? null;
|
||||
if (!$device) return null;
|
||||
|
||||
return [
|
||||
'deviceId' => $device->id,
|
||||
'assetName' => $device->asset->name ?? 'N/A',
|
||||
'deviceName' => $device->label,
|
||||
'deviceType' => $device->type,
|
||||
'deviceCustomer' => $device->customer->title ?? 'N/A',
|
||||
'deviceCreatedAt' => $device->created_at ?? 'N/A'
|
||||
];
|
||||
})->filter(); // remove nulls
|
||||
|
||||
// Count
|
||||
$deviceCount = $this->customerInfoService->getDevicesCount($orderedDeviceIds);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'totalDevices' => $deviceCount['totalDevices'] ?? 0,
|
||||
'activeDevices' => $deviceCount['activeDevices'] ?? 0,
|
||||
'data' => $liveDevices
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDeviceIndicators($assetId){
|
||||
@@ -1091,6 +1124,7 @@ class TelemetryController extends Controller
|
||||
{
|
||||
return TimeseriesKeyMaster::where('display_on_dashboard', true)
|
||||
->where('device_profile_xid', $deviceProfileId)
|
||||
->orderBy('display_on_popup_sequence','asc')
|
||||
->get(['key_name', 'display_name']);
|
||||
}
|
||||
|
||||
@@ -1108,8 +1142,8 @@ class TelemetryController extends Controller
|
||||
|
||||
$transformedTelemetry[] = [
|
||||
'display_name' => $displayNameMap[$key] ?? $key,
|
||||
'value' => $item['value'],
|
||||
'averageVal' => number_format((float)$averageVal, 2, '.', ''),
|
||||
'value' => $this->telemetryService->getTypeWiseValue($key, $item['value']),
|
||||
'averageVal' => $this->telemetryService->getTypeWiseValue($key, $averageVal),
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
@@ -1130,6 +1164,15 @@ class TelemetryController extends Controller
|
||||
return 'green';
|
||||
}
|
||||
|
||||
if ($key == "GlobalLevel_value") {
|
||||
if ($value > 7) {
|
||||
return 'red';
|
||||
} elseif ($value > 4) {
|
||||
return 'orange';
|
||||
}
|
||||
return 'green';
|
||||
}
|
||||
|
||||
if ($value > 70) {
|
||||
return 'green';
|
||||
} elseif ($value > 30) {
|
||||
@@ -1292,13 +1335,6 @@ class TelemetryController extends Controller
|
||||
$cachedData = Cache::remember($cacheKey, now()->addSeconds(value: 60), function () use ($deviceId) {
|
||||
$deviceParams = $this->getPopupTimeseriesKeys($deviceId);
|
||||
|
||||
if ($deviceParams->isEmpty()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => 'No indicator parameters found for this device'
|
||||
];
|
||||
}
|
||||
|
||||
$keyNameList = $deviceParams->pluck('key_name')->implode(',');
|
||||
$displayNameMap = $deviceParams->pluck('display_name', 'key_name')->toArray();
|
||||
|
||||
@@ -1396,9 +1432,31 @@ class TelemetryController extends Controller
|
||||
$y2 = array_key_exists(1, $key2) ? TimeseriesKeyMaster::where('key_name', $key2[1])->first('display_name') : null;
|
||||
}
|
||||
|
||||
if($key1[0] === 'PowerLoss_value' || $key1[0] === 'GlobalLevel_value'){
|
||||
$min1 = 0;
|
||||
$max1 = 10;
|
||||
} else if($key1[0] === 'StaticTorque_value'){
|
||||
$min1 = 0;
|
||||
$max1 = 500000;
|
||||
} else {
|
||||
$min1 = 0;
|
||||
$max1 = 100;
|
||||
}
|
||||
|
||||
$min1 = $key1[0] === 'PowerLoss_value' ? 0 : 0;
|
||||
$max1 = $key1[0] === 'PowerLoss_value' ? 10 : 100;
|
||||
if($key2[0] === 'StaticPower_value'){
|
||||
$min2 = 0;
|
||||
$max2 = 500000;
|
||||
} else if($key2[0] === 'TDN'){
|
||||
$min2 = 0;
|
||||
$max2 = 1500;
|
||||
} else {
|
||||
$min2 = 0;
|
||||
$max2 = 100;
|
||||
}
|
||||
|
||||
|
||||
// $min1 = $key1[0] === 'PowerLoss_value' ? 0 : 0;
|
||||
// $max1 = $key1[0] === 'PowerLoss_value' ? 10 : 100;
|
||||
|
||||
$telemetryValue1 = app(CustomerInfoService::class)->fetchTelemetryData($deviceId, $parameters[$deviceProfileId]['keyNameList1'], $ts);
|
||||
$trendsData1 = $telemetryValue1 instanceof \Illuminate\Http\JsonResponse ? $telemetryValue1->getData(true) : $telemetryValue1;
|
||||
@@ -1410,7 +1468,7 @@ class TelemetryController extends Controller
|
||||
foreach ($trendsData1 as $key => $trend) {
|
||||
$displayName = TimeseriesKeyMaster::where('key_name', $key)->first('display_name');
|
||||
foreach ($trend as $val) {
|
||||
$value1[0][$displayName['display_name']][] = $val['value'];
|
||||
$value1[0][$displayName['display_name']][] = $this->telemetryService->getTypeWiseValue($key, $val['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1419,18 +1477,65 @@ class TelemetryController extends Controller
|
||||
foreach ($trendsData2 as $key => $trend) {
|
||||
$displayName = TimeseriesKeyMaster::where('key_name', $key)->first('display_name');
|
||||
foreach ($trend as $val) {
|
||||
$value2[0][$displayName['display_name']][] = $val['value'];
|
||||
$value2[0][$displayName['display_name']][] = $this->telemetryService->getTypeWiseValue($key, $val['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$graph1['y1'] = count($key1) === 3 ? ['name' => [$x1[0]['display_name'], $x1[1]['display_name']], 'min' => $min1, 'max' => $max1] : ['name' => [$x1['display_name']], 'min' => $min1, 'max' => $max1];
|
||||
$graph1['y2'] = $x2 ? ['name' => [$x2['display_name']], 'min' => 0, 'max' => 50000] : null;
|
||||
$getLimit = Device::where('id', $deviceId)->select('speed_limit','torque_limit','power_limit')->first();
|
||||
|
||||
$graph1['y1'] = count($key1) === 3
|
||||
? [
|
||||
'name' => [$x1[0]['display_name'], $x1[1]['display_name']],
|
||||
'min' => $min1,
|
||||
'max' => ($key1[0] === 'StaticTorque_value')
|
||||
? ($getLimit['speed_limit'] ?? $max1)
|
||||
: $max1
|
||||
]
|
||||
: [
|
||||
'name' => [$x1['display_name']],
|
||||
'min' => $min1,
|
||||
'max' => ($key1[0] === 'StaticTorque_value')
|
||||
? ($getLimit['speed_limit'] ?? $max1)
|
||||
: $max1
|
||||
];
|
||||
|
||||
$graph1['y2'] = $x2
|
||||
? [
|
||||
'name' => [$x2['display_name']],
|
||||
'min' => 0,
|
||||
'max' => $getLimit['speed_limit'] ?? 50000
|
||||
]
|
||||
: null;
|
||||
|
||||
$graph1[$date] = $value1;
|
||||
|
||||
$graph2['y1'] = count($key2) === 3 ? ['name' => [$y1[0]['display_name'], $y1[1]['display_name']], 'min' => $min1, 'max' => $max1] : ['name' => [$y1['display_name']], 'min' => 0, 'max' => 100];
|
||||
$graph2['y2'] = $y2 ? ['name' => [$y2['display_name']], 'min' => 0, 'max' => 50000] : null;
|
||||
$graph2['y1'] = count($key2) === 3
|
||||
? [
|
||||
'name' => [$y1[0]['display_name'], $y1[1]['display_name']],
|
||||
'min' => $min2,
|
||||
'max' => ($key2[0] === 'StaticPower_value')
|
||||
? ($getLimit['speed_limit'] ?? $max2)
|
||||
: $max2
|
||||
]
|
||||
: [
|
||||
'name' => [$y1['display_name']],
|
||||
'min' => $min2,
|
||||
'max' => ($key2[0] === 'StaticPower_value')
|
||||
? ($getLimit['speed_limit'] ?? $max2)
|
||||
: $max2
|
||||
];
|
||||
|
||||
$graph2['y2'] = $y2
|
||||
? [
|
||||
'name' => [$y2['display_name']],
|
||||
'min' => 0,
|
||||
'max' => $getLimit['speed_limit'] ?? 50000
|
||||
]
|
||||
: null;
|
||||
|
||||
$graph2[$date] = $value2;
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -1511,14 +1616,14 @@ class TelemetryController extends Controller
|
||||
|
||||
$prefixMap = [
|
||||
0 => 'Compression',
|
||||
1 => 'Injection',
|
||||
1 => 'InjectionCondition',
|
||||
2 => 'Bearing',
|
||||
3 => 'InjectionCondition',
|
||||
3 => 'BearingBis',
|
||||
4 => 'Misfiring'
|
||||
];
|
||||
|
||||
$prefix = $prefixMap[$index];
|
||||
$colorKey = "{$prefix}_cylinderHealth_" . $i++;
|
||||
$colorKey = "{$prefix}_cylinderValues_" . $i++;
|
||||
|
||||
$val = $colorData[$colorKey][0]['value'] ?? null;
|
||||
$color = is_null($val) ? 'grey' : ($val > 70 ? 'green' : ($val > 30 ? 'orange' : 'red'));
|
||||
@@ -1670,7 +1775,7 @@ class TelemetryController extends Controller
|
||||
->get()
|
||||
->pluck('asset.devices')
|
||||
->flatten()
|
||||
->select('id','name');
|
||||
->select('id','name','label');
|
||||
|
||||
return response()->json($userDevices);
|
||||
}
|
||||
|
||||
@@ -394,13 +394,13 @@ function parameters()
|
||||
],
|
||||
// 4. Bearing
|
||||
"b82d42a0-f34d-11ef-a9dc-45dd276e4cd5" => [
|
||||
"keyNameList1" => 'GlobalMixed_valueInPercent,ChannelSpeed',
|
||||
"keyNameList1" => 'GlobalLevel_value,ChannelSpeed',
|
||||
"keyNameList2" => 'BearingGlobal_valueInPercent,GlobalKurto_valueInPercent,ChannelSpeed',
|
||||
],
|
||||
// 5. Gearbox
|
||||
"b60d08f0-16b3-11f0-a9dc-45dd276e4cd5" => [
|
||||
"keyNameList1" => 'GlobalMixed_valueInPercent,ChannelSpeed',
|
||||
"keyNameList2" => 'BearingGlobal_valueInPercent,ChannelSpeed',
|
||||
"keyNameList1" => 'GlobalLevel_value,ChannelSpeed',
|
||||
"keyNameList2" => 'BearingGlobal_valueInPercent,GlobalKurto_valueInPercent,ChannelSpeed',
|
||||
],
|
||||
// 6. Turbine
|
||||
"b13497a0-f34d-11ef-a9dc-45dd276e4cd5" => [
|
||||
|
||||
@@ -595,9 +595,9 @@ class CustomerInfoService
|
||||
'X-Authorization' => 'Bearer ' . $token,
|
||||
])->post($url, $payload);
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \Exception("Failed to fetch active devices: " . $response->body());
|
||||
}
|
||||
// if (!$response->successful()) {
|
||||
// throw new \Exception("Failed to fetch active devices: " . $response->body());
|
||||
// }
|
||||
|
||||
$activeDevices = $response->json();
|
||||
return [
|
||||
@@ -640,8 +640,8 @@ public function fetchDeviceAlarms(array $deviceIds, $data=[])
|
||||
"entityList" => $entityList
|
||||
],
|
||||
"pageLink" => [
|
||||
"startTs" => $startTs,
|
||||
"endTs" => $endTs,
|
||||
// "startTs" => $startTs,
|
||||
// "endTs" => $endTs,
|
||||
"pageSize" => 100,
|
||||
"page" => 0,
|
||||
"textSearch" => "",
|
||||
|
||||
@@ -63,10 +63,6 @@ class DeviceService
|
||||
'id' => $data['customerId'] ?? null,
|
||||
'entityType' => 'CUSTOMER'
|
||||
],
|
||||
'deviceProfileId' => [
|
||||
'id' => $data['deviceProfileId'] ?? null,
|
||||
'entityType' => 'DEVICE_PROFILE'
|
||||
],
|
||||
'deviceData' => $data['deviceData'] ?? [],
|
||||
'additionalInfo' => $data['additionalInfo'] ?? [],
|
||||
];
|
||||
|
||||
@@ -26,26 +26,61 @@ class TelemetryService
|
||||
$hasOrange = false;
|
||||
|
||||
foreach ($values as $value) {
|
||||
if ($value['key_name'] == 'PowerLoss_value') {
|
||||
if ($value['value'] > 5 && $value['value'] < 10) {
|
||||
$hasRed = true;
|
||||
$key = $value['key_name'];
|
||||
$val = $value['value'];
|
||||
|
||||
switch ($key) {
|
||||
case 'PowerLoss_value':
|
||||
if ($val > 5 && $val < 10) {
|
||||
return 'red';
|
||||
} elseif ($val > 2.5 && $val < 6) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
break;
|
||||
} elseif ($value['value'] > 2.5 && $value['value'] < 5) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
} else {
|
||||
if ($value['value'] > 0 && $value['value'] < 31) {
|
||||
$hasRed = true;
|
||||
|
||||
case 'GlobalLevel_value':
|
||||
if ($val > 6 && $val < 10) {
|
||||
return 'red';
|
||||
} elseif ($val > 3 && $val < 7) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'PropellerEfficiency_value':
|
||||
if ($val > 5 && $val < 10) {
|
||||
return 'red';
|
||||
} elseif ($val > 3 && $val < 6) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// case 'OT':
|
||||
// case 'AT':
|
||||
// $val > 50 ? $hasRed = true : $hasOrange = true;
|
||||
// break;
|
||||
|
||||
case 'TDN':
|
||||
if ($val > 0 && $val < 401) {
|
||||
return 'red';
|
||||
} elseif ($val < 701) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($val > 0 && $val < 31) {
|
||||
return 'red';
|
||||
} elseif ($val < 71) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
break;
|
||||
} elseif ($value['value'] < 71) {
|
||||
$hasOrange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $hasRed ? 'red' : ($hasOrange ? 'orange' : 'green');
|
||||
}
|
||||
|
||||
|
||||
public function getAssetHealth(array $deviceHealthStatuses): string
|
||||
{
|
||||
if (in_array('red', $deviceHealthStatuses)) {
|
||||
@@ -164,6 +199,7 @@ class TelemetryService
|
||||
'red' => 'Alert',
|
||||
'orange' => 'Attention',
|
||||
'green' => 'Stable',
|
||||
'blue' => 'Stable',
|
||||
default => $t['threshold'] == 70 ? 'Stable' : 'Alert'
|
||||
};
|
||||
}
|
||||
@@ -185,21 +221,35 @@ class TelemetryService
|
||||
$thresholds = $this->getThresholdMap()[$key] ?? $this->getThresholdMap()['default'];
|
||||
$thresholdLimits = $this->getThresholdLimit($deviceId)[$key] ?? $this->getThresholdLimit($deviceId)['default'];
|
||||
|
||||
$status = $this->getHealthStatus($value, $thresholds);
|
||||
$statusColor = match($status) {
|
||||
'Alert' => 'red',
|
||||
'Attention' => 'orange',
|
||||
'Stable' => 'green'
|
||||
};
|
||||
if(!$value){
|
||||
$transformedTelemetry[] = [
|
||||
'display_name' => $displayNameMap[$key] ?? $key,
|
||||
'value' => "",
|
||||
'health_status' => "",
|
||||
'status_color' => "",
|
||||
'thresholds' => $thresholds,
|
||||
'limit' => $thresholdLimits
|
||||
];
|
||||
} else {
|
||||
$status = $this->getHealthStatus($value, $thresholds);
|
||||
$statusColor = match($status) {
|
||||
'Alert' => 'red',
|
||||
'Attention' => 'orange',
|
||||
'Stable' => 'green'
|
||||
};
|
||||
|
||||
$transformedTelemetry[] = [
|
||||
'display_name' => $displayNameMap[$key] ?? $key,
|
||||
'value' => number_format((float)$value, 2, '.', ''),
|
||||
'health_status' => !$isActive ? 'Offline' : $status,
|
||||
'status_color' => !$isActive ? 'gray' : $statusColor,
|
||||
'thresholds' => $thresholds,
|
||||
'limit' => $thresholdLimits
|
||||
];
|
||||
$transformedTelemetry[] = [
|
||||
'display_name' => $displayNameMap[$key] ?? $key,
|
||||
'value' => $this->getTypeWiseValue($key, $value),
|
||||
'health_status' => !$isActive
|
||||
? 'Offline'
|
||||
: (in_array($displayNameMap[$key], ['Speed', 'RPM']) ? '' : $status),
|
||||
// 'health_status' => in_array($displayNameMap[$key], ['Speed', 'RPM']) ? '' : $status,
|
||||
'status_color' => !$isActive ? 'gray' : $statusColor,
|
||||
'thresholds' => $thresholds,
|
||||
'limit' => $thresholdLimits
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,4 +259,14 @@ class TelemetryService
|
||||
'dateTime' => $dateTime
|
||||
];
|
||||
}
|
||||
|
||||
public function getTypeWiseValue($key, $value){
|
||||
if($key === 'PowerLoss_value' || $key === 'GlobalLevel_value' || $key === 'OT' || $key === 'PropellerEfficiency_value') {
|
||||
return round($value, 2);
|
||||
} else if($key === 'StaticTorsion_value' || $key === 'StaticTorque_value' || $key === 'StaticPower_value'){
|
||||
return round($value,3);
|
||||
} else {
|
||||
return round($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ Route::get('/adminapi', function () {
|
||||
//******************************************************* Admin Assest API ********************************************************
|
||||
Route::post('/admin-login', [LoginController::class, 'adminLogin'])->name('admin.login');
|
||||
Route::get('/admin-dashboard', [AdminDashboardController::class, 'adminDashboard'])->name('admin.dashboard');
|
||||
Route::get('/get-admin-active-devices-list', [AdminDashboardController::class, 'getAdminActiveDevicesList']);
|
||||
|
||||
Route::post('/asset', [AssetadmintController::class, 'storeAssest'])->name('assest.create');
|
||||
Route::get('/assets-list', [AssetadmintController::class, 'listAssest'])->name('assest.list');
|
||||
|
||||
158818
vib360_api.sql
Normal file
158818
vib360_api.sql
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user