diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJobV2.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJobV2.cs index 2e9d319..3171d2f 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJobV2.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJobV2.cs @@ -355,11 +355,7 @@ namespace SolarPower.Quartz.Jobs "today_carbon", "total_carbon", "today_irradiance", - "SolarHour", - "WeathersStationId", - "TodayWeatherTemp", - "TodayWeather", - "RateOfRain" + "SolarHour" }; logger.LogInformation("【update Power_Station】【ArchiveStation】【開始更新 Power_Station 資料】- {0}", dateTime); await powerStationRepository.UpdateList(calcPowerStations, power_station_properties); @@ -733,6 +729,7 @@ namespace SolarPower.Quartz.Jobs { Root2 observation = null; List weatherObservations = new List(); + List calcPowerStations = new List(); #region 氣象觀測(取資料) try { @@ -760,14 +757,14 @@ namespace SolarPower.Quartz.Jobs #region 確認是否有觀測站(沒有則新增) try { - if (powerStation.WeathersStationId == null) + if (powerStation.WeathersStationId == null || powerStation.TodayWeatherTemp == -99) { var weatherStationId = ""; double shortLocation = 9999; foreach (var Location in observation.Records.Location) { - if (powerStation.Coordinate != null) + if (powerStation.Coordinate != null ) { var powerLocation = powerStation.Coordinate.Split(','); double p1 = Convert.ToDouble(powerLocation[0].Replace("°", string.Empty)); @@ -777,7 +774,8 @@ namespace SolarPower.Quartz.Jobs double x = Math.Pow(p1 - dLat, 2); double y = Math.Pow(p2 - dLon, 2); var nowLocation = Math.Sqrt(x + y); - if (nowLocation < shortLocation) + double temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); + if (nowLocation < shortLocation && temp != -99) { shortLocation = nowLocation; weatherStationId = Location.StationId; @@ -816,6 +814,7 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.TodayWeather = weather.WeatherKey; calcPowerStation.RateOfRain = weather.PoP; } + calcPowerStations.Add(calcPowerStation); } catch (Exception ex) { @@ -845,7 +844,21 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【Insert WeatherObservation】【ArchiveWeather】【開始寫入 weather_observation 資料】- {0}", dateTime); await powerStationRepository.AddWeatherObservation(weatherObservations, weather_observation_properties); logger.LogInformation("【Insert WeatherObservation】【ArchiveWeather】【完成寫入 weather_observation 資料】- {0}", dateTime); - #endregion + #endregion + + #region step5. calcPowerStations UPDATE 到 power_station 資料表 + List power_station_properties = new List() + { + "Id", + "WeathersStationId", + "TodayWeatherTemp", + "TodayWeather", + "RateOfRain" + }; + logger.LogInformation("【update Power_Station Weather】【ArchiveStation】【開始更新 Power_Station 資料】- {0}", dateTime); + await powerStationRepository.UpdateList(calcPowerStations, power_station_properties); + logger.LogInformation("【update Power_Station Weather】【ArchiveStation】【完成更新 Power_Station 資料】- {0}", dateTime); + #endregion //} }