From 1db98a9e7ec127a6ca68a76fe3548c32dc2b54a1 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Wed, 10 Nov 2021 21:31:41 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E8=88=8A=E6=9C=89=E8=B3=87=E6=96=99?= =?UTF-8?q?=E5=8C=AF=E5=85=A5v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/excelHelper.cs | 18 ++++---- solarApp/fmExcel.Designer.cs | 80 +++++++++++++++++++++++++-------- solarApp/fmExcel.cs | 71 +++++++++++++++++++++++++++-- 3 files changed, 139 insertions(+), 30 deletions(-) diff --git a/solarApp/Service/excelHelper.cs b/solarApp/Service/excelHelper.cs index 8c4dc2a..53c05aa 100644 --- a/solarApp/Service/excelHelper.cs +++ b/solarApp/Service/excelHelper.cs @@ -74,8 +74,9 @@ namespace solarApp.Service int i = 0; foreach (DataRow row in dt.Rows) { - //ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) - ss.Append(@"INSERT INTO solar_import.auo_aimai(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) + //ss.Append(@"INSERT INTO solar_import.auo_taiping_October(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) + //ss.Append(@"INSERT INTO solar_import.auo_aimai(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) + ss.Append(@"INSERT INTO solar_import.auo_aimai_october(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) values( '" + row.Field("1").ToString() + "' ,'" + row.Field("2").ToString() + "' ,'" @@ -202,7 +203,7 @@ values( '" return result; } - public bool insert_dailyReport2DB(DataTable dt, string filename) + public bool insert_dailyReport2DB(DataTable dt, string filename, string tablename) { bool result = false; StringBuilder ss = new StringBuilder(); @@ -211,9 +212,9 @@ values( '" conn.Open(); int i = 0; foreach (DataRow row in dt.Rows) - { - //ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) - ss.Append(@"INSERT INTO solar_import.iPVita_temp (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, insertDate) + { //c10, c11, c12, c13, c14, c15, c16, + //iPVita_temp ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID) + ss.Append(@"INSERT INTO solar_import."+ tablename + @"(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13 , c14, c15, c16, insertDate) values( '" + row.Field("1").ToString() + "' ,'" + row.Field("2").ToString() + "' ,'" @@ -229,9 +230,8 @@ values( '" + row.Field("12").ToString() + "' ,'" + row.Field("13").ToString() + "' ,'" + row.Field("14").ToString() + "' ,'" -+ row.Field("15").ToString() + "', '" -+ row.Field("Column1").ToString() + "', now());"); - + + row.Field("15").ToString() + "', '" ++ row.Field("Column1").ToString() + "', now());"); if (i % 10 == 0) { conn.Execute(ss.ToString()); diff --git a/solarApp/fmExcel.Designer.cs b/solarApp/fmExcel.Designer.cs index 15b80bb..1da179f 100644 --- a/solarApp/fmExcel.Designer.cs +++ b/solarApp/fmExcel.Designer.cs @@ -42,6 +42,7 @@ namespace solarApp this.panel1 = new System.Windows.Forms.Panel(); this.lbSiteName_sensor = new System.Windows.Forms.Label(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.bt_dailyReport = new System.Windows.Forms.Button(); this.bt_sun_yadong = new System.Windows.Forms.Button(); this.bt_sun_taoyuan = new System.Windows.Forms.Button(); this.bt_gong34 = new System.Windows.Forms.Button(); @@ -51,7 +52,9 @@ namespace solarApp this.rt1 = new System.Windows.Forms.RichTextBox(); this.tb1 = new System.Windows.Forms.TabPage(); this.tabControl = new System.Windows.Forms.TabControl(); - this.bt_dailyReport = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -97,7 +100,7 @@ namespace solarApp // 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(3, 640); + this.bt_archive.Location = new System.Drawing.Point(0, 682); this.bt_archive.Name = "bt_archive"; this.bt_archive.Size = new System.Drawing.Size(226, 60); this.bt_archive.TabIndex = 8; @@ -120,7 +123,7 @@ namespace solarApp // bt_read_taiping // this.bt_read_taiping.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_read_taiping.Location = new System.Drawing.Point(0, 337); + this.bt_read_taiping.Location = new System.Drawing.Point(3, 286); this.bt_read_taiping.Name = "bt_read_taiping"; this.bt_read_taiping.Size = new System.Drawing.Size(192, 47); this.bt_read_taiping.TabIndex = 6; @@ -131,7 +134,7 @@ namespace solarApp // bt_inv_day_hj // this.bt_inv_day_hj.Font = new System.Drawing.Font("Microsoft JhengHei UI", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_inv_day_hj.Location = new System.Drawing.Point(0, 270); + this.bt_inv_day_hj.Location = new System.Drawing.Point(0, 236); this.bt_inv_day_hj.Name = "bt_inv_day_hj"; this.bt_inv_day_hj.Size = new System.Drawing.Size(143, 44); this.bt_inv_day_hj.TabIndex = 5; @@ -202,6 +205,9 @@ namespace solarApp // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.Color.PaleGoldenrod; + this.splitContainer1.Panel1.Controls.Add(this.button3); + this.splitContainer1.Panel1.Controls.Add(this.button2); + this.splitContainer1.Panel1.Controls.Add(this.button1); this.splitContainer1.Panel1.Controls.Add(this.bt_dailyReport); this.splitContainer1.Panel1.Controls.Add(this.bt_sun_yadong); this.splitContainer1.Panel1.Controls.Add(this.bt_sun_taoyuan); @@ -225,32 +231,45 @@ namespace solarApp this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 0; // + // bt_dailyReport + // + this.bt_dailyReport.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bt_dailyReport.Location = new System.Drawing.Point(7, 748); + this.bt_dailyReport.Name = "bt_dailyReport"; + this.bt_dailyReport.Size = new System.Drawing.Size(237, 74); + this.bt_dailyReport.TabIndex = 15; + this.bt_dailyReport.Text = "daily_report 太陽能光電-桃園全虹"; + this.bt_dailyReport.UseVisualStyleBackColor = true; + this.bt_dailyReport.Click += new System.EventHandler(this.bt_dailyReport_Click); + // // bt_sun_yadong // this.bt_sun_yadong.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_sun_yadong.Location = new System.Drawing.Point(5, 576); + this.bt_sun_yadong.Location = new System.Drawing.Point(3, 479); this.bt_sun_yadong.Name = "bt_sun_yadong"; this.bt_sun_yadong.Size = new System.Drawing.Size(213, 47); this.bt_sun_yadong.TabIndex = 14; this.bt_sun_yadong.Text = "太陽能光電-亞東觀音"; this.bt_sun_yadong.UseVisualStyleBackColor = true; + this.bt_sun_yadong.Visible = false; this.bt_sun_yadong.Click += new System.EventHandler(this.bt_sun_yadong_Click); // // bt_sun_taoyuan // this.bt_sun_taoyuan.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_sun_taoyuan.Location = new System.Drawing.Point(3, 523); + this.bt_sun_taoyuan.Location = new System.Drawing.Point(3, 433); this.bt_sun_taoyuan.Name = "bt_sun_taoyuan"; this.bt_sun_taoyuan.Size = new System.Drawing.Size(213, 47); this.bt_sun_taoyuan.TabIndex = 13; this.bt_sun_taoyuan.Text = "太陽能光電-桃園全虹"; this.bt_sun_taoyuan.UseVisualStyleBackColor = true; + this.bt_sun_taoyuan.Visible = false; this.bt_sun_taoyuan.Click += new System.EventHandler(this.bt_sun_taoyuan_Click); // // bt_gong34 // this.bt_gong34.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_gong34.Location = new System.Drawing.Point(0, 443); + this.bt_gong34.Location = new System.Drawing.Point(3, 392); this.bt_gong34.Name = "bt_gong34"; this.bt_gong34.Size = new System.Drawing.Size(189, 47); this.bt_gong34.TabIndex = 12; @@ -261,7 +280,7 @@ namespace solarApp // bt_AUO_aimai // this.bt_AUO_aimai.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_AUO_aimai.Location = new System.Drawing.Point(0, 390); + this.bt_AUO_aimai.Location = new System.Drawing.Point(3, 339); this.bt_AUO_aimai.Name = "bt_AUO_aimai"; this.bt_AUO_aimai.Size = new System.Drawing.Size(189, 47); this.bt_AUO_aimai.TabIndex = 11; @@ -283,7 +302,7 @@ namespace solarApp // bt_day_archive_hj // this.bt_day_archive_hj.Font = new System.Drawing.Font("Microsoft JhengHei UI", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_day_archive_hj.Location = new System.Drawing.Point(149, 270); + this.bt_day_archive_hj.Location = new System.Drawing.Point(149, 236); this.bt_day_archive_hj.Name = "bt_day_archive_hj"; this.bt_day_archive_hj.Size = new System.Drawing.Size(119, 44); this.bt_day_archive_hj.TabIndex = 9; @@ -325,16 +344,38 @@ namespace solarApp this.tabControl.Size = new System.Drawing.Size(1782, 853); this.tabControl.TabIndex = 1; // - // bt_dailyReport + // button1 // - this.bt_dailyReport.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_dailyReport.Location = new System.Drawing.Point(5, 706); - this.bt_dailyReport.Name = "bt_dailyReport"; - this.bt_dailyReport.Size = new System.Drawing.Size(237, 74); - this.bt_dailyReport.TabIndex = 15; - this.bt_dailyReport.Text = "daily_report 太陽能光電-桃園全虹"; - this.bt_dailyReport.UseVisualStyleBackColor = true; - this.bt_dailyReport.Click += new System.EventHandler(this.bt_dailyReport_Click); + this.button1.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button1.Location = new System.Drawing.Point(5, 527); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(213, 47); + this.button1.TabIndex = 16; + this.button1.Text = "太陽能光電-高雄臨廣"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button2.Location = new System.Drawing.Point(3, 569); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(213, 47); + this.button2.TabIndex = 17; + this.button2.Text = "太陽能光電-翔億大"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button3.Location = new System.Drawing.Point(3, 613); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(213, 47); + this.button3.TabIndex = 18; + this.button3.Text = "太陽能光電-翔億小"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); // // fmExcel // @@ -383,5 +424,8 @@ namespace solarApp private System.Windows.Forms.Button bt_sun_taoyuan; private System.Windows.Forms.Button bt_sun_yadong; private System.Windows.Forms.Button bt_dailyReport; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button3; } } \ No newline at end of file diff --git a/solarApp/fmExcel.cs b/solarApp/fmExcel.cs index 8861cd0..370b671 100644 --- a/solarApp/fmExcel.cs +++ b/solarApp/fmExcel.cs @@ -697,7 +697,7 @@ namespace solarApp //str = inverterID.Split(" "); //inverterID = str[str.Length - 1]; - xlsSvc.insert_dailyReport2DB(dt, filename); + xlsSvc.insert_dailyReport2DB(dt, filename, "daily_taoyuan_quanhong"); dt.Rows.Clear(); x++; } @@ -716,8 +716,73 @@ namespace solarApp private void bt_dailyReport_Click(object sender, EventArgs e) { - ImporExcel_dailyReport(""); - + ImporExcel_dailyReport("daily_taoyuan_quanhong"); + //insert_dailyReport2DB("daily_taoyuan_quanhong"); } + + private void button2_Click(object sender, EventArgs e) + { + insert_sunLightCsv("sun_zhanghua_xy1"); + } + + private void button3_Click(object sender, EventArgs e) + { + insert_sunLightCsv("sun_zhanghua_xy2"); + } + + private void button1_Click(object sender, EventArgs e) + { + insert_sunLightCsv("sun_gaoxiong_linguang"); + } + + void insert_sunLightCsv(string tableName) { + string fname = ""; + string[] fileEntries = new string[0]; + Array.Clear(fileEntries, 0, fileEntries.Length); + //取得選取檔案的路徑 + string dir;//= Path.GetDirectoryName(fname); + + using (var fbd = new FolderBrowserDialog()) + { + DialogResult result = fbd.ShowDialog(); + if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) + { + //dir = Path.GetDirectoryName(fname); + //fileEntries = Directory.GetFiles(fbd.SelectedPath); + fileEntries = Directory.GetFiles(fbd.SelectedPath, "*.*", SearchOption.AllDirectories); + MessageBox.Show("Files found: " + fileEntries.Length.ToString(), "Message"); + } + } + + Service.operateCSV csvSvc = new Service.operateCSV(); // readCsvTxt + System.Data.DataTable dt = new System.Data.DataTable(); + bool isFirst = true; + foreach (string fileName in fileEntries) + { + #region 取得 filename 中的 InvID + string fName = Path.GetFileName(fileName); + rt1.AppendText(fName + " "); + rt1.SelectionStart = rt1.Text.Length; + rt1.ScrollToCaret(); + #endregion + + if (isFirst) + { + //csvSvc.clear_inv("hour"); + csvSvc.taoYuan_createColumnHour(ref dt, fileName); + csvSvc.taoYuan_readCsvFile(ref dt, fileName, dt.Columns.Count, isFirst); + isFirst = false; + } + else + csvSvc.taoYuan_readCsvFile(ref dt, fileName, dt.Columns.Count, isFirst); + } + MessageBox.Show(" 共 " + dt.Rows.Count.ToString()); + + //System.Data.DataTable dt = solarApp.Service.csvHelper.OpenCSV(fname); + csvSvc.taoYuan_insertHour2DB(ref dt, tableName); + MessageBox.Show("OK"); + } + + } } From 1b0a2407b5dc44e8c4a5c1ff83a00b1ee21856b0 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Thu, 2 Dec 2021 10:26:49 +0800 Subject: [PATCH 02/14] =?UTF-8?q?Inv=20=E6=AD=B8=E6=AA=94=E6=94=B9?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + solarApp/App.config | 2 +- solarApp/Service/getInvSvc.cs | 9 +- solarApp/Service/procInvSvc.cs | 341 +++++++++++++++++++++++++-------- solarApp/fmArchive.Designer.cs | 248 +++++++++++++++++++++--- solarApp/fmArchive.cs | 29 ++- 6 files changed, 520 insertions(+), 111 deletions(-) diff --git a/.gitignore b/.gitignore index c573630..d06434a 100644 --- a/.gitignore +++ b/.gitignore @@ -344,3 +344,5 @@ healthchecksdb /SolarPower/wwwroot/upload/operation_recode/1 /SolarPower/wwwroot/upload/report/20210819 +/SolarPower/SolarPower.zip +/SolarPower.zip diff --git a/solarApp/App.config b/solarApp/App.config index ca0c681..1210e63 100644 --- a/solarApp/App.config +++ b/solarApp/App.config @@ -2,7 +2,7 @@ - + diff --git a/solarApp/Service/getInvSvc.cs b/solarApp/Service/getInvSvc.cs index 9c71aa4..4550ae1 100644 --- a/solarApp/Service/getInvSvc.cs +++ b/solarApp/Service/getInvSvc.cs @@ -101,8 +101,11 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); + //string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H:%i') reportdate, inverterid, KWH, TODAYKWH, TOTALKWH, round(PR, 2) PR + // from inverter_history_hour where left(`TIMESTAMP`, 10) = '" + reportDate + "' and inverterid = '" + invID + "' "; + string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H:%i') reportdate, inverterid, KWH, TODAYKWH, TOTALKWH, round(PR, 2) PR - from inverter_history_hour where left(`TIMESTAMP`, 10) = '" + reportDate + "' and inverterid = '" + invID + "' "; + from inverter_history_hour where crdDate = '" + reportDate + "' and inverterid = '" + invID + "' "; List ds = conn.Query(sql).AsList(); conn.Close(); return ds; @@ -122,11 +125,11 @@ select DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') reportdate, a.inverterid, round(a.K from inverter_history_day a left 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 + @"' + where crdDate 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"; +where crdDate 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/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 65243d1..632d31e 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -15,6 +15,7 @@ namespace solarApp.Service string Connection1 = string.Empty; ILogger _logger; + public procInvSvc(string Connection_parame = null, ILogger logger = null) { if (!string.IsNullOrEmpty(Connection_parame)) @@ -54,10 +55,15 @@ namespace solarApp.Service _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1); } + //string sql = @" + // delete from inverter_history_15min where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; + // delete from inverter_history_hour where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; + // delete from inverter_history_day where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; + // delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;"; string sql = @" - delete from inverter_history_15min where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; - delete from inverter_history_hour where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; - delete from inverter_history_day where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1; + delete from inverter_history_15min where powerstationID = @powerStationID and CrdDate = @date1; + delete from inverter_history_hour where powerstationID = @powerStationID and CrdDate = @date1; + delete from inverter_history_day where powerstationID = @powerStationID and CrdDate = @date1; delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;"; var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); @@ -85,19 +91,21 @@ namespace solarApp.Service public bool archiveData(string siteID, string date1) { bool result = false; - try - { + //try + //{ _siteID = siteID; _date1 = date1; get_siteInfo(); clearData(); insert_inv(); + //日報表 + //insert_report_invDay(); result = true; - } - catch (Exception ex) - { - throw ex; - } + //} + //catch (Exception ex) + //{ + // throw ex; + //} return result; } public bool get_siteInfo() @@ -150,8 +158,8 @@ namespace solarApp.Service bool insert_inv() { bool result = false; - try - { + //try + //{ using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); @@ -168,34 +176,64 @@ namespace solarApp.Service } sql = @" - INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) - select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from - ( - select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid, + INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) + select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from + ( + select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid, + (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, + (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, + (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, (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, - (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, - (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, - (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 - ) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid"; - var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + 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 + ) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid"; + + // sql = @" + // INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) + // select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from + // ( + //select @PowerStationId PowerStationId,CONCAT(left(CrdTime, 13), '%Y-%m-%d %H'), ':00:00')reportdate, inverterid, + // (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH + // from " + _siteDB + ".s" + _siteID01 + @"_inv + // where left(CrdTime, 10) = @date1 and CONCAT(left(CrdTime, 13), '%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(left(CrdTime, 13), ':15:00')reportdate, inverterid, + // (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH + // from " + _siteDB + ".s" + _siteID01 + @"_inv + // where left(CrdTime, 10) = @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(left(CrdTime, 13), ':30:00')reportdate, inverterid, + // (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH + // from " + _siteDB + ".s" + _siteID01 + @"_inv + // where left(CrdTime, 10) = @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(left(CrdTime, 13), ':45:00')reportdate, inverterid, + // (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH + // from " + _siteDB + ".s" + _siteID01 + @"_inv + // where left(CrdTime, 10) = @date1 and MINUTE(CrdTime) between '45' and '55' + // group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid + // ) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid"; + + var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); if (_logger != null) { @@ -218,51 +256,101 @@ namespace solarApp.Service _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1); } - sql = @" - insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, - AC3V, AC3A, AC3W, AC3F, AC3WH, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, - PR, RA1, RA2, RA3, RA4, RA5, DCKW, ACKW, KWH, TODAYKWH, TOTALKWH, KWHKWP) + //sql = @" + // insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, + // AC3V, AC3A, AC3W, AC3F, AC3WH, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, + // PR, RA1, RA2, RA3, RA4, RA5, DCKW, ACKW, KWH, TODAYKWH, TOTALKWH, KWHKWP) - SELECT @powerstationID powerStationID, a.INVERTERID, a.reportDate, IFNULL(Irradiance, 0), a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH, - a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH, a.DC1V, a.DC1A, a.DC1W, a.DC1WH, a.DC2V, a.DC2A, a.DC2W, a.DC2WH, a.DC3V, a.DC3A, a.DC3W, - a.DC3WH, a.DC4V, a.DC4A, a.DC4W, a.DC4WH, a.DC5V, a.DC5A, a.DC5W, a.DC5WH, - inv_pr.PR, a.RA1, a.RA2, a.RA3, a.RA4, a.RA5, ((DC1W + DC2W + DC3W + DC4W+ DC5W) / 1000) DCKW, - ((AC1W + AC2W + AC3W) / 1000) ACKW, a.KWH, a.TODAYKWH, a.TOTALKWH, (a.KWH / i.Capacity) AS KWHKWP - from - ( -- 取得該時間區間的KWH - SELECT concat(FROM_UNIXTIME(a.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') reportDate, a.INVERTERID, - AVG(a.AC1V) AS AC1V, AVG(a.AC1A) AS AC1A, round(SUM(a.AC1W), 5) AS AC1W, AVG(a.AC1F) AS AC1F, SUM(a.AC1WH) AS AC1WH, AVG(a.AC2V) AS AC2V, - AVG(a.AC2A) AS AC2A, round(SUM(a.AC2W), 5) AS AC2W, AVG(a.AC2F) AS AC2F, SUM(a.AC2WH) AS AC2WH,AVG(a.AC3V) AS AC3V, AVG(a.AC3A) AS AC3A, - round(SUM(a.AC3W),5) AS AC3W, AVG(a.AC3F) AS AC3F, SUM(a.AC3WH) AS AC3WH, AVG(a.DC1V) AS DC1V, AVG(a.DC1A) AS DC1A, SUM(a.DC1W) AS DC1W, - SUM(a.DC1WH) AS DC1WH, AVG(a.DC2V) AS DC2V, AVG(a.DC2A) AS DC2A, SUM(a.DC2W) AS DC2W, SUM(a.DC2WH) AS DC2WH, AVG(a.DC3V) AS DC3V, - AVG(a.DC3A) AS DC3A, AVG(a.DC3W) AS DC3W, AVG(a.DC3WH) AS DC3WH, AVG(a.DC4V) AS DC4V, AVG(a.DC4A) AS DC4A, SUM(a.DC4W) AS DC4W, - SUM(a.DC4WH) AS DC4WH,AVG(a.DC5V) AS DC5V, AVG(a.DC5A) AS DC5A, SUM(a.DC5W) AS DC5W, SUM(a.DC5WH) AS DC5WH, - AVG(a.RA1) AS RA1, AVG(a.RA2) AS RA2, AVG(a.RA3) AS RA3, - AVG(a.RA4) AS RA4, AVG(a.RA5) AS RA5, MAX(a.TODAYKWH) AS TODAYKWH, MAX(a.TOTALKWH) AS TOTALKWH, (SUM(a.WH)/1000) AS KWH - FROM " + _siteDB + ".s" + _siteID01 + @"_inv a - WHERE left(FROM_UNIXTIME(a.TIMESTAMP / 1000, '%Y-%m-%d'), 10) = @date1 - GROUP BY left(FROM_UNIXTIME(a.TIMESTAMP/ 1000, '%Y-%m-%d %H'), 13), a.INVERTERID - ) a - LEFT JOIN( -- 取得整點值PR - SELECT concat(FROM_UNIXTIME(inv.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') AS reportDate, inv.INVERTERID, inv.PR - FROM " + _siteDB + ".s" + _siteID01 + @"_inv inv - WHERE left(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 10) = @date1 - and right(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 2) = '55' - GROUP BY FROM_UNIXTIME(inv.TIMESTAMP/ 1000, '%Y-%m-%d %H'), inv.INVERTERID - ) inv_pr - ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID - -- 取得逆變器容量 - LEFT JOIN " + _siteDB + @".inverter i ON a.INVERTERID = i.InverterId - -- 取日照度 --------------------- - left join ( - select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H'), ':00:00') AS reportDate, Irradiance - from sensor_history_hour a - where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 - )irr on a.reportDate = irr.reportDate - order by a.INVERTERID, a.reportDate;"; - int ct = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + // SELECT @powerstationID powerStationID, a.INVERTERID, a.reportDate, IFNULL(Irradiance, 0), a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH, + // a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH, a.DC1V, a.DC1A, a.DC1W, a.DC1WH, a.DC2V, a.DC2A, a.DC2W, a.DC2WH, a.DC3V, a.DC3A, a.DC3W, + // a.DC3WH, a.DC4V, a.DC4A, a.DC4W, a.DC4WH, a.DC5V, a.DC5A, a.DC5W, a.DC5WH, + // inv_pr.PR, a.RA1, a.RA2, a.RA3, a.RA4, a.RA5, ((DC1W + DC2W + DC3W + DC4W+ DC5W) / 1000) DCKW, + // ((AC1W + AC2W + AC3W) / 1000) ACKW, a.KWH, a.TODAYKWH, a.TOTALKWH, (a.KWH / i.Capacity) AS KWHKWP + // from + // ( -- 取得該時間區間的KWH + // SELECT concat(FROM_UNIXTIME(a.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') reportDate, a.INVERTERID, + // AVG(a.AC1V) AS AC1V, AVG(a.AC1A) AS AC1A, round(SUM(a.AC1W), 5) AS AC1W, AVG(a.AC1F) AS AC1F, SUM(a.AC1WH) AS AC1WH, AVG(a.AC2V) AS AC2V, + // AVG(a.AC2A) AS AC2A, round(SUM(a.AC2W), 5) AS AC2W, AVG(a.AC2F) AS AC2F, SUM(a.AC2WH) AS AC2WH,AVG(a.AC3V) AS AC3V, AVG(a.AC3A) AS AC3A, + // round(SUM(a.AC3W),5) AS AC3W, AVG(a.AC3F) AS AC3F, SUM(a.AC3WH) AS AC3WH, AVG(a.DC1V) AS DC1V, AVG(a.DC1A) AS DC1A, SUM(a.DC1W) AS DC1W, + // SUM(a.DC1WH) AS DC1WH, AVG(a.DC2V) AS DC2V, AVG(a.DC2A) AS DC2A, SUM(a.DC2W) AS DC2W, SUM(a.DC2WH) AS DC2WH, AVG(a.DC3V) AS DC3V, + // AVG(a.DC3A) AS DC3A, AVG(a.DC3W) AS DC3W, AVG(a.DC3WH) AS DC3WH, AVG(a.DC4V) AS DC4V, AVG(a.DC4A) AS DC4A, SUM(a.DC4W) AS DC4W, + // SUM(a.DC4WH) AS DC4WH,AVG(a.DC5V) AS DC5V, AVG(a.DC5A) AS DC5A, SUM(a.DC5W) AS DC5W, SUM(a.DC5WH) AS DC5WH, + // AVG(a.RA1) AS RA1, AVG(a.RA2) AS RA2, AVG(a.RA3) AS RA3, + // AVG(a.RA4) AS RA4, AVG(a.RA5) AS RA5, MAX(a.TODAYKWH) AS TODAYKWH, MAX(a.TOTALKWH) AS TOTALKWH, (SUM(a.WH)/1000) AS KWH + // FROM " + _siteDB + ".s" + _siteID01 + @"_inv a + // WHERE left(FROM_UNIXTIME(a.TIMESTAMP / 1000, '%Y-%m-%d'), 10) = @date1 + // GROUP BY left(FROM_UNIXTIME(a.TIMESTAMP/ 1000, '%Y-%m-%d %H'), 13), a.INVERTERID + // ) a + // LEFT JOIN( -- 取得整點值PR + // SELECT concat(FROM_UNIXTIME(inv.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') AS reportDate, inv.INVERTERID, inv.PR + // FROM " + _siteDB + ".s" + _siteID01 + @"_inv inv + // WHERE left(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 10) = @date1 + // and right(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 2) = '55' + // GROUP BY FROM_UNIXTIME(inv.TIMESTAMP/ 1000, '%Y-%m-%d %H'), inv.INVERTERID + // ) inv_pr + // ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID + // -- 取得逆變器容量 + // LEFT JOIN " + _siteDB + @".inverter i ON a.INVERTERID = i.InverterId + // -- 取日照度 --------------------- + // left join ( + // select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H'), ':00:00') AS reportDate, Irradiance + // from sensor_history_hour a + // where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 + // )irr on a.reportDate = irr.reportDate + // order by a.INVERTERID, a.reportDate;"; + //int ct = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); - if (_logger != null) + sql = @$"DROP TEMPORARY TABLE IF EXISTS Inv_day_"+ _powerStationID + @"_s1; + CREATE TEMPORARY TABLE Inv_day_" + _powerStationID + @"_s1 + select * from " + _siteDB + ".s" + _siteID01 + @"_inv a + WHERE left(crdTime, 10) = @date1; + # 2. add index + ALTER TABLE Inv_day_" + _powerStationID + @"_s1 ADD INDEX `temp_index` (crdTime, inverterid);"; + int ct = conn.Execute(sql, new { date1 = _date1}); + + sql = @$"DROP TEMPORARY TABLE IF EXISTS Inv_day_" + _powerStationID + @"_s2; + CREATE TEMPORARY TABLE Inv_day_" + _powerStationID + @"_s2 + SELECT " + _powerStationID + @" powerStationID, a.INVERTERID, a.reportDate,a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH, + a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH, a.DC1V, a.DC1A, a.DC1W, a.DC1WH, a.DC2V, a.DC2A, a.DC2W, a.DC2WH, a.DC3V, a.DC3A, a.DC3W, + a.DC3WH, a.DC4V, a.DC4A, a.DC4W, a.DC4WH, a.DC5V, a.DC5A, a.DC5W, a.DC5WH, + a.RA1, a.RA2, a.RA3, a.RA4, a.RA5, a.KWH, a.TODAYKWH, a.TOTALKWH, + IFNULL(Irradiance, 0) irr, 0 as PR, ((DC1W + DC2W + DC3W + DC4W + DC5W) / 1000) DCKW, ((AC1W + AC2W + AC3W) / 1000) ACKW, (a.KWH / i.Capacity) AS KWHKWP + from + (-- 取得該時間區間的KWH + SELECT concat(left(crdTime, 13), ':00:00') reportDate, INVERTERID, + AVG(AC1V) AS AC1V, AVG(AC1A) AS AC1A, round(SUM(AC1W), 5) AS AC1W, AVG(AC1F) AS AC1F, SUM(AC1WH) AS AC1WH, AVG(AC2V) AS AC2V, + AVG(AC2A) AS AC2A, round(SUM(AC2W), 5) AS AC2W, AVG(AC2F) AS AC2F, SUM(AC2WH) AS AC2WH, AVG(AC3V) AS AC3V, AVG(AC3A) AS AC3A, + round(SUM(AC3W), 5) AS AC3W, AVG(AC3F) AS AC3F, SUM(AC3WH) AS AC3WH, AVG(DC1V) AS DC1V, AVG(DC1A) AS DC1A, SUM(DC1W) AS DC1W, + SUM(DC1WH) AS DC1WH, AVG(DC2V) AS DC2V, AVG(DC2A) AS DC2A, SUM(DC2W) AS DC2W, SUM(DC2WH) AS DC2WH, AVG(DC3V) AS DC3V, + AVG(DC3A) AS DC3A, AVG(DC3W) AS DC3W, AVG(DC3WH) AS DC3WH, AVG(DC4V) AS DC4V, AVG(DC4A) AS DC4A, SUM(DC4W) AS DC4W, + SUM(DC4WH) AS DC4WH, AVG(DC5V) AS DC5V, AVG(DC5A) AS DC5A, SUM(DC5W) AS DC5W, SUM(DC5WH) AS DC5WH, + AVG(RA1) AS RA1, AVG(RA2) AS RA2, AVG(RA3) AS RA3, + AVG(RA4) AS RA4, AVG(RA5) AS RA5, MAX(TODAYKWH) AS TODAYKWH, MAX(TOTALKWH) AS TOTALKWH, (SUM(WH) / 1000) AS KWH + FROM Inv_day_" + _powerStationID + @"_s1 + GROUP BY left(crdTime, 13), INVERTERID + ) a + -- 取得逆變器容量 + LEFT JOIN " + _siteDB + @".inverter i ON a.INVERTERID = i.InverterId + -- 取日照度-------------------- - + left join( + select concat(DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d %H'), ':00:00') AS reportDate, Irradiance + from sensor_history_hour + where powerstationID = " + _powerStationID + @" and DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = @date1 + )irr on a.reportDate = irr.reportDate; "; + ct = conn.Execute(sql, new { date1 = _date1 }); + //# 3. insert ans + sql = @$" + INSERT INTO solar_master.inverter_history_hour(`powerStationID`, `INVERTERID`, `TIMESTAMP`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `KWH`, `TODAYKWH`, `TOTALKWH`, `Irradiance`, `PR`, `DCKW`, `ACKW`, `KWHKWP`) + select `powerStationID`, a.`INVERTERID`, a.`reportDate`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `KWH`, `TODAYKWH`, `TOTALKWH`, `irr`, inv_pr.`PR`, `DCKW`, `ACKW`, `KWHKWP` + from Inv_day_" + _powerStationID + @"_s2 a left JOIN( -- 取得整點值PR + SELECT concat(left(crdTime, 13), ':00:00') AS reportDate, inv.INVERTERID, inv.PR + FROM Inv_day_" + _powerStationID + @"_s1 inv + WHERE minute(crdtime) = '55' + GROUP BY left(crdTime, 13), inv.INVERTERID + ) inv_pr + ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID;"; + ct = conn.Execute(sql, new { date1 = _date1 }); + if (_logger != null) { _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1); } @@ -387,6 +475,95 @@ namespace solarApp.Service #endregion month + conn.Close(); + } + result = true; + //} + //catch (Exception ex) + //{ + // throw ex; + //} + return result; + } + + void ck_empty_archivedData(string siteID, string date1) + { + _siteID = siteID; + _date1 = date1; + get_siteInfo(); + } + + //建立日報表 + bool insert_report_invDay() { + bool result = false; + try + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + string ss = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));"; + conn.Execute(ss); + + string sql = string.Empty; + #region get SQL + try + { + if (_logger != null) + { + _logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); + } + + #region 取得 inv 數量 + sql = $@"select * from v_company_inv where "; + #endregion + + sql = @$" +SET @sql = NULL; +SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 2), '''') + ) INTO @sql +FROM inverter_history_hour where powerstationId = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{_date1}'; +SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, + ', b.KWH hourKWH, + ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour + WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{_date1}'' and powerstationid = {_powerStationID}))*100,2) + , 0) ''hourKWHp'', ifnull(d.irradiance, 0) ''irradiance'', ifnull(d.Temperature, 0) ''temperature'', + ifnull(b.money, 0) ''hourmoney'', ifnull(round(b.PR, 2), 0) as pr + FROM inverter_history_hour a left join + ( # 每小時加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') report_date, siteid, sitetype, round(KWH, 2) KWH, + round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money + from power_station_history_hour + where powerstationid = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{_date1}'' + ) b on a.powerStationid = b.powerStationid and concat(a.crdDate,' ', left(a.crdTime, 5)) = b.report_date + + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:00'')report_date, irradiance, Temperature + from sensor_history_hour + where powerstationid = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{_date1}'' + ) d on a.powerStationid = d.powerStationid and concat(a.crdDate,' ', left(a.crdTime, 2), '':00'') = d.report_date + where a.crdDate = ''{_date1}'' + GROUP BY concat(a.crdDate,' ', left(a.crdTime, 2)) + order by a.crdTime '); + select @sql as 'mySelect'; #顯示動態語法"; + var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + + if (_logger != null) + { + _logger.LogInformation("【Proc_inv_日報】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1); + } + } + catch (Exception ex) + { + _logger.LogError("【Proc_inv_日報】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); + _logger.LogError("【Proc_inv_日報】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString()); + throw ex; + } + #endregion + + conn.Close(); } result = true; diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index 397770b..df16b74 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -32,6 +32,7 @@ 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_rpt_invDay = new System.Windows.Forms.Button(); this.bt_meter = new System.Windows.Forms.Button(); this.lbmsg = new System.Windows.Forms.Label(); this.dtSelect2 = new System.Windows.Forms.DateTimePicker(); @@ -44,21 +45,41 @@ namespace solarApp this.bt_site = new System.Windows.Forms.Button(); this.bt_Inv = new System.Windows.Forms.Button(); this.bt_Sensor = new System.Windows.Forms.Button(); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.br_rpt_invDay = new System.Windows.Forms.DataGridView(); this.panel1 = new System.Windows.Forms.Panel(); this.btVerifyData = new System.Windows.Forms.Button(); this.lbSiteDB_sensor = new System.Windows.Forms.Label(); this.lbSiteID_sensor = new System.Windows.Forms.Label(); this.lbSiteName_sensor = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.button3 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); + this.button2 = new System.Windows.Forms.Button(); + this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); + this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker(); + this.dataGridView2 = new System.Windows.Forms.DataGridView(); + this.panel2 = new System.Windows.Forms.Panel(); + this.button9 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.br_rpt_invDay)).BeginInit(); this.panel1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); + this.panel2.SuspendLayout(); this.SuspendLayout(); // // tabControl1 @@ -78,7 +99,7 @@ namespace solarApp this.tabPage1.Controls.Add(this.splitContainer1); this.tabPage1.Location = new System.Drawing.Point(4, 31); this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3); + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Size = new System.Drawing.Size(1774, 918); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "tabPage1"; @@ -93,6 +114,7 @@ namespace solarApp // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.splitContainer1.Panel1.Controls.Add(this.bt_rpt_invDay); this.splitContainer1.Panel1.Controls.Add(this.bt_meter); this.splitContainer1.Panel1.Controls.Add(this.lbmsg); this.splitContainer1.Panel1.Controls.Add(this.dtSelect2); @@ -108,17 +130,28 @@ namespace solarApp // // splitContainer1.Panel2 // - this.splitContainer1.Panel2.Controls.Add(this.dataGridView1); + this.splitContainer1.Panel2.Controls.Add(this.br_rpt_invDay); this.splitContainer1.Panel2.Controls.Add(this.panel1); this.splitContainer1.Size = new System.Drawing.Size(1768, 912); - this.splitContainer1.SplitterDistance = 299; + this.splitContainer1.SplitterDistance = 400; this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 0; // + // bt_rpt_invDay + // + this.bt_rpt_invDay.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bt_rpt_invDay.Location = new System.Drawing.Point(223, 790); + this.bt_rpt_invDay.Name = "bt_rpt_invDay"; + this.bt_rpt_invDay.Size = new System.Drawing.Size(135, 44); + this.bt_rpt_invDay.TabIndex = 12; + this.bt_rpt_invDay.Text = "日報表"; + this.bt_rpt_invDay.UseVisualStyleBackColor = true; + this.bt_rpt_invDay.Click += new System.EventHandler(this.bt_rpt_invDay_Click); + // // bt_meter // - this.bt_meter.Location = new System.Drawing.Point(156, 786); - this.bt_meter.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.bt_meter.Location = new System.Drawing.Point(10, 786); + this.bt_meter.Margin = new System.Windows.Forms.Padding(4); this.bt_meter.Name = "bt_meter"; this.bt_meter.Size = new System.Drawing.Size(135, 56); this.bt_meter.TabIndex = 11; @@ -159,7 +192,7 @@ namespace solarApp 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(10, 635); this.bt_clear_sensor.Name = "bt_clear_sensor"; - this.bt_clear_sensor.Size = new System.Drawing.Size(135, 44); + this.bt_clear_sensor.Size = new System.Drawing.Size(119, 44); this.bt_clear_sensor.TabIndex = 7; this.bt_clear_sensor.Text = "clear data"; this.bt_clear_sensor.UseVisualStyleBackColor = true; @@ -171,7 +204,7 @@ namespace solarApp this.bt_clear_station.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.bt_clear_station.Location = new System.Drawing.Point(10, 735); this.bt_clear_station.Name = "bt_clear_station"; - this.bt_clear_station.Size = new System.Drawing.Size(135, 44); + this.bt_clear_station.Size = new System.Drawing.Size(119, 44); this.bt_clear_station.TabIndex = 6; this.bt_clear_station.Text = "clear data"; this.bt_clear_station.UseVisualStyleBackColor = true; @@ -183,7 +216,7 @@ namespace solarApp this.bt_clear_inv.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.bt_clear_inv.Location = new System.Drawing.Point(10, 686); this.bt_clear_inv.Name = "bt_clear_inv"; - this.bt_clear_inv.Size = new System.Drawing.Size(135, 44); + this.bt_clear_inv.Size = new System.Drawing.Size(119, 44); this.bt_clear_inv.TabIndex = 5; this.bt_clear_inv.Text = "clear data"; this.bt_clear_inv.UseVisualStyleBackColor = true; @@ -194,7 +227,7 @@ 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(299, 530); + this.fp_site.Size = new System.Drawing.Size(400, 530); this.fp_site.TabIndex = 4; // // dtSelect1 @@ -238,16 +271,16 @@ namespace solarApp this.bt_Sensor.UseVisualStyleBackColor = true; this.bt_Sensor.Click += new System.EventHandler(this.bt_Sensor_Click); // - // dataGridView1 + // br_rpt_invDay // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView1.Location = new System.Drawing.Point(0, 125); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersWidth = 51; - this.dataGridView1.RowTemplate.Height = 29; - this.dataGridView1.Size = new System.Drawing.Size(1459, 787); - this.dataGridView1.TabIndex = 1; + this.br_rpt_invDay.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.br_rpt_invDay.Dock = System.Windows.Forms.DockStyle.Fill; + this.br_rpt_invDay.Location = new System.Drawing.Point(0, 125); + this.br_rpt_invDay.Name = "br_rpt_invDay"; + this.br_rpt_invDay.RowHeadersWidth = 51; + this.br_rpt_invDay.RowTemplate.Height = 29; + this.br_rpt_invDay.Size = new System.Drawing.Size(1358, 787); + this.br_rpt_invDay.TabIndex = 1; // // panel1 // @@ -259,7 +292,7 @@ namespace solarApp this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(1459, 125); + this.panel1.Size = new System.Drawing.Size(1358, 125); this.panel1.TabIndex = 0; // // btVerifyData @@ -309,14 +342,158 @@ namespace solarApp // // tabPage2 // + this.tabPage2.Controls.Add(this.splitContainer2); this.tabPage2.Location = new System.Drawing.Point(4, 31); this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3); + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Size = new System.Drawing.Size(1774, 918); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "tabPage2"; this.tabPage2.UseVisualStyleBackColor = true; // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Location = new System.Drawing.Point(3, 3); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.BackColor = System.Drawing.Color.OldLace; + this.splitContainer2.Panel1.Controls.Add(this.button3); + this.splitContainer2.Panel1.Controls.Add(this.label1); + this.splitContainer2.Panel1.Controls.Add(this.dateTimePicker1); + this.splitContainer2.Panel1.Controls.Add(this.button2); + this.splitContainer2.Panel1.Controls.Add(this.flowLayoutPanel2); + this.splitContainer2.Panel1.Controls.Add(this.dateTimePicker2); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.dataGridView2); + this.splitContainer2.Panel2.Controls.Add(this.panel2); + this.splitContainer2.Size = new System.Drawing.Size(1768, 912); + this.splitContainer2.SplitterDistance = 299; + this.splitContainer2.SplitterWidth = 10; + this.splitContainer2.TabIndex = 1; + // + // button3 + // + this.button3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button3.Location = new System.Drawing.Point(10, 640); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(135, 44); + this.button3.TabIndex = 12; + this.button3.Text = "Sensor 歸檔"; + this.button3.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(10, 569); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(20, 19); + this.label1.TabIndex = 10; + this.label1.Text = "~"; + // + // dateTimePicker1 + // + this.dateTimePicker1.Location = new System.Drawing.Point(10, 593); + this.dateTimePicker1.Name = "dateTimePicker1"; + this.dateTimePicker1.Size = new System.Drawing.Size(145, 27); + this.dateTimePicker1.TabIndex = 9; + // + // button2 + // + this.button2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button2.Location = new System.Drawing.Point(9, 846); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(282, 61); + this.button2.TabIndex = 8; + this.button2.Text = "單日歸檔"; + this.button2.UseVisualStyleBackColor = true; + // + // flowLayoutPanel2 + // + this.flowLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Top; + this.flowLayoutPanel2.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel2.Name = "flowLayoutPanel2"; + this.flowLayoutPanel2.Size = new System.Drawing.Size(299, 530); + this.flowLayoutPanel2.TabIndex = 4; + // + // dateTimePicker2 + // + this.dateTimePicker2.Location = new System.Drawing.Point(10, 536); + this.dateTimePicker2.Name = "dateTimePicker2"; + this.dateTimePicker2.Size = new System.Drawing.Size(145, 27); + this.dateTimePicker2.TabIndex = 3; + // + // dataGridView2 + // + this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView2.Location = new System.Drawing.Point(0, 125); + this.dataGridView2.Name = "dataGridView2"; + this.dataGridView2.RowHeadersWidth = 51; + this.dataGridView2.RowTemplate.Height = 29; + this.dataGridView2.Size = new System.Drawing.Size(1459, 787); + this.dataGridView2.TabIndex = 1; + // + // panel2 + // + this.panel2.BackColor = System.Drawing.Color.Moccasin; + this.panel2.Controls.Add(this.button9); + this.panel2.Controls.Add(this.label2); + this.panel2.Controls.Add(this.label3); + this.panel2.Controls.Add(this.label4); + this.panel2.Dock = System.Windows.Forms.DockStyle.Top; + this.panel2.Location = new System.Drawing.Point(0, 0); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1459, 125); + this.panel2.TabIndex = 0; + // + // button9 + // + this.button9.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button9.Location = new System.Drawing.Point(635, 8); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(158, 44); + this.button9.TabIndex = 12; + this.button9.Text = "檢核結果"; + this.button9.UseVisualStyleBackColor = true; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(49, 19); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(79, 24); + this.label2.TabIndex = 11; + this.label2.Text = "Site_DB"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label3.Location = new System.Drawing.Point(201, 19); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 24); + this.label3.TabIndex = 10; + this.label3.Text = "Site_ID"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label4.Location = new System.Drawing.Point(360, 19); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(107, 24); + this.label4.TabIndex = 9; + this.label4.Text = "Site_Name"; + // // fmArchive // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); @@ -333,9 +510,18 @@ namespace solarApp this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.br_rpt_invDay)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.tabPage2.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); this.ResumeLayout(false); } @@ -345,7 +531,7 @@ namespace solarApp private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridView br_rpt_invDay; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.DateTimePicker dtSelect1; @@ -365,5 +551,19 @@ namespace solarApp private System.Windows.Forms.Label lbmsg; private System.Windows.Forms.DateTimePicker dtSelect2; private System.Windows.Forms.Button bt_meter; + private System.Windows.Forms.Button bt_rpt_invDay; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.DateTimePicker dateTimePicker1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; + private System.Windows.Forms.DateTimePicker dateTimePicker2; + private System.Windows.Forms.DataGridView dataGridView2; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Button button9; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index b54f78a..50c7929 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -82,9 +82,17 @@ namespace solarApp fm.Show(); } + public IEnumerable EachDay(DateTime from, DateTime thru) + { + for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1)) + yield return day; + } + + private void bt_Inv_Click(object sender, EventArgs e) { string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); procInvSvc invSvc = new procInvSvc(); //invSvc._siteDB = lbSiteDB_sensor.Text; @@ -92,7 +100,11 @@ namespace solarApp //invSvc._siteID01 = lbSiteID_sensor.Text; //invSvc._date1 = date1; //invSvc._date2 = date1; - invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + //string d1 = day.ToString("yyyy-MM-dd"); + invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + } //sensorSvc.archiveData(); MessageBox.Show("OK"); } @@ -188,5 +200,20 @@ namespace solarApp sensorSvc.archiveMeterData(lbSiteID_sensor.Text.Substring(0, 9), date1); MessageBox.Show("OK"); } + + private void bt_rpt_invDay_Click(object sender, EventArgs e) + { + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); + procInvSvc invSvc = new procInvSvc(); + //invSvc._siteDB = lbSiteDB_sensor.Text; + //invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); + //invSvc._siteID01 = lbSiteID_sensor.Text; + //invSvc._date1 = date1; + //invSvc._date2 = date1; + invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + //sensorSvc.archiveData(); + MessageBox.Show("OK"); + } } } From 38e8623799788bc97c57d78b739074fe7feb3f7f Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 2 Dec 2021 18:30:34 +0800 Subject: [PATCH 03/14] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E8=A3=9C=E5=84=9F?= =?UTF-8?q?=E7=9A=84=E5=A4=A9=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/appsettings.Development.json | 2 +- SolarPower/appsettings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SolarPower/appsettings.Development.json b/SolarPower/appsettings.Development.json index 01634b4..2949b04 100644 --- a/SolarPower/appsettings.Development.json +++ b/SolarPower/appsettings.Development.json @@ -7,7 +7,7 @@ } }, "LoginExpireMinute": 60, //nJɶA() - "GoBackDay": 3, //v(I(C))A^Ѽ + "GoBackDay": 1, //v(I(C))A^Ѽ "DBConfig": { "Server": "MVgHWzR3rGDgD57TUoFunA==", "port": "r4AoXMUDodcQjIzofGNCcg==", diff --git a/SolarPower/appsettings.json b/SolarPower/appsettings.json index 7c7e91c..83eefa0 100644 --- a/SolarPower/appsettings.json +++ b/SolarPower/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "LoginExpireMinute": 60, //nJɶA() - "GoBackDay": 3, //v(I(C))A^Ѽ + "GoBackDay": 1, //v(I(C))A^Ѽ "mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;", //"DBConfig": { // "Server": "MVgHWzR3rGDgD57TUoFunA==", From a182fdce779cf5df39b99c005ee789d747305700 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Thu, 9 Dec 2021 15:12:41 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=89=8B=E5=8B=95=E6=AA=A2=E6=9F=A5=20?= =?UTF-8?q?=E7=B8=BD=E9=AB=94=E6=AD=B8=E6=AA=94=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Model/inv_hour.cs | 30 +++++++++ solarApp/Service/getInvSvc.cs | 64 ++++++++++++++++++ solarApp/Service/getSensorSvc.cs | 6 +- solarApp/Service/procInvSvc.cs | 28 +++++--- solarApp/fmArchive.Designer.cs | 85 ++++++++++++++++++------ solarApp/fmArchive.cs | 108 +++++++++++++++++++++++++++++-- 6 files changed, 284 insertions(+), 37 deletions(-) diff --git a/solarApp/Model/inv_hour.cs b/solarApp/Model/inv_hour.cs index 049eab2..880b26b 100644 --- a/solarApp/Model/inv_hour.cs +++ b/solarApp/Model/inv_hour.cs @@ -124,4 +124,34 @@ namespace solarApp.Model public string date { get; set; } public string count { get; set; } } + + public class ck_inv_day + { + public int PowerStationId { get; set; } + public string station_code { get; set; } + public string station_name { get; set; } + public int dataRows_A { get; set; } + public int invCT_B { get; set; } + public double AdivB_C { get; set; } + public int periodDay_B { get; set; } + public double CsubstrctionB { get; set; } + } + + public class ck_inv_day_detail1 + { + public int PowerStationId { get; set; } + public string inverterid { get; set; } + public double todaykWh { get; set; } + public int RowCT { get; set; } + } + + public class ck_inv_day_detail2 + { + public int PowerStationId { get; set; } + public string crdDate { get; set; } + public string inverterid { get; set; } + public double kwh { get; set; } + public double todaykWh { get; set; } + public double pr { get; set; } + } } diff --git a/solarApp/Service/getInvSvc.cs b/solarApp/Service/getInvSvc.cs index 4550ae1..dee4fa5 100644 --- a/solarApp/Service/getInvSvc.cs +++ b/solarApp/Service/getInvSvc.cs @@ -166,5 +166,69 @@ where crdDate between '" + date1 + "' and '" + date2 + "' and a.inverterid = '" return ds; } } + + /// + /// 總計每天應有數據, inv hour --> day + /// + /// + /// + /// + public List get_ck_invDay_list(string date1, string date2) + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + string sql = @$"select PowerStationId, station_code, station_name, dataRows as dataRows_A, invCT as invCT_B, periodCT AdivB_C, periodDay periodDay_B, (periodCT - periodDay) CsubstrctionB from + ( + select a.PowerStationId, station_code, station_name, b.ct dataRows, a.ct invCT, ifnull(round((b.ct / a.ct), 2), 0) periodCT, (DATEDIFF('{date2}' , '{date1}') + 1) periodDay + from + ( -- 每個電站的 inv 數量 + select b.id PowerStationId, b.`name` station_name, left(inverterid, 11) station_code, count(*) ct + from v_company_inv a join power_station b on left(a.inverterid, 9) = b.`code` + where b.Deleted = 0 and a.`enabled` = 1 and b.`status` = 1 # 啟用 + group by left(inverterid, 11) + ) a left outer join + ( + select PowerStationId , left(crddate, 7) crddate , a.inverterid, round(a.TODAYKWH, 2) todaykWh, count(*) ct + from inverter_history_day a + where a.crddate between '{date1}' and '{date2}' + group by a.PowerStationId , left(crddate, 7) + )b on a.PowerStationId = b.PowerStationId + )x "; + List ds = conn.Query(sql).AsList(); + conn.Close(); + return ds; + } + } + + public List get_ck_invDay_detail1(string powerstationID, string date1, string date2) + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + string sql = @$"select PowerStationId , a.inverterid, round(avg(a.TODAYKWH), 2) todaykWh, count(*) RowCT + from inverter_history_day a + where PowerStationId = '{powerstationID}' and a.crddate between '{date1}' and '{date2}' + group by a.PowerStationId , inverterid "; + List ds = conn.Query(sql).AsList(); + conn.Close(); + return ds; + } + } + + public List get_ck_invDay_detail2(string inverterid, string date1, string date2) + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + string sql = @$"select a.PowerStationId, left(crddate, 10) crdDate , a.inverterid, round(a.kwh, 2) kwh, round(a.TODAYKWH, 2) todaykWh, round(a.pr, 2) pr + from inverter_history_day a + where inverterid = '{inverterid}' and a.crddate between '{date1}' and '{date2}' + "; + List ds = conn.Query(sql).AsList(); + conn.Close(); + return ds; + } + } } } diff --git a/solarApp/Service/getSensorSvc.cs b/solarApp/Service/getSensorSvc.cs index db37c7a..b8a4177 100644 --- a/solarApp/Service/getSensorSvc.cs +++ b/solarApp/Service/getSensorSvc.cs @@ -81,20 +81,24 @@ namespace solarApp.Service // { "Name":"環境濕度計","EName":"EMM"}, // { "Name":"風速計","EName":"VAN"}, // { "Name":" 電表","EName":"PWR"}]} + // { "Name":" 累計日照量","EName":"TPY"}]} + var irrlst = ds_sensor.FindAll(x => x.type.Contains("PYR")); var modelTemplst = ds_sensor.FindAll(x => x.type.Contains("MTR")); var envTemplst = ds_sensor.FindAll(x => x.type.Contains("ETR")); var humlst = ds_sensor.FindAll(x => x.type.Contains("EMM")); var windlst = ds_sensor.FindAll(x => x.type.Contains("VAN")); var dustlst = ds_sensor.FindAll(x => x.type.Contains("DST")); //需要新增於DB + var totIrrlst = ds_sensor.FindAll(x => x.type.Contains("TPY")); //累計日照量 //var meterlst = ds_sensor.FindAll(x => x.type.Contains("PWR")); 電錶暫不處理 - string irrCol = string.Empty; string modelTempCol = string.Empty; string evnTempCol = string.Empty; string humCol = string.Empty; string windCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty; + string irrCol = string.Empty; string modelTempCol = string.Empty; string evnTempCol = string.Empty; string humCol = string.Empty; string windCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty; string totIrrCol = string.Empty; irrCol = ConcatColumn(irrlst);//日照計 modelTempCol = ConcatColumn(modelTemplst); evnTempCol = ConcatColumn(envTemplst); humCol = ConcatColumn(humlst); windCol = ConcatColumn(windlst); dustCol = ConcatColumn(dustlst); + totIrrCol = ConcatColumn(totIrrlst); string irrNot0 = string.Empty; // and 日照1 <> 0 and 日照2 <> 0 # region 日照計需要過濾 0 diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 632d31e..59a9e5e 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -98,9 +98,10 @@ namespace solarApp.Service get_siteInfo(); clearData(); insert_inv(); - //日報表 - //insert_report_invDay(); - result = true; + + //日報表 + //insert_report_invDay(); get_ck_invDay_list + result = true; //} //catch (Exception ex) //{ @@ -357,8 +358,11 @@ namespace solarApp.Service } catch (Exception ex) { - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1); - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + if (_logger != null) + { + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1); + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } throw ex; } @@ -412,8 +416,11 @@ namespace solarApp.Service } catch (Exception ex) { - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1); - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + if (_logger != null) + { + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1); + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } throw ex; } #endregion day @@ -468,8 +475,11 @@ namespace solarApp.Service } catch (Exception ex) { - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1); - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + if (_logger != null) + { + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1); + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } throw ex; } diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index df16b74..dcabc40 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -29,6 +29,8 @@ namespace solarApp /// private void InitializeComponent() { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); @@ -45,8 +47,10 @@ namespace solarApp this.bt_site = new System.Windows.Forms.Button(); this.bt_Inv = new System.Windows.Forms.Button(); this.bt_Sensor = new System.Windows.Forms.Button(); - this.br_rpt_invDay = new System.Windows.Forms.DataGridView(); + this.gv_inv_detail = new System.Windows.Forms.DataGridView(); + this.gv_rpt_invDay = new System.Windows.Forms.DataGridView(); this.panel1 = new System.Windows.Forms.Panel(); + this.bt_invDay = new System.Windows.Forms.Button(); this.btVerifyData = new System.Windows.Forms.Button(); this.lbSiteDB_sensor = new System.Windows.Forms.Label(); this.lbSiteID_sensor = new System.Windows.Forms.Label(); @@ -71,7 +75,8 @@ namespace solarApp this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.br_rpt_invDay)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.gv_inv_detail)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.gv_rpt_invDay)).BeginInit(); this.panel1.SuspendLayout(); this.tabPage2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); @@ -130,7 +135,8 @@ namespace solarApp // // splitContainer1.Panel2 // - this.splitContainer1.Panel2.Controls.Add(this.br_rpt_invDay); + this.splitContainer1.Panel2.Controls.Add(this.gv_inv_detail); + this.splitContainer1.Panel2.Controls.Add(this.gv_rpt_invDay); this.splitContainer1.Panel2.Controls.Add(this.panel1); this.splitContainer1.Size = new System.Drawing.Size(1768, 912); this.splitContainer1.SplitterDistance = 400; @@ -271,20 +277,45 @@ namespace solarApp this.bt_Sensor.UseVisualStyleBackColor = true; this.bt_Sensor.Click += new System.EventHandler(this.bt_Sensor_Click); // - // br_rpt_invDay + // gv_inv_detail // - this.br_rpt_invDay.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.br_rpt_invDay.Dock = System.Windows.Forms.DockStyle.Fill; - this.br_rpt_invDay.Location = new System.Drawing.Point(0, 125); - this.br_rpt_invDay.Name = "br_rpt_invDay"; - this.br_rpt_invDay.RowHeadersWidth = 51; - this.br_rpt_invDay.RowTemplate.Height = 29; - this.br_rpt_invDay.Size = new System.Drawing.Size(1358, 787); - this.br_rpt_invDay.TabIndex = 1; + this.gv_inv_detail.AllowUserToAddRows = false; + this.gv_inv_detail.AllowUserToDeleteRows = false; + dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_inv_detail.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3; + this.gv_inv_detail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gv_inv_detail.Dock = System.Windows.Forms.DockStyle.Fill; + this.gv_inv_detail.Location = new System.Drawing.Point(768, 75); + this.gv_inv_detail.Name = "gv_inv_detail"; + this.gv_inv_detail.ReadOnly = true; + this.gv_inv_detail.RowHeadersWidth = 51; + this.gv_inv_detail.RowTemplate.Height = 29; + this.gv_inv_detail.Size = new System.Drawing.Size(590, 837); + this.gv_inv_detail.TabIndex = 2; + this.gv_inv_detail.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gv_inv_detail_CellDoubleClick); + // + // gv_rpt_invDay + // + this.gv_rpt_invDay.AllowUserToAddRows = false; + this.gv_rpt_invDay.AllowUserToDeleteRows = false; + dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_rpt_invDay.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle4; + this.gv_rpt_invDay.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gv_rpt_invDay.Dock = System.Windows.Forms.DockStyle.Left; + this.gv_rpt_invDay.Location = new System.Drawing.Point(0, 75); + this.gv_rpt_invDay.Name = "gv_rpt_invDay"; + this.gv_rpt_invDay.ReadOnly = true; + this.gv_rpt_invDay.RowHeadersWidth = 51; + this.gv_rpt_invDay.RowTemplate.Height = 29; + this.gv_rpt_invDay.Size = new System.Drawing.Size(768, 837); + this.gv_rpt_invDay.TabIndex = 1; + this.gv_rpt_invDay.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_rpt_invDay_CellFormatting); + this.gv_rpt_invDay.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.gv_rpt_invDay_CellMouseDoubleClick); // // panel1 // this.panel1.BackColor = System.Drawing.SystemColors.GradientActiveCaption; + this.panel1.Controls.Add(this.bt_invDay); this.panel1.Controls.Add(this.btVerifyData); this.panel1.Controls.Add(this.lbSiteDB_sensor); this.panel1.Controls.Add(this.lbSiteID_sensor); @@ -292,17 +323,28 @@ namespace solarApp this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(1358, 125); + this.panel1.Size = new System.Drawing.Size(1358, 75); this.panel1.TabIndex = 0; // + // bt_invDay + // + this.bt_invDay.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bt_invDay.Location = new System.Drawing.Point(21, 8); + this.bt_invDay.Name = "bt_invDay"; + this.bt_invDay.Size = new System.Drawing.Size(159, 44); + this.bt_invDay.TabIndex = 14; + this.bt_invDay.Text = "Inv 檢核"; + this.bt_invDay.UseVisualStyleBackColor = true; + this.bt_invDay.Click += new System.EventHandler(this.bt_invDay_Click); + // // btVerifyData // this.btVerifyData.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.btVerifyData.Location = new System.Drawing.Point(635, 8); + this.btVerifyData.Location = new System.Drawing.Point(746, 8); this.btVerifyData.Name = "btVerifyData"; this.btVerifyData.Size = new System.Drawing.Size(158, 44); this.btVerifyData.TabIndex = 12; - this.btVerifyData.Text = "檢核結果"; + this.btVerifyData.Text = "各資料表明細"; this.btVerifyData.UseVisualStyleBackColor = true; this.btVerifyData.Click += new System.EventHandler(this.btVerifyData_Click); // @@ -310,7 +352,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(49, 19); + this.lbSiteDB_sensor.Location = new System.Drawing.Point(209, 20); 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); @@ -322,7 +364,7 @@ namespace solarApp // this.lbSiteID_sensor.AutoSize = true; this.lbSiteID_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.lbSiteID_sensor.Location = new System.Drawing.Point(201, 19); + this.lbSiteID_sensor.Location = new System.Drawing.Point(361, 20); this.lbSiteID_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbSiteID_sensor.Name = "lbSiteID_sensor"; this.lbSiteID_sensor.Size = new System.Drawing.Size(72, 24); @@ -333,7 +375,7 @@ namespace solarApp // this.lbSiteName_sensor.AutoSize = true; this.lbSiteName_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.lbSiteName_sensor.Location = new System.Drawing.Point(360, 19); + this.lbSiteName_sensor.Location = new System.Drawing.Point(520, 20); this.lbSiteName_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbSiteName_sensor.Name = "lbSiteName_sensor"; this.lbSiteName_sensor.Size = new System.Drawing.Size(107, 24); @@ -510,7 +552,8 @@ namespace solarApp this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.br_rpt_invDay)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.gv_inv_detail)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.gv_rpt_invDay)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.tabPage2.ResumeLayout(false); @@ -531,7 +574,7 @@ namespace solarApp private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.DataGridView br_rpt_invDay; + private System.Windows.Forms.DataGridView gv_rpt_invDay; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.DateTimePicker dtSelect1; @@ -565,5 +608,7 @@ namespace solarApp private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button bt_invDay; + private System.Windows.Forms.DataGridView gv_inv_detail; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 50c7929..3abd20b 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -26,13 +26,25 @@ namespace solarApp { string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); + //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); procSensorSvc sensorSvc = new procSensorSvc(); + //invSvc._siteDB = lbSiteDB_sensor.Text; + //invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); + //invSvc._siteID01 = lbSiteID_sensor.Text; + //invSvc._date1 = date1; + //invSvc._date2 = date1; + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + //string d1 = day.ToString("yyyy-MM-dd"); + sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + } //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.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + //sensorSvc.archiveData(); MessageBox.Show("OK"); } @@ -56,6 +68,9 @@ namespace solarApp i++; } #endregion + // dtselect_station1.Value = DateTime.Today.AddDays(-1); + dtSelect1.Value = System.DateTime.Today.AddDays(-1); + dtSelect2.Value = System.DateTime.Today.AddDays(-1); } private void rb_site_CheckedChanged(object sender, EventArgs e) @@ -152,14 +167,19 @@ namespace solarApp private void bt_site_Click(object sender, EventArgs e) { string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); procStationSvc siteSvc = new procStationSvc(); - //siteSvc._siteDB = lbSiteDB_sensor.Text; - //siteSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); - //siteSvc._siteID01 = lbSiteID_sensor.Text; - //siteSvc._date1 = date1; - //siteSvc._date2 = date1; - siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + //invSvc._siteDB = lbSiteDB_sensor.Text; + //invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); + //invSvc._siteID01 = lbSiteID_sensor.Text; + //invSvc._date1 = date1; + //invSvc._date2 = date1; + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + //string d1 = day.ToString("yyyy-MM-dd"); + siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + } //sensorSvc.archiveData(); MessageBox.Show("OK"); } @@ -215,5 +235,79 @@ namespace solarApp //sensorSvc.archiveData(); MessageBox.Show("OK"); } + + private void bt_invDay_Click(object sender, EventArgs e) + { + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); + get_inv_svc invSvc = new get_inv_svc(); + var ds = invSvc.get_ck_invDay_list(date1, date2); + gv_rpt_invDay.DataSource = ds; + gv_rpt_invDay.Columns[0].Width = 60; + gv_rpt_invDay.Columns[1].Width = 70; + gv_rpt_invDay.Columns[2].Width = 80; + gv_rpt_invDay.Columns[3].Width = 90; + gv_rpt_invDay.Columns[4].Width = 90; + gv_rpt_invDay.Columns[5].Width = 90; + gv_rpt_invDay.Columns[6].Width = 90; + gv_rpt_invDay.Columns[7].Width = 90; + + } + + private void gv_rpt_invDay_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value != null && !string.IsNullOrWhiteSpace(gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value.ToString())) + { + if (gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value.ToString() != "0") + { + gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } + + private void gv_rpt_invDay_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) + { + string powerStationID = gv_rpt_invDay.Rows[e.RowIndex].Cells[0].Value.ToString(); + // MessageBox.Show(powerStationID); + + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); + get_inv_svc invSvc = new get_inv_svc(); + var ds = invSvc.get_ck_invDay_detail1( powerStationID, date1, date2); + gv_inv_detail.DataSource = ds; + gv_inv_detail.Columns[0].Width = 60; + gv_inv_detail.Columns[1].Width = 160; //invID + gv_inv_detail.Columns[2].Width = 80; + gv_inv_detail.Columns[3].Width = 90; + + //switch (e.ColumnIndex) + //{ + // case 0: + // MessageBox.Show("这是第零列得"); + // break; + // default: + // break; + //} + } + + private void gv_inv_detail_CellDoubleClick(object sender, DataGridViewCellEventArgs e) + { + if (gv_inv_detail.Columns.Count == 5) return; + + string inverterID = gv_inv_detail.Rows[e.RowIndex].Cells[1].Value.ToString(); + //MessageBox.Show(inverterID); + + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); + get_inv_svc invSvc = new get_inv_svc(); + var ds = invSvc.get_ck_invDay_detail2(inverterID, date1, date2); + gv_inv_detail.DataSource = ds; + gv_inv_detail.Columns[0].Width = 60; + gv_inv_detail.Columns[1].Width = 150; + gv_inv_detail.Columns[2].Width = 80; + gv_inv_detail.Columns[3].Width = 100; + gv_inv_detail.Columns[4].Width = 80; + gv_inv_detail.Columns[5].Width = 80; + } } } From 583524bde79adc7706a17f46e8f50708a93916f0 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Thu, 9 Dec 2021 15:14:24 +0800 Subject: [PATCH 05/14] test --- solarApp/Service/procInvSvc.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 59a9e5e..2a0e56c 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -496,8 +496,8 @@ namespace solarApp.Service return result; } - void ck_empty_archivedData(string siteID, string date1) - { + void ck_empty_archivedData(string siteID, string date1) + { _siteID = siteID; _date1 = date1; get_siteInfo(); From 654331e11f3b89646c2478bb4a1626816137b5dc Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Thu, 9 Dec 2021 15:18:12 +0800 Subject: [PATCH 06/14] test2 --- solarApp/Service/procInvSvc.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 59a9e5e..3d6fb90 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -501,6 +501,7 @@ namespace solarApp.Service _siteID = siteID; _date1 = date1; get_siteInfo(); + } //建立日報表 From 42ea0d476ce0ec648ff49570197d6268f75c336e Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Thu, 9 Dec 2021 15:23:44 +0800 Subject: [PATCH 07/14] test3 --- solarApp/fmArchive.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 3abd20b..c8c74dc 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -210,6 +210,7 @@ namespace solarApp { fmExcel fm = new fmExcel(); fm.Show(); + } private void bt_meter_Click(object sender, EventArgs e) From c1e3f106a248c7d2541fd1c85879469e9ef49cc5 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Fri, 10 Dec 2021 01:50:11 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E6=97=A5=E5=A0=B1=E8=A1=A8=E5=BF=AB?= =?UTF-8?q?=E5=8F=96=20OK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Model/inv_hour.cs | 125 +++++++++++++++++++++ solarApp/Service/procInvSvc.cs | 192 +++++++++++++++++++++------------ solarApp/fmArchive.cs | 19 ++-- 3 files changed, 256 insertions(+), 80 deletions(-) diff --git a/solarApp/Model/inv_hour.cs b/solarApp/Model/inv_hour.cs index 880b26b..42e85f8 100644 --- a/solarApp/Model/inv_hour.cs +++ b/solarApp/Model/inv_hour.cs @@ -154,4 +154,129 @@ namespace solarApp.Model public double todaykWh { get; set; } public double pr { get; set; } } + + public class station_inv_list + { + public int PowerStationId { get; set; } + public string station_name { get; set; } + public string inverterid { get; set; } + public string station_code { get; set; } + } + + public class report_inv_resualt + { + public string report_date { get; set; } + public int PowerStationId { get; set; } + public string inv_01 { get; set; } + public string inv_02 { get; set; } + public string inv_03 { get; set; } + public string inv_04 { get; set; } + public string inv_05 { get; set; } + public string inv_06 { get; set; } + public string inv_07 { get; set; } + public string inv_08 { get; set; } + public string inv_09 { get; set; } + public string inv_10 { get; set; } + public string inv_11 { get; set; } + public string inv_12 { get; set; } + public string inv_13 { get; set; } + public string inv_14 { get; set; } + public string inv_15 { get; set; } + public string inv_16 { get; set; } + public string inv_17 { get; set; } + public string inv_18 { get; set; } + public string inv_19 { get; set; } + public string inv_20 { get; set; } + public string inv_21 { get; set; } + public string inv_22 { get; set; } + public string inv_23 { get; set; } + public string inv_24 { get; set; } + public string inv_25 { get; set; } + public string inv_26 { get; set; } + public string inv_27 { get; set; } + public string inv_28 { get; set; } + public string inv_29 { get; set; } + public string inv_30 { get; set; } + public string inv_31 { get; set; } + public string inv_32 { get; set; } + public string inv_33 { get; set; } + public string inv_34 { get; set; } + public string inv_35 { get; set; } + public string inv_36 { get; set; } + public string inv_37 { get; set; } + public string inv_38 { get; set; } + public string inv_39 { get; set; } + public string inv_40 { get; set; } + public string inv_41 { get; set; } + public string inv_42 { get; set; } + public string inv_43 { get; set; } + public string inv_44 { get; set; } + public string inv_45 { get; set; } + public string inv_46 { get; set; } + public string inv_47 { get; set; } + public string inv_48 { get; set; } + public string inv_49 { get; set; } + public string inv_50 { get; set; } + public string inv_51 { get; set; } + public string inv_52 { get; set; } + public string inv_53 { get; set; } + public string inv_54 { get; set; } + public string inv_55 { get; set; } + public string inv_56 { get; set; } + public string inv_57 { get; set; } + public string inv_58 { get; set; } + public string inv_59 { get; set; } + public string inv_60 { get; set; } + public string inv_61 { get; set; } + public string inv_62 { get; set; } + public string inv_63 { get; set; } + public string inv_64 { get; set; } + public string inv_65 { get; set; } + public string inv_66 { get; set; } + public string inv_67 { get; set; } + public string inv_68 { get; set; } + public string inv_69 { get; set; } + public string inv_70 { get; set; } + public string inv_71 { get; set; } + public string inv_72 { get; set; } + public string inv_73 { get; set; } + public string inv_74 { get; set; } + public string inv_75 { get; set; } + public string inv_76 { get; set; } + public string inv_77 { get; set; } + public string inv_78 { get; set; } + public string inv_79 { get; set; } + public string inv_80 { get; set; } + public string inv_81 { get; set; } + public string inv_82 { get; set; } + public string inv_83 { get; set; } + public string inv_84 { get; set; } + public string inv_85 { get; set; } + public string inv_86 { get; set; } + public string inv_87 { get; set; } + public string inv_88 { get; set; } + public string inv_89 { get; set; } + public string inv_90 { get; set; } + public string inv_91 { get; set; } + public string inv_92 { get; set; } + public string inv_93 { get; set; } + public string inv_94 { get; set; } + public string inv_95 { get; set; } + public string inv_96 { get; set; } + public string inv_97 { get; set; } + public string inv_98 { get; set; } + public string inv_99 { get; set; } + public string inv_100 { get; set; } + public double hourKWH { get; set; } + public double hourKWHp { get; set; } + public double irradiance { get; set; } + public double temperature { get; set; } + public double hourmoney { get; set; } + public double totKWH { get; set; } + public double totKWHKWP { get; set; } + public double totmoney { get; set; } + public double daymoney { get; set; } + public double tothour { get; set; } + public double pr { get; set; } + } } diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index aa0f19a..d55ced8 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -91,24 +91,33 @@ namespace solarApp.Service public bool archiveData(string siteID, string date1) { bool result = false; - //try - //{ - _siteID = siteID; - _date1 = date1; - get_siteInfo(); - clearData(); - insert_inv(); + _siteID = siteID; + _date1 = date1; + get_siteInfo(); + clearData(); + insert_inv(); //日報表 - //insert_report_invDay(); get_ck_invDay_list - result = true; - //} - //catch (Exception ex) - //{ - // throw ex; - //} + insert_report_invDay(); //get_ck_invDay_list + return result; } + + public bool report_invDay(string siteID, string date1) + { + bool result = false; + + _siteID = siteID; + _date1 = date1; + get_siteInfo(); + + //日報表 + insert_report_invDay(); //get_ck_invDay_list + result = true; + + return result; + } + public bool get_siteInfo() { bool result = false; @@ -236,15 +245,17 @@ namespace solarApp.Service var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); - if (_logger != null) - { - _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1); - } + if (_logger != null) + _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1); } catch (Exception ex) { - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1); - _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + + if (_logger != null) + { + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1); + _logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } throw ex; } #endregion @@ -252,10 +263,8 @@ namespace solarApp.Service #region hour try { - if (_logger != null) - { - _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1); - } + if (_logger != null) + _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1); //sql = @" // insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, @@ -351,10 +360,8 @@ namespace solarApp.Service ) inv_pr ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID;"; ct = conn.Execute(sql, new { date1 = _date1 }); - if (_logger != null) - { - _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1); - } + if (_logger != null) + _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1); } catch (Exception ex) { @@ -409,10 +416,8 @@ namespace solarApp.Service )irr on a.reportDate = irr.reportDate ;"; conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); - if (_logger != null) - { - _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1); - } + if (_logger != null) + _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1); } catch (Exception ex) { @@ -428,10 +433,8 @@ namespace solarApp.Service #region month try { - if (_logger != null) - { - _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1); - } + if (_logger != null) + _logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1); sql = @" delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ; @@ -501,7 +504,6 @@ namespace solarApp.Service _siteID = siteID; _date1 = date1; get_siteInfo(); - } //建立日報表 @@ -512,7 +514,7 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string ss = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));"; + string ss = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'"; conn.Execute(ss); string sql = string.Empty; @@ -524,52 +526,102 @@ namespace solarApp.Service _logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); } - #region 取得 inv 數量 - sql = $@"select * from v_company_inv where "; - #endregion - + #region 先新增 inv_no01 sql = @$" -SET @sql = NULL; -SELECT - GROUP_CONCAT(DISTINCT - CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 2), '''') - ) INTO @sql -FROM inverter_history_hour where powerstationId = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{_date1}'; -SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, - ', b.KWH hourKWH, - ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour - WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{_date1}'' and powerstationid = {_powerStationID}))*100,2) - , 0) ''hourKWHp'', ifnull(d.irradiance, 0) ''irradiance'', ifnull(d.Temperature, 0) ''temperature'', - ifnull(b.money, 0) ''hourmoney'', ifnull(round(b.PR, 2), 0) as pr - FROM inverter_history_hour a left join +insert report_invday(`report_date`, `PowerStationID`, inv_01, `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`, createTime) +select a.TIMESTAMP report_date, a.powerstationId , ifnull(a.kwh, 0) inv_01, ifnull(b.KWH, 0) hourKWH, + ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour + WHERE DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') = '{_date1}' and powerstationid = {_powerStationID} ))*100,2) + , 0) 'hourKWHp', ifnull(d.irradiance, 0) 'irradiance', ifnull(d.Temperature, 0) 'temperature', + ifnull(b.money, 0) 'hourmoney', ifnull(round(b.PR, 2), 0) as pr, now() + from inverter_history_hour a left join ( # 每小時加總 inv - select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') report_date, siteid, sitetype, round(KWH, 2) KWH, + select powerStationid, `TIMESTAMP` report_date, siteid, sitetype, round(KWH, 2) KWH, round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money from power_station_history_hour - where powerstationid = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{_date1}'' - ) b on a.powerStationid = b.powerStationid and concat(a.crdDate,' ', left(a.crdTime, 5)) = b.report_date + where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' + ) b on a.powerStationid = b.powerStationid and a.`TIMESTAMP` = b.report_date left join ( - select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:00'')report_date, irradiance, Temperature + select powerStationID, DATE_FORMAT(TIMESTAMP,'%Y-%m-%d %H:00')report_date, irradiance, Temperature from sensor_history_hour - where powerstationid = {_powerStationID} and DATE_FORMAT(`TIMESTAMP`,''%Y-%m-%d'') = ''{_date1}'' - ) d on a.powerStationid = d.powerStationid and concat(a.crdDate,' ', left(a.crdTime, 2), '':00'') = d.report_date - where a.crdDate = ''{_date1}'' - GROUP BY concat(a.crdDate,' ', left(a.crdTime, 2)) - order by a.crdTime '); - select @sql as 'mySelect'; #顯示動態語法"; - var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' + ) d on a.powerStationid = d.powerStationid and concat(left(a.`TIMESTAMP`, 13), ':00') = d.report_date + where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '0001' + GROUP BY left(a.`TIMESTAMP`, 13) + order by a.crdTime ;"; + conn.Execute(sql); + #endregion - if (_logger != null) + #region inv_02 之後的 kwh + #region 取得 inv 數量 + sql = $@" select b.id PowerStationId, b.`name` station_name, inverterid, b.`code` station_code + from v_company_inv a join power_station b on left(a.inverterid, 9) = b.`code` + where b.`id` = '{_powerStationID}' and b.Deleted = 0 and a.`enabled` = 1 and b.`status` = 1 # 啟用 "; + var ds = conn.Query(sql).AsList(); + #endregion + StringBuilder sb = new StringBuilder(); + StringBuilder sb_column = new StringBuilder(); + StringBuilder sb_select = new StringBuilder(); + StringBuilder sb_update_columns = new StringBuilder(); + + for (int i = 0; i < ds.Count; i++) { - _logger.LogInformation("【Proc_inv_日報】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1); + if (i == 0) continue; + if (i < 9) + { + sb_column.Append(@$", `inv_0{(i + 1).ToString()}`"); + if (i == 1) + { + sb.Append(@" update report_invday a join ( + select a02.powerstationID, a02.report_date, ifnull(a02.inv_02, 0) inv_02"); + sb_select.Append(@$" from + (select powerstationID, `TIMESTAMP` report_date, kwh inv_02 from inverter_history_hour a + where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} "); + sb_update_columns.Append($@" ) b + on a.powerstationid = b.powerstationid and a.report_date = b.report_date +set a.inv_02 = b.inv_02 "); + } + else { + sb.Append(@$" , ifnull(a0{(i + 1).ToString()}.inv_0{(i + 1).ToString()}, 0) inv_0{(i + 1).ToString()}"); + sb_select.Append($@" left join (select `TIMESTAMP` report_date, kwh inv_0{(i + 1).ToString()} from inverter_history_hour a + where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} on a02.report_date = a0{(i + 1).ToString()}.report_date "); + sb_update_columns.Append($@", a.inv_0{(i + 1).ToString()} = b.inv_0{(i + 1).ToString()}"); + } + } + else + { + sb.Append(@$" , ifnull(a{(i + 1).ToString()}.inv_{(i + 1).ToString()}, 0) inv_{(i + 1).ToString()} "); + sb_column.Append(@$", `inv_{(i + 1).ToString()}`"); + sb_select.Append($@" left join (select `TIMESTAMP` report_date, kwh inv_{(i + 1).ToString()} from inverter_history_hour a + where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '00{(i + 1).ToString()}') a{(i + 1).ToString()} on a02.report_date = a{(i + 1).ToString()}.report_date "); + sb_update_columns.Append($@", a.inv_{(i + 1).ToString()} = b.inv_{(i + 1).ToString()}"); + } } + // sb.Append(", `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`)"); + + #endregion + + + #region insert report_invDay + sb_column.Clear(); + sql = sb.ToString() + sb_select.ToString() + sb_update_columns.ToString(); + conn.Execute(sql); + + #endregion + + if (_logger != null) + _logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1); + } catch (Exception ex) { - _logger.LogError("【Proc_inv_日報】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); - _logger.LogError("【Proc_inv_日報】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString()); + if (_logger != null) + { + _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); + _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } throw ex; } #endregion diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index c8c74dc..f2e657e 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -37,7 +37,7 @@ namespace solarApp foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) { //string d1 = day.ToString("yyyy-MM-dd"); - sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); } //sensorSvc._siteDB = lbSiteDB_sensor.Text; //sensorSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); @@ -178,7 +178,7 @@ namespace solarApp foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) { //string d1 = day.ToString("yyyy-MM-dd"); - siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); + siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); } //sensorSvc.archiveData(); MessageBox.Show("OK"); @@ -225,15 +225,14 @@ namespace solarApp private void bt_rpt_invDay_Click(object sender, EventArgs e) { string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); - //procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); procInvSvc invSvc = new procInvSvc(); - //invSvc._siteDB = lbSiteDB_sensor.Text; - //invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9); - //invSvc._siteID01 = lbSiteID_sensor.Text; - //invSvc._date1 = date1; - //invSvc._date2 = date1; - invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), date1); - //sensorSvc.archiveData(); + + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + } + MessageBox.Show("OK"); } From 4e3e4e1217940eba731ab111a519f58e08c4e367 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Sun, 12 Dec 2021 12:05:31 +0800 Subject: [PATCH 09/14] =?UTF-8?q?report=5FinvDay=20=E6=97=A5=E5=A0=B1?= =?UTF-8?q?=E8=A1=A8=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procInvSvc.cs | 247 +++++++++++++++++---------------- 1 file changed, 128 insertions(+), 119 deletions(-) diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index d55ced8..e743235 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -509,132 +509,141 @@ namespace solarApp.Service //建立日報表 bool insert_report_invDay() { bool result = false; - try + + using (MySqlConnection conn = new MySqlConnection(Connection1)) { - using (MySqlConnection conn = new MySqlConnection(Connection1)) + conn.Open(); + string ss = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'"; + conn.Execute(ss); + + string sql = string.Empty; + #region get SQL + try { - conn.Open(); - string ss = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'"; + if (_logger != null) + { + _logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); + } + + #region 建立 temp table + ss = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; +CREATE TABLE temp_invDay{_powerStationID}_s1 + select a.`TIMESTAMP` report_date, a.powerstationId, a.INVERTERID, a.kwh , + round(TODAYKWH, 6) TODAYKWH, round(KWHKWP, 6) KWHKWP, round(PR, 6) PR + from solar_master.inverter_history_hour a + WHERE powerstationid = {_powerStationID} and crdDate = '{_date1}'; +# 2. add index +ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_date, inverterid);"; conn.Execute(ss); - - string sql = string.Empty; - #region get SQL - try - { - if (_logger != null) - { - _logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); - } - - #region 先新增 inv_no01 - sql = @$" -insert report_invday(`report_date`, `PowerStationID`, inv_01, `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`, createTime) -select a.TIMESTAMP report_date, a.powerstationId , ifnull(a.kwh, 0) inv_01, ifnull(b.KWH, 0) hourKWH, - ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour - WHERE DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') = '{_date1}' and powerstationid = {_powerStationID} ))*100,2) - , 0) 'hourKWHp', ifnull(d.irradiance, 0) 'irradiance', ifnull(d.Temperature, 0) 'temperature', - ifnull(b.money, 0) 'hourmoney', ifnull(round(b.PR, 2), 0) as pr, now() - from inverter_history_hour a left join - ( # 每小時加總 inv - select powerStationid, `TIMESTAMP` report_date, siteid, sitetype, round(KWH, 2) KWH, - round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money - from power_station_history_hour - where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' - ) b on a.powerStationid = b.powerStationid and a.`TIMESTAMP` = b.report_date - - left join - ( - select powerStationID, DATE_FORMAT(TIMESTAMP,'%Y-%m-%d %H:00')report_date, irradiance, Temperature - from sensor_history_hour - where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' - ) d on a.powerStationid = d.powerStationid and concat(left(a.`TIMESTAMP`, 13), ':00') = d.report_date - where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '0001' - GROUP BY left(a.`TIMESTAMP`, 13) - order by a.crdTime ;"; - conn.Execute(sql); - #endregion - - #region inv_02 之後的 kwh - #region 取得 inv 數量 - sql = $@" select b.id PowerStationId, b.`name` station_name, inverterid, b.`code` station_code - from v_company_inv a join power_station b on left(a.inverterid, 9) = b.`code` - where b.`id` = '{_powerStationID}' and b.Deleted = 0 and a.`enabled` = 1 and b.`status` = 1 # 啟用 "; - var ds = conn.Query(sql).AsList(); - #endregion - StringBuilder sb = new StringBuilder(); - StringBuilder sb_column = new StringBuilder(); - StringBuilder sb_select = new StringBuilder(); - StringBuilder sb_update_columns = new StringBuilder(); - - for (int i = 0; i < ds.Count; i++) - { - if (i == 0) continue; - if (i < 9) - { - sb_column.Append(@$", `inv_0{(i + 1).ToString()}`"); - if (i == 1) - { - sb.Append(@" update report_invday a join ( - select a02.powerstationID, a02.report_date, ifnull(a02.inv_02, 0) inv_02"); - sb_select.Append(@$" from - (select powerstationID, `TIMESTAMP` report_date, kwh inv_02 from inverter_history_hour a - where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} "); - sb_update_columns.Append($@" ) b - on a.powerstationid = b.powerstationid and a.report_date = b.report_date -set a.inv_02 = b.inv_02 "); - } - else { - sb.Append(@$" , ifnull(a0{(i + 1).ToString()}.inv_0{(i + 1).ToString()}, 0) inv_0{(i + 1).ToString()}"); - sb_select.Append($@" left join (select `TIMESTAMP` report_date, kwh inv_0{(i + 1).ToString()} from inverter_history_hour a - where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} on a02.report_date = a0{(i + 1).ToString()}.report_date "); - sb_update_columns.Append($@", a.inv_0{(i + 1).ToString()} = b.inv_0{(i + 1).ToString()}"); - } - } - else - { - sb.Append(@$" , ifnull(a{(i + 1).ToString()}.inv_{(i + 1).ToString()}, 0) inv_{(i + 1).ToString()} "); - sb_column.Append(@$", `inv_{(i + 1).ToString()}`"); - sb_select.Append($@" left join (select `TIMESTAMP` report_date, kwh inv_{(i + 1).ToString()} from inverter_history_hour a - where a.powerstationid = {_powerStationID} and a.crdDate = '{_date1}' and right(a.inverterid, 4) = '00{(i + 1).ToString()}') a{(i + 1).ToString()} on a02.report_date = a{(i + 1).ToString()}.report_date "); - sb_update_columns.Append($@", a.inv_{(i + 1).ToString()} = b.inv_{(i + 1).ToString()}"); - } - } - // sb.Append(", `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`)"); - - #endregion - - - #region insert report_invDay - sb_column.Clear(); - sql = sb.ToString() + sb_select.ToString() + sb_update_columns.ToString(); - conn.Execute(sql); - - #endregion - - if (_logger != null) - _logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1); - - } - catch (Exception ex) - { - if (_logger != null) - { - _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); - _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString()); - } - throw ex; - } #endregion + + #region 先新增 inv_no01 + sql = @$" +insert report_invday(`report_date`, `PowerStationID`, inv_01, `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`, createTime) +select a.report_date, a.powerstationId , ifnull(round(a.kwh, 6), 0) inv_01, ifnull(b.KWH, 0) hourKWH, + ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour + WHERE DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') = '{_date1}' and powerstationid = {_powerStationID} ))*100,2) + , 0) 'hourKWHp', ifnull(d.irradiance, 0) 'irradiance', ifnull(d.Temperature, 0) 'temperature', + ifnull(b.money, 0) 'hourmoney', ifnull(round(b.PR, 2), 0) as pr, now() createTime +from temp_invDay{_powerStationID}_s1 a left join + ( # 每小時加總 inv + select powerStationid, `TIMESTAMP` report_date, siteid, sitetype, round(KWH, 2) KWH, + round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money + from power_station_history_hour + where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' + ) b on a.powerStationid = b.powerStationid and a.`report_date` = b.report_date + + left join + ( + select powerStationID, `TIMESTAMP` report_date, irradiance, Temperature + from sensor_history_hour + where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' + ) d on a.powerStationid = d.powerStationid and a.`report_date` = d.report_date + where right(a.inverterid, 4) = '0001' + GROUP BY left(a.report_date, 13) + order by a.report_date ;"; + conn.Execute(sql); + #endregion + + #region inv_02 之後的 kwh + #region 取得 inv 數量 + sql = $@" select b.id PowerStationId, b.`name` station_name, inverterid, b.`code` station_code + from v_company_inv a join power_station b on left(a.inverterid, 9) = b.`code` + where b.`id` = '{_powerStationID}' and b.Deleted = 0 and a.`enabled` = 1 and b.`status` = 1 # 啟用 "; + var ds = conn.Query(sql).AsList(); + #endregion + StringBuilder sb = new StringBuilder(); + StringBuilder sb_column = new StringBuilder(); + StringBuilder sb_select = new StringBuilder(); + StringBuilder sb_update_columns = new StringBuilder(); + + for (int i = 0; i < ds.Count; i++) + { + if (i == 0) continue; + if (i < 9) + { + sb_column.Append(@$", `inv_0{(i + 1).ToString()}`"); + if (i == 1) + { + sb.Append(@" update report_invday a join ( + select a02.powerstationID, a02.report_date, ifnull(a02.inv_02, 0) inv_02"); + sb_select.Append(@$" from + (select powerstationID, report_date, ifnull(round(kwh , 6), 0) inv_02 from temp_invDay{_powerStationID}_s1 a + where right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} "); + sb_update_columns.Append($@" ) b +on a.powerstationid = b.powerstationid and a.report_date = b.report_date +set a.inv_02 = b.inv_02 "); + } + else { + sb.Append(@$" , ifnull(a0{(i + 1).ToString()}.inv_0{(i + 1).ToString()}, 0) inv_0{(i + 1).ToString()}"); + sb_select.Append($@" left join (select report_date, ifnull(round(kwh , 6), 0) inv_0{(i + 1).ToString()} from temp_invDay{_powerStationID}_s1 a + where right(a.inverterid, 4) = '000{(i + 1).ToString()}') a0{(i + 1).ToString()} on a02.report_date = a0{(i + 1).ToString()}.report_date "); + sb_update_columns.Append($@", a.inv_0{(i + 1).ToString()} = b.inv_0{(i + 1).ToString()}"); + } + } + else + { + sb.Append(@$" , ifnull(a{(i + 1).ToString()}.inv_{(i + 1).ToString()}, 0) inv_{(i + 1).ToString()} "); + sb_column.Append(@$", `inv_{(i + 1).ToString()}`"); + sb_select.Append($@" left join (select report_date, ifnull(round(kwh , 6), 0) inv_{(i + 1).ToString()} from temp_invDay{_powerStationID}_s1 a + where right(a.inverterid, 4) = '00{(i + 1).ToString()}') a{(i + 1).ToString()} on a02.report_date = a{(i + 1).ToString()}.report_date "); + sb_update_columns.Append($@", a.inv_{(i + 1).ToString()} = b.inv_{(i + 1).ToString()}"); + } + } + // sb.Append(", `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`)"); + + #endregion + + + #region insert report_invDay + sb_column.Clear(); + sql = sb.ToString() + sb_select.ToString() + sb_update_columns.ToString(); + conn.Execute(sql); + + ss = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; "; + conn.Execute(ss); + #endregion + + if (_logger != null) + _logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1); + + } + catch (Exception ex) + { + if (_logger != null) + { + _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1); + _logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString()); + } + throw ex; + } + #endregion - conn.Close(); - } - result = true; - } - catch (Exception ex) - { - throw ex; + conn.Close(); } + result = true; + return result; } } From 9e8771d7810388e68962c227ce6c41848b887361 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 13 Dec 2021 10:17:59 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E6=AD=B8=E6=AA=94=20-?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9ESensor=EF=BC=9A1.=E7=B4=AF=E8=A8=88?= =?UTF-8?q?=E6=97=A5=E7=85=A7=E9=87=8F=202.=E9=A2=A8=E5=90=91=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procSensorSvc.cs | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index e4c307d..3a3e660 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -180,20 +180,26 @@ namespace solarApp.Service // { "Name":"環境濕度計","EName":"EMM"}, // { "Name":"風速計","EName":"VAN"}, // { "Name":" 電表","EName":"PWR"}]} + // { "Name":"風向計","EName":"WIN"}]} + // { "Name":" 累計日照計","EName":"TPY"}]} var irrlst = ds_sensor.FindAll(x => x.type.Contains("PYR")); var modelTemplst = ds_sensor.FindAll(x => x.type.Contains("MTR")); var envTemplst = ds_sensor.FindAll(x => x.type.Contains("ETR")); var humlst = ds_sensor.FindAll(x => x.type.Contains("EMM")); - var windlst = ds_sensor.FindAll(x => x.type.Contains("VAN")); - var dustlst = ds_sensor.FindAll(x => x.type.Contains("DST")); //需要新增於DB + var vandlst = ds_sensor.FindAll(x => x.type.Contains("VAN")); + var dustlst = ds_sensor.FindAll(x => x.type.Contains("DST")); //落塵計 add @ 2021-12-12 + var winlst = ds_sensor.FindAll(x => x.type.Contains("WIN")); //風向計 add @ 2021-12-12 + var irrDaylst = ds_sensor.FindAll(x => x.type.Contains("TPY")); //累計日照計 add @ 2021-12-12 //var meterlst = ds_sensor.FindAll(x => x.type.Contains("PWR")); 電錶暫不處理 - string irrCol = string.Empty; string modelTempCol = string.Empty; string evnTempCol = string.Empty; string humCol = string.Empty; string windCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty; + string irrCol = string.Empty; string modelTempCol = string.Empty; string evnTempCol = string.Empty; string humCol = string.Empty; string vanCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty; string winCol = string.Empty; string irrDayCol = string.Empty; irrCol = ConcatColumn(irrlst);//日照計 modelTempCol = ConcatColumn(modelTemplst); evnTempCol = ConcatColumn(envTemplst); humCol = ConcatColumn(humlst); - windCol = ConcatColumn(windlst); + vanCol = ConcatColumn(vandlst); dustCol = ConcatColumn(dustlst); + winCol = ConcatColumn(winlst); + irrDayCol = ConcatColumn(irrDaylst); string irrNot0 = string.Empty; // and 日照1 <> 0 and 日照2 <> 0 # region 日照計需要過濾 0 @@ -210,11 +216,11 @@ namespace solarApp.Service try { #region hour - sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust) - select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from + sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay) + select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay from ( select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(avg(" + modelTempCol + @"), 4) Temperature, - avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + windCol + @") Vane, avg(" + dustCol + @") Dust + avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + vanCol + @") Vane, avg(" + dustCol + @") Dust, avg(" + winCol + @") WingDirection, max(" + irrDayCol + @") irrDay from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') @@ -232,11 +238,11 @@ namespace solarApp.Service #endregion hour #region day - sql = @"insert into sensor_history_day( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust) - select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from + sql = @"insert into sensor_history_day( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay) + select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, a.WingDirection, a.irrDay from ( select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature, - envTemperature, humidity, Vane, Dust + envTemperature, humidity, Vane, Dust, WingDirection, irrDay from solar_master.sensor_history_hour where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') @@ -256,11 +262,11 @@ namespace solarApp.Service sql = @" delete from sensor_history_month where left(`TIMESTAMP`, 7) = @date1 and PowerStationID = @powerStationID; - insert into sensor_history_month( `PowerStationId`, `TIMESTAMP`, `Irradiance`, Temperature, EnvTemperature, Humidity, Vane, Dust) - select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from + insert into sensor_history_month( `PowerStationId`, `TIMESTAMP`, `Irradiance`, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay) + select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay from ( select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m'), '-01 00:00') reportdate, round(avg(Temperature), 6) Temperature, - envTemperature, humidity, Vane, Dust + envTemperature, humidity, Vane, Dust, WingDirection, irrDay from solar_master.sensor_history_day where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1 group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m') From 27499fa70f930a6c4f6c01ba131a88940ce66ee8 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Tue, 14 Dec 2021 19:15:40 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=AD=B8=E6=AA=94=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E7=B4=AF=E8=A8=88=E6=97=A5=E7=85=A7=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/fmArchive.Designer.cs | 28 +++++++++++++++++++++------- solarApp/fmArchive.cs | 14 ++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index dcabc40..301cd21 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -29,8 +29,8 @@ namespace solarApp /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); @@ -69,6 +69,7 @@ namespace solarApp this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); + this.btInvDay_oldData = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -119,6 +120,7 @@ namespace solarApp // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.splitContainer1.Panel1.Controls.Add(this.btInvDay_oldData); this.splitContainer1.Panel1.Controls.Add(this.bt_rpt_invDay); this.splitContainer1.Panel1.Controls.Add(this.bt_meter); this.splitContainer1.Panel1.Controls.Add(this.lbmsg); @@ -146,7 +148,7 @@ namespace solarApp // bt_rpt_invDay // this.bt_rpt_invDay.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bt_rpt_invDay.Location = new System.Drawing.Point(223, 790); + this.bt_rpt_invDay.Location = new System.Drawing.Point(262, 790); this.bt_rpt_invDay.Name = "bt_rpt_invDay"; this.bt_rpt_invDay.Size = new System.Drawing.Size(135, 44); this.bt_rpt_invDay.TabIndex = 12; @@ -281,8 +283,8 @@ namespace solarApp // this.gv_inv_detail.AllowUserToAddRows = false; this.gv_inv_detail.AllowUserToDeleteRows = false; - dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); - this.gv_inv_detail.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_inv_detail.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.gv_inv_detail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gv_inv_detail.Dock = System.Windows.Forms.DockStyle.Fill; this.gv_inv_detail.Location = new System.Drawing.Point(768, 75); @@ -298,8 +300,8 @@ namespace solarApp // this.gv_rpt_invDay.AllowUserToAddRows = false; this.gv_rpt_invDay.AllowUserToDeleteRows = false; - dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); - this.gv_rpt_invDay.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_rpt_invDay.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2; this.gv_rpt_invDay.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gv_rpt_invDay.Dock = System.Windows.Forms.DockStyle.Left; this.gv_rpt_invDay.Location = new System.Drawing.Point(0, 75); @@ -536,6 +538,17 @@ namespace solarApp this.label4.TabIndex = 9; this.label4.Text = "Site_Name"; // + // btInvDay_oldData + // + this.btInvDay_oldData.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.btInvDay_oldData.Location = new System.Drawing.Point(156, 790); + this.btInvDay_oldData.Name = "btInvDay_oldData"; + this.btInvDay_oldData.Size = new System.Drawing.Size(100, 44); + this.btInvDay_oldData.TabIndex = 13; + this.btInvDay_oldData.Text = "日報-舊"; + this.btInvDay_oldData.UseVisualStyleBackColor = true; + this.btInvDay_oldData.Click += new System.EventHandler(this.btInvDay_oldData_Click); + // // fmArchive // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); @@ -610,5 +623,6 @@ namespace solarApp private System.Windows.Forms.Label label4; private System.Windows.Forms.Button bt_invDay; private System.Windows.Forms.DataGridView gv_inv_detail; + private System.Windows.Forms.Button btInvDay_oldData; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index f2e657e..3bdc812 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -222,6 +222,11 @@ namespace solarApp MessageBox.Show("OK"); } + /// + /// 日報表 - 每日歸檔 + /// + /// + /// private void bt_rpt_invDay_Click(object sender, EventArgs e) { string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); @@ -309,5 +314,14 @@ namespace solarApp gv_inv_detail.Columns[4].Width = 80; gv_inv_detail.Columns[5].Width = 80; } + + private void btInvDay_oldData_Click(object sender, EventArgs e) + { + procInvSvc invSvc = new procInvSvc(); + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + } + } } } From 7510b7432f7ffda849752d7b8feef51887f3dfcf Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Tue, 14 Dec 2021 19:16:46 +0800 Subject: [PATCH 12/14] debug --- solarApp/fmArchive.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 3bdc812..f620cbc 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -317,11 +317,11 @@ namespace solarApp private void btInvDay_oldData_Click(object sender, EventArgs e) { - procInvSvc invSvc = new procInvSvc(); - foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) - { - invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); - } + //procInvSvc invSvc = new procInvSvc(); + //foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + //{ + // invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + //} } } } From 6d3bcb7d0dd7f51ce57b559e4b3b035dd15f5467 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Tue, 14 Dec 2021 19:17:24 +0800 Subject: [PATCH 13/14] debug2 --- solarApp/fmArchive.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index f620cbc..59f1796 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -317,7 +317,7 @@ namespace solarApp private void btInvDay_oldData_Click(object sender, EventArgs e) { - //procInvSvc invSvc = new procInvSvc(); + //procInvSvc invSvc = new procInvSvc(); //foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) //{ // invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); From 355ad963308c1f23114889257fbab9dac2cab0d6 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 14 Dec 2021 19:45:23 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E6=AF=8F=E5=B0=8F=E6=99=82=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=9F=B7=E8=A1=8C=20=E5=8A=A0=E5=85=A5=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E8=A8=AD=E5=82=99=E8=A8=88=E7=AE=97(=E9=A2=A8?= =?UTF-8?q?=E5=90=91=E8=A8=88=E3=80=81=E7=B4=AF=E8=A8=88=E6=97=A5=E7=85=A7?= =?UTF-8?q?=E9=87=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/PowerStation.cs | 6 ++- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 50 ++++++++++++++++++- .../Implement/PowerStationRepository.cs | 17 ++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 4d2e793..d4367f6 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -21,7 +21,9 @@ namespace SolarPower.Models.PowerStation EMM = 4, //環境濕度計 VAN = 5, //風速計 FOM = 6, //落塵計 - PWR = 7 //電錶 + PWR = 7, //電錶 + WIN = 8, //風向計 + TPY = 9 //累計日照量 } public class PowerStation : Created @@ -729,6 +731,8 @@ namespace SolarPower.Models.PowerStation public double Humidity { get; set; } //濕度 public double Vane { get; set; } //風速 public double Dust { get; set; } //落塵計 + public double WingDirection { get; set; } //風向計 + public double IrrDay { get; set; } //累計日照量 } public class AvgPyrheliometerHistory diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index e6fa27e..85d8213 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -428,7 +428,7 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); } - //5. 計算該電站 - 落塵計(FOM) + //6. 計算該電站 - 落塵計(FOM) try { logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); @@ -452,6 +452,54 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); } + //7. 計算該電站 - 風向計(WIN) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的風向計設備資訊】", powerStation.Code, dateTime); + var WINdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.WIN.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的風向計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的風向計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(WINdeviceInfos)); + if (WINdeviceInfos != null && WINdeviceInfos.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的風向計的平均%】", powerStation.Code, dateTime); + var WINHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, WINdeviceInfos, Convert.ToInt32(SensorTypeEnum.WIN)); + if (WINHistory != null) + { + sensorHistory.WingDirection = WINHistory.WingDirection; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的風向計的平均值】", powerStation.Code, dateTime); + } + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的風向計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //8. 計算該電站 - 累計日照量(TPY) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime); + var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的累計日照量備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的累計日照量設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(TPYdeviceInfos)); + if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的累計日照量的平均%】", powerStation.Code, dateTime); + var TPYHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, TPYdeviceInfos, Convert.ToInt32(SensorTypeEnum.TPY)); + if (TPYHistory != null) + { + sensorHistory.IrrDay = TPYHistory.IrrDay; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); + } + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + sensorHistoriesHour.Add(sensorHistory); } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index f748416..ac15bf7 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2523,26 +2523,41 @@ namespace SolarPower.Repository.Implement { SensorTypeEnum SensorTypeEnum = (SensorTypeEnum)type; var typename = ""; + var calc = ""; switch (SensorTypeEnum) { case SensorTypeEnum.PYR: //日照計 + calc = "AVG"; typename = "Irradiance"; break; case SensorTypeEnum.MTR: //模組溫度計 + calc = "AVG"; typename = "Temperature"; break; case SensorTypeEnum.ETR: //環境溫度計 + calc = "AVG"; typename = "EnvTemperature"; break; case SensorTypeEnum.EMM: //環境濕度計 + calc = "AVG"; typename = "Humidity"; break; case SensorTypeEnum.VAN: //風速計 + calc = "AVG"; typename = "Vane"; break; case SensorTypeEnum.FOM: //落塵計 + calc = "AVG"; typename = "Dust"; break; + case SensorTypeEnum.WIN: //風向計 + calc = "AVG"; + typename = "WingDirection"; + break; + case SensorTypeEnum.TPY: //累計日照量 + calc = "MAX"; + typename = "IrrDay"; + break; } PyrheliometerHistory result; @@ -2563,7 +2578,7 @@ namespace SolarPower.Repository.Implement sql_per_device.Add(str); } - var sql = @$"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY `TIMESTAMP`"; + var sql = @$"SELECT a.TIMESTAMP, {calc}(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY `TIMESTAMP`"; result = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }); }