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

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

View File

@ -260,60 +260,63 @@
// 左上方 系統小類卡片區塊
function getSubSysList(type = 0) {
subSysList = [];
let url = baseApiUrl + "/api/Device/GetMainSub";
let sendData = {
building_tag: pageAct.buiTag,
};
objSendData.Data = sendData;
ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
if (!res || res.code != "0000" || !res.data) {
} else {
let strHtml = '';
$.each(res.data.history_Main_Systems, (index, mainSysObj) => {
$.each(mainSysObj.history_Sub_systems, (index2, subSysObj) => {
subSysList.push(subSysObj);
if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNotShowSysSub.indexOf(subSysObj.sub_system_tag) == -1) {
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-body">
<h4 class="card-title color-white">${subSysObj.full_name}用電</h4>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text1}</span>
<span id="insPow${mainSysObj.main_system_tag}_${subSysObj.sub_system_tag}"></span>
</p>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text2}</span>
<span id="insPowPer${mainSysObj.main_system_tag}_${subSysObj.sub_system_tag}"></span>
</p>
</div>
</div>
</div>`;
let url = baseApiUrl + "/api/Energe/GetElecBySubSysTag";
// let sendData = {
// building_tag: pageAct.buiTag,
// };
// objSendData.Data = sendData;
ytAjax = new YourTeam.Ajax(
url,
null,
function (res) {
if (!res || res.code != "0000" || !res.data) {
} else {
let strHtml = "";
$.each(res.data, (index, mainSysObj) => {
if ((type == 0 || (type == 3 && mainSysObj.mainSubTag == "ELEV_EL"))
// && 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">
<div class="card elecCard cur-poi" data-id="${mainSysObj.mainSubTag}" data-name="${mainSysObj.mainSubTag}">
<div class="card-body">
<h4 class="card-title color-white">${full_name}用電</h4>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text1}</span>
<span id="insPow${mainSysObj.mainSubTag}"></span>
</p>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text2}</span>
<span id="insPowPer${mainSysObj.mainSubTag}"></span>
</p>
</div>
</div>
</div>`;
}
})
})
if (type == 3) {
strHtml += `<div class="col-sm-12 col-xl-4 mb-2">
<div class="card elecCard cur-poi">
<div class="card-body">
<h4 class="card-title color-white">太陽能設備用電</h4>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text1}</span>
<span id="insPow">---</span>
</p>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text2}</span>
<span id="insPow">---</span>
</p>
</div>
</div>
</div>`;
});
if (type == 3) {
strHtml += `<div class="col-sm-12 col-xl-4 mb-2">
<div class="card elecCard cur-poi">
<div class="card-body">
<h4 class="card-title color-white">太陽能設備用電</h4>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text1}</span>
<span id="insPow">---</span>
</p>
<p class="card-text color-white pl-5 pr-3 d-flex justify-content-between">
<span>${elecCardConText[type]?.text2}</span>
<span id="insPow">---</span>
</p>
</div>
</div>
</div>`;
}
$("#eneSubSysList").html(strHtml);
}
console.log(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) => {
let devPath
devPath = elecObj.system_device_tag?.split("_").slice(0, 8).join("/");
console.log(424, devPath)
getElectricMeterNoweDataByBaja(devPath, (data) => {
data = data.data;
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);
$(`#insPow${elecObj.mainSubTag}`).text(result);
result = data.filter(x => x.name == "KWH_rec")[0]?.value?.roundDecimal(2);
console.log(429, data, result)
$(`#insPowPer${elecObj.mainSubTag}`).text((result / totalPow * 100).roundDecimal(2) + " %");
$(`#insPowPer${elecObj.mainSubTag}`).text((result / result * 100).roundDecimal(2) + " %");
} else {
/* result = result ? result.roundDecimal(2) : 0;*/
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();
return;
}
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"));
chartTodaysElec(todayData);
@ -552,6 +552,7 @@ if ((type == 0 || (type == 3 && mainSysObj.main_system_tag == "ELEV")) && filNot
// 圖表 - 今天用電量 (折線圖)
function chartTodaysElec(todayData) {
todayElecChart?.destroy();
let todayElecChartCanvas = $('#todayElecChart').get(0).getContext('2d');
let curHour = (new Date()).getHours();
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日內平均用電量比較 (長條圖)
function chartEveWeeksElec(curWeekData, avgData) {
elecCompChart?.destroy()
let elecCompChartCanvas = $('#elecCompChart').get(0).getContext('2d');
let elecCompChartData = {
labels: curWeekData.map(x => dayToChiDay(strToDate(x.timestamp.$cEncStr, "day"))),