总累计运行数据数据来源改为电表报表表数据

This commit is contained in:
xiaoyang
2026-04-16 19:50:30 +08:00
parent 801d8eab1d
commit 1499085561

View File

@ -151,7 +151,7 @@
<script>
import * as echarts from "echarts";
import {getSingleSiteBaseInfo} from "@/api/ems/zddt";
import {getDzjkHomeTotalView, getProjectDisplayData} from "@/api/ems/dzjk";
import {getAmmeterData, getDzjkHomeTotalView, getProjectDisplayData} from "@/api/ems/dzjk";
import {getPointConfigCurve} from "@/api/ems/site";
import WeekChart from "./WeekChart.vue";
import ActiveChart from "./ActiveChart.vue";
@ -229,6 +229,7 @@ export default {
info: {}, //基本信息
runningInfo: {}, //总累计运行数据+报警表格
runningDisplayData: [], //单站监控项目配置展示数据
ammeterDailySummary: {},
};
},
computed: {
@ -264,7 +265,7 @@ export default {
.filter(item => item.fieldCode !== revenueFieldCode)
.map((item, index) => ({
title: item.fieldName,
value: item.fieldValue,
value: this.getRunningCardValue(item),
color: this.getCardColor(index),
loading: this.isRunningInfoLoading,
raw: item,
@ -272,7 +273,7 @@ export default {
}
return this.fallbackSjglData.map(item => ({
title: item.title,
value: this.runningInfo[item.attr],
value: this.getRunningCardValue(item),
color: item.color,
loading: this.isRunningInfoLoading,
raw: item,
@ -468,6 +469,131 @@ export default {
const colors = ['#4472c4', '#70ad47', '#4472c4', '#f67438', '#4472c4', '#70ad47', '#70ad47', '#f67438'];
return colors[index % colors.length];
},
formatDateOnly(date) {
const value = new Date(date);
if (isNaN(value.getTime())) {
return "";
}
const pad = (num) => String(num).padStart(2, "0");
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
},
normalizeDateOnly(value) {
if (!value) {
return "";
}
const raw = String(value).trim();
const matched = raw.match(/\d{4}-\d{2}-\d{2}/);
if (matched) {
return matched[0];
}
return this.formatDateOnly(raw);
},
toDisplayNumber(value) {
if (value === null || value === undefined || value === "") {
return value;
}
const num = Number(value);
return Number.isNaN(num) ? value : num;
},
getAmmeterSummaryAttr(item) {
const fieldCode = String(item?.fieldCode || item?.attr || "").trim();
const fieldName = String(item?.fieldName || item?.title || "").trim();
if (["dayChargedCap", "今日充电量kWh"].includes(fieldCode) || fieldName === "今日充电量kWh") {
return "dayChargedCap";
}
if (["dayDisChargedCap", "今日放电量kWh"].includes(fieldCode) || fieldName === "今日放电量kWh") {
return "dayDisChargedCap";
}
if (["yesterdayChargedCap", "昨日充电量kWh"].includes(fieldCode) || fieldName === "昨日充电量kWh") {
return "yesterdayChargedCap";
}
if (["yesterdayDisChargedCap", "昨日放电量kWh"].includes(fieldCode) || fieldName === "昨日放电量kWh") {
return "yesterdayDisChargedCap";
}
if (["totalChargedCap", "总充电量kWh"].includes(fieldCode) || fieldName === "总充电量kWh") {
return "totalChargedCap";
}
if (["totalDischargedCap", "总放电量kWh"].includes(fieldCode) || fieldName === "总放电量kWh") {
return "totalDischargedCap";
}
return "";
},
getRunningCardValue(item) {
const summaryAttr = this.getAmmeterSummaryAttr(item);
if (summaryAttr) {
const summaryValue = this.ammeterDailySummary?.[summaryAttr];
if (summaryValue !== undefined && summaryValue !== null && summaryValue !== "") {
return summaryValue;
}
}
const rawValue = item?.fieldValue !== undefined ? item.fieldValue : this.runningInfo?.[item?.attr];
return this.toDisplayNumber(rawValue);
},
queryAllAmmeterDailyRows({ startTime = "", endTime = "", pageSize = 500, pageNum = 1, rows = [] } = {}) {
return getAmmeterData({
siteId: this.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.queryAllAmmeterDailyRows({
startTime,
endTime,
pageSize,
pageNum: pageNum + 1,
rows: allRows,
});
});
},
getAmmeterDailySummary() {
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
const startTime = this.formatDateOnly(yesterday);
const endTime = this.formatDateOnly(today);
return Promise.all([
this.queryAllAmmeterDailyRows({
startTime,
endTime,
pageSize: 20,
pageNum: 1,
}),
this.queryAllAmmeterDailyRows(),
]).then(([recentRows, allRows]) => {
const rowMap = recentRows.reduce((result, row) => {
const dateKey = this.normalizeDateOnly(row?.dataTime);
if (dateKey) {
result[dateKey] = row;
}
return result;
}, {});
const todayKey = this.formatDateOnly(today);
const yesterdayKey = this.formatDateOnly(yesterday);
const todayRow = rowMap[todayKey] || {};
const yesterdayRow = rowMap[yesterdayKey] || {};
const totalChargedCap = allRows.reduce((result, row) => {
return result + (Number(row?.activeTotalKwh) || 0);
}, 0);
const totalDischargedCap = allRows.reduce((result, row) => {
return result + (Number(row?.reActiveTotalKwh) || 0);
}, 0);
return {
dayChargedCap: this.toDisplayNumber(todayRow.activeTotalKwh),
dayDisChargedCap: this.toDisplayNumber(todayRow.reActiveTotalKwh),
yesterdayChargedCap: this.toDisplayNumber(yesterdayRow.activeTotalKwh),
yesterdayDisChargedCap: this.toDisplayNumber(yesterdayRow.reActiveTotalKwh),
totalChargedCap: this.toDisplayNumber(totalChargedCap),
totalDischargedCap: this.toDisplayNumber(totalDischargedCap),
};
}).catch(() => ({}));
},
toAlarm() {
this.$router.push({path: "/dzjk/gzgj", query: this.$route.query});
},
@ -484,12 +610,14 @@ export default {
return Promise.all([
getDzjkHomeTotalView(this.siteId),
getProjectDisplayData(this.siteId),
]).then(([homeResponse, displayResponse]) => {
this.getAmmeterDailySummary(),
]).then(([homeResponse, displayResponse, ammeterDailySummary]) => {
const nextRunningInfo = homeResponse?.data || {};
const nextRunningDisplayData = displayResponse?.data || [];
const changed = hasOldData && this.hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData);
const changed = hasOldData && this.hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData, ammeterDailySummary || {});
this.runningInfo = nextRunningInfo;
this.runningDisplayData = nextRunningDisplayData;
this.ammeterDailySummary = ammeterDailySummary || {};
if (changed) {
this.triggerRunningUpdateSpinner();
}
@ -509,24 +637,30 @@ export default {
this.runningUpdateTimer = null;
}, 800);
},
hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData) {
const oldSnapshot = this.getTotalRunningSnapshot(this.runningInfo, this.runningDisplayData);
const newSnapshot = this.getTotalRunningSnapshot(nextRunningInfo, nextRunningDisplayData);
hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData, nextAmmeterDailySummary = {}) {
const oldSnapshot = this.getTotalRunningSnapshot(this.runningInfo, this.runningDisplayData, this.ammeterDailySummary || {});
const newSnapshot = this.getTotalRunningSnapshot(nextRunningInfo, nextRunningDisplayData, nextAmmeterDailySummary);
return JSON.stringify(oldSnapshot) !== JSON.stringify(newSnapshot);
},
getTotalRunningSnapshot(runningInfo, runningDisplayData) {
getTotalRunningSnapshot(runningInfo, runningDisplayData, ammeterDailySummary = {}) {
const snapshot = {};
const sectionData = (runningDisplayData || []).filter(item => item.sectionName === "总累计运行数据");
if (sectionData.length > 0) {
sectionData.forEach(item => {
const key = item.fieldCode || item.fieldName;
if (!key) return;
snapshot[`cfg:${key}`] = this.normalizeRunningCompareValue(item.fieldValue);
const summaryAttr = this.getAmmeterSummaryAttr(item);
const value = summaryAttr ? ammeterDailySummary?.[summaryAttr] : item.fieldValue;
snapshot[`cfg:${key}`] = this.normalizeRunningCompareValue(value);
});
return snapshot;
}
this.fallbackSjglData.forEach(item => {
snapshot[`fallback:${item.attr}`] = this.normalizeRunningCompareValue(runningInfo?.[item.attr]);
const summaryAttr = this.getAmmeterSummaryAttr(item);
const value = summaryAttr
? ammeterDailySummary?.[summaryAttr]
: runningInfo?.[item.attr];
snapshot[`fallback:${item.attr}`] = this.normalizeRunningCompareValue(value);
});
snapshot["fallback:totalRevenue"] = this.normalizeRunningCompareValue(runningInfo?.totalRevenue);
return snapshot;