From 69de707137d36ad755d31c7ba64b5814a262b3b4 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 4 Aug 2021 18:39:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StationReportController.cs | 23 +++++++++++++++---- SolarPower/Models/StationReport.cs | 2 +- .../Implement/StationReportRepository.cs | 23 +++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index acd4e08..0fa6c31 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -1192,11 +1192,24 @@ namespace SolarPower.Controllers return Path.Combine("\\" + "upload" ,"report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid+ Datename + ".xlsx"); } - //public async Task>> GetMaxForm (Select_table2 post) - //{ - - // return; - //} + public async Task>> GetMaxForm(Select_table2 post) + { + ApiResult> apiResult = new ApiResult>(); + List body = new List(); + try + { + var a = await stationReportRepository.GetMaxtablebody(post); + apiResult.Code = "0000"; + apiResult.Data = a; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】"); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } } } diff --git a/SolarPower/Models/StationReport.cs b/SolarPower/Models/StationReport.cs index 92d2d15..0905a32 100644 --- a/SolarPower/Models/StationReport.cs +++ b/SolarPower/Models/StationReport.cs @@ -85,7 +85,7 @@ namespace SolarPower.Models public string AreaName { get; set; } public string PowerstationName { get; set; } public int PowerstationId { get; set; } - public double Kwp { get; set; } + public double Kwh { get; set; } public string PowerstationDB { get; set; } public double SolarHour { get; set; } public double AvgIrradiance { get; set; } diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 871bac5..260a5de 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -232,5 +232,28 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task> GetMaxtablebody(Select_table2 post) + { + List result = new List(); + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + try + { + string sql = @$""; + result = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } } } From 31598b95f5d30712fff30fa1a6e322d7bc94c594 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Thu, 5 Aug 2021 15:46:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=B6=9C=E5=90=88=E5=A0=B1=E8=A1=A8(?= =?UTF-8?q?=E4=B8=8D=E5=90=AB=E5=8C=AF=E5=87=BA)=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/StationReport.cs | 1 + .../Implement/StationReportRepository.cs | 62 +++++++++- .../Interface/IStationReportRepository.cs | 1 + SolarPower/Views/StationReport/Index.cshtml | 116 ++++++++++++++++-- 4 files changed, 165 insertions(+), 15 deletions(-) diff --git a/SolarPower/Models/StationReport.cs b/SolarPower/Models/StationReport.cs index 0905a32..89ed921 100644 --- a/SolarPower/Models/StationReport.cs +++ b/SolarPower/Models/StationReport.cs @@ -90,6 +90,7 @@ namespace SolarPower.Models public double SolarHour { get; set; } public double AvgIrradiance { get; set; } public double AvgPR { get; set; } + public double AvgKWHKWP { get; set; } } diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 260a5de..f9b407f 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -241,8 +241,66 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = @$""; - result = (await conn.QueryAsync(sql)).ToList(); + List ids = new List(); + foreach (var i in post.PowerStation) + { + ids.Add(Convert.ToInt32(i.Value)); + } + string[] times = { }; + if(post.SearchType == 1) + { + times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a'); + } + + var wheretime = post.SearchType switch + { + 0 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') = '{post.Time}'", + 1 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'", + 2 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m') = '{post.Time}'", + 3 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y') = '{post.Time}'", + _ => "" + }; + string sql = @$"SELECT + c.Name AS 'CityName', + a.Name AS 'AreaName', + ps.Name AS 'PowerstationName', + ps.SiteDB AS 'PowerstationDB', + n.* + FROM power_station ps + LEFT JOIN city c ON c.Id = ps.CityId + LEFT JOIN area a ON a.Id = ps.AreaId + left JOIN + ( + SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,a.PowerStationId FROM + ( + SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d ') AS 'time', ps.PowerStationId + FROM power_station_history_hour ps + WHERE ps.PowerStationId IN @ids {wheretime} + GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') + ) a + left JOIN + ( + SELECT B.PR ,B.KWHKWP, DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM + ( + SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps + WHERE ps.PowerStationId IN @ids {wheretime} + GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') + ) A + LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP + ) b + ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(b.time,'%Y-%m-%d') + LEFT JOIN + ( + SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME + from sensor_history_hour ps + WHERE ps.PowerStationId IN @ids {wheretime} + GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') + ) c + ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(c.time,'%Y-%m-%d') + ) n + ON n.PowerStationId = ps.Id + WHERE ps.Id IN @ids ORDER BY ps.CityId"; + result = (await conn.QueryAsync(sql,new { ids = ids})).ToList(); } catch (Exception exception) { diff --git a/SolarPower/Repository/Interface/IStationReportRepository.cs b/SolarPower/Repository/Interface/IStationReportRepository.cs index 3988133..81de8fd 100644 --- a/SolarPower/Repository/Interface/IStationReportRepository.cs +++ b/SolarPower/Repository/Interface/IStationReportRepository.cs @@ -11,5 +11,6 @@ namespace SolarPower.Repository.Interface Task> GetInverterId(string DBname, Select_table post); Task Gettablebody(Select_table post); Task> GetHire(PsIdAndSiteDB post); + Task> GetMaxtablebody(Select_table2 post); } } diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index fa84ed5..19bef73 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -304,6 +304,7 @@ var a = $('#collapse').trigger("click"); //document.getElementById("collapse").click(); $('.overflow-auto').hide(); + $('#maxtable').hide(); $('#hiretable').hide(); $('#DateGet').val(new Date().toISOString().substring(0, 10)); document.getElementById("DateGettextdiv").style.display = "none";//隱藏 @@ -311,7 +312,7 @@ $('#DateGettext').attr('style', 'width:205px'); timerange = $('#DateGet').val(); document.getElementById("monthbtn").disabled = true;//月報表鎖定 - document.getElementById("yearbtn").disabled = true;//綜合報表鎖定 + document.getElementById("yearbtn").disabled = false;//綜合報表鎖定 document.getElementById("daybtn").disabled = false;//日報表鎖定 //#endregion @@ -336,7 +337,7 @@ var today = new Date().toISOString().substring(0, 10); $('#DateGet').val(today); document.getElementById("monthbtn").disabled = true;//月報表鎖定 - document.getElementById("yearbtn").disabled = true;//綜合報表鎖定 + document.getElementById("yearbtn").disabled = false;//綜合報表鎖定 document.getElementById("daybtn").disabled = false;//日報表鎖定 break; case 1: @@ -505,6 +506,9 @@ $('#selectOneStation').find('.btn-station').removeClass("btn-success").addClass("btn-outline-success"); } $(e).removeClass("btn-outline-success").addClass("btn-success"); + if (nowform != null && nowform != 2) { + Dateform(nowform); + } } //#endregion @@ -659,16 +663,14 @@ } $('#TableHead').empty(); var str = ""; - if (form != 2) { - $.each(rel.data.inv, function (index, inverter) { - haveinvertName.push(inverter); - str += "" + inverter + ""; - }) - } switch (form) { case 0: str += "Date"; + $.each(rel.data.inv, function (index, inverter) { + haveinvertName.push(inverter); + str += "" + inverter + ""; + }) str += "小時
發電量
(kWh)"; str += "小時
發電量
百分比
(%)"; str += "小時
平均
日照度
(W/㎡)"; @@ -679,6 +681,10 @@ break; case 1: str += "Date"; + $.each(rel.data.inv, function (index, inverter) { + haveinvertName.push(inverter); + str += "" + inverter + ""; + }) str += "日
發電量
(kWh)"; str += "日
發電量
百分比
(%)"; str += "日照小時(hr)"; @@ -711,15 +717,12 @@ } else { maxtableinfobody(rel.data.showMoney); } - - - }, 'json'); } function Dateform(form) { $('#hiretable').hide(); - + $('#maxtable').hide(); tablehand(form); } @@ -953,12 +956,99 @@ { SearchType: searchType, Time: timerange, - FormType: form, + FormType: 2, PowerStation: selecterd_invert } var url = "/StationReport/GetMaxForm"; + var StrInfoBody; + var CityArray = []; + var CityInfoBody; + var TotalHead; + var TotalBody; + var kwhkwp = 0; + var kwp = 0; $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_warning(rel.msg); + return; + } + //下方 + $.each(rel.data, function (index, data) { + var cityinfo = { + city: data.cityName, + kwp: data.kwh, + hour: data.solarHour, + count : 1 + } + if (CityArray.length == 0) { + CityArray.push(cityinfo); + } + else + { + var npush = true; + CityArray.filter(function (n, i) { + if (n.city == data.cityName) { + n.kwp += cityinfo.kwp; + n.hour += cityinfo.hour; + n.count += cityinfo.count; + npush = false; + } + }); + if (npush) { + CityArray.push(cityinfo); + } + } + + StrInfoBody += ""; + StrInfoBody += "" + data.cityName + data.areaName + ""; + StrInfoBody += "" + data.powerstationName + ""; + StrInfoBody += "" + data.kwh.toFixed(2) + ""; + StrInfoBody += "" + data.solarHour.toFixed(2) + ""; + StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; + StrInfoBody += "" + data.avgPR.toFixed(2) + ""; + StrInfoBody += ""; + kwp += data.kwh; + kwhkwp += data.avgKWHKWP; + + }) + //中間 + $.each(CityArray, function (index, data) { + CityInfoBody += ""; + CityInfoBody += "" + data.city + ""; + CityInfoBody += "" + (data.kwp / data.count).toFixed(2) + ""; + CityInfoBody += "" + (data.hour / data.count).toFixed(2) + ""; + CityInfoBody += ""; + }) + //上面 + //#region TotalHead + TotalHead += ""; + TotalHead += "" + "時間" + ""; + TotalHead += "" + "發電量" + ""; + TotalHead += "" + "有效日照時數" + ""; + TotalHead += ""; + //#endregion + //#region TotalBody + TotalBody += ""; + TotalBody += "" + timerange + ""; + TotalBody += "" + kwp.toFixed(2) + ""; + TotalBody += "" + (kwhkwp / rel.data.length).toFixed(2) + ""; + TotalBody += ""; + //#endregion + + $('#totbody').empty(); + $('#totbody').append(TotalBody); + + $('#tothead').empty(); + $('#tothead').append(TotalHead); + $('#TableBody').empty(); + $('#TableBody').append(StrInfoBody); + $('#maxtableBody').empty(); + $('#maxtableBody').append(CityInfoBody); + $('#maxtable').show(); + + $('.overflow-auto').show(); + nowform = 2; }) }