solar_App: 即時更新(全部電站的發電量、發電金額等資料)
This commit is contained in:
parent
da507694fa
commit
8133a69266
@ -276,6 +276,33 @@ namespace solarApp.Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PowerStationHistory GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name)
|
||||||
|
{
|
||||||
|
PowerStationHistory result;
|
||||||
|
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = $@"
|
||||||
|
SELECT
|
||||||
|
DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') AS TIMESTAMP,
|
||||||
|
SITEID, SiteType, KWH, TodayKWh, TotalKWH,
|
||||||
|
KWHKWP, PR, MP, SolarHour
|
||||||
|
FROM {table_name}
|
||||||
|
WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d') = @DateTime
|
||||||
|
AND kwh > 0
|
||||||
|
order by timestamp desc";
|
||||||
|
|
||||||
|
result = conn.QueryFirstOrDefault<PowerStationHistory>(sql, new { DateTime = dateTime }, commandTimeout: 600);//加上時間
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 透過電站編號,取得所有土地房屋資訊
|
/// 透過電站編號,取得所有土地房屋資訊
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -80,6 +80,7 @@ namespace solarApp.Service
|
|||||||
{
|
{
|
||||||
var calcPowerStation = new PowerStation();
|
var calcPowerStation = new PowerStation();
|
||||||
calcPowerStation.Id = powerStation.Id;
|
calcPowerStation.Id = powerStation.Id;
|
||||||
|
string calcPowerStationTime = "";
|
||||||
|
|
||||||
#region step2-1. 取得該電站的當前這小時的歷史資料
|
#region step2-1. 取得該電站的當前這小時的歷史資料
|
||||||
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
|
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
|
||||||
@ -92,53 +93,167 @@ namespace solarApp.Service
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
//// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||||
var history = stationSvc.GetPowerStationHistoryPerHour(dateTime, full_table_name);
|
//var history = stationSvc.GetPowerStationHistoryPerHour(dateTime, full_table_name);
|
||||||
// 當前用不到
|
//// 當前用不到
|
||||||
// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
|
//// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
|
||||||
|
|
||||||
if (history == null)
|
//if (history == null)
|
||||||
|
//{
|
||||||
|
// // logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// // logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||||
|
// // logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
|
||||||
|
|
||||||
|
// // logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||||
|
// history.PowerStationId = powerStation.Id;
|
||||||
|
// history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
// #region 計算單一電站每小時發電量、發電金額等資料
|
||||||
|
|
||||||
|
// #region 發電量
|
||||||
|
// //每小時發電量(直接填寫
|
||||||
|
// calcPowerStation.kwh = history.KWH;
|
||||||
|
// //今日發電量(直接填寫
|
||||||
|
// calcPowerStation.Today_kWh = history.TodayKWh;
|
||||||
|
// //總發電量(直接填寫
|
||||||
|
// calcPowerStation.Total_kWh = history.TotalKWH;
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region 發電金額
|
||||||
|
|
||||||
|
// history.MONEY = history.KWH * powerStation.PowerRate;
|
||||||
|
// history.TODAYMONEY = history.TodayKWh * powerStation.PowerRate;
|
||||||
|
// history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate;
|
||||||
|
|
||||||
|
// //即時發電金額
|
||||||
|
// switch (powerStation.SolarType)
|
||||||
|
// {
|
||||||
|
// case (int)SolarTypeEnum.SelfSold: //自建躉售
|
||||||
|
|
||||||
|
// //今日發電金額 計算方式:todaykWh * 授電費率
|
||||||
|
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||||
|
// //calcPowerStation.Today_Money = history.TODAYMONEY;
|
||||||
|
|
||||||
|
// ////總發電金額 計算方式:totalkWh * 授電費率
|
||||||
|
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
|
||||||
|
// //calcPowerStation.Total_Money = history.TOTALMONEY;
|
||||||
|
// break;
|
||||||
|
// case (int)SolarTypeEnum.HireSold: //租建躉售
|
||||||
|
// //找出該電站的所有土地房屋資訊
|
||||||
|
// var landBuildings = stationSvc.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
|
||||||
|
// var sumLeaseRate = 0.00;
|
||||||
|
// var avgLeaseRate = 0.00;
|
||||||
|
|
||||||
|
// foreach (var landBuilding in landBuildings)
|
||||||
|
// {
|
||||||
|
// sumLeaseRate += landBuilding.LeaseRate;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
|
||||||
|
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// case (int)SolarTypeEnum.SelfUse: //自建自用
|
||||||
|
|
||||||
|
|
||||||
|
// //今日發電金額 計算方式:todaykWh * 授電費率
|
||||||
|
// //calcPowerStation.Today_Money = history.TODAYMONEY;
|
||||||
|
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||||
|
|
||||||
|
// //總發電金額 計算方式:totalkWh * 授電費率
|
||||||
|
// //calcPowerStation.Total_Money = history.TOTALMONEY;
|
||||||
|
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region kWh/kWp
|
||||||
|
// //直接填寫
|
||||||
|
// calcPowerStation.Today_kwhkwp = history.KWHKWP;
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region PR
|
||||||
|
// //直接填寫
|
||||||
|
// calcPowerStation.Today_PR = history.PR;
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region 減碳量
|
||||||
|
// carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate"));
|
||||||
|
|
||||||
|
// history.CARBON = history.KWH * carbonRate;
|
||||||
|
// history.TODAYCARBON = history.TodayKWh * carbonRate;
|
||||||
|
// history.TOTALCARBON = history.TotalKWH * carbonRate;
|
||||||
|
|
||||||
|
|
||||||
|
// //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
|
||||||
|
// //calcPowerStation.Today_Carbon = history.TODAYCARBON;
|
||||||
|
// calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
|
||||||
|
|
||||||
|
// //總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
|
||||||
|
// //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
||||||
|
// calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region 發電時間
|
||||||
|
// calcPowerStation.SolarHour = history.SolarHour;
|
||||||
|
// #endregion
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// powerStationHistoriesHour.Add(history);
|
||||||
|
|
||||||
|
// // logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||||
|
//}
|
||||||
|
|
||||||
|
#region 計算單一電站每小時發電量、發電金額等資料 for calcPowerStation
|
||||||
|
//logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTime);
|
||||||
|
//var dateTimeforPowerStation = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
|
||||||
|
var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
|
var history_for_powerStation = stationSvc.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name);
|
||||||
|
|
||||||
|
if (history_for_powerStation == null)
|
||||||
{
|
{
|
||||||
// logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
//logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料 for calcPowerStation;發電量、發電金額等資料設定為0】", powerStation.Code, dateTime);
|
||||||
|
calcPowerStation.kwh = 0;
|
||||||
|
calcPowerStation.Today_kWh = 0;
|
||||||
|
calcPowerStation.Total_kWh = 0;
|
||||||
|
calcPowerStation.Today_Money = 0;
|
||||||
|
calcPowerStation.Total_Money = 0;
|
||||||
|
calcPowerStation.Today_kwhkwp = 0;
|
||||||
|
calcPowerStation.Today_PR = 0;
|
||||||
|
calcPowerStation.Today_Carbon = 0;
|
||||||
|
calcPowerStation.Total_Carbon = 0;
|
||||||
|
calcPowerStation.SolarHour = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
//logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTime);
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
|
|
||||||
|
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
|
||||||
history.PowerStationId = powerStation.Id;
|
|
||||||
history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
#region 計算單一電站每小時發電量、發電金額等資料
|
|
||||||
|
|
||||||
#region 發電量
|
#region 發電量
|
||||||
//每小時發電量(直接填寫
|
//每小時發電量(直接填寫
|
||||||
calcPowerStation.kwh = history.KWH;
|
calcPowerStation.kwh = history_for_powerStation.KWH;
|
||||||
//今日發電量(直接填寫
|
//今日發電量(直接填寫
|
||||||
calcPowerStation.Today_kWh = history.TodayKWh;
|
calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh;
|
||||||
//總發電量(直接填寫
|
//總發電量(直接填寫
|
||||||
calcPowerStation.Total_kWh = history.TotalKWH;
|
calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 發電金額
|
#region 發電金額
|
||||||
|
history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate;
|
||||||
history.MONEY = history.KWH * powerStation.PowerRate;
|
history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate;
|
||||||
history.TODAYMONEY = history.TodayKWh * powerStation.PowerRate;
|
history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate;
|
||||||
history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate;
|
|
||||||
|
|
||||||
//即時發電金額
|
//即時發電金額
|
||||||
switch (powerStation.SolarType)
|
switch (powerStation.SolarType)
|
||||||
{
|
{
|
||||||
case (int)SolarTypeEnum.SelfSold: //自建躉售
|
case (int)SolarTypeEnum.SelfSold: //自建躉售
|
||||||
|
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
|
||||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
|
||||||
//calcPowerStation.Today_Money = history.TODAYMONEY;
|
|
||||||
|
|
||||||
////總發電金額 計算方式:totalkWh * 授電費率
|
////總發電金額 計算方式:totalkWh * 授電費率
|
||||||
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
|
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
|
||||||
//calcPowerStation.Total_Money = history.TOTALMONEY;
|
|
||||||
break;
|
break;
|
||||||
case (int)SolarTypeEnum.HireSold: //租建躉售
|
case (int)SolarTypeEnum.HireSold: //租建躉售
|
||||||
//找出該電站的所有土地房屋資訊
|
//找出該電站的所有土地房屋資訊
|
||||||
@ -151,61 +266,53 @@ namespace solarApp.Service
|
|||||||
sumLeaseRate += landBuilding.LeaseRate;
|
sumLeaseRate += landBuilding.LeaseRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
|
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
|
||||||
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
|
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case (int)SolarTypeEnum.SelfUse: //自建自用
|
case (int)SolarTypeEnum.SelfUse: //自建自用
|
||||||
|
|
||||||
|
|
||||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||||
//calcPowerStation.Today_Money = history.TODAYMONEY;
|
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
|
||||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
|
||||||
|
|
||||||
//總發電金額 計算方式:totalkWh * 授電費率
|
//總發電金額 計算方式:totalkWh * 授電費率
|
||||||
//calcPowerStation.Total_Money = history.TOTALMONEY;
|
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
|
||||||
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region kWh/kWp
|
#region kWh/kWp
|
||||||
//直接填寫
|
////直接填寫
|
||||||
calcPowerStation.Today_kwhkwp = history.KWHKWP;
|
calcPowerStation.Today_kwhkwp = history_for_powerStation.KWHKWP;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region PR
|
#region PR
|
||||||
//直接填寫
|
//直接填寫
|
||||||
calcPowerStation.Today_PR = history.PR;
|
calcPowerStation.Today_PR = history_for_powerStation.PR;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 減碳量
|
#region 減碳量
|
||||||
carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate"));
|
carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate"));
|
||||||
|
history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate;
|
||||||
history.CARBON = history.KWH * carbonRate;
|
history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate;
|
||||||
history.TODAYCARBON = history.TodayKWh * carbonRate;
|
history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate;
|
||||||
history.TOTALCARBON = history.TotalKWH * carbonRate;
|
|
||||||
|
|
||||||
|
|
||||||
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
|
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
|
||||||
//calcPowerStation.Today_Carbon = history.TODAYCARBON;
|
calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate;
|
||||||
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
|
|
||||||
|
|
||||||
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
|
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
|
||||||
//calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate;
|
||||||
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 發電時間
|
#region 發電時間
|
||||||
calcPowerStation.SolarHour = history.SolarHour;
|
calcPowerStation.SolarHour = history_for_powerStation.SolarHour;
|
||||||
#endregion
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
powerStationHistoriesHour.Add(history);
|
#region 取拿到資料的時間
|
||||||
|
calcPowerStationTime = history_for_powerStation.Timestamp;
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
#endregion
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -236,7 +343,16 @@ namespace solarApp.Service
|
|||||||
{
|
{
|
||||||
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
|
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
|
||||||
var pyrheliometerHistory = stationSvc.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
|
var pyrheliometerHistory = stationSvc.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
|
||||||
|
string dateTimeForCalc;
|
||||||
|
if (calcPowerStationTime != "")
|
||||||
|
{
|
||||||
|
dateTimeForCalc = calcPowerStationTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dateTimeForCalc = dateTime;
|
||||||
|
}
|
||||||
|
var pyrheliometerHistory_for_calcPowerStation = stationSvc.CalcSensorHistoryPerHour(dateTimeForCalc, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
|
||||||
if (pyrheliometerHistory != null)
|
if (pyrheliometerHistory != null)
|
||||||
{
|
{
|
||||||
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance;
|
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance;
|
||||||
@ -314,7 +430,7 @@ namespace solarApp.Service
|
|||||||
"SolarHour"
|
"SolarHour"
|
||||||
};
|
};
|
||||||
// logger.LogInformation("【update Power_Station 】【update Power_Station】", dateTime);
|
// logger.LogInformation("【update Power_Station 】【update Power_Station】", dateTime);
|
||||||
//stationSvc.UpdateList(calcPowerStations, power_station_properties);
|
stationSvc.UpdateList(calcPowerStations, power_station_properties);
|
||||||
#endregion
|
#endregion
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user