背景執行工作: 增加計算每小時的累積日照量差(IrrDayHour)
This commit is contained in:
parent
a178d4bb1b
commit
8fa15f190d
@ -500,6 +500,30 @@ namespace SolarPower.Quartz.Jobs
|
|||||||
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
|
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
sensorHistoriesHour.Add(sensorHistory);
|
sensorHistoriesHour.Add(sensorHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1884,8 +1884,16 @@ namespace SolarPower.Repository.Implement
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "inverter");
|
string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "inverter");
|
||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, inverter);
|
count = await conn.ExecuteAsync(sql, inverter);
|
||||||
|
|
||||||
|
//string updateToInv_Status = @"DROP TABLE IF EXISTS solar_master.`inv_status`;
|
||||||
|
// create table solar_master.inv_status
|
||||||
|
// select * from solar_master.v_company_inv
|
||||||
|
// where enabled = 1;
|
||||||
|
// ALTER TABLE solar_master.`inv_status` ADD INDEX inv_status_index (`inverterid`);";
|
||||||
|
|
||||||
|
//count = await conn.ExecuteAsync(updateToInv_Status, inverter);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -1897,6 +1905,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得控制器所有id
|
/// 取得控制器所有id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -2497,6 +2506,14 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
|
//string updateToInv_Status = @"DROP TABLE IF EXISTS solar_master.`inv_status`;
|
||||||
|
// create table solar_master.inv_status
|
||||||
|
// select * from solar_master.v_company_inv
|
||||||
|
// where enabled = 1;
|
||||||
|
// ALTER TABLE solar_master.`inv_status` ADD INDEX inv_status_index (`inverterid`);";
|
||||||
|
|
||||||
|
//await conn.ExecuteAsync(updateToInv_Status, entity, trans);
|
||||||
|
|
||||||
trans.Commit();
|
trans.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -2513,6 +2530,43 @@ namespace SolarPower.Repository.Implement
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public virtual async Task DeleteOneInverter(int id, string db_name, string table_name)
|
||||||
|
//{
|
||||||
|
// using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||||
|
// {
|
||||||
|
// conn.Open();
|
||||||
|
// using (var trans = conn.BeginTransaction())
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var sql = $"UPDATE {db_name}.{table_name} SET Deleted = 1 WHERE Id = @Id";
|
||||||
|
|
||||||
|
// await conn.ExecuteAsync(sql, new { Id = id }, trans);
|
||||||
|
|
||||||
|
// string updateToInv_Status = @"DROP TABLE IF EXISTS solar_master.`inv_status`;
|
||||||
|
// create table solar_master.inv_status
|
||||||
|
// select * from solar_master.v_company_inv
|
||||||
|
// where enabled = 1;
|
||||||
|
// ALTER TABLE solar_master.`inv_status` ADD INDEX inv_status_index (`inverterid`);";
|
||||||
|
|
||||||
|
// await conn.ExecuteAsync(updateToInv_Status, new { Id = id }, trans);
|
||||||
|
|
||||||
|
// trans.Commit();
|
||||||
|
// }
|
||||||
|
// catch (Exception exception)
|
||||||
|
// {
|
||||||
|
// trans.Rollback();
|
||||||
|
// throw exception;
|
||||||
|
// }
|
||||||
|
// finally
|
||||||
|
// {
|
||||||
|
// conn.Close();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name)
|
public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name)
|
||||||
{
|
{
|
||||||
List<DeviceInfo> result;
|
List<DeviceInfo> result;
|
||||||
@ -6363,5 +6417,43 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PyrheliometerHistory> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId)
|
||||||
|
{
|
||||||
|
PyrheliometerHistory result;
|
||||||
|
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//var 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
|
||||||
|
// from sensor_history_hour z
|
||||||
|
// 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 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
|
||||||
|
from sensor_history_hour z
|
||||||
|
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 = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
|
||||||
|
where a.powerstationID = {powerStationId}";
|
||||||
|
result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, commandTimeout: 600);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -632,5 +632,6 @@ namespace SolarPower.Repository.Interface
|
|||||||
Task AlertColStationTableColumn(string dbname, string code);
|
Task AlertColStationTableColumn(string dbname, string code);
|
||||||
|
|
||||||
Task<List<PowerStation>> GetAllNoStatusAsync();
|
Task<List<PowerStation>> GetAllNoStatusAsync();
|
||||||
|
Task<PyrheliometerHistory> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user