From 995f7dc4992959cb6814e9873984e8e7fc8cfcce Mon Sep 17 00:00:00 2001 From: cesar liu Date: Thu, 4 Aug 2022 21:38:52 +0800 Subject: [PATCH] =?UTF-8?q?debug=20=E7=B3=BB=E7=B5=B1=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?-=20=E7=B4=AF=E8=A8=88=E6=97=A5=E7=85=A7=E7=9B=B8=E6=B8=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 15 +++++----- .../Implement/PowerStationRepository.cs | 29 +++++++++++-------- .../Interface/IPowerStationRepository.cs | 2 +- SolarPower/Startup.cs | 3 +- solarApp/fmArchive.Designer.cs | 3 -- solarApp/fmArchive.cs | 20 ++++++------- 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 0b6ec0a..99a87bb 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -42,10 +42,10 @@ namespace SolarPower.Quartz.Jobs Root2 observation = null; - if (this.environment.IsDevelopment()) - { - dateTime = "2022-08-04 18"; - } + //if (this.environment.IsDevelopment()) + //{ + // dateTime = "2022-08-04 18"; + //} logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -492,10 +492,10 @@ namespace SolarPower.Quartz.Jobs sensorHistory.IrrDay = TPYHistory.IrrDay; logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); - TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); - if (TPYHistory != null) + var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); + if (ss != null) { - sensorHistory.IrrDayHour = TPYHistory.IrrDayHour; + sensorHistory.IrrDayHour = double.Parse( ss); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); } @@ -773,6 +773,7 @@ namespace SolarPower.Quartz.Jobs "Dust", "WingDirection", "IrrDay", + "IrrDayHour" }; await powerStationRepository.AddSensorHistoryHour(sensorHistoriesHour, sensor_history_properties); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index c247c1a..ecb6390 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -6418,9 +6418,9 @@ namespace SolarPower.Repository.Implement } } - public async Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId) + public async Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId) { - PyrheliometerHistory result; + string result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try @@ -6434,16 +6434,21 @@ namespace SolarPower.Repository.Implement // ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` // Set a.irrdayhour = b.irrdayhour where a.powerstationID = {powerStationId}"; string d1 = dateTime + ":00:00"; - string sql = $@"update sensor_history_hour a join - ( - select powerstationID, `TIMESTAMP`, irrday - - (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour - from sensor_history_hour z - where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' - ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` - Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end - where a.powerstationID = {powerStationId}"; - result = await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600); + //string sql = $@"update sensor_history_hour a join + // ( + // select powerstationID, `TIMESTAMP`, irrday - + // (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + // from sensor_history_hour z + // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' + // ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` + // Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end + // where a.powerstationID = {powerStationId}"; + //result = await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600); + string sql = $@" select irrday - + (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + from sensor_history_hour z + where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' "; + result = await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600); } catch (Exception exception) { diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 7de6af7..7e9ff54 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -632,6 +632,6 @@ namespace SolarPower.Repository.Interface Task AlertColStationTableColumn(string dbname, string code); Task> GetAllNoStatusAsync(); - Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); + Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); } } diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 80f04ad..a22c6d0 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -95,7 +95,8 @@ namespace SolarPower #region [JI //services.AddHostedService(); - if (envName == "Production") + //if (envName == "Production") + if (!envName != "Production") { ////K[QuartzA services.AddSingleton(); diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index da5b5f7..64cdef2 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -176,7 +176,6 @@ namespace solarApp this.label2.Size = new System.Drawing.Size(42, 19); this.label2.TabIndex = 19; this.label2.Text = "小時:"; - this.label2.Visible = false; // // textBox1 // @@ -184,7 +183,6 @@ namespace solarApp this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(125, 27); this.textBox1.TabIndex = 18; - this.textBox1.Visible = false; // // button2 // @@ -195,7 +193,6 @@ namespace solarApp this.button2.TabIndex = 17; this.button2.Text = "測試當下 irrdayHour"; this.button2.UseVisualStyleBackColor = true; - this.button2.Visible = false; this.button2.Click += new System.EventHandler(this.button2_Click); // // bt_archive_One diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 6b7d597..dc39114 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -111,16 +111,16 @@ namespace solarApp } //臨時的 累計日照 - //if (DateTime.Now.Minute == 39 && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10) && autoTask == false) - //{ - // //MessageBox.Show("ok"); - // autoTask = true; - // lbMsgTitle.Text = DateTime.Now.ToString() + " 臨時的 累計日照 start"; - - // button2.PerformClick(); - // //bt_archive_Click.PerformClick(); - //} - + if (DateTime.Now.Minute == 30 && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10) && autoTask == false) + { + //MessageBox.Show("ok"); + autoTask = true; + lbMsgTitle.Text = DateTime.Now.ToString() + " 臨時的 累計日照 start"; + + button2.PerformClick(); + //bt_archive_Click.PerformClick(); + } + //水位管理 if (System.DateTime.Now.Hour == 03 && DateTime.Now.Minute == 30