总累计运行数据数据来源改为电表报表表数据
This commit is contained in:
@ -151,7 +151,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import {getSingleSiteBaseInfo} from "@/api/ems/zddt";
|
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 {getPointConfigCurve} from "@/api/ems/site";
|
||||||
import WeekChart from "./WeekChart.vue";
|
import WeekChart from "./WeekChart.vue";
|
||||||
import ActiveChart from "./ActiveChart.vue";
|
import ActiveChart from "./ActiveChart.vue";
|
||||||
@ -229,6 +229,7 @@ export default {
|
|||||||
info: {}, //基本信息
|
info: {}, //基本信息
|
||||||
runningInfo: {}, //总累计运行数据+报警表格
|
runningInfo: {}, //总累计运行数据+报警表格
|
||||||
runningDisplayData: [], //单站监控项目配置展示数据
|
runningDisplayData: [], //单站监控项目配置展示数据
|
||||||
|
ammeterDailySummary: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -264,7 +265,7 @@ export default {
|
|||||||
.filter(item => item.fieldCode !== revenueFieldCode)
|
.filter(item => item.fieldCode !== revenueFieldCode)
|
||||||
.map((item, index) => ({
|
.map((item, index) => ({
|
||||||
title: item.fieldName,
|
title: item.fieldName,
|
||||||
value: item.fieldValue,
|
value: this.getRunningCardValue(item),
|
||||||
color: this.getCardColor(index),
|
color: this.getCardColor(index),
|
||||||
loading: this.isRunningInfoLoading,
|
loading: this.isRunningInfoLoading,
|
||||||
raw: item,
|
raw: item,
|
||||||
@ -272,7 +273,7 @@ export default {
|
|||||||
}
|
}
|
||||||
return this.fallbackSjglData.map(item => ({
|
return this.fallbackSjglData.map(item => ({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
value: this.runningInfo[item.attr],
|
value: this.getRunningCardValue(item),
|
||||||
color: item.color,
|
color: item.color,
|
||||||
loading: this.isRunningInfoLoading,
|
loading: this.isRunningInfoLoading,
|
||||||
raw: item,
|
raw: item,
|
||||||
@ -468,6 +469,131 @@ export default {
|
|||||||
const colors = ['#4472c4', '#70ad47', '#4472c4', '#f67438', '#4472c4', '#70ad47', '#70ad47', '#f67438'];
|
const colors = ['#4472c4', '#70ad47', '#4472c4', '#f67438', '#4472c4', '#70ad47', '#70ad47', '#f67438'];
|
||||||
return colors[index % colors.length];
|
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() {
|
toAlarm() {
|
||||||
this.$router.push({path: "/dzjk/gzgj", query: this.$route.query});
|
this.$router.push({path: "/dzjk/gzgj", query: this.$route.query});
|
||||||
},
|
},
|
||||||
@ -484,12 +610,14 @@ export default {
|
|||||||
return Promise.all([
|
return Promise.all([
|
||||||
getDzjkHomeTotalView(this.siteId),
|
getDzjkHomeTotalView(this.siteId),
|
||||||
getProjectDisplayData(this.siteId),
|
getProjectDisplayData(this.siteId),
|
||||||
]).then(([homeResponse, displayResponse]) => {
|
this.getAmmeterDailySummary(),
|
||||||
|
]).then(([homeResponse, displayResponse, ammeterDailySummary]) => {
|
||||||
const nextRunningInfo = homeResponse?.data || {};
|
const nextRunningInfo = homeResponse?.data || {};
|
||||||
const nextRunningDisplayData = displayResponse?.data || [];
|
const nextRunningDisplayData = displayResponse?.data || [];
|
||||||
const changed = hasOldData && this.hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData);
|
const changed = hasOldData && this.hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData, ammeterDailySummary || {});
|
||||||
this.runningInfo = nextRunningInfo;
|
this.runningInfo = nextRunningInfo;
|
||||||
this.runningDisplayData = nextRunningDisplayData;
|
this.runningDisplayData = nextRunningDisplayData;
|
||||||
|
this.ammeterDailySummary = ammeterDailySummary || {};
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.triggerRunningUpdateSpinner();
|
this.triggerRunningUpdateSpinner();
|
||||||
}
|
}
|
||||||
@ -509,24 +637,30 @@ export default {
|
|||||||
this.runningUpdateTimer = null;
|
this.runningUpdateTimer = null;
|
||||||
}, 800);
|
}, 800);
|
||||||
},
|
},
|
||||||
hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData) {
|
hasTotalRunningChanged(nextRunningInfo, nextRunningDisplayData, nextAmmeterDailySummary = {}) {
|
||||||
const oldSnapshot = this.getTotalRunningSnapshot(this.runningInfo, this.runningDisplayData);
|
const oldSnapshot = this.getTotalRunningSnapshot(this.runningInfo, this.runningDisplayData, this.ammeterDailySummary || {});
|
||||||
const newSnapshot = this.getTotalRunningSnapshot(nextRunningInfo, nextRunningDisplayData);
|
const newSnapshot = this.getTotalRunningSnapshot(nextRunningInfo, nextRunningDisplayData, nextAmmeterDailySummary);
|
||||||
return JSON.stringify(oldSnapshot) !== JSON.stringify(newSnapshot);
|
return JSON.stringify(oldSnapshot) !== JSON.stringify(newSnapshot);
|
||||||
},
|
},
|
||||||
getTotalRunningSnapshot(runningInfo, runningDisplayData) {
|
getTotalRunningSnapshot(runningInfo, runningDisplayData, ammeterDailySummary = {}) {
|
||||||
const snapshot = {};
|
const snapshot = {};
|
||||||
const sectionData = (runningDisplayData || []).filter(item => item.sectionName === "总累计运行数据");
|
const sectionData = (runningDisplayData || []).filter(item => item.sectionName === "总累计运行数据");
|
||||||
if (sectionData.length > 0) {
|
if (sectionData.length > 0) {
|
||||||
sectionData.forEach(item => {
|
sectionData.forEach(item => {
|
||||||
const key = item.fieldCode || item.fieldName;
|
const key = item.fieldCode || item.fieldName;
|
||||||
if (!key) return;
|
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;
|
return snapshot;
|
||||||
}
|
}
|
||||||
this.fallbackSjglData.forEach(item => {
|
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);
|
snapshot["fallback:totalRevenue"] = this.normalizeRunningCompareValue(runningInfo?.totalRevenue);
|
||||||
return snapshot;
|
return snapshot;
|
||||||
|
|||||||
Reference in New Issue
Block a user