From efdeb5d8bceb36805b62ebfe13f7c8c184965034 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Fri, 13 Aug 2021 19:31:19 +0800 Subject: [PATCH 1/5] debug --- solarApp/Model/inv_hour.cs | 1 + solarApp/Model/sensor_model.cs | 2 ++ solarApp/Service/getInvSvc.cs | 49 +++++++++++++++++++++---------- solarApp/Service/getSensorSvc.cs | 8 ++--- solarApp/Service/getStationSvc.cs | 20 +++++++------ solarApp/Service/procInvSvc.cs | 10 +++---- solarApp/Service/procSensorSvc.cs | 8 ++--- solarApp/fmArchive.Designer.cs | 33 +++++++++++++++++++-- solarApp/fmArchive.cs | 24 +++++++++++++++ solarApp/fmMain.Designer.cs | 47 +++++++++++------------------ solarApp/fmMain.cs | 22 ++++++++++++++ 11 files changed, 155 insertions(+), 69 deletions(-) diff --git a/solarApp/Model/inv_hour.cs b/solarApp/Model/inv_hour.cs index 457543a..40a72f2 100644 --- a/solarApp/Model/inv_hour.cs +++ b/solarApp/Model/inv_hour.cs @@ -106,6 +106,7 @@ namespace solarApp.Model public double TODAYKWH { get; set; } public double TOTALKWH { get; set; } public double PR { get; set; } + public int count { get; set; } } public class web_inv_list diff --git a/solarApp/Model/sensor_model.cs b/solarApp/Model/sensor_model.cs index 0c002ae..02bac14 100644 --- a/solarApp/Model/sensor_model.cs +++ b/solarApp/Model/sensor_model.cs @@ -36,6 +36,8 @@ namespace solarApp.Model public double humidityAvg { get; set; } public double windAvg { get; set; } public double dustAvg { get; set; } + + public int count { get; set; } } public class sensor_hour diff --git a/solarApp/Service/getInvSvc.cs b/solarApp/Service/getInvSvc.cs index c129208..126edc2 100644 --- a/solarApp/Service/getInvSvc.cs +++ b/solarApp/Service/getInvSvc.cs @@ -25,7 +25,7 @@ namespace solarApp.Service conn.Open(); //string sql = @"select ID, TIMESTAMP, SITEID, SITETYPE, CONTROLLERID, INVERTERID, SN, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, AC3V, AC3A, AC3W, AC3F, AC3WH, ACRUNTIME, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, DCRUNTIME, WH, TODAYKWH, TOTALKWH, PR, RA1, RA2, RA3, RA4, RA5 // from solar_com0002.s02202000101_inv order by id desc limit 100; "; - string sql = @"select id , FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, inverterid, WH,round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH,round(PR, 2) PR, RA1 + string sql = @"select id , FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, inverterid, WH, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, round(PR, 2) PR, RA1 from " + siteDB + ".s" + siteID + @"_inv where left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 10) = '" + reportDate + "' and inverterid = '" + invID + "'"; //List ds = conn.Query(sql, new { kind = kind }).ToList(); @@ -49,18 +49,26 @@ namespace solarApp.Service // round(max(TOTALKWH), 2) TOTALKWH, round(max(PR), 2) PR, count(*) count // from v_inv_temp where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + "' " + // "group by left(reportdate, 13), inverterid"; //round(avg(PR), 2) PR, - string sql = @" select a.reportdate, a.inverterid, a.KWH, b.TODAYKWH, b.TOTALKWH, b.PR, a.count from - ( - select left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 13)reportdate, inverterid - ,round((sum(WH)/1000), 2) KWH, count(*) count - from " + siteDB + ".s" + siteID + @"_inv - where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + "' and inverterid = '" + invID + @"' - group by left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 13), inverterid - )a join ( - select FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, inverterid, round(PR, 2) PR - from " + siteDB + ".s" + siteID + @"_inv - where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + @"' and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 2) = '55' and inverterid = '" + invID + @"' - )b on a.reportdate = left(b.reportdate, 13) and a.inverterid = b.inverterid "; + string sql = @" + select FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')reportdate, inverterid ,round((sum(WH)/1000), 2) KWH, + round(max(TODAYKWH), 2) TODAYKWH, round(max(TOTALKWH), 2) TOTALKWH, round(max(PR), 2) PR, count(*) count + from " + siteDB + ".s" + siteID + @"_inv + where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + "' and inverterid = '" + invID + @"' + group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), inverterid + order by 1; "; + +//select a.reportdate, a.inverterid, a.KWH, b.TODAYKWH, b.TOTALKWH, b.PR, a.count from +// ( +// select left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 13)reportdate, inverterid +// ,round((sum(WH)/1000), 2) KWH, count(*) count +// from " + siteDB + ".s" + siteID + @"_inv +// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + "' and inverterid = '" + invID + @"' +// group by left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 13), inverterid +// )a join ( +// select FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, inverterid, round(PR, 2) PR +// from " + siteDB + ".s" + siteID + @"_inv +// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + @"' and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 2) = '55' and inverterid = '" + invID + @"' +// )b on a.reportdate = left(b.reportdate, 13) and a.inverterid = b.inverterid "; List ds = conn.Query(sql).AsList(); conn.Close(); return ds; @@ -106,8 +114,19 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, inverterid, round(KWH, 2) KWH, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, round(PR, 2) PR - from inverter_history_day where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+ date2 +"' and inverterid = '" + invID + "' "; + //string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, inverterid, round(KWH, 2) KWH, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, round(PR, 2) PR + // from inverter_history_day where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+ date2 +"' and inverterid = '" + invID + "' "; + string sql = @" +select DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') reportdate, a.inverterid, round(a.KWH, 2) KWH, round(a.TODAYKWH, 2) TODAYKWH, + round(a.TOTALKWH, 2) TOTALKWH, round(a.PR, 2) PR, count +from inverter_history_day a join ( + select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, inverterid, count(*) count + from inverter_history_hour + where left(`TIMESTAMP`, 10) between '" + date1 + "' and '" + date2 + @"' and inverterid = '" + invID + @"' + + group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), inverterid +) b on a.inverterid = b.inverterid and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = b.reportdate +where left(a.`TIMESTAMP`, 10) between '" + date1 + "' and '" + date2 + "' and a.inverterid = '" + invID + "' order by 1"; List ds = conn.Query(sql).AsList(); conn.Close(); return ds; diff --git a/solarApp/Service/getSensorSvc.cs b/solarApp/Service/getSensorSvc.cs index 87b6cda..94a2e34 100644 --- a/solarApp/Service/getSensorSvc.cs +++ b/solarApp/Service/getSensorSvc.cs @@ -107,16 +107,16 @@ namespace solarApp.Service //電表 #endregion 獲取 Sensor 類別 - sql = @"select a.siteID, a.reportdate, a.modelTempAvg, ifnull(b.irrAvg, 0) irrAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg from + sql = @"select a.siteID, a.reportdate, a.modelTempAvg, ifnull(b.irrAvg, 0) irrAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg, count from ( - select @siteID siteID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, "+ modelTempCol+ @" modelTempAvg - ," + evnTempCol + @" envTempAvg, " + humCol + @" humidityAvg, " + windCol + @" windAvg, " + dustCol + @" dustAvg + select @siteID siteID, CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, " + modelTempCol+ @" modelTempAvg + ," + evnTempCol + @" envTempAvg, " + humCol + @" humidityAvg, " + windCol + @" windAvg, " + dustCol + @" dustAvg, count(*) count from " + siteDB + ".s" + siteID + @"_sensorAvg where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') ) a left join ( - select FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate , " + irrCol + @" irrAvg + select CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate , " + irrCol + @" irrAvg from " + siteDB + ".s" + siteID + @"_sensorAvg where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate "+ irrNot0 + @" #需要過濾 0 的數值 group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') diff --git a/solarApp/Service/getStationSvc.cs b/solarApp/Service/getStationSvc.cs index a09c034..3e89bec 100644 --- a/solarApp/Service/getStationSvc.cs +++ b/solarApp/Service/getStationSvc.cs @@ -27,7 +27,7 @@ namespace solarApp.Service { conn.Open(); string sql = @"select id , FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, siteid, round(KWH, 3) KWH, round(TODAYKWH, 3) TODAYKWH, - round(TOTALKWH, 3)TOTALKWH, round(PR, 3) PR, round(TODAYKWH, 3)SOLARHOUR , round(kwhkwp, 3) kwhkwp + round(TOTALKWH, 3)TOTALKWH, round(PR, 3) PR, round(SOLARHOUR, 3) SOLARHOUR , round(kwhkwp, 3) kwhkwp from " + siteDB + ".s" + siteID + @"_station where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate"; List ds = conn.Query(sql, new { reportDate = reportDate }).AsList(); @@ -92,9 +92,11 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, siteid, round(KWH, 2) KWH, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, - round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, round(money, 3) money, round(todaymoney, 3) todaymoney, round(totalmoney, 3) totalmoney, - round(carbon, 3) carbon, round(todayCarbon, 3) todayCarbon, round(totalCarbon, 3) totalCarbon + string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, siteid, round(KWH, 2) KWH, + round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, + round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, + round(money, 3) money, round(todaymoney, 3) todaymoney, round(totalmoney, 3) totalmoney, + round(carbon, 3) carbon, round(todayCarbon, 3) todayCarbon, round(totalCarbon, 3) totalCarbon from power_station_history_hour where siteID = @siteID and left(`TIMESTAMP`, 10) = '" + reportDate + "' "; List ds = conn.Query(sql, new { siteID = siteID.Substring(0, 9) }).AsList(); @@ -109,7 +111,7 @@ namespace solarApp.Service /// /// /// - public List get_web_station_day(string date1, string date2, string siteID) + public List get_web_station_day(string date1, string date2, string siteID) { using (MySqlConnection conn = new MySqlConnection(Connection1)) { @@ -117,20 +119,20 @@ namespace solarApp.Service string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money from power_station_history_day where left(`TIMESTAMP`, 10) between @date1 and @date2 and siteid = @siteID"; - List ds = conn.Query(sql, new { date1 = date1, date2 = date2 , siteID = siteID}).AsList(); + List ds = conn.Query(sql, new { date1 = date1, date2 = date2 , siteID = siteID}).AsList(); conn.Close(); return ds; } } - public List get_web_station_month(string date1, string date2, string siteID) + public List get_web_station_month(string date1, string date2, string siteID) { using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TOTALKWH, 2) TOTALKWH, round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money from power_station_history_month where left(`TIMESTAMP`, 7) between @date1 and @date2 and siteid = @siteID"; - List ds = conn.Query(sql, new { date1 = date1, date2 = date2, siteID = siteID }).AsList(); + List ds = conn.Query(sql, new { date1 = date1, date2 = date2, siteID = siteID }).AsList(); conn.Close(); return ds; } @@ -147,7 +149,7 @@ namespace solarApp.Service conn.Open(); // 01 控制器編號 string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName from power_station - where id in (1, 8)"; + where id in (1, 8, 9)"; List ds = conn.Query(sql).AsList(); conn.Close(); return ds; diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 54efdd0..c502894 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -88,28 +88,28 @@ namespace solarApp.Service #region 15 min string sql = @" INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) - select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, round((kwh/capacity), 3) kwpkwp from + select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/capacity) kwpkwp from ( select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid, - round((sum(WH)/1000), 3) KWH, round(max(TODAYKWH), 3) TODAYKWH + (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH from " + _siteDB + ".s" + _siteID01 + @"_inv where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '00' and '10' group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid union select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':15:00')reportdate, inverterid, - round((sum(WH)/1000), 3) KWH, round(max(TODAYKWH), 3) TODAYKWH + (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH from " + _siteDB + ".s" + _siteID01 + @"_inv where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '15' and '25' group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid union select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':30:00')reportdate, inverterid, - round((sum(WH)/1000), 3) KWH, round(max(TODAYKWH), 3) TODAYKWH + (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH from " + _siteDB + ".s" + _siteID01 + @"_inv where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '30' and '40' group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid union select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':45:00')reportdate, inverterid, - round((sum(WH)/1000), 3) KWH, round(max(TODAYKWH), 3) TODAYKWH + (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH from " + _siteDB + ".s" + _siteID01 + @"_inv where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '45' and '55' group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index b5e8bde..9165a85 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -61,7 +61,7 @@ namespace solarApp.Service /// 清除指定期間、指定電站的 Sensor hour、day、month 資料 /// /// - private bool clearData() + public bool clearData() { bool result = false; try @@ -185,9 +185,9 @@ namespace solarApp.Service sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, `Irradiance`, `Temperature`) select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.modelTempAvg from ( - select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(avg(" + modelTempCol + @"), 2) modelTempAvg, - round(avg(" + evnTempCol + @"), 2) envTempAvg, round(avg(" + humCol + @"), 2) humidityAvg, round(avg(" + windCol + @"), 2) windAvg, - round(avg(" + dustCol + @"), 2) dustAvg + select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, avg(" + modelTempCol + @") modelTempAvg, + avg(" + evnTempCol + @") envTempAvg, avg(" + humCol + @") humidityAvg, avg(" + windCol + @") windAvg, + avg(" + dustCol + @") dustAvg from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') between @date1 and @date2 group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index c914109..f8e9c01 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -32,6 +32,8 @@ namespace solarApp this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.bt_archive = new System.Windows.Forms.Button(); + this.bt_clear_sensor = new System.Windows.Forms.Button(); this.bt_clear_station = new System.Windows.Forms.Button(); this.bt_clear_inv = new System.Windows.Forms.Button(); this.fp_site = new System.Windows.Forms.FlowLayoutPanel(); @@ -88,6 +90,8 @@ namespace solarApp // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.splitContainer1.Panel1.Controls.Add(this.bt_archive); + this.splitContainer1.Panel1.Controls.Add(this.bt_clear_sensor); this.splitContainer1.Panel1.Controls.Add(this.bt_clear_station); this.splitContainer1.Panel1.Controls.Add(this.bt_clear_inv); this.splitContainer1.Panel1.Controls.Add(this.fp_site); @@ -105,6 +109,29 @@ namespace solarApp this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 0; // + // bt_archive + // + this.bt_archive.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bt_archive.Location = new System.Drawing.Point(5, 528); + this.bt_archive.Name = "bt_archive"; + this.bt_archive.Size = new System.Drawing.Size(282, 100); + this.bt_archive.TabIndex = 8; + this.bt_archive.Text = "單日歸檔"; + this.bt_archive.UseVisualStyleBackColor = true; + this.bt_archive.Click += new System.EventHandler(this.bt_archive_Click); + // + // bt_clear_sensor + // + this.bt_clear_sensor.Enabled = false; + this.bt_clear_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bt_clear_sensor.Location = new System.Drawing.Point(5, 256); + this.bt_clear_sensor.Name = "bt_clear_sensor"; + this.bt_clear_sensor.Size = new System.Drawing.Size(135, 44); + this.bt_clear_sensor.TabIndex = 7; + this.bt_clear_sensor.Text = "clear data"; + this.bt_clear_sensor.UseVisualStyleBackColor = true; + this.bt_clear_sensor.Click += new System.EventHandler(this.bt_clear_sensor_Click); + // // bt_clear_station // this.bt_clear_station.Enabled = false; @@ -134,12 +161,12 @@ namespace solarApp this.fp_site.Dock = System.Windows.Forms.DockStyle.Top; this.fp_site.Location = new System.Drawing.Point(0, 0); this.fp_site.Name = "fp_site"; - this.fp_site.Size = new System.Drawing.Size(300, 150); + this.fp_site.Size = new System.Drawing.Size(300, 176); this.fp_site.TabIndex = 4; // // dtSelect // - this.dtSelect.Location = new System.Drawing.Point(37, 156); + this.dtSelect.Location = new System.Drawing.Point(3, 193); this.dtSelect.Name = "dtSelect"; this.dtSelect.Size = new System.Drawing.Size(204, 27); this.dtSelect.TabIndex = 3; @@ -298,5 +325,7 @@ namespace solarApp private System.Windows.Forms.Button btVerifyData; private System.Windows.Forms.Button bt_clear_inv; private System.Windows.Forms.Button bt_clear_station; + private System.Windows.Forms.Button bt_archive; + private System.Windows.Forms.Button bt_clear_sensor; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 2c5ee0d..ed6d17c 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -101,8 +101,10 @@ namespace solarApp { bt_clear_inv.Enabled = true; bt_clear_station.Enabled = true; + bt_clear_sensor.Enabled = true; bt_clear_inv.Text = "clear " + dtSelect.Value.ToString("MM-dd"); bt_clear_station.Text = "clear " + dtSelect.Value.ToString("MM-dd"); + bt_clear_sensor.Text = "clear " + dtSelect.Value.ToString("MM-dd"); } private void bt_clear_inv_Click(object sender, EventArgs e) @@ -149,5 +151,27 @@ namespace solarApp //sensorSvc.archiveData(); MessageBox.Show("OK"); } + + private void bt_archive_Click(object sender, EventArgs e) + { + bt_Sensor.PerformClick(); + bt_Inv.PerformClick(); + bt_site.PerformClick(); + } + + private void bt_clear_sensor_Click(object sender, EventArgs e) + { + string date1 = dtSelect.Value.ToString("yyyy-MM-dd"); + //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); + procSensorSvc sensorSvc = new procSensorSvc(); + sensorSvc._siteDB = lbSiteDB_sensor.Text; + sensorSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); + sensorSvc._siteID01 = lbSiteID_sensor.Text; + sensorSvc._date1 = date1; + sensorSvc._date2 = date1; + sensorSvc.clearData(); + //sensorSvc.archiveData(); + MessageBox.Show("OK"); + } } } diff --git a/solarApp/fmMain.Designer.cs b/solarApp/fmMain.Designer.cs index 8569d89..7906b34 100644 --- a/solarApp/fmMain.Designer.cs +++ b/solarApp/fmMain.Designer.cs @@ -109,11 +109,10 @@ namespace solarApp this.lb_raw_inv_hour = new System.Windows.Forms.Label(); this.tb2 = new System.Windows.Forms.TabPage(); this.sp_main_station = new System.Windows.Forms.SplitContainer(); - this.label13 = new System.Windows.Forms.Label(); + this.fp_site = new System.Windows.Forms.FlowLayoutPanel(); this.lbMsg_station = new System.Windows.Forms.Label(); this.bt_find_station = new System.Windows.Forms.Button(); this.dtselect_station1 = new System.Windows.Forms.DateTimePicker(); - this.fp_site = new System.Windows.Forms.FlowLayoutPanel(); this.sp_child_station = new System.Windows.Forms.SplitContainer(); this.gv_web_station_month = new System.Windows.Forms.DataGridView(); this.panel10 = new System.Windows.Forms.Panel(); @@ -499,6 +498,7 @@ namespace solarApp this.gv_web_inv_day.RowTemplate.Height = 25; this.gv_web_inv_day.Size = new System.Drawing.Size(666, 270); this.gv_web_inv_day.TabIndex = 4; + this.gv_web_inv_day.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_web_inv_day_CellFormatting); // // panel8 // @@ -751,11 +751,10 @@ namespace solarApp // // sp_main_station.Panel1 // - this.sp_main_station.Panel1.Controls.Add(this.label13); + this.sp_main_station.Panel1.Controls.Add(this.fp_site); this.sp_main_station.Panel1.Controls.Add(this.lbMsg_station); this.sp_main_station.Panel1.Controls.Add(this.bt_find_station); this.sp_main_station.Panel1.Controls.Add(this.dtselect_station1); - this.sp_main_station.Panel1.Controls.Add(this.fp_site); // // sp_main_station.Panel2 // @@ -765,23 +764,22 @@ namespace solarApp this.sp_main_station.SplitterDistance = 257; this.sp_main_station.TabIndex = 0; // - // label13 + // fp_site // - this.label13.AutoSize = true; - this.label13.Dock = System.Windows.Forms.DockStyle.Bottom; - this.label13.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label13.Location = new System.Drawing.Point(0, 367); - this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(110, 24); - this.label13.TabIndex = 13; - this.label13.Text = "請選擇 電站"; + this.fp_site.BackColor = System.Drawing.Color.Azure; + this.fp_site.Dock = System.Windows.Forms.DockStyle.Top; + this.fp_site.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.fp_site.Location = new System.Drawing.Point(0, 0); + this.fp_site.Margin = new System.Windows.Forms.Padding(4); + this.fp_site.Name = "fp_site"; + this.fp_site.Size = new System.Drawing.Size(257, 315); + this.fp_site.TabIndex = 14; // // lbMsg_station // this.lbMsg_station.AutoSize = true; this.lbMsg_station.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.lbMsg_station.Location = new System.Drawing.Point(30, 111); + this.lbMsg_station.Location = new System.Drawing.Point(23, 443); this.lbMsg_station.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbMsg_station.Name = "lbMsg_station"; this.lbMsg_station.Size = new System.Drawing.Size(22, 24); @@ -790,7 +788,7 @@ namespace solarApp // // bt_find_station // - this.bt_find_station.Location = new System.Drawing.Point(16, 73); + this.bt_find_station.Location = new System.Drawing.Point(9, 405); this.bt_find_station.Name = "bt_find_station"; this.bt_find_station.Size = new System.Drawing.Size(94, 29); this.bt_find_station.TabIndex = 7; @@ -801,22 +799,11 @@ namespace solarApp // dtselect_station1 // this.dtselect_station1.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.dtselect_station1.Location = new System.Drawing.Point(14, 8); + this.dtselect_station1.Location = new System.Drawing.Point(5, 357); this.dtselect_station1.Name = "dtselect_station1"; this.dtselect_station1.Size = new System.Drawing.Size(234, 31); this.dtselect_station1.TabIndex = 6; // - // fp_site - // - this.fp_site.BackColor = System.Drawing.Color.Azure; - this.fp_site.Dock = System.Windows.Forms.DockStyle.Bottom; - this.fp_site.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.fp_site.Location = new System.Drawing.Point(0, 391); - this.fp_site.Margin = new System.Windows.Forms.Padding(4); - this.fp_site.Name = "fp_site"; - this.fp_site.Size = new System.Drawing.Size(257, 645); - this.fp_site.TabIndex = 8; - // // sp_child_station // this.sp_child_station.Dock = System.Windows.Forms.DockStyle.Fill; @@ -1563,6 +1550,7 @@ namespace solarApp this.gv_fic_sensor_hour.RowTemplate.Height = 25; this.gv_fic_sensor_hour.Size = new System.Drawing.Size(695, 453); this.gv_fic_sensor_hour.TabIndex = 4; + this.gv_fic_sensor_hour.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_fic_sensor_hour_CellFormatting); // // panel14 // @@ -1789,7 +1777,6 @@ namespace solarApp private System.Windows.Forms.Label lbMsg_station; private System.Windows.Forms.Button bt_find_station; private System.Windows.Forms.DateTimePicker dtselect_station; - private System.Windows.Forms.FlowLayoutPanel fp_site; private System.Windows.Forms.Label lbMsg_inv; private System.Windows.Forms.DateTimePicker dateTimePicker1; private System.Windows.Forms.DateTimePicker dtselect_station1; @@ -1807,7 +1794,6 @@ namespace solarApp private System.Windows.Forms.DataGridView gv_web_station_month; private System.Windows.Forms.Label lbSiteID_inv; private System.Windows.Forms.Label lbSiteName_inv; - private System.Windows.Forms.Label label13; private System.Windows.Forms.Label lbSiteDB_inv; private System.Windows.Forms.Label lbSiteRaw; private System.Windows.Forms.Label lbInvRaw; @@ -1847,5 +1833,6 @@ namespace solarApp private System.Windows.Forms.Button btSearch_sensor; private System.Windows.Forms.Button btSensor_switch; private System.Windows.Forms.Button btInv_15min; + private System.Windows.Forms.FlowLayoutPanel fp_site; } } \ No newline at end of file diff --git a/solarApp/fmMain.cs b/solarApp/fmMain.cs index 45884e9..ce1f928 100644 --- a/solarApp/fmMain.cs +++ b/solarApp/fmMain.cs @@ -223,5 +223,27 @@ namespace solarApp gv_web_sensor_month.DataSource = sensorSvc.get_web_sensor50_month(date1.Substring(0, 7), date2.Substring(0, 7), lbSiteID_inv.Text.Substring(0, 09)); } + + private void gv_fic_sensor_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString())) + { + if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12") + { + gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } + + private void gv_web_inv_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_web_inv_day.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_web_inv_day.Rows[e.RowIndex].Cells["count"].Value.ToString())) + { + if (gv_web_inv_day.Rows[e.RowIndex].Cells["count"].Value.ToString() != "24") + { + gv_web_inv_day.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } } } From 49504ccb2df8ac89a506badb302729dc55cd4a03 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Fri, 13 Aug 2021 19:34:36 +0800 Subject: [PATCH 2/5] debugv1 --- solarApp/fmArchive.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index f8e9c01..a668d44 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -244,7 +244,7 @@ namespace solarApp // this.lbSiteDB_sensor.AutoSize = true; this.lbSiteDB_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.lbSiteDB_sensor.Location = new System.Drawing.Point(41, 19); + this.lbSiteDB_sensor.Location = new System.Drawing.Point(49, 19); this.lbSiteDB_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbSiteDB_sensor.Name = "lbSiteDB_sensor"; this.lbSiteDB_sensor.Size = new System.Drawing.Size(79, 24); From 0dc2b262835e578e18b549f24445999d6391a865 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 16 Aug 2021 10:43:18 +0800 Subject: [PATCH 3/5] =?UTF-8?q?station=20=E5=A2=9E=E5=8A=A0=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E8=88=87=E7=B8=BD=E8=A8=88=E7=AD=86=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Model/station_model.cs | 3 ++- solarApp/Service/getStationSvc.cs | 19 ++++++++++++++++--- solarApp/fmMain.Designer.cs | 2 ++ solarApp/fmMain.cs | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/solarApp/Model/station_model.cs b/solarApp/Model/station_model.cs index 3898318..0d808d9 100644 --- a/solarApp/Model/station_model.cs +++ b/solarApp/Model/station_model.cs @@ -56,7 +56,8 @@ namespace solarApp.Model public double TOTALKWH { get; set; } public double PR { get; set; } public double SOLARHOUR { get; set; } - public double kwhkwp { get; set; } + public double kwhkwp { get; set; } + public int count { get; set; } } public class station_list diff --git a/solarApp/Service/getStationSvc.cs b/solarApp/Service/getStationSvc.cs index 3e89bec..50a7f1e 100644 --- a/solarApp/Service/getStationSvc.cs +++ b/solarApp/Service/getStationSvc.cs @@ -116,9 +116,22 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, - round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money - from power_station_history_day where left(`TIMESTAMP`, 10) between @date1 and @date2 and siteid = @siteID"; + //string sql = @" + // select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, + // round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money + // from power_station_history_day where left(`TIMESTAMP`, 10) between @date1 and @date2 and siteid = @siteID"; + string sql = @" + select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, a.siteid, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, + round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money, count + from power_station_history_day a join ( + select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, SITEID, count(*) count + from power_station_history_hour + where siteid = @siteID and left(`TIMESTAMP`, 10) between @date1 and @date2 + group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), SITEID + ) b on a.SITEID = b.SITEID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = b.reportdate + where left(`TIMESTAMP`, 10) between @date1 and @date2 and a.siteid = @siteID + order by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') + "; List ds = conn.Query(sql, new { date1 = date1, date2 = date2 , siteID = siteID}).AsList(); conn.Close(); return ds; diff --git a/solarApp/fmMain.Designer.cs b/solarApp/fmMain.Designer.cs index 7906b34..24a81cb 100644 --- a/solarApp/fmMain.Designer.cs +++ b/solarApp/fmMain.Designer.cs @@ -929,6 +929,7 @@ namespace solarApp this.gv_web_station_day.RowTemplate.Height = 25; this.gv_web_station_day.Size = new System.Drawing.Size(711, 292); this.gv_web_station_day.TabIndex = 3; + this.gv_web_station_day.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_web_station_day_CellFormatting); // // panel7 // @@ -1061,6 +1062,7 @@ namespace solarApp this.gv_fic_station_day.RowTemplate.Height = 25; this.gv_fic_station_day.Size = new System.Drawing.Size(744, 453); this.gv_fic_station_day.TabIndex = 4; + this.gv_fic_station_day.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_fic_station_day_CellFormatting); // // panel5 // diff --git a/solarApp/fmMain.cs b/solarApp/fmMain.cs index ce1f928..71c2245 100644 --- a/solarApp/fmMain.cs +++ b/solarApp/fmMain.cs @@ -245,5 +245,27 @@ namespace solarApp } } } + + private void gv_fic_station_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_fic_station_day.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_station_day.Rows[e.RowIndex].Cells["count"].Value.ToString())) + { + if (gv_fic_station_day.Rows[e.RowIndex].Cells["count"].Value.ToString() != "24") + { + gv_fic_station_day.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } + + private void gv_web_station_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_web_station_day.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_web_station_day.Rows[e.RowIndex].Cells["count"].Value.ToString())) + { + if (gv_web_station_day.Rows[e.RowIndex].Cells["count"].Value.ToString() != "24") + { + gv_web_station_day.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } } } From 855fa4024d4cf8240273674d1ed6b22d7ff2a8f4 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 16 Aug 2021 12:04:53 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9B=BB=E7=AB=99=20rowc?= =?UTF-8?q?ount=20=E6=AA=A2=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/getStationSvc.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solarApp/Service/getStationSvc.cs b/solarApp/Service/getStationSvc.cs index 50a7f1e..fa4b003 100644 --- a/solarApp/Service/getStationSvc.cs +++ b/solarApp/Service/getStationSvc.cs @@ -93,10 +93,10 @@ namespace solarApp.Service { conn.Open(); string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, siteid, round(KWH, 2) KWH, - round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, - round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, - round(money, 3) money, round(todaymoney, 3) todaymoney, round(totalmoney, 3) totalmoney, - round(carbon, 3) carbon, round(todayCarbon, 3) todayCarbon, round(totalCarbon, 3) totalCarbon + round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, + round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, + round(money, 3) money, round(todaymoney, 3) todaymoney, round(totalmoney, 3) totalmoney, + round(carbon, 3) carbon, round(todayCarbon, 3) todayCarbon, round(totalCarbon, 3) totalCarbon from power_station_history_hour where siteID = @siteID and left(`TIMESTAMP`, 10) = '" + reportDate + "' "; List ds = conn.Query(sql, new { siteID = siteID.Substring(0, 9) }).AsList(); From ab0aa1ee1d2db27b48d2e678f40f22c5f6a9c393 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 16 Aug 2021 16:46:13 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1.=20=E5=A4=A9=E6=B0=A3=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5try=20catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index ec69123..c8a016e 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -40,9 +40,11 @@ namespace SolarPower.Quartz.Jobs var DateTimeNow = DateTime.Now; var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); + Root2 observation = null; + if (this.environment.IsDevelopment()) { - dateTime = "2021-08-09 10"; + dateTime = "2021-08-16 09"; } logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -64,13 +66,23 @@ namespace SolarPower.Quartz.Jobs List weatherObservations = new List(); #region 氣象觀測(取資料) - logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】"); - var client = new HttpClient(); - var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP"; - HttpResponseMessage response = client.GetAsync(UVUri).Result; - String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); - Root2 observation = JsonConvert.DeserializeObject(jsonUVs); - logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】"); + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】"); + var client = new HttpClient(); + var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP"; + HttpResponseMessage response = client.GetAsync(UVUri).Result; + String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); + observation = JsonConvert.DeserializeObject(jsonUVs); + logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】"); + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【取得失敗氣象觀測】"); + logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message); + observation = null; + } + #endregion #region step2. 從電站的DB及電站編號找出該電站的控制器 @@ -195,7 +207,7 @@ namespace SolarPower.Quartz.Jobs #endregion powerStationHistoriesHour.Add(history); - + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); } #endregion @@ -353,7 +365,7 @@ namespace SolarPower.Quartz.Jobs #endregion WeatherObservation weatherObservation = new WeatherObservation(); - if (powerStation.WeathersStationId != null) + if (powerStation.WeathersStationId != null && observation != null) { foreach (var Location in observation.Records.Location) { @@ -363,7 +375,7 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); weatherObservation.PowerStationId = powerStation.Id; weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); - weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime)? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime) ? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); calcPowerStation.WeathersStationId = powerStation.WeathersStationId; break; } @@ -380,8 +392,8 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.RateOfRain = weather.PoP; } - - + + } #endregion @@ -581,7 +593,7 @@ namespace SolarPower.Quartz.Jobs #endregion #region step8. 將 meter INSERT 到 meter_history_hour 資料表 - List memter_history_properties = new List() + List memter_history_properties = new List() { "PowerStationId", "TIMESTAMP",