一周充放柱状图改为电表报表的数据接口
This commit is contained in:
@ -14,12 +14,11 @@
|
||||
import * as echarts from 'echarts'
|
||||
import resize from '@/mixins/ems/resize'
|
||||
import DateRangeSelect from '@/components/Ems/DateRangeSelect/index.vue'
|
||||
import { getPointConfigCurve } from '@/api/ems/site'
|
||||
import { getAmmeterData } from '@/api/ems/dzjk'
|
||||
|
||||
const DAY = 24 * 60 * 60 * 1000
|
||||
const TEXT = {
|
||||
cardTitle: '\u4e00\u5468\u5145\u653e\u67f1\u72b6\u56fe',
|
||||
sectionName: '\u4e00\u5468\u5145\u653e\u66f2\u7ebf',
|
||||
empty: '\u6682\u65e0\u6570\u636e',
|
||||
date: '\u65e5\u671f',
|
||||
charge: '\u5145\u7535\u91cf',
|
||||
@ -54,13 +53,6 @@ export default {
|
||||
cardTitle: TEXT.cardTitle
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
displayData() {
|
||||
if (this.siteId && this.timeRange.length === 2) {
|
||||
this.getWeekKData()
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
this.initChart()
|
||||
@ -80,33 +72,21 @@ export default {
|
||||
},
|
||||
getWeekKData() {
|
||||
const { siteId, timeRange } = this
|
||||
const displayData = this.displayData || []
|
||||
const sectionRows = displayData.filter(item =>
|
||||
item && item.sectionName === TEXT.sectionName && item.useFixedDisplay !== 1 && item.dataPoint
|
||||
)
|
||||
const tasks = sectionRows.map(row => {
|
||||
const pointId = String(row.dataPoint || '').trim()
|
||||
if (!pointId) return Promise.resolve(null)
|
||||
return getPointConfigCurve({
|
||||
siteId,
|
||||
pointId,
|
||||
pointType: 'data',
|
||||
rangeType: 'custom',
|
||||
startTime: this.normalizeDateTime(timeRange[0], false),
|
||||
endTime: this.normalizeDateTime(timeRange[1], true)
|
||||
}).then(curveResponse => {
|
||||
const list = curveResponse?.data || []
|
||||
return {
|
||||
name: row.fieldName || row.fieldCode || pointId,
|
||||
fieldCode: row.fieldCode || '',
|
||||
data: list
|
||||
.map(item => [this.parseToTimestamp(item.dataTime), Number(item.pointValue)])
|
||||
.filter(item => item[0] && !Number.isNaN(item[1]))
|
||||
if (!siteId || !Array.isArray(timeRange) || timeRange.length !== 2) {
|
||||
this.summary = createEmptySummary()
|
||||
this.renderEmptyState()
|
||||
return
|
||||
}
|
||||
}).catch(() => null)
|
||||
})
|
||||
Promise.all(tasks).then(series => {
|
||||
this.setOption((series || []).filter(Boolean))
|
||||
|
||||
this.queryAllAmmeterRows({
|
||||
siteId,
|
||||
startTime: String(timeRange[0] || '').trim(),
|
||||
endTime: String(timeRange[1] || '').trim(),
|
||||
}).then((rows) => {
|
||||
this.setOption(rows || [])
|
||||
}).catch(() => {
|
||||
this.summary = createEmptySummary()
|
||||
this.renderEmptyState()
|
||||
})
|
||||
},
|
||||
init(siteId) {
|
||||
@ -155,6 +135,24 @@ export default {
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
},
|
||||
queryAllAmmeterRows({ siteId, startTime, endTime, pageSize = 500, pageNum = 1, rows = [] }) {
|
||||
return getAmmeterData({ siteId, startTime, endTime, pageSize, pageNum }).then((response) => {
|
||||
const currentRows = Array.isArray(response?.rows) ? response.rows : []
|
||||
const allRows = rows.concat(currentRows)
|
||||
const total = Number(response?.total) || 0
|
||||
if (allRows.length >= total || currentRows.length < pageSize) {
|
||||
return allRows
|
||||
}
|
||||
return this.queryAllAmmeterRows({
|
||||
siteId,
|
||||
startTime,
|
||||
endTime,
|
||||
pageSize,
|
||||
pageNum: pageNum + 1,
|
||||
rows: allRows
|
||||
})
|
||||
})
|
||||
},
|
||||
buildDatasetSource(labels = [], chargeData = [], dischargeData = []) {
|
||||
const source = [[TEXT.date, TEXT.charge, TEXT.discharge]]
|
||||
labels.forEach((label, index) => {
|
||||
@ -166,17 +164,12 @@ export default {
|
||||
})
|
||||
return source
|
||||
},
|
||||
resolveSeriesType(item = {}) {
|
||||
const text = `${item?.name || ''} ${item?.fieldCode || ''}`.toLowerCase()
|
||||
if (text.includes('\u653e') || text.includes('discharge') || text.includes('discharged')) {
|
||||
return 'discharge'
|
||||
}
|
||||
if (text.includes('\u5145') || text.includes('charge') || text.includes('charged')) {
|
||||
return 'charge'
|
||||
}
|
||||
return ''
|
||||
normalizeDateOnly(value) {
|
||||
const raw = String(value || '').trim()
|
||||
if (!raw) return ''
|
||||
return raw.includes(' ') ? raw.split(' ')[0] : raw
|
||||
},
|
||||
buildDailyChartData(seriesData = []) {
|
||||
buildDailyChartData(rows = []) {
|
||||
const normalizedRange = this.timeRange || []
|
||||
const startTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[0], false))
|
||||
const endTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[1], true))
|
||||
@ -197,22 +190,13 @@ export default {
|
||||
const chargeMap = {}
|
||||
const dischargeMap = {}
|
||||
|
||||
;(seriesData || []).forEach(item => {
|
||||
const seriesType = this.resolveSeriesType(item)
|
||||
if (!seriesType) return
|
||||
;(rows || []).forEach((row) => {
|
||||
const dateText = this.normalizeDateOnly(row?.dataTime)
|
||||
const bucketStart = this.parseToTimestamp(this.normalizeDateTime(dateText, false))
|
||||
if (!bucketStart || bucketStart < this.startOfDay(startTime) || bucketStart > this.startOfDay(endTime)) return
|
||||
|
||||
;(item?.data || []).forEach(([timestamp, pointValue]) => {
|
||||
if (!timestamp || Number.isNaN(pointValue)) return
|
||||
if (timestamp < startTime || timestamp > endTime) return
|
||||
|
||||
const bucketStart = this.startOfDay(timestamp)
|
||||
const normalizedValue = Math.abs(Number(pointValue) || 0)
|
||||
if (seriesType === 'charge') {
|
||||
chargeMap[bucketStart] = (chargeMap[bucketStart] || 0) + normalizedValue
|
||||
} else if (seriesType === 'discharge') {
|
||||
dischargeMap[bucketStart] = (dischargeMap[bucketStart] || 0) + normalizedValue
|
||||
}
|
||||
})
|
||||
chargeMap[bucketStart] = Math.abs(Number(row?.activeTotalKwh) || 0)
|
||||
dischargeMap[bucketStart] = Math.abs(Number(row?.reActiveTotalKwh) || 0)
|
||||
})
|
||||
|
||||
const labels = []
|
||||
@ -267,13 +251,12 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
setOption(seriesData = []) {
|
||||
setOption(rows = []) {
|
||||
if (!this.chart) return
|
||||
|
||||
const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(seriesData)
|
||||
const hasValue = chargeData.some(item => Number(item?.value || 0) > 0) || dischargeData.some(item => Number(item?.value || 0) > 0)
|
||||
const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(rows)
|
||||
|
||||
if (!labels.length || !hasValue) {
|
||||
if (!labels.length) {
|
||||
this.summary = createEmptySummary()
|
||||
this.renderEmptyState()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user