1. bug fix

This commit is contained in:
Kai 2021-08-17 12:03:51 +08:00
parent ab0aa1ee1d
commit 2ef57ba44d
2 changed files with 362 additions and 341 deletions

View File

@ -212,16 +212,29 @@ namespace SolarPower.Quartz.Jobs
var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd"); var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd");
var dateNowMonth = DateTimeNow.AddDays(-1).ToString("yyyy-MM"); var dateNowMonth = DateTimeNow.AddDays(-1).ToString("yyyy-MM");
Root2 observation = null;
#region () #region ()
try
{
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得氣象觀測】"); logger.LogInformation("【CalcAvgPowerStationJob】【開始取得氣象觀測】");
var client = new HttpClient(); var client = new HttpClient();
var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-C0032-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=Wx,PoP&sort=time"; var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-C0032-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=Wx,PoP&sort=time";
HttpResponseMessage response = client.GetAsync(UVUri).Result; HttpResponseMessage response = client.GetAsync(UVUri).Result;
String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
Root2 observation = JsonConvert.DeserializeObject<Root2>(jsonUVs); observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功氣象觀測】"); logger.LogInformation("【CalcAvgPowerStationJob】【取得成功氣象觀測】");
#endregion }
catch (Exception ex)
{
logger.LogError("【CalcAvgPowerStationJob】【取得失敗氣象觀測】");
logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message);
observation = null;
}
#endregion
if (observation != null)
{
foreach (var location in observation.Records.Location) foreach (var location in observation.Records.Location)
{ {
WeatherForecast weatherForecast = new WeatherForecast(); WeatherForecast weatherForecast = new WeatherForecast();
@ -283,6 +296,8 @@ namespace SolarPower.Quartz.Jobs
} }
weatherForecasts.AddRange(SubweatherForecasts); weatherForecasts.AddRange(SubweatherForecasts);
} }
}
List<string> weather_forecast_properties = new List<string>() List<string> weather_forecast_properties = new List<string>()
{ {
"LocationName", "LocationName",

View File

@ -40,6 +40,8 @@ namespace SolarPower.Quartz.Jobs
var DateTimeNow = DateTime.Now; var DateTimeNow = DateTime.Now;
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
var hasException = false;
Root2 observation = null; Root2 observation = null;
if (this.environment.IsDevelopment()) if (this.environment.IsDevelopment())
@ -87,6 +89,8 @@ namespace SolarPower.Quartz.Jobs
#region step2. DB及電站編號找出該電站的控制器 #region step2. DB及電站編號找出該電站的控制器
foreach (var powerStation in powerStations) foreach (var powerStation in powerStations)
{
try
{ {
var calcPowerStation = new PowerStation(); var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id; calcPowerStation.Id = powerStation.Id;
@ -391,9 +395,11 @@ namespace SolarPower.Quartz.Jobs
calcPowerStation.TodayWeather = weather.WeatherKey; calcPowerStation.TodayWeather = weather.WeatherKey;
calcPowerStation.RateOfRain = weather.PoP; calcPowerStation.RateOfRain = weather.PoP;
} }
}
catch (Exception exception)
{
logger.LogError("【{0}】{1}", "CalcPowerStationJob", exception.Message);
}
} }
#endregion #endregion