Fixed the bug of seeing duplciate alarms in the historical alarms

This commit is contained in:
Salijoghli 2025-06-23 13:18:13 +04:00
parent 543c430448
commit 76e026896d
2 changed files with 47 additions and 31 deletions

View File

@ -699,10 +699,10 @@
}, },
"value": { "value": {
"Description": "MCM01 Hello world", "Description": "MCM01 Hello world",
"Duration": "00:01:14", "Duration": "00:05:48",
"EventTimestamp": "2025-06-20 21:11:53", "EventTimestamp": "2025-06-23 13:10:26",
"Location": "MCM01", "Location": "MCM01",
"NumberID": 42, "NumberID": 60,
"Priority": "Low", "Priority": "Low",
"Tag": "MCM01.HMI.Beacon_Light" "Tag": "MCM01.HMI.Beacon_Light"
} }
@ -1409,10 +1409,10 @@
"data": [ "data": [
{ {
"Description": "MCM01 Hello world", "Description": "MCM01 Hello world",
"Duration": "00:01:14", "Duration": "00:03:48",
"EventTimestamp": "2025-06-20 21:11:53", "EventTimestamp": "2025-06-23 13:10:26",
"Location": "MCM01", "Location": "MCM01",
"NumberID": 42, "NumberID": 60,
"Priority": "Low", "Priority": "Low",
"Tag": "MCM01.HMI.Beacon_Light" "Tag": "MCM01.HMI.Beacon_Light"
} }
@ -2731,7 +2731,7 @@
"value": { "value": {
"$": [ "$": [
"ts", "ts",
192, 201,
1750436956149 1750436956149
], ],
"$ts": 1750436956149 "$ts": 1750436956149
@ -2910,7 +2910,6 @@
"children": [ "children": [
{ {
"custom": { "custom": {
"initial_data": [],
"max_duration": { "max_duration": {
"$": [ "$": [
"ts", "ts",
@ -2924,7 +2923,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1750436956154 1750667761263
], ],
"$ts": 1750435156149 "$ts": 1750435156149
}, },
@ -2932,7 +2931,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1750436956154 1750667761263
], ],
"$ts": 1750436956149 "$ts": 1750436956149
} }
@ -3872,7 +3871,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1750436956154 1750667761263
], ],
"$ts": 1750435156149 "$ts": 1750435156149
}, },
@ -3880,7 +3879,7 @@
"$": [ "$": [
"ts", "ts",
192, 192,
1750436956154 1750667761263
], ],
"$ts": 1750436956149 "$ts": 1750436956149
}, },
@ -4139,6 +4138,7 @@
"contentStyle": { "contentStyle": {
"classes": "Background-Styles/Grey-Background" "classes": "Background-Styles/Grey-Background"
}, },
"currentTabIndex": 2,
"menuType": "modern", "menuType": "modern",
"style": { "style": {
"classes": "Background-Styles/Grey-Background" "classes": "Background-Styles/Grey-Background"

View File

@ -1,7 +1,36 @@
WITH Active AS (
SELECT
ae.id,
ae.eventtime,
ae.eventid,
ae.source,
ae.priority,
ae.displaypath,
TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW())) AS duration_seconds
FROM alarm_events ae
LEFT JOIN alarm_events ae_clear
ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
WHERE ae.eventtype = 0
GROUP BY ae.id -- Ensure one row per alarm
),
SingleMyTag AS (
SELECT aed.id, aed.strValue
FROM alarm_event_data aed
WHERE aed.propname = 'myTag'
GROUP BY aed.id -- Collapse duplicates by id
),
SingleClear AS (
SELECT eventid, MIN(eventtime) AS eventtime
FROM alarm_events
WHERE eventtype = 1
GROUP BY eventid
)
SELECT SELECT
Active.id AS ID, Active.id AS ID,
Active.eventtime AS StartTimestamp, Active.eventtime AS StartTimestamp,
Clear.eventtime AS EndTimestamp, Clear.eventtime AS EndTimestamp,
CONCAT( CONCAT(
LPAD(FLOOR(Active.duration_seconds / 3600), 2, '0'), ':', LPAD(FLOOR(Active.duration_seconds / 3600), 2, '0'), ':',
LPAD(FLOOR((Active.duration_seconds % 3600) / 60), 2, '0'), ':', LPAD(FLOOR((Active.duration_seconds % 3600) / 60), 2, '0'), ':',
@ -27,25 +56,12 @@ SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location SUBSTRING_INDEX(SUBSTRING_INDEX(aed.strValue, '/', 2), '/', -1) AS Location
FROM ( FROM Active
SELECT
ae.id,
ae.eventtime,
ae.eventid,
ae.source,
ae.priority,
ae.displaypath,
TIMESTAMPDIFF(SECOND, ae.eventtime, COALESCE(ae_clear.eventtime, NOW())) AS duration_seconds
FROM alarm_events ae
LEFT JOIN alarm_events ae_clear
ON ae.eventid = ae_clear.eventid AND ae_clear.eventtype = 1
WHERE ae.eventtype = 0
) AS Active
LEFT JOIN alarm_events Clear LEFT JOIN SingleClear Clear
ON Active.eventid = Clear.eventid AND Clear.eventtype = 1 ON Active.eventid = Clear.eventid
LEFT JOIN alarm_event_data aed LEFT JOIN SingleMyTag aed
ON aed.id = Active.id AND aed.propname = 'myTag' ON aed.id = Active.id
ORDER BY Active.eventtime DESC; ORDER BY Active.eventtime DESC;