日報 - 最後一列 小計 OK
This commit is contained in:
parent
b7456ab29e
commit
848d57ca30
@ -52,53 +52,58 @@ namespace SolarPower.Repository.Implement
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = "SET SESSION group_concat_max_len = 102400;";
|
string sql = "SET SESSION group_concat_max_len = 102400;";
|
||||||
switch(post.FormType)
|
sql += @$"
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
sql += @$"
|
|
||||||
SET @sql = NULL;
|
SET @sql = NULL;
|
||||||
SELECT
|
SELECT GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2))
|
||||||
GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2)) INTO @sql
|
|
||||||
from v_company_inv v
|
from v_company_inv v
|
||||||
LEFT JOIN power_station p ON p.Code = left(inverterid, 9)
|
LEFT JOIN power_station p ON p.Code = left(inverterid, 9)
|
||||||
WHERE p.Id = {post.PowerStation} AND v.enabled = 1 ;
|
WHERE p.Id = {post.PowerStation} AND v.enabled = 1 ;";
|
||||||
|
var inv = conn.Query<string>(sql).FirstOrDefault();
|
||||||
SET @sql = CONCAT('SELECT DATE_FORMAT(a.report_date,''%m-%d %H'') report_date, ', @SQL,
|
// sum(inv_01) as inv_01
|
||||||
', a.hourKWH hourKWH, a.hourKWHp ''hourKWHp'', a.irradiance ''irradiance'', a.Temperature ''temperature'',
|
sql = $@" select GROUP_CONCAT( ' round(sum(inv_',RIGHT(v.InverterId, 2), '), 3) inv_',RIGHT(v.InverterId, 2) )
|
||||||
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 inv_status v LEFT JOIN power_station p ON p.Code = left(inverterid, 9)
|
||||||
|
WHERE p.Id = {post.PowerStation} and v.enabled = 1;";
|
||||||
|
var inv_sum = conn.Query<string>(sql).FirstOrDefault();
|
||||||
|
|
||||||
|
switch (post.FormType)
|
||||||
|
{
|
||||||
|
case 0: //日報
|
||||||
|
sql = $@"
|
||||||
|
DROP TABLE IF EXISTS temp_inv;
|
||||||
|
create TEMPORARY TABLE temp_inv as
|
||||||
|
SELECT DATE_FORMAT(a.report_date,'%m-%d %H') report_date, {inv},
|
||||||
|
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
|
FROM report_invday a
|
||||||
left join
|
left join
|
||||||
( # day
|
( # 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
|
, round(PR, 2) PR, round(money, 2) money , round(SOLARHOUR, 2) SOLARHOUR
|
||||||
from power_station_history_day
|
from power_station_history_day
|
||||||
where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{post.Time}''
|
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
|
) c on a.PowerStationID = c.powerStationid and DATE_FORMAT(a.`report_date`,'%Y-%m-%d') = c.report_date
|
||||||
join
|
join
|
||||||
(
|
(
|
||||||
select id, name stationName, powerRate,GeneratingCapacity from power_station where id = {post.PowerStation}
|
select id, name stationName, powerRate,GeneratingCapacity from power_station where id = {post.PowerStation}
|
||||||
)z on a.PowerStationID = z.id
|
)z on a.PowerStationID = z.id
|
||||||
where DATE_FORMAT(a.report_date,''%Y-%m-%d'') = ''{post.Time}'' and a.PowerStationID = {post.PowerStation}
|
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'')
|
GROUP BY DATE_FORMAT(a.report_date,'%Y-%m-%d %H:%i')
|
||||||
order by DATE_FORMAT(a.report_date,''%Y-%m-%d %H:%i'') ;
|
order by DATE_FORMAT(a.report_date,'%Y-%m-%d %H:%i') ;
|
||||||
-- step 2
|
-- step 2
|
||||||
|
DROP TABLE IF EXISTS temp_inv2;
|
||||||
create TEMPORARY TABLE temp_inv2 as
|
create TEMPORARY TABLE temp_inv2 as
|
||||||
select * from temp_inv;
|
select * from temp_inv;
|
||||||
-- step 3
|
-- step 3
|
||||||
select * from temp_inv
|
select * from temp_inv
|
||||||
union
|
union
|
||||||
SELECT ''總計'' report_date, ', @SQL,
|
SELECT '總計' report_date, {inv_sum},
|
||||||
', round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(sum(irradiance), 2) irradiance,
|
round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(sum(irradiance), 2) irradiance,
|
||||||
avg(temperature) temperature, round(sum(hourmoney), 2) hourmoney, avg(totKWH) totKWH, avg(totKWHKWP) totKWHKWP, avg(totmoney) totmoney, ''電站名稱'' stationName,
|
avg(temperature) temperature, round(sum(hourmoney), 2) hourmoney, avg(totKWH) totKWH, avg(totKWHKWP) totKWHKWP, avg(totmoney) totmoney, '電站名稱' stationName,
|
||||||
avg(daymoney) daymoney, avg(tothour) tothour, avg(pr) pr, avg(GeneratingCapacity) GeneratingCapacity
|
avg(daymoney) daymoney, avg(tothour) tothour, avg(pr) pr, avg(GeneratingCapacity) GeneratingCapacity
|
||||||
from temp_inv2');
|
from temp_inv2 a; ";
|
||||||
#select @sql as 'mySelect'; #顯示動態語法
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;";
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1: //月報
|
||||||
if(post.SearchType == 2)
|
if(post.SearchType == 2)
|
||||||
{
|
{
|
||||||
sql += @$"
|
sql += @$"
|
||||||
@ -146,7 +151,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
DEALLOCATE PREPARE stmt;";
|
DEALLOCATE PREPARE stmt;";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ //區間
|
||||||
var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a');
|
var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a');
|
||||||
|
|
||||||
sql += @$"SET @sql = NULL;
|
sql += @$"SET @sql = NULL;
|
||||||
@ -196,7 +201,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3: //年報
|
||||||
sql += @$"
|
sql += @$"
|
||||||
SET @sql = NULL;
|
SET @sql = NULL;
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user