feat: connect device history to database
This commit is contained in:
@@ -315,6 +315,8 @@ export default {
|
|||||||
storageMatrixRequesting: false,
|
storageMatrixRequesting: false,
|
||||||
alarmEventTimer: null,
|
alarmEventTimer: null,
|
||||||
alarmEventRequesting: false,
|
alarmEventRequesting: false,
|
||||||
|
deviceHistoryTimer: null,
|
||||||
|
deviceHistoryRequesting: false,
|
||||||
clockTimer: null,
|
clockTimer: null,
|
||||||
resizeHandler: null,
|
resizeHandler: null,
|
||||||
alarmPieChart: null,
|
alarmPieChart: null,
|
||||||
@@ -629,6 +631,7 @@ export default {
|
|||||||
this.loadLineMonitorData()
|
this.loadLineMonitorData()
|
||||||
this.loadStorageMatrixData()
|
this.loadStorageMatrixData()
|
||||||
this.loadAlarmEventData()
|
this.loadAlarmEventData()
|
||||||
|
this.loadDeviceHistoryData()
|
||||||
this.clockTimer = setInterval(this.updateTime, 1000)
|
this.clockTimer = setInterval(this.updateTime, 1000)
|
||||||
this.lineMonitorTimer = setInterval(() => {
|
this.lineMonitorTimer = setInterval(() => {
|
||||||
this.loadLineMonitorData()
|
this.loadLineMonitorData()
|
||||||
@@ -639,6 +642,9 @@ export default {
|
|||||||
this.alarmEventTimer = setInterval(() => {
|
this.alarmEventTimer = setInterval(() => {
|
||||||
this.loadAlarmEventData()
|
this.loadAlarmEventData()
|
||||||
}, 10000)
|
}, 10000)
|
||||||
|
this.deviceHistoryTimer = setInterval(() => {
|
||||||
|
this.loadDeviceHistoryData()
|
||||||
|
}, 60000)
|
||||||
this.resizeHandler = () => {
|
this.resizeHandler = () => {
|
||||||
this.setScale()
|
this.setScale()
|
||||||
if (this.alarmPieChart) {
|
if (this.alarmPieChart) {
|
||||||
@@ -682,6 +688,10 @@ export default {
|
|||||||
clearInterval(this.alarmEventTimer)
|
clearInterval(this.alarmEventTimer)
|
||||||
this.alarmEventTimer = null
|
this.alarmEventTimer = null
|
||||||
}
|
}
|
||||||
|
if (this.deviceHistoryTimer) {
|
||||||
|
clearInterval(this.deviceHistoryTimer)
|
||||||
|
this.deviceHistoryTimer = null
|
||||||
|
}
|
||||||
if (this.alarmPieChart) {
|
if (this.alarmPieChart) {
|
||||||
this.alarmPieChart.dispose()
|
this.alarmPieChart.dispose()
|
||||||
this.alarmPieChart = null
|
this.alarmPieChart = null
|
||||||
@@ -851,6 +861,72 @@ export default {
|
|||||||
const text = String(value == null ? '' : value).trim()
|
const text = String(value == null ? '' : value).trim()
|
||||||
return text.length > 9 ? `${text.slice(0, 9)}...` : text
|
return text.length > 9 ? `${text.slice(0, 9)}...` : text
|
||||||
},
|
},
|
||||||
|
loadDeviceHistoryData() {
|
||||||
|
if (this.deviceHistoryRequesting) return
|
||||||
|
this.deviceHistoryRequesting = 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.applyDeviceHistoryData(list)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('TV_设备运行履历_查询失败', error)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.deviceHistoryRequesting = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
applyDeviceHistoryData(list) {
|
||||||
|
const rowMap = {}
|
||||||
|
list.forEach((item) => {
|
||||||
|
const deviceKey = this.formatDisplayValue(this.pickRecordValue(item, ['DeviceKey', 'deviceKey']))
|
||||||
|
if (!deviceKey || deviceKey === '--') return
|
||||||
|
if (!rowMap[deviceKey]) {
|
||||||
|
rowMap[deviceKey] = {
|
||||||
|
key: deviceKey,
|
||||||
|
name: this.formatDisplayValue(this.pickRecordValue(item, ['DeviceName', 'deviceName'])),
|
||||||
|
sortNo: Number(this.pickRecordValue(item, ['SortNo', 'sortNo'])) || 999,
|
||||||
|
segments: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const segment = this.createDeviceHistorySegment(item)
|
||||||
|
if (segment.end > segment.start) {
|
||||||
|
rowMap[deviceKey].segments.push(segment)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const rows = Object.keys(rowMap)
|
||||||
|
.map(key => rowMap[key])
|
||||||
|
.filter(row => row.segments.length > 0)
|
||||||
|
.sort((a, b) => a.sortNo - b.sortNo || a.name.localeCompare(b.name, 'zh-CN'))
|
||||||
|
rows.forEach((row) => {
|
||||||
|
row.segments.sort((a, b) => a.start - b.start)
|
||||||
|
})
|
||||||
|
if (rows.length) {
|
||||||
|
this.deviceHistoryList = rows
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createDeviceHistorySegment(item) {
|
||||||
|
const start = this.clampHistoryHour(this.pickRecordValue(item, ['StartHour', 'startHour']))
|
||||||
|
const end = this.clampHistoryHour(this.pickRecordValue(item, ['EndHour', 'endHour']))
|
||||||
|
return {
|
||||||
|
label: this.formatDisplayValue(this.pickRecordValue(item, ['StatusText', 'statusText'])),
|
||||||
|
type: this.normalizeHistoryStatusType(this.pickRecordValue(item, ['StatusType', 'statusType'])),
|
||||||
|
start,
|
||||||
|
end
|
||||||
|
}
|
||||||
|
},
|
||||||
|
normalizeHistoryStatusType(value) {
|
||||||
|
const type = String(value || '').trim().toLowerCase()
|
||||||
|
return ['off', 'standby', 'run', 'alarm'].includes(type) ? type : 'off'
|
||||||
|
},
|
||||||
|
clampHistoryHour(value) {
|
||||||
|
const hour = Number(value)
|
||||||
|
if (!Number.isFinite(hour)) return 0
|
||||||
|
return Math.max(0, Math.min(24, hour))
|
||||||
|
},
|
||||||
loadLineMonitorData() {
|
loadLineMonitorData() {
|
||||||
if (this.lineMonitorRequesting) return
|
if (this.lineMonitorRequesting) return
|
||||||
this.lineMonitorRequesting = true
|
this.lineMonitorRequesting = true
|
||||||
|
|||||||
Reference in New Issue
Block a user