From 883d3d21eb6fead6a88d5bacad57929a6d370b86 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Sat, 11 Sep 2021 17:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B4=E5=A0=B1=E8=A1=A8SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricitySoldRecordController.cs | 2 +- .../Implement/StationReportRepository.cs | 49 +++++ SolarPower/Views/PowerGeneration/Index.cshtml | 10 +- SolarPower/Views/StationReport/Index.cshtml | 167 +++++++++++++++--- 4 files changed, 199 insertions(+), 29 deletions(-) diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index c9d55cf..0349c60 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -655,7 +655,7 @@ namespace SolarPower.Controllers region = new CellRangeAddress(27, 29, 1, 6); sheet.AddMergedRegion(region); cell = row.CreateCell(1); - cell.SetCellValue($"{bill.Result.PowerName}-太陽光電售電收入 \r計算期間:{bill.Result.StartAt}-{bill.Result.EndAt} \r售電收入 = ( 度數 {bill.Result.Kwh} * 費率{bill.Result.PowerRate}) * 1.05 = {Math.Round(bill.Result.Kwh * bill.Result.PowerRate * 1.05,2) } 元"); + cell.SetCellValue($"{bill.Result.PowerName}-太陽光電售電收入 \r計算期間:{bill.Result.StartAt}-{bill.Result.EndAt} \r售電收入 = ( 度數 {bill.Result.Kwh} * 費率{bill.Result.PowerRate}) * 1.05 = {Math.Round(bill.Result.Kwh * bill.Result.PowerRate * 1.05) } 元"); cell.CellStyle = style14bodyleftnoborder; cell = row.CreateCell(6); cell.CellStyle = style14bodyrightnoborder; diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 879237c..a7e1dd8 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -195,6 +195,55 @@ namespace SolarPower.Repository.Implement } break; + case 3: + sql = @$" + SET @sql = NULL; + SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''') + ) INTO @sql + FROM inverter_history_hour where powerstationId = {post.PowerStation}; + 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'', c.KWHKWP ''KWHKWP'', c.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 + ( # 每日加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m'') report_date, siteid, sitetype, + round(MONTHKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_month + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}'' + ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = b.report_date + left join + ( # month + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y'') report_date, sitetype, sum(round(monthKWH, 2)) monthKWH , avg(round(KWHKWP, 2)) KWHKWP + , avg(round(PR, 2)) PR, sum(round(money, 2)) money , sum(round(SOLARHOUR, 2)) SOLARHOUR + from power_station_history_month + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}'' group by DATE_FORMAT(TIMESTAMP,''%Y'') + ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y'') = c.report_date + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m'')report_date, irradiance, Temperature + from sensor_history_month + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}'' + ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = d.report_date + join + ( + select id, name stationName, powerRate,SolarType,SiteDB from power_station where id = {post.PowerStation} + )z on a.powerstationid = z.id + where DATE_FORMAT(a.TIMESTAMP,''%Y'') = ''{post.Time}'' + GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') + order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') '); + + # select @sql as 'mySelect'; #顯示動態語法 + PREPARE stmt FROM @sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + "; + + break; + } a = await conn.QueryAsync(sql); } diff --git a/SolarPower/Views/PowerGeneration/Index.cshtml b/SolarPower/Views/PowerGeneration/Index.cshtml index 7bc5cb8..24cd908 100644 --- a/SolarPower/Views/PowerGeneration/Index.cshtml +++ b/SolarPower/Views/PowerGeneration/Index.cshtml @@ -570,9 +570,9 @@ str += "" + (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01).toFixed(2) + ""; str += "" + (val.rate * (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01)).toFixed(2) + ""; str += "" + val.realKWH.toFixed(2) + ""; - str += "" + val.realMoney.toFixed(2) + ""; + str += "" + Math.round(val.realMoney) + ""; str += "" + val.actualkwh.toFixed(2) + ""; - str += "" + val.actualMoney.toFixed(2) + ""; + str += "" + Math.round(val.actualMoney) + ""; var cba = val.cbAkwh * val.cbAeff * days * val.capacity * 0.01 / days / val.capacity; str += "" + cba.toFixed(2) + ""; var real = val.realKWH / days / val.capacity; @@ -590,12 +590,12 @@ } var stra = ""; stra += ""; - stra += "" + capacity.toFixed(2) + ""; + stra += "" + capacity.toFixed(3) + ""; stra += "" + cbAkwh.toFixed(2) + ""; stra += "" + rate.toFixed(2) + ""; - stra += "" + capacity.toFixed(2) + ""; + stra += "" + capacity.toFixed(3) + ""; stra += "" + rate.toFixed(2) + ""; - stra += "" + capacity.toFixed(2) + ""; + stra += "" + capacity.toFixed(3) + ""; stra += "" + rate.toFixed(2) + ""; stra += "" + (checkvalue ? 0 : (totalcbAkwh / totaldays / capacity).toFixed(2)) + ""; stra += "" + ((totaldays == 0) ? 0 : (totalrealKWH / totaldays / capacity).toFixed(2)) + ""; diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index f58d198..56cef1c 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -209,6 +209,7 @@
+
@@ -785,7 +786,7 @@ if (inverter[i] == null) { sta += "" + 0 + ""; } else { - sta += "" + Number(inverter[i]).toFixed(2) + ""; + sta += "" + Number(inverter[i]).toFixed(2) + ""; } }); sta += "" + Number(inverter.hourKWH) + ""; @@ -800,8 +801,8 @@ tpr = inverter.pr ? inverter.pr.toFixed(2) : 0; tkwh = inverter.totKWH ? inverter.totKWH.toFixed(2) : 0; kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0; - ntd = inverter.totmoney ? inverter.totmoney.toFixed(2) : 0; - ntdone = inverter.totmoney / inverter.totKWH ? (inverter.totmoney / inverter.totKWH).toFixed(2) : 0; + ntd = inverter.totmoney ? Math.round(inverter.totmoney) : 0; + ntdone = inverter.totmoney / inverter.totKWH ? Math.round(inverter.totmoney / inverter.totKWH) : 0; }) var stc = ""; stc += "" + '日照小時' + ""; @@ -832,7 +833,7 @@ $('#tothead').append(stc); haveinvertName = []; } - else {//月報表 + else if (form == 1) {//月報表 var avghour = 0; var avgKWHKWP = 0; var avgdayKWH = 0; @@ -871,8 +872,7 @@ monthmoney = inverter.monthmoney ? inverter.monthmoney : 0; monthmoneyone += inverter.monthmoneyone ? inverter.monthmoneyone : 0; - if (inverter.SolarType == 1) - { + if (inverter.SolarType == 1) { check_hire = true; sitedb = inverter.SiteDB } @@ -882,17 +882,19 @@ var stc = ""; - stc += "" + '日日照小時平均' + ""; - stc += "" + '日kWH/kWP平均' + ""; - stc += "" + '日發電量平均(kWh)' + ""; - stc += "" + '月發電量(kWh)' + ""; + stc += "" + '日照平均(日)' + ""; + stc += "" + 'kWH/kWP(日)' + ""; + stc += "" + '發電量平均(kWh)(日)' + ""; + stc += "" + '發電量(kWh)(月)' + ""; if (showmoney == 1) { - stc += "" + '月售電金額(NTD)' + ""; - stc += "" + '月售電單價(NTD)' + ""; + stc += "" + '售電金額(NTD)(月)' + ""; + stc += "" + '售電單價(NTD)(月)' + ""; } - stc += "" + '月售電天數' + ""; + stc += "" + '售電天數(月)' + ""; stc += ""; + + var stb = ""; if (monthday == 0) { stb += "" + 0 + ""; @@ -904,22 +906,20 @@ stb += "" + 0 + ""; stb += ""; } - else - { + else { stb += "" + (avghour / monthday).toFixed(2) + ""; stb += "" + (avgKWHKWP / monthday).toFixed(2) + ""; stb += "" + (avgdayKWH / monthday).toFixed(2) + ""; stb += "" + monthKWH + ""; if (showmoney == 1) { stb += "" + monthmoney + ""; - stb += "" + (monthmoneyone / monthday).toFixed(2) + ""; + stb += "" + Math.round(monthmoneyone / monthday) + ""; } stb += "" + monthday + ""; stb += ""; } var std = ""; - if (check_hire == true && showmoney == 1) - { + if (check_hire == true && showmoney == 1) { var dataTosent = { Sitedb: sitedb, @@ -936,8 +936,8 @@ std += ""; std += "" + value.landowner + ""; std += "" + value.leaseRate + "%" + ""; - std += "" + (monthmoney * value.leaseRate / 100).toFixed(2) + ""; - std += "" + (monthmoney * value.leaseRate / 100 * 1.05).toFixed(2) + ""; + std += "" + Math.round(monthmoney * value.leaseRate / 100) + ""; + std += "" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + ""; std += ""; }) $('#HireTableBody').append(std); @@ -953,6 +953,127 @@ haveinvertName = []; } + else if (form == 3) { + var avghour = 0; + var avgKWHKWP = 0; + var avgdayKWH = 0; + var monthKWH = 0; + var monthmoney = 0; + var monthmoneyone = 0; + var monthday = 0; + + var check_hire = false; + var sitedb = ""; + $.each(rel.data, function (index, inverter) { + sta += ""; + sta += "" + inverter.report_date + ""; + $.each(haveinvertName, function (item, i) { + if (inverter[i] == null) { + sta += "" + 0 + ""; + } else { + sta += "" + inverter[i] + ""; + } + }); + sta += "" + inverter.dayKWH + ""; + sta += "" + inverter.dayKWHp + ""; + sta += "" + inverter.tothour + ""; + sta += "" + inverter.KWHKWP + ""; + sta += "" + inverter.PR + ""; + sta += "" + inverter.irradiance + ""; + sta += "" + inverter.temperature + ""; + if (showmoney == 1) { + sta += "" + inverter.soldmoney + ""; + } + sta += ""; + avghour += inverter.tothour ? inverter.tothour : 0; + avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0; + avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0; + monthKWH = inverter.monthKWH ? inverter.monthKWH : 0; + monthmoney = inverter.monthmoney ? inverter.monthmoney : 0; + monthmoneyone += inverter.monthmoneyone ? inverter.monthmoneyone : 0; + + if (inverter.SolarType == 1) { + check_hire = true; + sitedb = inverter.SiteDB + } + + }) + monthday = rel.data.length; + + + var stc = ""; + stc += "" + '日照平均(日)' + ""; + stc += "" + 'kWH/kWP(日)' + ""; + stc += "" + '發電量平均(kWh)(日)' + ""; + stc += "" + '發電量(kWh)(月)' + ""; + if (showmoney == 1) { + stc += "" + '售電金額(NTD)(月)' + ""; + stc += "" + '售電單價(NTD)(月)' + ""; + } + stc += "" + '售電天數(月)' + ""; + stc += ""; + + + + var stb = ""; + if (monthday == 0) { + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += "" + 0 + ""; + stb += ""; + } + else { + stb += "" + (avghour / monthday).toFixed(2) + ""; + stb += "" + (avgKWHKWP / monthday).toFixed(2) + ""; + stb += "" + (avgdayKWH / monthday).toFixed(2) + ""; + stb += "" + monthKWH + ""; + if (showmoney == 1) { + stb += "" + monthmoney + ""; + stb += "" + Math.round(monthmoneyone / monthday) + ""; + } + stb += "" + monthday + ""; + stb += ""; + } + var std = ""; + if (check_hire == true && showmoney == 1) { + var dataTosent = + { + Sitedb: sitedb, + PowerstationId: nowpowerstation + } + $('#HireTableBody').empty(); + var posturl = "/StationReport/GetHireInfo"; + $.post(posturl, dataTosent, function (rel) { + if (rel.code != "0000") { + toast_error(rel.data.msg); + return; + } + $.each(rel.data, function (index, value) { + std += ""; + std += "" + value.landowner + ""; + std += "" + value.leaseRate + "%" + ""; + std += "" + Math.round(monthmoney * value.leaseRate / 100) + ""; + std += "" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + ""; + std += ""; + }) + $('#HireTableBody').append(std); + $('#hiretable').show(); + }) + } + + + $('#TableBody').append(sta); + $('#totbody').append(stb); + $('#tothead').append(stc); + + + haveinvertName = []; + + } $('#overviewtable').show(); $('#detailtable').show(); @@ -1047,11 +1168,11 @@ StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; StrInfoBody += "" + data.avgPR.toFixed(2) + ""; if (showmoney == 1) { - StrInfoBody += "" + data.todayMoney.toFixed(2) + ""; + StrInfoBody += "" + Math.round(data.todayMoney) + ""; - StrInfoBody += "" + (data.todayMoney * hirerate * 0.01).toFixed(2)+ ""; + StrInfoBody += "" + Math.round(data.todayMoney * hirerate * 0.01)+ ""; - StrInfoBody += "" + data.todayMoney.toFixed(2) + ""; + StrInfoBody += "" + Math.round(data.todayMoney) + ""; }