solar_App: test 修改 irrDayHour In TPY

This commit is contained in:
wanling040@gmail.com 2022-08-04 20:29:55 +08:00
parent b053f20bbe
commit 6179d549a4
2 changed files with 34 additions and 25 deletions

View File

@ -44,7 +44,7 @@ namespace SolarPower.Quartz.Jobs
if (this.environment.IsDevelopment())
{
dateTime = "2022-06-01 16";
dateTime = "2022-08-04 18";
}
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
@ -491,6 +491,14 @@ 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)
{
sensorHistory.IrrDayHour = TPYHistory.IrrDayHour;
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
}
}
}
}
@ -501,28 +509,28 @@ namespace SolarPower.Quartz.Jobs
}
//9. 計算該電站 - 每小時累計日照量(IrrDayHour)
try
{
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime);
var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.ToString(), powerStation.SiteDB);
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的累計日照量備資訊】", powerStation.Code, dateTime);
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的相減的累計日照量設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(TPYdeviceInfos));
if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0)
{
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
var TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id);
if (TPYHistory != null)
{
sensorHistory.IrrDayHour = TPYHistory.IrrDayHour;
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
}
}
}
catch (Exception ex)
{
logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
}
//try
//{
// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime);
// var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.ToString(), powerStation.SiteDB);
// logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的累計日照量備資訊】", powerStation.Code, dateTime);
// logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的相減的累計日照量設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(TPYdeviceInfos));
// if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0)
// {
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
// var TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id);
// if (TPYHistory != null)
// {
// sensorHistory.IrrDayHour = TPYHistory.IrrDayHour;
// logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
// }
// }
//}
//catch (Exception ex)
//{
// logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
// logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
//}
sensorHistoriesHour.Add(sensorHistory);
}

View File

@ -6433,12 +6433,13 @@ namespace SolarPower.Repository.Implement
// where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd HH")}'
// ) 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(dateTime).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
(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 ) = '{(Convert.ToDateTime(dateTime)).ToString("yyyy-MM-dd HH")}'
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}";