[前台] 能源管理 Api 修改 & 解決圖表圖表切換錯誤 & 再生能源界面資料取得

This commit is contained in:
Celeste6666 2023-02-03 11:42:25 +08:00
parent 270e0855fc
commit cacf72f99e

View File

@ -260,38 +260,40 @@
// 左上方 系統小類卡片區塊 // 左上方 系統小類卡片區塊
function getSubSysList(type = 0) { function getSubSysList(type = 0) {
subSysList = []; subSysList = [];
let url = baseApiUrl + "/api/Device/GetMainSub"; let url = baseApiUrl + "/api/Energe/GetElecBySubSysTag";
let sendData = { // let sendData = {
building_tag: pageAct.buiTag, // building_tag: pageAct.buiTag,
}; // };
objSendData.Data = sendData; // objSendData.Data = sendData;
ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { ytAjax = new YourTeam.Ajax(
url,
null,
function (res) {
if (!res || res.code != "0000" || !res.data) { if (!res || res.code != "0000" || !res.data) {
} else { } else {
let strHtml = ''; let strHtml = "";
$.each(res.data.history_Main_Systems, (index, mainSysObj) => { $.each(res.data, (index, mainSysObj) => {
$.each(mainSysObj.history_Sub_systems, (index2, subSysObj) => { if ((type == 0 || (type == 3 && mainSysObj.mainSubTag == "ELEV_EL"))
subSysList.push(subSysObj); // && filNotShowSysSub.indexOf(subSysObj.sub_system_tag) == -1
if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNotShowSysSub.indexOf(subSysObj.sub_system_tag) == -1) { ) {
const full_name = mainSysObj.system_remark.split("-")[1];
strHtml += `<div class="col-sm-12 col-xl-4 mb-2"> strHtml += `<div class="col-sm-12 col-xl-4 mb-2">
<div class="card elecCard cur-poi" data-id="${mainSysObj.main_system_tag}_${subSysObj.sub_system_tag}" data-name="${subSysObj.full_name}"> <div class="card elecCard cur-poi" data-id="${mainSysObj.mainSubTag}" data-name="${mainSysObj.mainSubTag}">
<div class="card-body"> <div class="card-body">
<h4 class="card-title color-white">${subSysObj.full_name}用電</h4> <h4 class="card-title color-white">${full_name}用電</h4>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between"> <p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text1}</span> <span>${elecCardConText[type]?.text1}</span>
<span id="insPow${mainSysObj.main_system_tag}_${subSysObj.sub_system_tag}"></span> <span id="insPow${mainSysObj.mainSubTag}"></span>
</p> </p>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between"> <p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text2}</span> <span>${elecCardConText[type]?.text2}</span>
<span id="insPowPer${mainSysObj.main_system_tag}_${subSysObj.sub_system_tag}"></span> <span id="insPowPer${mainSysObj.mainSubTag}"></span>
</p> </p>
</div> </div>
</div> </div>
</div>`; </div>`;
} }
}) });
})
if (type == 3) { if (type == 3) {
strHtml += `<div class="col-sm-12 col-xl-4 mb-2"> strHtml += `<div class="col-sm-12 col-xl-4 mb-2">
<div class="card elecCard cur-poi"> <div class="card elecCard cur-poi">
@ -309,11 +311,12 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
</div> </div>
</div>`; </div>`;
} }
console.log(strHtml)
$("#eneSubSysList").html(strHtml); $("#eneSubSysList").html(strHtml);
} }
}, null, "POST").send(); },
null,
"POST",
).send();
} }
// 取得 對應系統小類的總電錶 // 取得 對應系統小類的總電錶
@ -420,7 +423,6 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
$.each(subSysElecList, (idx, elecObj) => { $.each(subSysElecList, (idx, elecObj) => {
let devPath let devPath
devPath = elecObj.system_device_tag?.split("_").slice(0, 8).join("/"); devPath = elecObj.system_device_tag?.split("_").slice(0, 8).join("/");
console.log(424, devPath)
getElectricMeterNoweDataByBaja(devPath, (data) => { getElectricMeterNoweDataByBaja(devPath, (data) => {
data = data.data; data = data.data;
let result = 0; let result = 0;
@ -428,8 +430,7 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
result = data.filter(x => x.name == "P_rec")[0]?.value?.roundDecimal(2); result = data.filter(x => x.name == "P_rec")[0]?.value?.roundDecimal(2);
$(`#insPow${elecObj.mainSubTag}`).text(result); $(`#insPow${elecObj.mainSubTag}`).text(result);
result = data.filter(x => x.name == "KWH_rec")[0]?.value?.roundDecimal(2); result = data.filter(x => x.name == "KWH_rec")[0]?.value?.roundDecimal(2);
console.log(429, data, result) $(`#insPowPer${elecObj.mainSubTag}`).text((result / result * 100).roundDecimal(2) + " %");
$(`#insPowPer${elecObj.mainSubTag}`).text((result / totalPow * 100).roundDecimal(2) + " %");
} else { } else {
/* result = result ? result.roundDecimal(2) : 0;*/ /* result = result ? result.roundDecimal(2) : 0;*/
result = data.filter(x => x.name == "P")[0]?.value?.roundDecimal(2); result = data.filter(x => x.name == "P")[0]?.value?.roundDecimal(2);
@ -471,7 +472,6 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
todayElecChart?.destroy(); todayElecChart?.destroy();
return; return;
} }
getElectricMeterHourDataByBaja(tarDevNum + "_KWH", n4Sup, yesterday, tomorrow, (data) => { getElectricMeterHourDataByBaja(tarDevNum + "_KWH", n4Sup, yesterday, tomorrow, (data) => {
let todayData = data.data.filter(x => x.timestamp.$date.$year == getTimeByType("year") && x.timestamp.$date.$month == getTimeByType("month") && x.timestamp.$date.$day == getTimeByType("date")); let todayData = data.data.filter(x => x.timestamp.$date.$year == getTimeByType("year") && x.timestamp.$date.$month == getTimeByType("month") && x.timestamp.$date.$day == getTimeByType("date"));
chartTodaysElec(todayData); chartTodaysElec(todayData);
@ -552,6 +552,7 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
// 圖表 - 今天用電量 (折線圖) // 圖表 - 今天用電量 (折線圖)
function chartTodaysElec(todayData) { function chartTodaysElec(todayData) {
todayElecChart?.destroy();
let todayElecChartCanvas = $('#todayElecChart').get(0).getContext('2d'); let todayElecChartCanvas = $('#todayElecChart').get(0).getContext('2d');
let curHour = (new Date()).getHours(); let curHour = (new Date()).getHours();
todayData.data = todayData.filter(x => x.timestamp.$time.$hour < curHour); todayData.data = todayData.filter(x => x.timestamp.$time.$hour < curHour);
@ -618,7 +619,7 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
// 圖表 - 今日與30日內平均用電量比較 (長條圖) // 圖表 - 今日與30日內平均用電量比較 (長條圖)
function chartEveWeeksElec(curWeekData, avgData) { function chartEveWeeksElec(curWeekData, avgData) {
elecCompChart?.destroy()
let elecCompChartCanvas = $('#elecCompChart').get(0).getContext('2d'); let elecCompChartCanvas = $('#elecCompChart').get(0).getContext('2d');
let elecCompChartData = { let elecCompChartData = {
labels: curWeekData.map(x => dayToChiDay(strToDate(x.timestamp.$cEncStr, "day"))), labels: curWeekData.map(x => dayToChiDay(strToDate(x.timestamp.$cEncStr, "day"))),