From 5f4a3529728e02e9b2b76cac6366d926c4cb9a92 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 14 Sep 2021 18:46:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A3=9C=E5=84=9F?= =?UTF-8?q?=E6=A9=9F=E5=88=B6=20Part1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procStationSvc.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/solarApp/Service/procStationSvc.cs b/solarApp/Service/procStationSvc.cs index 2a4b7f3..222b298 100644 --- a/solarApp/Service/procStationSvc.cs +++ b/solarApp/Service/procStationSvc.cs @@ -158,12 +158,34 @@ namespace solarApp.Service select b.id PowerStationId, concat(FROM_UNIXTIME(`TIMESTAMP`/1000, '%Y-%m-%d %H'), ':00:00') reportdate, a.siteid, a.siteType, a.KWH, TODAYKWH, TOTALKWH, KWHKWP , PR, MP, a.SOLARHOUR , - (a.KWH * PowerRate) MONEY, (a.TODAYKWH * PowerRate) TODAYMONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, + CASE + WHEN b.SolarType = 1 THEN a.KWH * c.LeaseRate + ELSE a.KWH * PowerRate + END MONEY, + CASE + WHEN b.SolarType = 1 THEN a.TODAYKWH * c.LeaseRate + ELSE a.KWH * PowerRate + END TODAYMONEY, + CASE + WHEN b.SolarType = 1 THEN a.TOTALKWH * c.LeaseRate + ELSE a.KWH * PowerRate + END TOTALMONEY, + -- (a.KWH * PowerRate) MONEY, + -- (a.TODAYKWH * PowerRate) TODAYMONEY, + -- (a.TOTALKWH * PowerRate) TOTALMONEY, (a.KWH * CarbonRate) CARBON, (a.TODAYKWH * CarbonRate) TODAYCARBON, round((a.TOTALKWH * CarbonRate), 3) TOTALCARBON from " + _siteDB + ".s" + _siteID01 + @"_station a join (select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType from solar_master.power_station where `code` = @siteID ) b on a.siteID = b.siteID + LEFT JOIN ( + SELECT + SUM(lb.LeaseRate) LeaseRate, + ps.Code siteID FROM " + _siteDB + @".land_building lb + LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id + WHERE ps.Code = @siteID + GROUP BY lb.PowerStationId + ) c ON a.siteID = c.siteID where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and a.SITEID = @siteID "; int ct = conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); From ff7126fc5436412d9451a7108370a765733fe7cc Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 15 Sep 2021 11:11:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E8=A3=9C=E5=84=9F?= =?UTF-8?q?=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procStationSvc.cs | 56 ++++++++++++++++++++++++------ solarApp/fmArchive.cs | 1 + 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/solarApp/Service/procStationSvc.cs b/solarApp/Service/procStationSvc.cs index 222b298..3325749 100644 --- a/solarApp/Service/procStationSvc.cs +++ b/solarApp/Service/procStationSvc.cs @@ -134,8 +134,8 @@ namespace solarApp.Service #region hour -- solar_type 計費類別:0 自建、1 租建、2自建 ------------ 1 租建計算方式 後再再補上 //select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.KWH, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a.PR, a.MP, a.SOLARHOUR, - // (KWH * PowerRate) MONEY, (a.TODAYKWH * PowerRate) TODAYMONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, - // (KWH * CarbonRate) CARBON, (a.TODAYKWH * CarbonRate) TODAYCARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON + // (KWH * PowerRate) MONEY, (a.TODAYKWH * PowerRate) TODAYMONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, + // (KWH * CarbonRate) CARBON, (a.TODAYKWH * CarbonRate) TODAYCARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON // from // ( // select siteid, siteType, concat(FROM_UNIXTIME(`TIMESTAMP`/ 1000, '%Y-%m-%d %H'), ':00:00') reportdate, @@ -164,11 +164,11 @@ namespace solarApp.Service END MONEY, CASE WHEN b.SolarType = 1 THEN a.TODAYKWH * c.LeaseRate - ELSE a.KWH * PowerRate + ELSE a.TODAYKWH * PowerRate END TODAYMONEY, CASE WHEN b.SolarType = 1 THEN a.TOTALKWH * c.LeaseRate - ELSE a.KWH * PowerRate + ELSE a.TOTALKWH * PowerRate END TOTALMONEY, -- (a.KWH * PowerRate) MONEY, -- (a.TODAYKWH * PowerRate) TODAYMONEY, @@ -187,7 +187,7 @@ namespace solarApp.Service GROUP BY lb.PowerStationId ) c ON a.siteID = c.siteID where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and a.SITEID = @siteID "; - int ct = conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); + int ct = conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); #endregion hour @@ -196,7 +196,16 @@ namespace solarApp.Service PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a.PR, a.MP, a.SOLARHOUR, - (KWH * PowerRate) MONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, + CASE + WHEN b.SolarType = 1 THEN a.KWH * c.LeaseRate + ELSE a.KWH * PowerRate + END MONEY, + CASE + WHEN b.SolarType = 1 THEN a.TOTALKWH * c.LeaseRate + ELSE a.TOTALKWH * PowerRate + END TOTALMONEY, + -- (KWH * PowerRate) MONEY, + -- (a.TOTALKWH * PowerRate) TOTALMONEY, (KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON from ( @@ -210,8 +219,16 @@ namespace solarApp.Service ( select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType from solar_master.power_station - where `code` = @siteID - ) b on a.siteID = b.siteID "; + where `code` = @siteID + ) b on a.siteID = b.siteID + LEFT JOIN ( + SELECT + SUM(lb.LeaseRate) LeaseRate, + ps.Code siteID FROM " + _siteDB + @".land_building lb + LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id + WHERE ps.Code = @siteID + GROUP BY lb.PowerStationId + ) c ON a.siteID = c.siteID"; conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); #endregion day @@ -223,7 +240,16 @@ namespace solarApp.Service PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, TODAYKWH as monthKwh , a.TOTALKWH, a.KWHKWP, a.PR, a.MP, a.SOLARHOUR, - (TODAYKWH * PowerRate) MONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, + CASE + WHEN b.SolarType = 1 THEN a.TODAYKWH * c.LeaseRate + ELSE a.TODAYKWH * PowerRate + END MONEY, + CASE + WHEN b.SolarType = 1 THEN a.TOTALKWH * c.LeaseRate + ELSE a.TOTALKWH * PowerRate + END TOTALMONEY, + -- (TODAYKWH * PowerRate) MONEY, + -- (a.TOTALKWH * PowerRate) TOTALMONEY, (TODAYKWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON from ( @@ -238,8 +264,16 @@ namespace solarApp.Service select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType from solar_master.power_station where `code` = @siteID - ) b on a.siteID = b.siteID "; - conn.Execute(sql, new { date1 = _date1.Substring(0, 7), siteID = _siteID, powerStationID = _powerStationID }); + ) b on a.siteID = b.siteID + LEFT JOIN ( + SELECT + SUM(lb.LeaseRate) LeaseRate, + ps.Code siteID FROM " + _siteDB + @".land_building lb + LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id + WHERE ps.Code = @siteID + GROUP BY lb.PowerStationId + ) c ON a.siteID = c.siteID"; + conn.Execute(sql, new { date1 = _date1.Substring(0, 7), siteID = _siteID, powerStationID = _powerStationID }); #endregion month diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index f8bd23e..b54f78a 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -186,6 +186,7 @@ namespace solarApp procSensorSvc sensorSvc = new procSensorSvc(); sensorSvc.archiveMeterData(lbSiteID_sensor.Text.Substring(0, 9), date1); + MessageBox.Show("OK"); } } }