From 2236bc9717194631ea25924289042477a2485699 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Sat, 10 Jul 2021 19:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=B7=E5=8F=B2(=E7=84=A1=E6=9F=B1=E7=8B=80?= =?UTF-8?q?=E5=9C=96=E5=8F=8A=E6=BA=AB=E5=BA=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StationOverviewController.cs | 43 +++++++++ SolarPower/Models/Overview.cs | 17 ++++ .../Quartz/Jobs/CalcAvgPowerStationJob.cs | 12 +-- .../Implement/OverviewRepository.cs | 76 +++++++++++++++ .../Implement/PowerStationRepository.cs | 26 +++++ .../Interface/IOverviewRepository.cs | 2 +- .../StationOverviewInfo.cshtml | 96 +++++++++++++++++-- .../Views/StationOverview/_History.cshtml | 32 ++++--- 8 files changed, 277 insertions(+), 27 deletions(-) diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index aeb23e2..087b3be 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -358,5 +358,48 @@ namespace SolarPower.Controllers return result; } + + public async Task>> GetTotalTableToHistory(HistorySent post) + { + var History = new List(); + ApiResult> apiResult = new ApiResult>(); + var powerStation = await powerStationRepository.GetOneAsync(post.PowerstationId); + + try + { + History = await overviewRepository.GethistoryTable(post); + foreach(var a in History) + { + switch (post.GroupType) + { + case 0: + a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd"); + a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd hh:mm:ss"); + break; + case 1: + a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM"); + a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd"); + break; + case 2: + a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy"); + a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM"); + break; + case 3: + a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy"); + a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy"); + break; + } + } + apiResult.Code = "0000"; + apiResult.Data = History; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } } } diff --git a/SolarPower/Models/Overview.cs b/SolarPower/Models/Overview.cs index 0078567..2267772 100644 --- a/SolarPower/Models/Overview.cs +++ b/SolarPower/Models/Overview.cs @@ -125,5 +125,22 @@ namespace SolarPower.Models public double Value { get; set; } } + public class HistorySent + { + public int GroupType { get; set; } + public string HistoryRange { get; set; } + public int PowerstationId { get; set; } + } + public class HistoryTable + { + public string TIMESTAMP { get; set; } + public double KWH { get; set; } + public double SOLARHOUR { get; set; } + public double Irradiance { get; set; } + public double PR { get; set; } + public double Temp { get; set; } + public double DiffSOLARHOUR { get; set; } + public string TOTALTIME { get; set; } + } } diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index ea9684a..32d6173 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -110,12 +110,12 @@ namespace SolarPower.Quartz.Jobs pyrheliometerHistoryDays.Add(pyrheliometerHistorDay); } - //逆變器 - var inverterHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id); - if (inverterHistorDay != null) - { - inverterHistorDays.Add(inverterHistorDay); - } + ////逆變器 + //var inverterHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id); + //if (inverterHistorDay != null) + //{ + // inverterHistorDays.Add(inverterHistorDay); + //} #endregion #region step2-4. 計算這個月的所有值總和 diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 107c6d6..fe1285d 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -378,5 +378,81 @@ namespace SolarPower.Repository.Implement } } + public async Task> GethistoryTable(HistorySent post) + { + List result; + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + var kwh = ""; + var usedb = ""; + var pyrdb = ""; + var timeGroup = ""; + var range = ""; + switch(post.GroupType) + { + case 0: + kwh = "C.KWH"; + usedb = "power_station_history_hour"; + pyrdb = "pyrheliometer_history_hour"; + timeGroup = "%Y-%m-%d %H:%M:%S"; + range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m-%d') = '{post.HistoryRange}'"; + break; + case 1: + kwh = "C.TODAYKWH"; + usedb = "power_station_history_day"; + pyrdb = "pyrheliometer_history_day"; + timeGroup = "%Y-%m-%d"; + range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m') = '{post.HistoryRange}'"; + break; + case 2: + kwh = "C.MONTHKWH"; + usedb = "power_station_history_month"; + pyrdb = "pyrheliometer_history_month"; + timeGroup = "%Y-%m"; + range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y') = '{post.HistoryRange}'"; + break; + case 3: + kwh = "C.TOTALKWH"; + usedb = "power_station_history_month"; + pyrdb = "pyrheliometer_history_month"; + timeGroup = "%Y-%m"; + range = ""; + break; + } + + try + { + var sql = @$"SELECT *, SOLARHOUR-PSValue AS DiffSOLARHOUR + FROM + ( + SELECT B.*, IFNULL(A.SOLARHOUR,0) AS PSValue + FROM + ( + SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID + , (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID, + C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance + FROM {usedb} C + LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP + ) A + RIGHT OUTER JOIN + ( + SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID + , (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID, + C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance + FROM {usedb} C + LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP + ) B + ON A.ROWID = B.PreROWID + ) V {range}" ; + result = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 6417ad7..7fae249 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2203,6 +2203,32 @@ namespace SolarPower.Repository.Implement return result; } } + public async Task> GetListTempByPowerStationId(int powerStationId, string db_name) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT * + FROM {db_name}.device d + WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + UNION + SELECT d.* + FROM {db_name}.sharedevice sd + LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id + WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + "; + + result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } public async Task GetPyrheliometerHistoryPerHour(string dateTime, List deviceInfos) { diff --git a/SolarPower/Repository/Interface/IOverviewRepository.cs b/SolarPower/Repository/Interface/IOverviewRepository.cs index 4112297..38998cf 100644 --- a/SolarPower/Repository/Interface/IOverviewRepository.cs +++ b/SolarPower/Repository/Interface/IOverviewRepository.cs @@ -22,7 +22,7 @@ namespace SolarPower.Repository.Interface Task> GetListPowerIrradianceYearByPowerStationId(int powerStationId, string nowDay); Task> GetExceptionTable(ExceptionSent post); Task> GetInvertCheckBoxByPowerStationId(int powerStationId, string db_name); - Task> GetListInverterByPowerStationIdAndDate(int powerStationId, string nowDay); + Task> GethistoryTable(HistorySent post); } } diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index b41cd90..c9653ea 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -742,7 +742,6 @@ }, 'json'); //#endregion //#endregion - }); //#region 維修單運維人員(異常紀錄) var url_power_station_operation_personnel = "/PowerStation/GetOperationPersonnelSelectOptionList"; @@ -826,8 +825,8 @@ "type": "POST", "data": function (d) { d.id = stationId, - d.status = err_status, - d.range = $('#date-range-exception').val() + d.status = err_status, + d.range = $('#date-range-exception').val() }, "dataSrc": function (rel) { if (rel.data.code == "9999") { @@ -844,9 +843,12 @@ }); //#endregion - + //歷史第一個table + getTable(); }); + + //#region 產生檔案html function CreateRecodeFileBox(dom, value, show_del_btn) { var str = ""; @@ -1765,7 +1767,7 @@ document.getElementById("DateGet").style.display = "";//隱藏 document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏 - + $('#DateGet').val(''); groupType = type; break; case 1: @@ -1776,6 +1778,7 @@ document.getElementById("DateGet").style.display = "none";//隱藏 document.getElementById("MonthGet").style.display = "";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏 + $('#MonthGet').val(''); groupType = type; break; case 2: @@ -1786,6 +1789,7 @@ document.getElementById("DateGet").style.display = "none";//隱藏 document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "";//隱藏 + $('#YearGet').val(''); groupType = type; break; case 3: @@ -1797,6 +1801,8 @@ document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏 groupType = type; + historyRange = ''; + getTable(); break; default: console.log('壞掉了'); @@ -1860,10 +1866,86 @@ } //#endregion + $('#DateGet').on('change', function () { + historyRange = $('#DateGet').val(); + getTable(); + }); + + $('#MonthGet').on('change', function () { + historyRange = $('#MonthGet').val(); + getTable(); + }); + + $('#YearGet').on('change', function () { + $('#YearGet').val(today_format); + getTable(); + }); + function getTable() { - console.log(groupType); - console.log(historyRange); + if (historyRange == "") + { + var today = new Date(); + var today_format = today.toISOString().slice(0, 10).replace(/-/g, "-"); + $('#DateGet').val(today_format); + historyRange = $('#DateGet').val(); + } + + + var send_data = { + GroupType: groupType, + HistoryRange: historyRange, + PowerstationId: stationId + } + + var Nurl = "/StationOverview/GetTotalTableToHistory"; + $.post(Nurl, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#HistoryTotalTable').empty(); + $('#HistoryDetailTable').empty(); + var TimestampALL; + var kwhALL = 0; + var diffSOLARHOURALL = 0; + var irradianceALL = 0; + var prALL; + var tempALL; + $.each(rel.data, function (index, val) { + TimestampALL = val.totaltime; + kwhALL += val.kwh; + diffSOLARHOURALL += val.diffSOLARHOUR; + irradianceALL += val.irradiance; + prALL = val.pr; + tempALL = val.temp; + if (val.length != 0) { + $('#HistoryDetailTable').append('' + + '' + val.timestamp + '' + + '' + val.kwh + '' + + '' + val.diffSOLARHOUR + '' + + '' + val.irradiance + '' + + '' + val.pr + '' + + '' + val.temp + '' + + ''); + } + }) + if (rel.data.length == 0) { + $('#HistoryTotalTable').append('' + '' + '無資料' + '' + ''); + $('#HistoryDetailTable').append('' + '' + '無資料' + '' + ''); + } + else + { + $('#HistoryTotalTable').append('' + + '' + TimestampALL + '' + + '' + kwhALL + '' + + '' + diffSOLARHOURALL + '' + + '' + irradianceALL + '' + + '' + prALL + '' + + '' + tempALL + '' + + ''); + } + }) } diff --git a/SolarPower/Views/StationOverview/_History.cshtml b/SolarPower/Views/StationOverview/_History.cshtml index dbbd714..97d8927 100644 --- a/SolarPower/Views/StationOverview/_History.cshtml +++ b/SolarPower/Views/StationOverview/_History.cshtml @@ -59,20 +59,13 @@ 時間 發電量(kWh) 發電小時 - 日射量(kWh/m2) + 日照度(kWh/m2) PR(%) 溫度(℃) - - - 2021-05 - 126,121.7 - 119.04 - 140.39 - 84.8 - 91.9 - + + @@ -80,8 +73,21 @@
-
-
-

放圖表

+
詳細資訊
+ + + + + + + + + + + + + + +
時間發電量(kWh)發電小時日照度(kWh/m2)PR(%)溫度(℃)
\ No newline at end of file