feat: connect alarm events to database
This commit is contained in:
@@ -313,6 +313,8 @@ export default {
|
|||||||
lineMonitorRequesting: false,
|
lineMonitorRequesting: false,
|
||||||
storageMatrixTimer: null,
|
storageMatrixTimer: null,
|
||||||
storageMatrixRequesting: false,
|
storageMatrixRequesting: false,
|
||||||
|
alarmEventTimer: null,
|
||||||
|
alarmEventRequesting: false,
|
||||||
clockTimer: null,
|
clockTimer: null,
|
||||||
resizeHandler: null,
|
resizeHandler: null,
|
||||||
alarmPieChart: null,
|
alarmPieChart: null,
|
||||||
@@ -626,6 +628,7 @@ export default {
|
|||||||
this.$nextTick(this.initAlarmPieChart)
|
this.$nextTick(this.initAlarmPieChart)
|
||||||
this.loadLineMonitorData()
|
this.loadLineMonitorData()
|
||||||
this.loadStorageMatrixData()
|
this.loadStorageMatrixData()
|
||||||
|
this.loadAlarmEventData()
|
||||||
this.clockTimer = setInterval(this.updateTime, 1000)
|
this.clockTimer = setInterval(this.updateTime, 1000)
|
||||||
this.lineMonitorTimer = setInterval(() => {
|
this.lineMonitorTimer = setInterval(() => {
|
||||||
this.loadLineMonitorData()
|
this.loadLineMonitorData()
|
||||||
@@ -633,6 +636,9 @@ export default {
|
|||||||
this.storageMatrixTimer = setInterval(() => {
|
this.storageMatrixTimer = setInterval(() => {
|
||||||
this.loadStorageMatrixData()
|
this.loadStorageMatrixData()
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
this.alarmEventTimer = setInterval(() => {
|
||||||
|
this.loadAlarmEventData()
|
||||||
|
}, 10000)
|
||||||
this.resizeHandler = () => {
|
this.resizeHandler = () => {
|
||||||
this.setScale()
|
this.setScale()
|
||||||
if (this.alarmPieChart) {
|
if (this.alarmPieChart) {
|
||||||
@@ -672,6 +678,10 @@ export default {
|
|||||||
clearInterval(this.storageMatrixTimer)
|
clearInterval(this.storageMatrixTimer)
|
||||||
this.storageMatrixTimer = null
|
this.storageMatrixTimer = null
|
||||||
}
|
}
|
||||||
|
if (this.alarmEventTimer) {
|
||||||
|
clearInterval(this.alarmEventTimer)
|
||||||
|
this.alarmEventTimer = null
|
||||||
|
}
|
||||||
if (this.alarmPieChart) {
|
if (this.alarmPieChart) {
|
||||||
this.alarmPieChart.dispose()
|
this.alarmPieChart.dispose()
|
||||||
this.alarmPieChart = null
|
this.alarmPieChart = null
|
||||||
@@ -760,6 +770,87 @@ export default {
|
|||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
},
|
},
|
||||||
|
loadAlarmEventData() {
|
||||||
|
if (this.alarmEventRequesting) return
|
||||||
|
this.alarmEventRequesting = true
|
||||||
|
const data = this.CreateData('11', 'TV_报警异常事件_查询', [])
|
||||||
|
this.ExecDatabase(data)
|
||||||
|
.then((response) => {
|
||||||
|
const list = response && response.data ? response.data : null
|
||||||
|
if (!Array.isArray(list) || list.length === 0) return
|
||||||
|
if (list.length === 1 && list[0] && (list[0].result === '0' || list[0].result === 0)) return
|
||||||
|
this.applyAlarmEventData(list)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('TV_报警异常事件_查询失败', error)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.alarmEventRequesting = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
applyAlarmEventData(list) {
|
||||||
|
const events = []
|
||||||
|
const stats = []
|
||||||
|
list.forEach((item) => {
|
||||||
|
const rowType = this.formatDisplayValue(this.pickRecordValue(item, ['RowType', 'rowType'])).toLowerCase()
|
||||||
|
if (rowType === 'stat') {
|
||||||
|
const stat = this.createAlarmStatRow(item)
|
||||||
|
if (stat.value > 0) {
|
||||||
|
stats.push(stat)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (rowType === 'event') {
|
||||||
|
events.push(this.createAlarmEventRow(item))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (events.length) {
|
||||||
|
this.alarmEvents = events
|
||||||
|
}
|
||||||
|
if (stats.length) {
|
||||||
|
this.alarmFrequencyTop5 = stats
|
||||||
|
this.$nextTick(this.initAlarmPieChart)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createAlarmEventRow(item) {
|
||||||
|
const type = this.normalizeAlarmEventType(this.pickRecordValue(item, ['EventType', 'eventType']))
|
||||||
|
const time = this.formatDisplayValue(this.pickRecordValue(item, ['TimeText', 'timeText']))
|
||||||
|
return {
|
||||||
|
time: time === '--' ? '--:--' : time,
|
||||||
|
device: this.formatDisplayValue(this.pickRecordValue(item, ['DeviceName', 'deviceName'])),
|
||||||
|
level: type === 'warn' ? '提示' : '报警',
|
||||||
|
type,
|
||||||
|
message: this.formatDisplayValue(this.pickRecordValue(item, ['Message', 'message'])),
|
||||||
|
code: this.formatDisplayValue(this.pickRecordValue(item, ['AlarmCode', 'alarmCode'])),
|
||||||
|
startTime: this.formatDisplayValue(this.pickRecordValue(item, ['StartTimeText', 'startTimeText']))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createAlarmStatRow(item) {
|
||||||
|
const name = this.formatDisplayValue(this.pickRecordValue(item, ['StatName', 'statName']))
|
||||||
|
const code = this.formatDisplayValue(this.pickRecordValue(item, ['AlarmCode', 'alarmCode']))
|
||||||
|
return {
|
||||||
|
name: name === '--' ? code : name,
|
||||||
|
code,
|
||||||
|
value: Number(this.pickRecordValue(item, ['CountValue', 'countValue'])) || 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
normalizeAlarmEventType(value) {
|
||||||
|
const type = String(value || '').trim().toLowerCase()
|
||||||
|
return ['alarm', 'warn', 'idle'].includes(type) ? type : 'alarm'
|
||||||
|
},
|
||||||
|
pickRecordValue(item, keys) {
|
||||||
|
for (let i = 0; i < keys.length; i += 1) {
|
||||||
|
const value = item[keys[i]]
|
||||||
|
if (value !== undefined && value !== null) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
},
|
||||||
|
formatAlarmChartName(value) {
|
||||||
|
const text = String(value == null ? '' : value).trim()
|
||||||
|
return text.length > 9 ? `${text.slice(0, 9)}...` : text
|
||||||
|
},
|
||||||
loadLineMonitorData() {
|
loadLineMonitorData() {
|
||||||
if (this.lineMonitorRequesting) return
|
if (this.lineMonitorRequesting) return
|
||||||
this.lineMonitorRequesting = true
|
this.lineMonitorRequesting = true
|
||||||
@@ -1026,6 +1117,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.alarmPieChart = echarts.init(this.$refs.alarmPieChart)
|
this.alarmPieChart = echarts.init(this.$refs.alarmPieChart)
|
||||||
const names = this.alarmFrequencyTop5.map(item => item.name)
|
const names = this.alarmFrequencyTop5.map(item => item.name)
|
||||||
|
const shortNames = names.map(name => this.formatAlarmChartName(name))
|
||||||
const values = this.alarmFrequencyTop5.map(item => item.value)
|
const values = this.alarmFrequencyTop5.map(item => item.value)
|
||||||
const maxValue = Math.max(...values, 1)
|
const maxValue = Math.max(...values, 1)
|
||||||
const yAxisMax = Math.max(2, Math.ceil(maxValue / 2) * 2)
|
const yAxisMax = Math.max(2, Math.ceil(maxValue / 2) * 2)
|
||||||
@@ -1051,7 +1143,7 @@ export default {
|
|||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
data: names,
|
data: shortNames,
|
||||||
axisTick: {
|
axisTick: {
|
||||||
show: false
|
show: false
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user