debug: 電站報表-區間報表內容沒數值

This commit is contained in:
wanling040@gmail.com 2022-07-28 10:48:36 +08:00
parent 1d6434c987
commit 0e62bc8062
2 changed files with 138 additions and 125 deletions

View File

@ -482,6 +482,8 @@ namespace SolarPower.Repository.Implement
#DEALLOCATE PREPARE stmt;"; #DEALLOCATE PREPARE stmt;";
break; break;
case 1: case 1:
if (post.SearchType == 2)
{
sql = @$" sql = @$"
SET @sql = NULL; SET @sql = NULL;
SELECT SELECT
@ -525,7 +527,56 @@ namespace SolarPower.Repository.Implement
#PREPARE stmt FROM @sql; #PREPARE stmt FROM @sql;
#EXECUTE stmt; #EXECUTE stmt;
#DEALLOCATE PREPARE 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; break;
case 3: case 3:
sql = @$" sql = @$"
@ -575,54 +626,6 @@ namespace SolarPower.Repository.Implement
"; ";
break; 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<dynamic>(sql,commandTimeout: 300); a = await conn.QueryAsync<dynamic>(sql,commandTimeout: 300);
} }

View File

@ -214,7 +214,7 @@
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(0,this)" id="daybtn">日報表</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(0,this)" id="daybtn">日報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(1,this)" id="monthbtn">月報表</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(1,this)" id="monthbtn">月報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(3,this)" id="year2btn">年報表</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(3,this)" id="year2btn">年報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(4,this)" id="intervalbtn">區間報表</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(1,this)" id="intervalbtn">區間報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(2,this)" id="yearbtn">綜合比較</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="Dateform(2,this)" id="yearbtn">綜合比較</button>
</div> </div>
</div> </div>
@ -474,7 +474,6 @@
} }
break; break;
case 1: case 1:
case 4://區間
if (day == 0) { if (day == 0) {
//#region 預設近7天 //#region 預設近7天
var today = new Date(new Date().setDate(new Date().getDate() - 1)); var today = new Date(new Date().setDate(new Date().getDate() - 1));
@ -723,12 +722,23 @@
$("#intervalbtn").attr("disabled", true); $("#intervalbtn").attr("disabled", true);
break; break;
case 1: case 1:
$("#daybtn").attr("disabled", true); if (searchType == 2) {
$("#monthbtn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true); $("#daybtn").attr("disabled", true);
$("#yearbtn").attr("disabled", true); $("#monthbtn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
$("#year2btn").attr("disabled", true); $("#yearbtn").attr("disabled", true);
$(".btn-station").attr("disabled", true); $("#year2btn").attr("disabled", true);
$("#intervalbtn").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('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
}
break; break;
case 2: case 2:
$("#daybtn").attr("disabled", true); $("#daybtn").attr("disabled", true);
@ -746,14 +756,6 @@
$(".btn-station").attr("disabled", true); $(".btn-station").attr("disabled", true);
$("#intervalbtn").attr("disabled", true); $("#intervalbtn").attr("disabled", true);
break; 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('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
break;
} }
showLoading(); showLoading();
@ -773,12 +775,23 @@
$("#intervalbtn").attr("disabled", false); $("#intervalbtn").attr("disabled", false);
break; break;
case 1: case 1:
$("#daybtn").attr("disabled", false); if (searchType == 2) {
$("#monthbtn").html('月報表').attr("disabled", false); $("#daybtn").attr("disabled", false);
$("#yearbtn").attr("disabled", false); $("#monthbtn").html('月報表').attr("disabled", false);
$("#year2btn").attr("disabled", false); $("#yearbtn").attr("disabled", false);
$(".btn-station").attr("disabled", false); $("#year2btn").attr("disabled", false);
$("#intervalbtn").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; break;
case 2: case 2:
$("#daybtn").attr("disabled", false); $("#daybtn").attr("disabled", false);
@ -796,14 +809,6 @@
$(".btn-station").attr("disabled", false); $(".btn-station").attr("disabled", false);
$("#intervalbtn").attr("disabled", false); $("#intervalbtn").attr("disabled", false);
break; 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; return;
} }
@ -827,21 +832,41 @@
str += "<th>小時<br />售電<br />金額<br />(NTD)</th>"; str += "<th>小時<br />售電<br />金額<br />(NTD)</th>";
} }
break; break;
case 1: // 月報 case 1:
str += "<th>Date</th>"; if (searchType == 2) { // 月報
$.each(rel.data.inv, function (index, inverter) { str += "<th>Date</th>";
haveinvertName.push(inverter); $.each(rel.data.inv, function (index, inverter) {
str += "<th>" + inverter + "</th>"; haveinvertName.push(inverter);
}) str += "<th>" + inverter + "</th>";
str += "<th>日<br />發電量<br />(kWh)</th>"; })
str += "<th>日<br />發電量<br />百分比<br />(%)</th>"; str += "<th>日<br />發電量<br />(kWh)</th>";
str += "<th>日照小時(hr)</th>"; str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
str += "<th>日均發電度數</th>"; str += "<th>日照小時(hr)</th>";
str += "<th>PR%</th>"; str += "<th>日均發電度數</th>";
str += "<th>累積日照量(W/㎡)</th>"; str += "<th>PR%</th>";
str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>"; str += "<th>累積日照量(W/㎡)</th>";
if (rel.data.showMoney == 1) { str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>";
str += "<th>日<br />售電金額<br />(NTD)</th>"; if (rel.data.showMoney == 1) {
str += "<th>日<br />售電金額<br />(NTD)</th>";
}
}
else // 區間報
{
str += "<th>Date</th>";
$.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>";
})
str += "<th>日<br />發電量<br />(kWh)</th>";
str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
str += "<th>日照小時(hr)</th>";
str += "<th>日均發電度數</th>";
str += "<th>PR%</th>";
str += "<th>累積日照量(W/㎡)</th>";
str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>日<br />售電金額<br />(NTD)</th>";
}
} }
break; break;
case 2: //綜合比較 case 2: //綜合比較
@ -874,23 +899,6 @@
str += "<th>月<br />售電金額<br />(NTD)</th>"; str += "<th>月<br />售電金額<br />(NTD)</th>";
} }
break; break;
case 4: // 區間報
str += "<th>Date</th>";
$.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>";
})
str += "<th>日<br />發電量<br />(kWh)</th>";
str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
str += "<th>日照小時(hr)</th>";
str += "<th>日均發電度數</th>";
str += "<th>PR%</th>";
str += "<th>累積日照量(W/㎡)</th>";
str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>日<br />售電金額<br />(NTD)</th>";
}
break;
} }
str += "</tr>"; str += "</tr>";
$('#TableHead').append(str); $('#TableHead').append(str);
@ -945,12 +953,22 @@
$("#intervalbtn").attr("disabled", false); $("#intervalbtn").attr("disabled", false);
break; break;
case 1: case 1:
$("#daybtn").attr("disabled", false); if (searchType == 2) {
$("#monthbtn").html('月報表').attr("disabled", false); $("#daybtn").attr("disabled", false);
$("#yearbtn").attr("disabled", false); $("#monthbtn").html('月報表').attr("disabled", false);
$("#year2btn").attr("disabled", false); $("#yearbtn").attr("disabled", false);
$(".btn-station").attr("disabled", false); $("#year2btn").attr("disabled", false);
$("#intervalbtn").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; break;
case 2: case 2:
$("#daybtn").attr("disabled", false); $("#daybtn").attr("disabled", false);
@ -968,14 +986,6 @@
$(".btn-station").attr("disabled", false); $(".btn-station").attr("disabled", false);
$("#intervalbtn").attr("disabled", false); $("#intervalbtn").attr("disabled", false);
break; 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") { if (rel.code != "0000") {