diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index b5d7f5a..409e1e2 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -266,7 +266,7 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; - var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; + var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = "";var GeneratingCapacity = ""; foreach (dynamic body in Formbody.Result.Data) { index = 0; @@ -276,13 +276,14 @@ namespace SolarPower.Controllers tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); + GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); if (double.IsNaN(onemoney)) { onemoney = 0; } - ntdone = Checknull(Math.Round(onemoney, 2).ToString()); + ntdone = Checknull(Math.Round(onemoney, 4).ToString()); row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -328,20 +329,20 @@ namespace SolarPower.Controllers #region 顯示總量//RowPosition = body + 2 RowPosition += 2;//空兩行 - index = 0; - row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue("日照小時:"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue(Convert.ToDouble(thour)); - cell.CellStyle = styleLine12; - RowPosition++; + //index = 0; + //row = sheet.CreateRow(RowPosition); + //cell = row.CreateCell(index); + //cell.SetCellValue("日照小時:"); + //cell.CellStyle = styleLine12; + //cell = row.CreateCell(1); + //cell.SetCellValue(Convert.ToDouble(thour)); + //cell.CellStyle = styleLine12; + //RowPosition++; index = 0; row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); - cell.SetCellValue("kWH/kWP:"); + cell.SetCellValue("有效發電小時:"); cell.CellStyle = styleLine12; cell = row.CreateCell(1); cell.SetCellValue(Convert.ToDouble(kWhkwp)); @@ -369,6 +370,15 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; RowPosition++; + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("裝置容量:"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue(Convert.ToDouble(GeneratingCapacity)); + cell.CellStyle = styleLine12; + RowPosition++; if (Formhead.Result.Data.ShowMoney == 1) { @@ -422,7 +432,7 @@ namespace SolarPower.Controllers "日照小時(hr)", "有效發電小時", "PR%", - "日平均日照度(W/㎡)", + "累積日照量(kWh)", "日平均模組溫度(°C)" }; @@ -443,6 +453,7 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; var avghour = "0"; var avgKWHKWP = "0"; var avgdayKWH = "0"; var monthKWH = "0"; var monthmoney = "0"; var monthmoneyone = "0"; + var monthGeneratingCapacity = ""; var check_hire = false; var sitedb = ""; foreach (dynamic body in Formbody.Result.Data) @@ -456,6 +467,7 @@ namespace SolarPower.Controllers monthKWH = dbody["monthKWH"] == null ? "0": dbody["monthKWH"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); + monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; @@ -481,7 +493,7 @@ namespace SolarPower.Controllers "tothour", "KWHKWP", "PR", - "irradiance", + "IrrDay", "temperature" }; if (Formhead.Result.Data.ShowMoney == 1) @@ -513,12 +525,12 @@ namespace SolarPower.Controllers var Useday = Formbody.Result.Data.Count; row = sheet.CreateRow(RowPosition); + //cell = row.CreateCell(index); + //cell.SetCellValue("日照平均(日)"); + //cell.CellStyle = styleLine12; + //index++; cell = row.CreateCell(index); - cell.SetCellValue("日照平均(日)"); - cell.CellStyle = styleLine12; - index++; - cell = row.CreateCell(index); - cell.SetCellValue("平均有效發電小時(日)"); + cell.SetCellValue("有效發電小時(日)"); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -529,6 +541,14 @@ namespace SolarPower.Controllers cell.SetCellValue("發電量(kWh)(月)"); cell.CellStyle = styleLine12; index++; + cell = row.CreateCell(index); + cell.SetCellValue("裝置容量"); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue("每度獲利"); + cell.CellStyle = styleLine12; + index++; if (Formhead.Result.Data.ShowMoney == 1) { cell = row.CreateCell(index); @@ -550,10 +570,10 @@ namespace SolarPower.Controllers RowPosition++; row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(avghour)/Useday,2)); - cell.CellStyle = styleLine12; - index++; + //cell = row.CreateCell(index); + //cell.SetCellValue(Math.Round(Convert.ToDouble(avghour)/Useday,2)); + //cell.CellStyle = styleLine12; + //index++; cell = row.CreateCell(index); cell.SetCellValue(Math.Round(Convert.ToDouble(avgKWHKWP) / Useday,2)); cell.CellStyle = styleLine12; @@ -566,6 +586,14 @@ namespace SolarPower.Controllers cell.SetCellValue(Convert.ToDouble(monthKWH)); cell.CellStyle = styleLine12; index++; + cell = row.CreateCell(index); + cell.SetCellValue(Convert.ToDouble(monthGeneratingCapacity)); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthKWH)/Convert.ToDouble(monthGeneratingCapacity),3) ); + cell.CellStyle = styleLine12; + index++; if (Formhead.Result.Data.ShowMoney == 1) { cell = row.CreateCell(index); @@ -573,7 +601,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); cell.CellStyle = styleLine12; index++; } @@ -1066,7 +1094,7 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; - var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; + var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; var GeneratingCapacity = ""; foreach (dynamic body in Formbody.Result.Data) { index = 0; @@ -1076,13 +1104,14 @@ namespace SolarPower.Controllers tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); + GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); if (double.IsNaN(onemoney)) { onemoney = 0; } - ntdone = Checknull(Math.Round(onemoney, 2).ToString()); + ntdone = Checknull(Math.Round(onemoney, 4).ToString()); row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -1128,15 +1157,15 @@ namespace SolarPower.Controllers #region 顯示總量//RowPosition = body + 2 RowPosition += 2;//空兩行 - index = 0; - row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue("日照小時:"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue(!string.IsNullOrEmpty(thour)? Convert.ToDouble(thour) : 0); - cell.CellStyle = styleLine12; - RowPosition++; + //index = 0; + //row = sheet.CreateRow(RowPosition); + //cell = row.CreateCell(index); + //cell.SetCellValue("日照小時:"); + //cell.CellStyle = styleLine12; + //cell = row.CreateCell(1); + //cell.SetCellValue(!string.IsNullOrEmpty(thour)? Convert.ToDouble(thour) : 0); + //cell.CellStyle = styleLine12; + //RowPosition++; index = 0; row = sheet.CreateRow(RowPosition); @@ -1169,6 +1198,16 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; RowPosition++; + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("裝置容量:"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue(Convert.ToDouble(GeneratingCapacity)); + cell.CellStyle = styleLine12; + RowPosition++; + if (Formhead.Result.Data.ShowMoney == 1) { @@ -1222,7 +1261,7 @@ namespace SolarPower.Controllers "日照小時(hr)", "有效發電小時", "PR%", - "日平均日照度(W/㎡)", + "累積日照量(kWh)", "日平均模組溫度(°C)" }; @@ -1243,6 +1282,7 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; var avghour = "0"; var avgKWHKWP = "0"; var avgdayKWH = "0"; var monthKWH = "0"; var monthmoney = "0"; var monthmoneyone = "0"; + var monthGeneratingCapacity = ""; var check_hire = false; var sitedb = ""; foreach (dynamic body in Formbody.Result.Data) @@ -1256,6 +1296,7 @@ namespace SolarPower.Controllers monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); + monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; @@ -1281,7 +1322,7 @@ namespace SolarPower.Controllers "tothour", "KWHKWP", "PR", - "irradiance", + "IrrDay", "temperature" }; if (Formhead.Result.Data.ShowMoney == 1) @@ -1313,20 +1354,28 @@ namespace SolarPower.Controllers var Useday = Formbody.Result.Data.Count; row = sheet.CreateRow(RowPosition); + //cell = row.CreateCell(index); + //cell.SetCellValue("日日照小時平均"); + //cell.CellStyle = styleLine12; + //index++; cell = row.CreateCell(index); - cell.SetCellValue("日日照小時平均"); + cell.SetCellValue("有效發電小時(日)"); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue("日kWH/kWP平均"); + cell.SetCellValue("發電量平均(kWh)(日)"); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue("日發電量平均(kWh)"); + cell.SetCellValue("發電量(kWh)(月)"); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue("月發電量(kWh)"); + cell.SetCellValue("裝置容量"); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue("每度獲利"); cell.CellStyle = styleLine12; index++; if (Formhead.Result.Data.ShowMoney == 1) @@ -1350,10 +1399,10 @@ namespace SolarPower.Controllers RowPosition++; row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(avghour) / Useday, 2)); - cell.CellStyle = styleLine12; - index++; + //cell = row.CreateCell(index); + //cell.SetCellValue(Math.Round(Convert.ToDouble(avghour) / Useday, 2)); + //cell.CellStyle = styleLine12; + //index++; cell = row.CreateCell(index); cell.SetCellValue(Math.Round(Convert.ToDouble(avgKWHKWP) / Useday, 2)); cell.CellStyle = styleLine12; @@ -1366,6 +1415,14 @@ namespace SolarPower.Controllers cell.SetCellValue(Convert.ToDouble(monthKWH)); cell.CellStyle = styleLine12; index++; + cell = row.CreateCell(index); + cell.SetCellValue(Convert.ToDouble(monthGeneratingCapacity)); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity), 3)); + cell.CellStyle = styleLine12; + index++; if (Formhead.Result.Data.ShowMoney == 1) { cell = row.CreateCell(index); @@ -1373,7 +1430,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); cell.CellStyle = styleLine12; index++; } diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 1de20d6..1111802 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -56,46 +56,35 @@ namespace SolarPower.Repository.Implement case 0: sql += @$" SET @sql = NULL; - SELECT - GROUP_CONCAT(DISTINCT - CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 2), '''') - ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{post.Time}'; - SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, - ', b.KWH hourKWH, round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' and powerstationid = {post.PowerStation}))*100,2) ''hourKWHp'', d.irradiance ''irradiance'', d.Temperature ''temperature'', - b.money ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(b.PR, 2) as pr - FROM inverter_history_hour a left join - ( # 每小時加總 inv - select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') report_date, siteid, sitetype, round(KWH, 2) KWH, - round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money - from power_station_history_hour - where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{post.Time}'' - ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.`TIMESTAMP`,''%Y-%m-%d %H:%i'') = b.report_date - left join - ( # day - 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}'' - ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.`TIMESTAMP`,''%Y-%m-%d'') = c.report_date - left join - ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:00'')report_date, irradiance, Temperature - from sensor_history_hour - where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{post.Time}'' - ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:00'') = d.report_date - join - ( - select id, name stationName, powerRate from power_station where id = {post.PowerStation} - )z on a.powerstationid = z.id - where DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' - GROUP BY DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d %H:%i'') - order by DATE_FORMAT(a.`TIMESTAMP`,''%Y-%m-%d %H:%i'') '); + SELECT + GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2)) INTO @sql + from v_company_inv v + LEFT JOIN power_station p ON p.Code = left(inverterid, 9) + WHERE p.Id = {post.PowerStation} AND v.enabled = 1 ; + + SET @sql = CONCAT('SELECT DATE_FORMAT(a.report_date,''%m-%d %H'') report_date, ', @SQL, + ', a.hourKWH hourKWH, a.hourKWHp ''hourKWHp'', a.irradiance ''irradiance'', a.Temperature ''temperature'', + a.hourmoney ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(a.PR, 2) as pr,GeneratingCapacity + 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 + , 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}'' + ) c on a.PowerStationID = c.powerStationid and DATE_FORMAT(a.`report_date`,''%Y-%m-%d'') = c.report_date + join + ( + select id, name stationName, powerRate,GeneratingCapacity from power_station where id = {post.PowerStation} + )z on a.PowerStationID = z.id + where DATE_FORMAT(a.report_date,''%Y-%m-%d'') = ''{post.Time}'' and a.PowerStationID = {post.PowerStation} + GROUP BY DATE_FORMAT(a.report_date,''%Y-%m-%d %H:%i'') + order by DATE_FORMAT(a.report_date,''%Y-%m-%d %H:%i'') '); - #select @sql as 'mySelect'; #顯示動態語法 - PREPARE stmt FROM @sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt;"; + #select @sql as 'mySelect'; #顯示動態語法 + PREPARE stmt FROM @sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt;"; break; case 1: if(post.SearchType == 2) @@ -108,9 +97,9 @@ namespace SolarPower.Repository.Implement ) INTO @sql FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, - ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, + ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR,z.GeneratingCapacity, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', - c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB + c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB,d.IrrDay FROM inverter_history_day a left join ( # 每日加總 inv select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, @@ -127,13 +116,13 @@ namespace SolarPower.Repository.Implement ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = c.report_date left join ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature ,IrrDay from sensor_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m'') = ''{post.Time}'' ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = d.report_date join ( - select id, name stationName, powerRate,SolarType,SiteDB from power_station where id = {post.PowerStation} + select id, name stationName, powerRate,SolarType,SiteDB,GeneratingCapacity from power_station where id = {post.PowerStation} )z on a.powerstationid = z.id where DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = ''{post.Time}'' GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') @@ -155,9 +144,9 @@ namespace SolarPower.Repository.Implement ) INTO @sql FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, - ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, + ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR,GeneratingCapacity, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', - c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB + c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB ,d.IrrDay FROM inverter_history_day a left join ( # 每日加總 inv select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, @@ -176,13 +165,13 @@ namespace SolarPower.Repository.Implement ) c on a.powerStationid = c.powerStationid left join ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature ,IrrDay from sensor_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = d.report_date join ( - select id, name stationName, powerRate, SolarType, SiteDB from power_station where id = {post.PowerStation} + select id, name stationName, powerRate, SolarType, SiteDB,GeneratingCapacity from power_station where id = {post.PowerStation} )z on a.powerstationid = z.id where DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') @@ -204,7 +193,7 @@ namespace SolarPower.Repository.Implement ) INTO @sql FROM inverter_history_month where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%Y/%m'') report_date, ', @sql, - ',b.todayKWH ''dayKWH'', round((b.todayKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', c.PR, + ',b.todayKWH ''dayKWH'', round((b.todayKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB FROM inverter_history_month a left join @@ -431,47 +420,36 @@ namespace SolarPower.Repository.Implement { case 0: sql = @$" - SET @sql = NULL; - SELECT - GROUP_CONCAT(DISTINCT - CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 2), '''') - ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{post.Time}'; - SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, - ', b.KWH hourKWH, round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' and powerstationid = {post.PowerStation}))*100,2) ''hourKWHp'', d.irradiance ''irradiance'', d.Temperature ''temperature'', - b.money ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(b.PR, 2) as pr - FROM inverter_history_hour a left join - ( # 每小時加總 inv - select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') report_date, siteid, sitetype, round(KWH, 2) KWH, - round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money - from power_station_history_hour - where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{post.Time}'' - ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.`TIMESTAMP`,''%Y-%m-%d %H:%i'') = b.report_date - left join - ( # day - 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}'' - ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = c.report_date - left join - ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'')report_date, irradiance, Temperature - from sensor_history_hour - where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' - ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:%i'') = d.report_date - join - ( - select id, name stationName, powerRate from power_station where id = {post.PowerStation} - )z on a.powerstationid = z.id - where DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' - GROUP BY DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') - order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:%i'') '); + SET @sql = NULL; + SELECT + GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2)) INTO @sql + from v_company_inv v + LEFT JOIN power_station p ON p.Code = left(inverterid, 9) + WHERE p.Id = {post.PowerStation} AND v.enabled = 1 ; + + SET @sql = CONCAT('SELECT DATE_FORMAT(a.report_date,''%m-%d %H'') report_date, ', @SQL, + ', a.hourKWH hourKWH, a.hourKWHp ''hourKWHp'', a.irradiance ''irradiance'', a.Temperature ''temperature'', + a.hourmoney ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(a.PR, 2) as pr,GeneratingCapacity + 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 + , 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}'' + ) c on a.PowerStationID = c.powerStationid and DATE_FORMAT(a.`report_date`,''%Y-%m-%d'') = c.report_date + join + ( + select id, name stationName, powerRate,GeneratingCapacity from power_station where id = {post.PowerStation} + )z on a.PowerStationID = z.id + where DATE_FORMAT(a.report_date,''%Y-%m-%d'') = ''{post.Time}'' and + GROUP BY DATE_FORMAT(a.report_date,''%Y-%m-%d %H:%i'') + order by DATE_FORMAT(a.report_date,''%Y-%m-%d %H:%i'') '); - select @sql as 'mySelect'; #顯示動態語法 - #PREPARE stmt FROM @sql; - #EXECUTE stmt; - #DEALLOCATE PREPARE stmt;"; + select @sql as 'mySelect'; #顯示動態語法 + #PREPARE stmt FROM @sql; + #EXECUTE stmt; + #DEALLOCATE PREPARE stmt;"; break; case 1: if (post.SearchType == 2) diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 3b2739e..d89eef8 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -785,7 +785,7 @@ str += "日照小時(hr)"; str += "有效發電小時"; str += "PR%"; - str += "日
平均
日照度
(W/㎡)"; + str += "累積日照量(kWh)"; str += "日
平均
模組溫度
(°C)"; if (rel.data.showMoney == 1) { str += "日
售電金額
(NTD)"; @@ -913,6 +913,7 @@ var ntd = 0; var ntdone = 0; var sta = ""; + var GeneratingCapacity = 0; $.each(rel.data, function (index, inverter) { sta += ""; sta += "" + inverter.report_date + ""; @@ -928,7 +929,7 @@ sta += "" + Number(inverter.irradiance) + ""; sta += "" + Number(inverter.temperature) + ""; if (showmoney == 1) { - sta += "" + Math.round(Number(inverter.hourmoney)) + ""; + sta += "" + toThousands(Math.round(Number(inverter.hourmoney))) + ""; } sta += ""; thour = inverter.tothour ? inverter.tothour.toFixed(2) : 0; @@ -936,13 +937,15 @@ tkwh = inverter.totKWH ? inverter.totKWH.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) : 0; + ntdone = inverter.totmoney / inverter.totKWH ? Math.round(inverter.totmoney / inverter.totKWH * 10000) / 10000 : 0; + GeneratingCapacity = inverter.GeneratingCapacity; }) var stc = ""; - stc += "" + '日照小時' + ""; +/* stc += "" + '日照小時' + "";*/ stc += "" + '有效發電小時' + ""; stc += "" + 'PR%' + ""; stc += "" + '日發電量(kWh)' + ""; + stc += "" + '裝置容量' + ""; if (showmoney == 1) { stc += "" + '日售電金額(NTD)' + ""; stc += "" + '日售電單價(NTD)' + ""; @@ -951,13 +954,14 @@ var stb = ""; - stb += "" + thour + ""; +/* stb += "" + thour + "";*/ stb += "" + kWhkwp + ""; stb += "" + tpr + ""; stb += "" + tkwh + ""; + stb += "" + GeneratingCapacity + ""; if (showmoney == 1) { - stb += "" + Math.round(ntd) + ""; - stb += "" + Math.round(ntdone) + ""; + stb += "" + toThousands(Math.round(ntd)) + ""; + stb += "" + Math.round(ntdone * 10000) / 10000 + ""; } stb += ""; @@ -979,6 +983,7 @@ var sta = ""; var check_hire = false; var sitedb = ""; + var GeneratingCapacity = 0; $.each(rel.data, function (index, inverter) { sta += ""; sta += "" + inverter.report_date + ""; @@ -994,10 +999,10 @@ sta += "" + inverter.tothour + ""; sta += "" + inverter.KWHKWP + ""; sta += "" + ((inverter.PR == null) ? 0 : inverter.PR.toFixed(2)) + ""; - sta += "" + inverter.irradiance + ""; + sta += "" + ((inverter.IrrDay == null) ? 0 : inverter.IrrDay) + ""; sta += "" + inverter.temperature + ""; if (showmoney == 1) { - sta += "" + Math.round(inverter.soldmoney) + ""; + sta += "" + toThousands(Math.round(inverter.soldmoney)) + ""; } sta += ""; avghour += inverter.tothour ? inverter.tothour : 0; @@ -1011,16 +1016,18 @@ check_hire = true; sitedb = inverter.SiteDB } - + GeneratingCapacity = inverter.GeneratingCapacity; }) monthday = rel.data.length; var stc = ""; - stc += "" + '日照平均(日)' + ""; + /*stc += "" + '日照平均(日)' + "";*/ stc += "" + '有效發電小時(日)' + ""; stc += "" + '發電量平均(kWh)(日)' + ""; stc += "" + '發電量(kWh)(月)' + ""; + stc += "" + '裝置容量' + ""; + stc += "" + '每度獲利' + ""; if (showmoney == 1) { stc += "" + '售電金額(NTD)(月)' + ""; stc += "" + '售電單價(NTD)(月)' + ""; @@ -1042,13 +1049,16 @@ stb += ""; } else { - stb += "" + (avghour / monthday).toFixed(2) + ""; + /*stb += "" + (avghour / monthday).toFixed(2) + "";*/ stb += "" + (avgKWHKWP / monthday).toFixed(2) + ""; stb += "" + (avgdayKWH / monthday).toFixed(2) + ""; stb += "" + monthKWH + ""; + stb += "" + GeneratingCapacity + ""; + stb += "" + (monthKWH / GeneratingCapacity).toFixed(3) + ""; if (showmoney == 1) { - stb += "" + Math.round(monthmoney) + ""; - stb += "" + Math.round(monthmoneyone / monthday) + ""; + + stb += "" + toThousands(Math.round(monthmoney)) + ""; + stb += "" + Math.round(monthmoneyone / monthday*10000)/10000 + ""; } stb += "" + monthday + ""; stb += ""; @@ -1071,8 +1081,8 @@ std += ""; std += "" + value.landowner + ""; std += "" + value.leaseRate + "%" + ""; - std += "" + Math.round(monthmoney * value.leaseRate / 100) + ""; - std += "" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + ""; + std += "" + toThousands(Math.round(monthmoney * value.leaseRate / 100)) + ""; + std += "" + toThousands(Math.round(monthmoney * value.leaseRate / 100 * 1.05)) + ""; std += ""; }) $('#HireTableBody').append(std); @@ -1117,7 +1127,7 @@ sta += "" + inverter.irradiance + ""; sta += "" + inverter.temperature + ""; if (showmoney == 1) { - sta += "" + Math.round(inverter.soldmoney) + ""; + sta += "" + toThousands(Math.round(inverter.soldmoney)) + ""; } sta += ""; avghour += inverter.tothour ? inverter.tothour : 0; @@ -1167,8 +1177,8 @@ stb += "" + (avgdayKWH / monthday).toFixed(2) + ""; stb += "" + monthKWH + ""; if (showmoney == 1) { - stb += "" + Math.round(monthmoney) + ""; - stb += "" + Math.round(monthmoneyone / monthday) + ""; + stb += "" + toThousands(Math.round(monthmoney)) + ""; + stb += "" + Math.round(monthmoneyone / monthday*10000)/10000 + ""; } stb += "" + monthday + ""; stb += ""; @@ -1191,8 +1201,8 @@ std += ""; std += "" + value.landowner + ""; std += "" + value.leaseRate + "%" + ""; - std += "" + Math.round(monthmoney * value.leaseRate / 100) + ""; - std += "" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + ""; + std += "" + toThousands(Math.round(monthmoney * value.leaseRate / 100)) + ""; + std += "" + toThousands(Math.round(monthmoney * value.leaseRate / 100 * 1.05)) + ""; std += ""; }) $('#HireTableBody').append(std); @@ -1347,11 +1357,11 @@ StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; StrInfoBody += "" + data.avgPR.toFixed(2) + ""; if (showmoney == 1) { - StrInfoBody += "" + Math.round(data.todayMoney) + ""; + StrInfoBody += "" + toThousands(main_system_guid) + ""; - StrInfoBody += "" + Math.round(data.todayMoney * hirerate * 0.01)+ ""; + StrInfoBody += "" + toThousands(Math.round(data.todayMoney * hirerate * 0.01))+ ""; - StrInfoBody += "" + Math.round(data.todayMoney) + ""; + StrInfoBody += "" + toThousands(Math.round(data.todayMoney)) + ""; } @@ -1436,5 +1446,22 @@ return hirerate; } + function toThousands(num) { + var num = (num || 0).toString(), result = ''; + var last = ""; + if (num.indexOf('.') != -1) { + var nn = num.split('.'); + num = nn[0]; + last = "." + nn[1]; + } + + while (num.length > 3) { + result = ',' + num.slice(-3) + result; + num = num.slice(0, num.length - 3); + } + if (num) { result = num + result + last; } + + return result; + } } \ No newline at end of file