From 84dc9a296d72eb2f2ed1d17552599e2f7ff19afd Mon Sep 17 00:00:00 2001 From: cesar liu Date: Tue, 22 Nov 2022 18:00:27 +0800 Subject: [PATCH] =?UTF-8?q?debug=20-=20=E5=90=88=E4=BD=B5=E9=9B=BB?= =?UTF-8?q?=E7=AB=99=20-=20=E7=95=B6=E5=A4=A9=E8=B3=87=E6=96=99=E4=B8=AD?= =?UTF-8?q?=E6=96=B7=EF=BC=8C=E4=BD=86=E9=A1=AF=E7=A4=BA=E6=8A=93=E5=8F=96?= =?UTF-8?q?=E6=9C=80=E5=BE=8C=E4=B8=80=E7=AD=86=E5=B0=8E=E8=87=B4=E9=A1=AF?= =?UTF-8?q?=E7=A4=BA=E7=82=BA=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisStationCombineRepository.cs | 13 ++++-- solarApp/Service/archiveLowData.cs | 14 +++---- solarApp/fmArchive.Designer.cs | 28 +++++++------ solarApp/fmArchive.cs | 42 +++++++++---------- solarApp/solarApp.csproj | 7 ++++ 5 files changed, 57 insertions(+), 47 deletions(-) diff --git a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs index 024fbfa..a5cd4aa 100644 --- a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs +++ b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs @@ -53,7 +53,7 @@ namespace SolarPower.Repository.Implement } - sql = $@"SELECT m.*,n.*,o.*,p.* FROM + sql = $@" SELECT m.*,n.*,o.*,p.* FROM ( SELECT SUM(ps.Total_kwh) AS All_kwh, @@ -70,10 +70,15 @@ namespace SolarPower.Repository.Implement AVG(b.KWHKWP) AS Now_KWH_KWP , AVG(b.PR) AS Now_PR, SUM(b.TODAYCARBON) AS Now_Carbon - FROM (SELECT MAX(a.`TIMESTAMP`) AS maxTIMESTAMP FROM - (SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}') a ) c + FROM ( + SELECT MAX(`TIMESTAMP`) maxTIMESTAMP FROM power_station_history_hour hr + WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' and PowerStationId IN @ids + ) c LEFT JOIN - (SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' ) b + ( + SELECT * FROM power_station_history_hour hr + WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' and PowerStationId IN @ids + ) b ON c.maxTIMESTAMP = b.`TIMESTAMP` WHERE PowerStationId IN @ids ) diff --git a/solarApp/Service/archiveLowData.cs b/solarApp/Service/archiveLowData.cs index d15cbca..006b20c 100644 --- a/solarApp/Service/archiveLowData.cs +++ b/solarApp/Service/archiveLowData.cs @@ -290,7 +290,7 @@ namespace solarApp.Service //System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_station]的資料表向[{_siteDB}_history.s{_siteID}_station]搬移"); string for_insert_station = $@"INSERT {_siteDB}_history.s{_siteID01}_station(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime`) SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime` FROM {_siteDB}.s{_siteID01}_station - WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-08'"; + WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-10'"; int rowCT = conn.Execute(for_insert_station, commandTimeout : 600); // System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_station的七月前資料寫入至{_siteDB}_history.s{_siteID}_station【寫入成功】於{dateTime}"); @@ -303,7 +303,7 @@ namespace solarApp.Service //刪除原本的資料 string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station - WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-08'"; + WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-10'"; rowCT = conn.Execute(for_delete_station, commandTimeout: 600); //System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_station.ToString()} 筆"); duration = DateTime.Now - dt_start1; @@ -346,7 +346,7 @@ namespace solarApp.Service // System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_inv]的資料表向[{_siteDB}_history.s{_siteID}_inv]搬移"); string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime`) SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime` FROM {_siteDB}.s{_siteID01}_inv - WHERE LEFT(crdTime, 7) < '2022-08' "; + WHERE LEFT(crdTime, 7) < '2022-10'"; int rowCT = conn.Execute(for_insert_inv, commandTimeout: 6000); //System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_inv的七月前資料寫入至{_siteDB}_history.s{_siteID}_inv【寫入成功】於{dateTime}"); // log @@ -356,8 +356,8 @@ namespace solarApp.Service dt_start1 = DateTime.Now; string for_delete_inv = $@"DELETE FROM {_siteDB}.s{_siteID01}_inv - WHERE LEFT(crdTime, 7) < '2022-08'"; - rowCT = conn.Execute(for_delete_inv, commandTimeout: 6000); + WHERE LEFT(crdTime, 7) < '2022-10'"; + rowCT = conn.Execute(for_delete_inv, commandTimeout: 6000); //System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_inv.ToString()} 筆"); duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", "", "0", "", rowCT.ToString(), conn, null); @@ -391,14 +391,14 @@ namespace solarApp.Service //System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_sensoravg]的資料表向[{_siteDB}_history.s{_siteID}_sensoravg]搬移"); string for_insert_sensoravg = $@"INSERT {_siteDB}_history.s{_siteID01}_sensoravg(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`) SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime` FROM {_siteDB}.s{_siteID01}_sensoravg - WHERE LEFT(crdTime, 7) < '2022-08'"; + WHERE LEFT(crdTime, 7) < '2022-10'"; int rowCT = conn.Execute(for_insert_sensoravg, commandTimeout: 600); // log TimeSpan duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null); dt_start1 = DateTime.Now; - string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '2022-08'"; + string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '2022-10'"; rowCT = conn.Execute(for_delete_sensoravg, commandTimeout: 600); duration = DateTime.Now - dt_start1; diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index b8971d1..4133ae9 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -72,7 +72,6 @@ namespace solarApp this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.panel2 = new System.Windows.Forms.Panel(); - this.button1 = new System.Windows.Forms.Button(); this.lbReceiver = new System.Windows.Forms.Label(); this.tbReceiver = new System.Windows.Forms.TextBox(); this.gbox = new System.Windows.Forms.GroupBox(); @@ -89,6 +88,7 @@ namespace solarApp this.tbUserName = new System.Windows.Forms.TextBox(); this.btSendMail = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); + this.bt_MoveRawData = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -100,6 +100,7 @@ namespace solarApp this.panel1.SuspendLayout(); this.tabPage2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); this.panel2.SuspendLayout(); @@ -557,6 +558,7 @@ namespace solarApp // splitContainer2.Panel1 // this.splitContainer2.Panel1.BackColor = System.Drawing.Color.OldLace; + this.splitContainer2.Panel1.Controls.Add(this.bt_MoveRawData); this.splitContainer2.Panel1.Cursor = System.Windows.Forms.Cursors.Default; // // splitContainer2.Panel2 @@ -580,7 +582,6 @@ namespace solarApp // panel2 // this.panel2.BackColor = System.Drawing.Color.Moccasin; - this.panel2.Controls.Add(this.button1); this.panel2.Controls.Add(this.lbReceiver); this.panel2.Controls.Add(this.tbReceiver); this.panel2.Controls.Add(this.gbox); @@ -591,16 +592,6 @@ namespace solarApp this.panel2.Size = new System.Drawing.Size(1459, 321); this.panel2.TabIndex = 0; // - // button1 - // - this.button1.Location = new System.Drawing.Point(1288, 73); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(94, 29); - this.button1.TabIndex = 17; - this.button1.Text = "button1"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click_1); - // // lbReceiver // this.lbReceiver.AutoSize = true; @@ -752,6 +743,16 @@ namespace solarApp // this.timer1.Interval = 10000; // + // bt_MoveRawData + // + this.bt_MoveRawData.Location = new System.Drawing.Point(59, 425); + this.bt_MoveRawData.Name = "bt_MoveRawData"; + this.bt_MoveRawData.Size = new System.Drawing.Size(148, 65); + this.bt_MoveRawData.TabIndex = 18; + this.bt_MoveRawData.Text = "MoveRawData"; + this.bt_MoveRawData.UseVisualStyleBackColor = true; + this.bt_MoveRawData.Click += new System.EventHandler(this.bt_MoveRawData_Click); + // // fmArchive // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); @@ -773,6 +774,7 @@ namespace solarApp this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.tabPage2.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); @@ -843,6 +845,6 @@ namespace solarApp private System.Windows.Forms.Label lbMsgStatus; private System.Windows.Forms.TabPage tabPage5; private System.Windows.Forms.Button btSyncErr; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button bt_MoveRawData; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 6348702..b279830 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -358,8 +358,8 @@ namespace solarApp private void lbSiteDB_sensor_Click(object sender, EventArgs e) { - fmExcel fm = new fmExcel(); - fm.Show(); + //fmExcel fm = new fmExcel(); + //fm.Show(); } @@ -725,27 +725,7 @@ namespace solarApp } } - /// - /// - /// - /// - /// - private void button1_Click_1(object sender, EventArgs e) - { - int i = 0; - var site_list = stationSvc.get_station_list(); - - archiveLowData archiveData = new archiveLowData(); - - foreach (var item in site_list) - { - archiveData.archiveData(item.SiteID.Substring(0, 9)); - - i++; - } - lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!"; - } - + private void button2_Click(object sender, EventArgs e) { // string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+System.DateTime.Now.AddHours(-2) + ":00:00"; @@ -800,6 +780,22 @@ namespace solarApp autoTask = false; } + private void bt_MoveRawData_Click(object sender, EventArgs e) + { + int i = 0; + var site_list = stationSvc.get_station_list(); + + archiveLowData archiveData = new archiveLowData(); + + foreach (var item in site_list) + { + archiveData.archiveData(item.SiteID.Substring(0, 9)); + + i++; + } + lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!"; + } + //test for email format //private void button3_Click(object sender, EventArgs e) //{ diff --git a/solarApp/solarApp.csproj b/solarApp/solarApp.csproj index 8bc98e4..2877e20 100644 --- a/solarApp/solarApp.csproj +++ b/solarApp/solarApp.csproj @@ -7,6 +7,13 @@ + + + + + + +