diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 8eb6ac4..e423a54 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -482,6 +482,8 @@ namespace SolarPower.Repository.Implement #DEALLOCATE PREPARE stmt;"; break; case 1: + if (post.SearchType == 2) + { sql = @$" SET @sql = NULL; SELECT @@ -525,7 +527,56 @@ namespace SolarPower.Repository.Implement #PREPARE stmt FROM @sql; #EXECUTE stmt; #DEALLOCATE PREPARE stmt;"; - + } + else + { + var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a'); + + sql = @$"SET @sql = NULL; + SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') + ) 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, + d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', + c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB + FROM inverter_history_day a left join + ( # 每日加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, + round(todayKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = b.report_date + left join + ( # month + SELECT powerStationid, ROUND(AVG(TODAYKWH),2) AS monthKWH, + ROUND(AVG(KWHKWP),2) AS KWHKWP, + ROUND(AVG(PR),2) AS PR, + ROUND(SUM(MONEY),2) AS money, + ROUND(SUM(SOLARHOUR),2) AS SOLARHOUR + FROM power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + ) c on a.powerStationid = c.powerStationid + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature + 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} + )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'') + order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') '); + + select @sql as 'mySelect'; #顯示動態語法 + #PREPARE stmt FROM @sql; + #EXECUTE stmt; + #DEALLOCATE PREPARE stmt;"; + } break; case 3: sql = @$" @@ -575,54 +626,6 @@ namespace SolarPower.Repository.Implement "; break; - case 4: - var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a'); - - sql = @$"SET @sql = NULL; - SELECT - GROUP_CONCAT(DISTINCT - CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') - ) 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, - d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', - c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB - FROM inverter_history_day a left join - ( # 每日加總 inv - select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, - round(todayKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR - from power_station_history_day - where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' - ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = b.report_date - left join - ( # month - SELECT powerStationid, ROUND(AVG(TODAYKWH),2) AS monthKWH, - ROUND(AVG(KWHKWP),2) AS KWHKWP, - ROUND(AVG(PR),2) AS PR, - ROUND(SUM(MONEY),2) AS money, - ROUND(SUM(SOLARHOUR),2) AS SOLARHOUR - FROM power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' - ) c on a.powerStationid = c.powerStationid - left join - ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature - 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} - )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'') - order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') '); - - select @sql as 'mySelect'; #顯示動態語法 - #PREPARE stmt FROM @sql; - #EXECUTE stmt; - #DEALLOCATE PREPARE stmt;"; - break; } a = await conn.QueryAsync(sql,commandTimeout: 300); } diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 78f58ea..5d3c0ab 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -214,7 +214,7 @@ - + @@ -474,7 +474,6 @@ } break; case 1: - case 4://區間 if (day == 0) { //#region 預設近7天 var today = new Date(new Date().setDate(new Date().getDate() - 1)); @@ -723,12 +722,23 @@ $("#intervalbtn").attr("disabled", true); break; case 1: - $("#daybtn").attr("disabled", true); - $("#monthbtn").html('').attr("disabled", true); - $("#yearbtn").attr("disabled", true); - $("#year2btn").attr("disabled", true); - $(".btn-station").attr("disabled", true); - $("#intervalbtn").attr("disabled", true); + if (searchType == 2) { + $("#daybtn").attr("disabled", true); + $("#monthbtn").html('').attr("disabled", true); + $("#yearbtn").attr("disabled", true); + $("#year2btn").attr("disabled", true); + $(".btn-station").attr("disabled", true); + $("#intervalbtn").attr("disabled", true); + } + else + { + $("#daybtn").attr("disabled", true); + $("#monthbtn").attr("disabled", true); + $("#yearbtn").attr("disabled", true); + $("#year2btn").attr("disabled", true); + $(".btn-station").attr("disabled", true); + $("#intervalbtn").html('').attr("disabled", true); + } break; case 2: $("#daybtn").attr("disabled", true); @@ -746,14 +756,6 @@ $(".btn-station").attr("disabled", true); $("#intervalbtn").attr("disabled", true); break; - case 4: - $("#daybtn").attr("disabled", true); - $("#monthbtn").attr("disabled", true); - $("#yearbtn").attr("disabled", true); - $("#year2btn").attr("disabled", true); - $(".btn-station").attr("disabled", true); - $("#intervalbtn").html('').attr("disabled", true); - break; } showLoading(); @@ -773,12 +775,23 @@ $("#intervalbtn").attr("disabled", false); break; case 1: - $("#daybtn").attr("disabled", false); - $("#monthbtn").html('月報表').attr("disabled", false); - $("#yearbtn").attr("disabled", false); - $("#year2btn").attr("disabled", false); - $(".btn-station").attr("disabled", false); - $("#intervalbtn").attr("disabled", false); + if (searchType == 2) { + $("#daybtn").attr("disabled", false); + $("#monthbtn").html('月報表').attr("disabled", false); + $("#yearbtn").attr("disabled", false); + $("#year2btn").attr("disabled", false); + $(".btn-station").attr("disabled", false); + $("#intervalbtn").attr("disabled", false); + } + else + { + $("#daybtn").attr("disabled", false); + $("#monthbtn").attr("disabled", false); + $("#yearbtn").attr("disabled", false); + $("#year2btn").attr("disabled", false); + $(".btn-station").attr("disabled", false); + $("#intervalbtn").html('區間報表').attr("disabled", false); + } break; case 2: $("#daybtn").attr("disabled", false); @@ -796,14 +809,6 @@ $(".btn-station").attr("disabled", false); $("#intervalbtn").attr("disabled", false); break; - case 4: - $("#daybtn").attr("disabled", false); - $("#monthbtn").attr("disabled", false); - $("#yearbtn").attr("disabled", false); - $("#year2btn").attr("disabled", false); - $(".btn-station").attr("disabled", false); - $("#intervalbtn").html('區間報表').attr("disabled", false); - break; } return; } @@ -827,21 +832,41 @@ str += "小時
售電
金額
(NTD)"; } break; - case 1: // 月報 - str += "Date"; - $.each(rel.data.inv, function (index, inverter) { - haveinvertName.push(inverter); - str += "" + inverter + ""; - }) - str += "日
發電量
(kWh)"; - str += "日
發電量
百分比
(%)"; - str += "日照小時(hr)"; - str += "日均發電度數"; - str += "PR%"; - str += "累積日照量(W/㎡)"; - str += "日
平均
模組溫度
(°C)"; - if (rel.data.showMoney == 1) { - str += "日
售電金額
(NTD)"; + case 1: + if (searchType == 2) { // 月報 + str += "Date"; + $.each(rel.data.inv, function (index, inverter) { + haveinvertName.push(inverter); + str += "" + inverter + ""; + }) + str += "日
發電量
(kWh)"; + str += "日
發電量
百分比
(%)"; + str += "日照小時(hr)"; + str += "日均發電度數"; + str += "PR%"; + str += "累積日照量(W/㎡)"; + str += "日
平均
模組溫度
(°C)"; + if (rel.data.showMoney == 1) { + str += "日
售電金額
(NTD)"; + } + } + else // 區間報 + { + str += "Date"; + $.each(rel.data.inv, function (index, inverter) { + haveinvertName.push(inverter); + str += "" + inverter + ""; + }) + str += "日
發電量
(kWh)"; + str += "日
發電量
百分比
(%)"; + str += "日照小時(hr)"; + str += "日均發電度數"; + str += "PR%"; + str += "累積日照量(W/㎡)"; + str += "日
平均
模組溫度
(°C)"; + if (rel.data.showMoney == 1) { + str += "日
售電金額
(NTD)"; + } } break; case 2: //綜合比較 @@ -874,23 +899,6 @@ str += "月
售電金額
(NTD)"; } break; - case 4: // 區間報 - str += "Date"; - $.each(rel.data.inv, function (index, inverter) { - haveinvertName.push(inverter); - str += "" + inverter + ""; - }) - str += "日
發電量
(kWh)"; - str += "日
發電量
百分比
(%)"; - str += "日照小時(hr)"; - str += "日均發電度數"; - str += "PR%"; - str += "累積日照量(W/㎡)"; - str += "日
平均
模組溫度
(°C)"; - if (rel.data.showMoney == 1) { - str += "日
售電金額
(NTD)"; - } - break; } str += ""; $('#TableHead').append(str); @@ -945,12 +953,22 @@ $("#intervalbtn").attr("disabled", false); break; case 1: - $("#daybtn").attr("disabled", false); - $("#monthbtn").html('月報表').attr("disabled", false); - $("#yearbtn").attr("disabled", false); - $("#year2btn").attr("disabled", false); - $(".btn-station").attr("disabled", false); - $("#intervalbtn").attr("disabled", false); + if (searchType == 2) { + $("#daybtn").attr("disabled", false); + $("#monthbtn").html('月報表').attr("disabled", false); + $("#yearbtn").attr("disabled", false); + $("#year2btn").attr("disabled", false); + $(".btn-station").attr("disabled", false); + $("#intervalbtn").attr("disabled", false); + } + else { + $("#daybtn").attr("disabled", false); + $("#monthbtn").attr("disabled", false); + $("#yearbtn").attr("disabled", false); + $("#year2btn").attr("disabled", false); + $(".btn-station").attr("disabled", false); + $("#intervalbtn").html('區間報表').attr("disabled", false); + } break; case 2: $("#daybtn").attr("disabled", false); @@ -968,14 +986,6 @@ $(".btn-station").attr("disabled", false); $("#intervalbtn").attr("disabled", false); break; - case 4: - $("#daybtn").attr("disabled", false); - $("#monthbtn").attr("disabled", false); - $("#yearbtn").attr("disabled", false); - $("#year2btn").attr("disabled", false); - $(".btn-station").attr("disabled", false); - $("#intervalbtn").html('區間報表').attr("disabled", false); - break; } if (rel.code != "0000") {