日報 - 最後一列 小計 OK
This commit is contained in:
parent
b7456ab29e
commit
848d57ca30
@ -52,53 +52,58 @@ namespace SolarPower.Repository.Implement
|
||||
try
|
||||
{
|
||||
string sql = "SET SESSION group_concat_max_len = 102400;";
|
||||
switch(post.FormType)
|
||||
{
|
||||
case 0:
|
||||
sql += @$"
|
||||
SET @sql = NULL;
|
||||
SELECT
|
||||
GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2)) INTO @sql
|
||||
SELECT GROUP_CONCAT( 'a.inv_',RIGHT(v.InverterId, 2))
|
||||
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 ;
|
||||
WHERE p.Id = {post.PowerStation} AND v.enabled = 1 ;";
|
||||
var inv = conn.Query<string>(sql).FirstOrDefault();
|
||||
// sum(inv_01) as inv_01
|
||||
sql = $@" select GROUP_CONCAT( ' round(sum(inv_',RIGHT(v.InverterId, 2), '), 3) inv_',RIGHT(v.InverterId, 2) )
|
||||
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();
|
||||
|
||||
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
|
||||
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
|
||||
left join
|
||||
( # 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
|
||||
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
|
||||
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'') ;
|
||||
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') ;
|
||||
-- step 2
|
||||
DROP TABLE IF EXISTS temp_inv2;
|
||||
create TEMPORARY TABLE temp_inv2 as
|
||||
select * from temp_inv;
|
||||
-- step 3
|
||||
select * from temp_inv
|
||||
union
|
||||
SELECT ''總計'' report_date, ', @SQL,
|
||||
', 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,
|
||||
SELECT '總計' report_date, {inv_sum},
|
||||
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(daymoney) daymoney, avg(tothour) tothour, avg(pr) pr, avg(GeneratingCapacity) GeneratingCapacity
|
||||
from temp_inv2');
|
||||
#select @sql as 'mySelect'; #顯示動態語法
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;";
|
||||
from temp_inv2 a; ";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
case 1: //月報
|
||||
if(post.SearchType == 2)
|
||||
{
|
||||
sql += @$"
|
||||
@ -146,7 +151,7 @@ namespace SolarPower.Repository.Implement
|
||||
DEALLOCATE PREPARE stmt;";
|
||||
}
|
||||
else
|
||||
{
|
||||
{ //區間
|
||||
var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a');
|
||||
|
||||
sql += @$"SET @sql = NULL;
|
||||
@ -196,7 +201,7 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
case 3: //年報
|
||||
sql += @$"
|
||||
SET @sql = NULL;
|
||||
SELECT
|
||||
|
||||
Loading…
Reference in New Issue
Block a user