From eb96541dd42bccfc7e555a20e86464f0ce51083a Mon Sep 17 00:00:00 2001 From: cesar liu Date: Sat, 21 May 2022 14:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=AD=B8=E6=AA=94=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=20PR=20=E8=A8=88=E7=AE=97=E8=88=87=E7=B4=AF=E8=A8=88?= =?UTF-8?q?=E6=97=A5=E7=85=A7=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + SolarPower/Helper/DatabaseHelper.cs | 6 ++ SolarPower/Startup.cs | 4 +- solarApp/Model/sensor_model.cs | 16 ++++-- solarApp/Service/getSensorSvc.cs | 10 ++-- solarApp/Service/getStationSvc.cs | 2 +- solarApp/Service/procSensorSvc.cs | 14 ++--- solarApp/Service/procStationSvc.cs | 88 ++++++++++++++++++++--------- solarApp/fmArchive.cs | 31 +++++++++- 9 files changed, 124 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index ff54230..7546f95 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,4 @@ healthchecksdb /SolarPower.zip /SolarPower/wwwroot/upload/report/20220227 *.diagsession +/SolarPower/wwwroot/upload/report/20220520 diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index 0bbdd56..2d4529e 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -36,12 +36,18 @@ namespace SolarPower.Helper var databaseStr = ed.AESDecrypt(dbConfig.Database); var rootStr = ed.AESDecrypt(dbConfig.Root); var passwordStr = ed.AESDecrypt(dbConfig.Password); + //var serverStr = ed.AESEncrypt("localhost"); + //var portStr = ed.AESEncrypt("3306"); + //var databaseStr = ed.AESEncrypt("solar_master"); + //var rootStr = ed.AESEncrypt("webUser"); + //var passwordStr = ed.AESEncrypt("ficAdmin99"); var connStr = $"server={serverStr};port={portStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;Allow User Variables=True;"; this._connectionString = connStr; } + public IDbConnection GetConnection() { var conn = new MySqlConnection(this._connectionString); diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 6fa73b6..a94360e 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -121,8 +121,8 @@ namespace SolarPower #region 計算電站日照量、PR、kWP 30日平均、(每天凌晨2點執行) services.AddSingleton(); services.AddSingleton( - new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcAvgPowerStationJob")) - //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0/10 * * * * ?") + //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcAvgPowerStationJob")) + new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *") ); #endregion diff --git a/solarApp/Model/sensor_model.cs b/solarApp/Model/sensor_model.cs index e9e9d0e..21f2372 100644 --- a/solarApp/Model/sensor_model.cs +++ b/solarApp/Model/sensor_model.cs @@ -43,26 +43,34 @@ namespace solarApp.Model { public string SiteID { get; set; } public string reportdate { get; set; } - public double irrAvg { get; set; } + public double modelTempAvg { get; set; } + /// + /// 蝝航亦折 + /// + public double irrSumAvg { get; set; } public double envTempAvg { get; set; } public double humidityAvg { get; set; } public double windAvg { get; set; } public double dustAvg { get; set; } - + public double irrAvg { get; set; } public int count { get; set; } } public class sensor_hour { public string SiteID { get; set; } - public string reportdate { get; set; } - public double irrAvg { get; set; } + public string reportdate { get; set; } public double modelTempAvg { get; set; } + /// + /// 蝝航亦折 + /// + public double irrSumAvg { get; set; } public double envTempAvg { get; set; } public double humidityAvg { get; set; } public double windAvg { get; set; } public double dustAvg { get; set; } + public double irrAvg { get; set; } public int count { get; set; } } } diff --git a/solarApp/Service/getSensorSvc.cs b/solarApp/Service/getSensorSvc.cs index eea3410..894eca0 100644 --- a/solarApp/Service/getSensorSvc.cs +++ b/solarApp/Service/getSensorSvc.cs @@ -137,9 +137,9 @@ namespace solarApp.Service //餉” #endregion 脣 Sensor 憿 - sql = @"select a.siteID, a.reportdate, a.modelTempAvg, ifnull(b.irrAvg, 0) irrAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg, count from + sql = @"select a.siteID, a.reportdate, a.modelTempAvg, irrSumAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg, ifnull(b.irrAvg, 0) irrAvg, count from ( - select @siteID siteID, CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, " + modelTempCol+ @" modelTempAvg + select @siteID siteID, CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, " + modelTempCol+ @" modelTempAvg , " + totIrrCol + @" irrSumAvg ," + evnTempCol + @" envTempAvg, " + humCol + @" humidityAvg, " + windCol + @" windAvg, " + dustCol + @" dustAvg, count(*) count from " + siteDB + ".s" + siteID + @"_sensorAvg where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate @@ -167,7 +167,7 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg + string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Temperature, 2) modelTempAvg, round(irrDay, 2) irrSumAvg, round(Irradiance, 2) irrAvg from sensor_history_hour a join power_station b on a.PowerStationId = b.id where left(`TIMESTAMP`, 10) = '" + reportDate + "' and b.`code` = @siteID"; List ds = conn.Query(sql, new {siteID = siteID }).AsList(); @@ -184,7 +184,7 @@ namespace solarApp.Service //string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg // from sensor_history_day a join power_station b on a.PowerStationId = b.id // where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+date2+"' and b.`code` = @siteID"; - string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg, c.count + string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Temperature, 2) modelTempAvg, round(irrDay, 2) irrSumAvg, round(Irradiance, 2) irrAvg, c.count from sensor_history_day a join power_station b on a.PowerStationId = b.id left join ( select PowerStationId, left(a.`TIMESTAMP`, 10) reportDate, count(*) count from sensor_history_hour a join power_station b on a.PowerStationId = b.id @@ -203,7 +203,7 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg + string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(irrDay, 2) irrSumAvg , round(Temperature, 2) modelTempAvg, round(Irradiance, 2) irrAvg from sensor_history_month a join power_station b on a.PowerStationId = b.id where left(`TIMESTAMP`, 7) between '" + date1 + "' and '" + date2 + "' and b.`code` = @siteID"; List ds = conn.Query(sql, new { siteID = siteID}).AsList(); diff --git a/solarApp/Service/getStationSvc.cs b/solarApp/Service/getStationSvc.cs index 0c76aa3..dec4842 100644 --- a/solarApp/Service/getStationSvc.cs +++ b/solarApp/Service/getStationSvc.cs @@ -179,7 +179,7 @@ namespace solarApp.Service conn.Open(); // 01 批嗅函楊 string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName from power_station - where deleted = 0 "; + where deleted = 0 and `status`= 1 "; List ds = conn.Query(sql).AsList(); conn.Close(); return ds; diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index e7c931a..f0303ff 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -57,19 +57,19 @@ namespace solarApp.Service public bool archiveData(string siteID, string date1) { bool result = false; - try - { + //try + //{ _siteID = siteID; _date1 = date1; get_siteInfo(); clearData(); insert_sensor(); result = true; - } - catch (Exception ex) - { - throw ex; - } + //} + //catch (Exception ex) + //{ + // throw ex; + //} return result; } diff --git a/solarApp/Service/procStationSvc.cs b/solarApp/Service/procStationSvc.cs index 80deb8c..c3fd4c6 100644 --- a/solarApp/Service/procStationSvc.cs +++ b/solarApp/Service/procStationSvc.cs @@ -215,19 +215,19 @@ namespace solarApp.Service cmd.Parameters.Clear(); #endregion hour - #region day + //#region 蝝航亦折 + //sql = $@"select a.TableName, a.ColName from solar_com0002.device a where `type` = 'TPY' and a.Deleted = 0 and a.`status` = 1 "; + //#endregion + + #region day PR = (蝝航潮駁/鋆蝵桀捆)*1000/蝝航亦折 + + sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP, PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) - select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a1.PR, a.MP, a.SOLARHOUR, - /*CASE - WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate - ELSE a.KWH * PowerRate - END MONEY, - CASE - WHEN b.SolarType = 1 THEN a.TOTALKWH * PowerRate * c.LeaseRate - ELSE a.TOTALKWH * PowerRate - END TOTALMONEY,*/ + select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, + a1.PR, -- (todayKWH/Capacity)*1000/b.IrrDay as PR, -- PR 閮蝞 + a.MP, a.SOLARHOUR, (a.TODAYKWH * PowerRate) MONEY, (a.TOTALKWH * PowerRate) TOTALMONEY, (KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON @@ -235,32 +235,68 @@ namespace solarApp.Service ( select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00:00') reportdate, siteid, siteType, round((sum(KWH)), 6) KWH, round((max(TODAYKWH)), 6) TODAYKWH, round((max(TOTALKWH)), 6) TOTALKWH, round((max(KWHKWP)), 6) KWHKWP, - #round((max(PR)), 6) PR, + # round((avg(PR)), 6) PR, round((max(MP)), 6) as MP, round((max(SOLARHOUR)), 6) SOLARHOUR from solar_master.power_station_history_hour a where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1 group by a.siteid, DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') - )a join - ( + )a join + ( select id, SITEID, round(PR, 4) PR from solar_master.power_station_history_hour a where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1 order by 1 desc limit 1 )a1 on a.siteID = a1.siteID join ( - select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType - from solar_master.power_station - where `code` = @siteID - ) b on a.siteID = b.siteID - LEFT JOIN ( - SELECT - SUM(lb.LeaseRate) LeaseRate, - ps.Code siteID FROM " + _siteDB + @".land_building lb - LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id - WHERE ps.Code = @siteID - GROUP BY lb.PowerStationId - ) c ON a.siteID = c.siteID"; - // conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); + select a.id, `code` siteID, PowerRate, GeneratingCapacity Capacity, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType, IrrDay + from solar_master.power_station a join sensor_history_day b on a.id = b.PowerStationID + where `code` = @siteID and left(`TIMESTAMP`, 10) = @date1 + ) b on a.siteID = b.siteID "; + // sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP, + // PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) + + // select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a1.PR, a.MP, a.SOLARHOUR, + // /*CASE + // WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate + // ELSE a.KWH * PowerRate + //END MONEY, + // CASE + // WHEN b.SolarType = 1 THEN a.TOTALKWH * PowerRate * c.LeaseRate + // ELSE a.TOTALKWH * PowerRate + //END TOTALMONEY,*/ + // (a.TODAYKWH * PowerRate) MONEY, + // (a.TOTALKWH * PowerRate) TOTALMONEY, + // (KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON + // from + // ( + // select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00:00') reportdate, siteid, siteType, round((sum(KWH)), 6) KWH, + // round((max(TODAYKWH)), 6) TODAYKWH, round((max(TOTALKWH)), 6) TOTALKWH, round((max(KWHKWP)), 6) KWHKWP, + // #round((max(PR)), 6) PR, + // round((max(MP)), 6) as MP, round((max(SOLARHOUR)), 6) SOLARHOUR + // from solar_master.power_station_history_hour a + // where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1 + // group by a.siteid, DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') + // )a join + // ( + // select id, SITEID, round(PR, 4) PR + // from solar_master.power_station_history_hour a + // where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1 + // order by 1 desc limit 1 + // )a1 on a.siteID = a1.siteID join + // ( + // select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType + // from solar_master.power_station + // where `code` = @siteID + // ) b on a.siteID = b.siteID + // LEFT JOIN ( + // SELECT + // SUM(lb.LeaseRate) LeaseRate, + // ps.Code siteID FROM " + _siteDB + @".land_building lb + // LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id + // WHERE ps.Code = @siteID + // GROUP BY lb.PowerStationId + // ) c ON a.siteID = c.siteID"; + // conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); cmd.Parameters.AddWithValue("@date1", _date1); cmd.Parameters.AddWithValue("@siteID", _siteID); cmd.CommandText = sql; diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index 8ba8401..65b17e4 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -186,9 +186,34 @@ namespace solarApp private void bt_archive_Click(object sender, EventArgs e) { - bt_Sensor.PerformClick(); - bt_Inv.PerformClick(); - bt_site.PerformClick(); + int i = 0; + var site_list = stationSvc.get_station_list(); + + //bt_Sensor.PerformClick(); + //bt_Inv.PerformClick(); + //bt_site.PerformClick(); + //bt_rpt_invDay.PerformClick(); + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd"); + procSensorSvc sensorSvc = new procSensorSvc(); + procInvSvc invSvc = new procInvSvc(); + procStationSvc siteSvc = new procStationSvc(); + + foreach (var item in site_list) + { + //RadioButton rb = new RadioButton(); + //rb.Name = item.SiteID; + //rb.Text = item.SiteName; + //rb.Tag = item.SiteDB; + foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + { + sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); + invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); + siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); + invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); + } + i++; + } } private void bt_clear_sensor_Click(object sender, EventArgs e)