diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 86c2cbb..bddd8d7 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -801,6 +801,7 @@ namespace SolarPower.Quartz.Jobs for (; start_date <= end_date; start_date = start_date.AddDays(1)) { var day_str = start_date.ToString("yyyy-MM-dd"); + #region 歸檔 Sensor try { logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Sensor補償機制】", powerStation.Code, day_str); @@ -816,7 +817,9 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); } } + #endregion + #region 歸檔 電錶 try { logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Meter補償機制】", powerStation.Code, day_str); @@ -832,7 +835,9 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); } } + #endregion + #region 歸檔 Inv try { logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Inverter補償機制】", powerStation.Code, day_str); @@ -848,7 +853,9 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); } } + #endregion + #region 歸檔 Station hour try { logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Site補償機制】", powerStation.Code, day_str); @@ -864,6 +871,25 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); } } + #endregion + + #region 製作日報表 + try + { + logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的 日報表製作】", powerStation.Code, day_str); + invSvc.report_invDay(powerStation.Code, day_str); + logger.LogInformation("【CalcAvgPowerStationJob】【執行完成電站[{0}]在{1}的 日報表製作】", powerStation.Code, day_str); + } + catch (Exception exception) + { + logger.LogInformation("【CalcAvgPowerStationJob】【執行失敗電站[{0}]在{1}的 日報表製作】", powerStation.Code, day_str); + logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message); + if (exception.InnerException != null) + { + logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); + } + } + #endregion } } logger.LogInformation("【CalcAvgPowerStationJob】【執行完成補償機制】"); diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 596da1e..733906c 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -68,7 +68,7 @@ namespace SolarPower.Repository.Implement FROM report_invday a left join ( # day - select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, sitetype, round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, sitetype, round(TODAYKWH, 2) TODAYKWH, round(KWHKWP, 2) KWHKWP , round(PR, 2) PR, round(money, 2) money , round(SOLARHOUR, 2) SOLARHOUR from power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{post.Time}'' @@ -315,6 +315,11 @@ namespace SolarPower.Repository.Implement } } + /// + /// 綜合報表 + /// + /// + /// public async Task> GetMaxtablebody(Select_table2 post) { List result = new List(); @@ -342,57 +347,82 @@ namespace SolarPower.Repository.Implement 3 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y') = '{post.Time}' AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') != '{DateTime.Now.ToString("yyyy-MM-dd")}'", _ => "" }; - string sql = @$"SELECT - c.Name AS 'CityName', - a.Name AS 'AreaName', - ps.Name AS 'PowerstationName', - ps.SiteDB AS 'PowerstationDB', - ps.SolarType AS 'PowerstationType', - ps.Id as 'PowerStationId', - 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 a.SolarHour ,a.Kwh ,b.PR AvgPR,b.KWHKWP AvgKWHKWP,c.Irradiance AvgIrradiance,b.TodayMoney as 'TodayMoney',a.Id,a.time,a.maxtime,a.mintime FROM - ( - SELECT ps.Id,SUM(k.SolarHour) SolarHour,SUM(k.Kwh) Kwh , k.time , max(k.maxtime) maxtime ,min(k.mintime) mintime FROM power_station ps - LEFT JOIN - ( - SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i') AS 'time',MAX(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'maxtime',MIN(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'mintime', ps.PowerStationId - FROM power_station_history_hour ps - WHERE ps.PowerStationId IN @ids {wheretime} - GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId - ) k ON k.PowerStationId = ps.Id WHERE ps.Id IN @ids GROUP BY k.PowerStationId - ) a - LEFT JOIN - ( - SELECT ps.Id,AVG(n.PR) PR,AVG(n.KWHKWP) KWHKWP,SUM(n.TodayMoney) TodayMoney FROM power_station ps - LEFT JOIN - ( - SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') 'time' ,B.PowerStationId 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'),ps.PowerStationId - ) A - LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP - GROUP BY B.PowerStationId ,DATE_FORMAT(A.bb,'%Y-%m-%d') - )n ON ps.Id = n.PowerStationId WHERE ps.Id IN @ids GROUP BY n.PowerStationId - ) b - ON a.Id = b.Id - LEFT JOIN - ( - SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME ,ps.PowerStationId - from sensor_history_hour ps - WHERE ps.PowerStationId IN @ids {wheretime} - GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId - ) c - ON a.Id = c.PowerStationId - GROUP BY a.Id,a.time - ) n ON n.Id = ps.Id - WHERE ps.Id IN @ids ORDER BY ps.CityId"; + //string sql = @$"SELECT + // c.Name AS 'CityName', + // a.Name AS 'AreaName', + // ps.Name AS 'PowerstationName', + // ps.SiteDB AS 'PowerstationDB', + // ps.SolarType AS 'PowerstationType', + // ps.Id as 'PowerStationId', + // 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 a.SolarHour ,a.Kwh ,b.PR AvgPR,b.KWHKWP AvgKWHKWP,c.Irradiance AvgIrradiance,b.TodayMoney as 'TodayMoney',a.Id,a.time,a.maxtime,a.mintime FROM + // ( + // SELECT ps.Id,SUM(k.SolarHour) SolarHour,SUM(k.Kwh) Kwh , k.time , max(k.maxtime) maxtime ,min(k.mintime) mintime FROM power_station ps + // LEFT JOIN + // ( + // SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i') AS 'time',MAX(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'maxtime',MIN(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'mintime', ps.PowerStationId + // FROM power_station_history_hour ps + // WHERE ps.PowerStationId IN @ids {wheretime} + // GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId + // ) k ON k.PowerStationId = ps.Id WHERE ps.Id IN @ids GROUP BY k.PowerStationId + // ) a + // LEFT JOIN + // ( + // SELECT ps.Id,AVG(n.PR) PR,AVG(n.KWHKWP) KWHKWP,SUM(n.TodayMoney) TodayMoney FROM power_station ps + // LEFT JOIN + // ( + // SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') 'time' ,B.PowerStationId 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'),ps.PowerStationId + // ) A + // LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP + // GROUP BY B.PowerStationId ,DATE_FORMAT(A.bb,'%Y-%m-%d') + // )n ON ps.Id = n.PowerStationId WHERE ps.Id IN @ids GROUP BY n.PowerStationId + // ) b + // ON a.Id = b.Id + // LEFT JOIN + // ( + // SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME ,ps.PowerStationId + // from sensor_history_hour ps + // WHERE ps.PowerStationId IN @ids {wheretime} + // GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId + // ) c + // ON a.Id = c.PowerStationId + // GROUP BY a.Id,a.time + // ) n ON n.Id = ps.Id + // WHERE ps.Id IN @ids ORDER BY ps.CityId"; + string sql = $@"SELECT ct.`Name` AS 'CityName', ar.Name AS 'AreaName', ps.Name AS 'PowerstationName', ps.SiteDB AS 'PowerstationDB', ps.SolarType AS 'PowerstationType', + ps.Id as 'PowerStationId', + a.SolarHour ,a.Kwh ,a.PR AvgPR, a.KWHKWP AvgKWHKWP,c.Irradiance AvgIrradiance, + (a.TODAYKWH * PowerRate) 'TodayMoney', a.Id,a.time,a.maxtime,a.mintime + FROM power_station ps + LEFT JOIN city ct ON ct.Id = ps.CityId + LEFT JOIN area ar ON ar.Id = ps.AreaId + left JOIN + ( + SELECT powerStationid id, ps.SOLARHOUR AS 'SolarHour',ps.TODAYKWH 'Kwh' , PR, KWHKWP, TODAYKWH, + DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS 'time', + MAX(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'maxtime', + MIN(DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i')) AS 'mintime', ps.PowerStationId + FROM power_station_history_day ps + WHERE ps.PowerStationId IN @ids {wheretime} + GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId + ) a ON ps.Id = a.Id + LEFT JOIN + ( + SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME ,ps.PowerStationId + from sensor_history_hour ps + WHERE ps.PowerStationId IN @ids {wheretime} + GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId + ) c ON a.Id = c.PowerStationId and a.time = c.time + WHERE ps.Id IN @ids ORDER BY ps.CityId"; result = (await conn.QueryAsync(sql,new { ids = ids}, commandTimeout: 300)).ToList(); } catch (Exception exception) diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 57e6ecf..4e427b0 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -751,20 +751,16 @@ $("#year2btn").html('年報表').attr("disabled", false); $(".btn-station").attr("disabled", false); break; - } - - + } return; } - - - + $('#TableHead').empty(); var str = ""; switch (form) { - case 0: + case 0: // 日報 str += "Date"; $.each(rel.data.inv, function (index, inverter) { haveinvertName.push(inverter); @@ -778,7 +774,7 @@ str += "小時
售電
金額
(NTD)"; } break; - case 1: + case 1: // 月報 str += "Date"; $.each(rel.data.inv, function (index, inverter) { haveinvertName.push(inverter); @@ -795,7 +791,7 @@ str += "日
售電金額
(NTD)"; } break; - case 2: + case 2: //綜合報表 str += "區域"; str += "電站名稱"; str += "發電量"; @@ -828,9 +824,12 @@ } str += ""; $('#TableHead').append(str); + if (form != 2) { + // 日月年 報 tablebody(form, rel.data.showMoney); } else { + //綜合報表 maxtableinfobody(rel.data.showMoney); } }, 'json'); @@ -932,8 +931,8 @@ }); sta += "" + Number(inverter.hourKWH) + ""; sta += "" + Number(inverter.hourKWHp) + ""; - sta += "" + Number(inverter.irradiance) + ""; - sta += "" + Number(inverter.temperature) + ""; + sta += "" + Number(inverter.irradiance) + ""; // body 小時平均日照度 + sta += "" + Number(inverter.temperature) + ""; //body 小時平均模組溫度 if (showmoney == 1) { sta += "" + toThousands(Math.round(Number(inverter.hourmoney))) + ""; } @@ -941,7 +940,7 @@ thour = inverter.tothour ? inverter.tothour.toFixed(2) : 0; tpr = inverter.pr ? inverter.pr.toFixed(2) : 0; tkwh = inverter.totKWH ? inverter.totKWH.toFixed(2) : 0; - kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0; + kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0; // 日報 有效發電小時 ntd = inverter.totmoney ? Math.round(inverter.totmoney) : 0; ntdone = inverter.totmoney / inverter.totKWH ? Math.round(inverter.totmoney / inverter.totKWH * 10000) / 10000 : 0; GeneratingCapacity = inverter.GeneratingCapacity; @@ -961,8 +960,8 @@ var stb = ""; /* stb += "" + thour + "";*/ - stb += "" + kWhkwp + ""; - stb += "" + tpr + ""; + stb += "" + kWhkwp + ""; //header - 有效發電小時 + stb += "" + tpr + ""; // stb += "" + tkwh + ""; stb += "" + GeneratingCapacity + ""; if (showmoney == 1) { @@ -1274,7 +1273,7 @@ } } } - + // 綜合報表 function maxtableinfobody(showmoney) { var send_data = @@ -1320,9 +1319,6 @@ mintime = data.mintime; } - - - var hirerate = 0; if (data.powerstationType == 1) { @@ -1358,11 +1354,11 @@ StrInfoBody += ""; - StrInfoBody += "" + data.cityName + data.areaName + ""; + StrInfoBody += "" + data.cityName + data.areaName + ""; StrInfoBody += "" + data.powerstationName + ""; - StrInfoBody += "" + data.kwh.toFixed(2) + ""; - StrInfoBody += "" + data.avgKWHKWP.toFixed(2) + ""; - StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; + StrInfoBody += "" + data.kwh.toFixed(2) + ""; // 發電量 + StrInfoBody += "" + data.avgKWHKWP.toFixed(2) + ""; // 有效發電小時 + StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; // 平均日照 StrInfoBody += "" + data.avgPR.toFixed(2) + ""; if (showmoney == 1) { diff --git a/SolarPower/appsettings.Development.json b/SolarPower/appsettings.Development.json index 2949b04..67ee146 100644 --- a/SolarPower/appsettings.Development.json +++ b/SolarPower/appsettings.Development.json @@ -8,21 +8,21 @@ }, "LoginExpireMinute": 60, //nJɶA() "GoBackDay": 1, //v(I(C))A^Ѽ - "DBConfig": { - "Server": "MVgHWzR3rGDgD57TUoFunA==", - "port": "r4AoXMUDodcQjIzofGNCcg==", - "Database": "z8TVtiXZ6MwgWbUEAOXA/fiHzd7c0iUhFqn1mHzxhKo=", - "Root": "mWlR2HshQNhRRE34jg4kdg==", - "Password": "y4uPqlH9ncTgR/I07qpwaA==" - }, - "mySql": "server=210.61.91.43;user=idafenweb;Database=solar_master;Port=10068;password=P@ssw0rd;charset='utf8';pooling=true;sslmode=none;", //"DBConfig": { - // "Server": "AVXfxd+IRlLtJ0MCi9HU1g==", - // "port": "CrEmevYrUsSo7Mkb7Gxn8A==", - // "Database": "CEyYZnO8B5+yTXQcFSsiBA==", - // "Root": "Aph7AzoiwAmmBHCfS1rqeQ==", - // "Password": "8WMHBEWuT0XoAB4kzduQHA==" + // "Server": "MVgHWzR3rGDgD57TUoFunA==", + // "port": "r4AoXMUDodcQjIzofGNCcg==", + // "Database": "z8TVtiXZ6MwgWbUEAOXA/fiHzd7c0iUhFqn1mHzxhKo=", + // "Root": "mWlR2HshQNhRRE34jg4kdg==", + // "Password": "y4uPqlH9ncTgR/I07qpwaA==" //}, + "mySql": "server=210.61.91.43;user=idafenweb;Database=solar_master;Port=10068;password=P@ssw0rd;charset='utf8';pooling=true;sslmode=none;", + "DBConfig": { + "Server": "AVXfxd+IRlLtJ0MCi9HU1g==", + "port": "CrEmevYrUsSo7Mkb7Gxn8A==", + "Database": "CEyYZnO8B5+yTXQcFSsiBA==", + "Root": "Aph7AzoiwAmmBHCfS1rqeQ==", + "Password": "8WMHBEWuT0XoAB4kzduQHA==" + }, "BackgroundServiceCron": { "CalcPowerStationJob": "0 5 * * * ?", "CalcAvgPowerStationJob": "0 0 2 * * ?", diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 67f15af..dacc466 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -107,7 +107,7 @@ namespace solarApp.Service clearData(); insert_inv(); //日報表 - insert_report_invDay(); //get_ck_invDay_list + //insert_report_invDay(); //get_ck_invDay_list return result; }