Admin alarms

This commit is contained in:
Nikhil Kadam
2025-05-14 16:00:50 +05:30
parent d0b4bcd930
commit e9948e4430
3 changed files with 22 additions and 5 deletions

View File

@@ -1033,7 +1033,7 @@ class TelemetryController extends Controller
}
}
private function getUserAssetLinkWithDevices($userId, $assetId = null)
private function getUserAssetLinkWithDevices($userId = null, $assetId = null)
{
$query = UserAssetLink::with('asset.devices')
->where('user_id', $userId);
@@ -1552,14 +1552,21 @@ class TelemetryController extends Controller
}
}
public function getDeviceByAsset($assetId){
$deviceList = Device::where('asset_id', $assetId)->select('id','name')->get()->toArray();
return response()->json($deviceList);
}
public function getAdminAlarms(Request $request){
try {
$getDeviceByAsset = Device::whereIn('asset_id', $request->assetIds)->pluck('id')->toArray();
$data = [
'statusList' => $request->statusList,
'severityList' => $request->severityList,
'startTs' => $request->startTs,
'endTs' => $request->endTs,
'deviceIds' => $request->deviceIds ?? $getDeviceByAsset,
];
$allDevices = Device::pluck('id')->toArray();

View File

@@ -552,16 +552,25 @@ public function fetchDeviceAlarms(array $deviceIds, $data=[])
}
$url = env('THINGSBOARD_URL') . 'api/alarmsQuery/find';
if (isset($data['startTs']) && isset($data['endTs'])) {
$startDate = \DateTime::createFromFormat('d/m/Y', $data['startTs']);
$endDate = \DateTime::createFromFormat('d/m/Y', $data['endTs']);
if ($startDate && $endDate) {
$startTimestamp = $startDate->getTimestamp() * 1000;
$endTimestamp = $endDate->getTimestamp() * 1000;
}
}
// Timestamp range (modify as needed)
$startTs = $data['startTs'] ?? now()->subDays(30)->timestamp * 1000;
$endTs = $data['endTs'] ?? now()->timestamp * 1000;
$startTs = $startTimestamp ?? now()->subHours(24)->timestamp * 1000;
$endTs = $endTimestamp ?? now()->timestamp * 1000;
$entityList = $data['deviceIds'] ?? $deviceIds;
$payload = [
"entityFilter" => [
"type" => "entityList",
"entityType" => "DEVICE",
"entityList" => $deviceIds
"entityList" => $entityList
],
"pageLink" => [
"startTs" => $startTs,

View File

@@ -68,7 +68,8 @@ Route::get('/alarm/{id}', [AlarmControllerCommon::class, 'getAlarmById'])->name(
Route::post('/alarm/ack/{id}', [AlarmControllerCommon::class, 'acknowledgeAlarmById'])->name('ack.alarm');
Route::post('/alarm/filter', [AlarmControllerCommon::class, 'filterAlarm'])->name('alarm.filter');
Route::post('/alarm/clear/{id}', [AlarmControllerCommon::class, 'clearAlarmById'])->name('clear.alarm');
Route::get('/get-admin-alarms', [TelemetryController::class, 'getAdminAlarms']);
Route::post('/get-admin-alarms', [TelemetryController::class, 'getAdminAlarms']);
Route::get('get-device-by-asset/{assetId}', [TelemetryController::class, 'getDeviceByAsset']);
//******************************************************* Rule Chain API ********************************************************
Route::get('/rule-chains', [RuleChainController::class, 'getRuleChainList'])->name('list.RuleChain');