diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 99a87bb..6d28052 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -93,6 +93,7 @@ namespace SolarPower.Quartz.Jobs { var calcPowerStation = new PowerStation(); calcPowerStation.Id = powerStation.Id; + string calcPowerStationTime = ""; #region step2-1. 取得該電站的當前這小時的歷史資料 var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code); @@ -107,6 +108,8 @@ namespace SolarPower.Quartz.Jobs { logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name); + //await setHistoryPerHourForPowerStation(dateTime, full_table_name, powerStation); + // 當前用不到 // var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime); @@ -126,12 +129,12 @@ namespace SolarPower.Quartz.Jobs #region 計算單一電站每小時發電量、發電金額等資料 #region 發電量 - //每小時發電量(直接填寫 - calcPowerStation.kwh = history.KWH; - //今日發電量(直接填寫 - calcPowerStation.Today_kWh = history.TodayKWh; - //總發電量(直接填寫 - calcPowerStation.Total_kWh = history.TotalKWH; + ////每小時發電量(直接填寫 + //calcPowerStation.kwh = history.KWH; + ////今日發電量(直接填寫 + //calcPowerStation.Today_kWh = history.TodayKWh; + ////總發電量(直接填寫 + //calcPowerStation.Total_kWh = history.TotalKWH; #endregion #region 發電金額 @@ -141,96 +144,96 @@ namespace SolarPower.Quartz.Jobs history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate; //即時發電金額 - switch (powerStation.SolarType) - { - case (int)SolarTypeEnum.SelfSold: //自建躉售 + //switch (powerStation.SolarType) + //{ + // case (int)SolarTypeEnum.SelfSold: //自建躉售 - //if (lastmoneyhistorybyhour != null) - //{ - // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; - //} - //else - //{ - // history.TODAYMONEY = history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = history.KWH * powerStation.PowerRate; - //} + // //if (lastmoneyhistorybyhour != null) + // //{ + // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; + // //} + // //else + // //{ + // // history.TODAYMONEY = history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = history.KWH * powerStation.PowerRate; + // //} - //今日發電金額 計算方式:todaykWh * 授電費率 - calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate; - //calcPowerStation.Today_Money = history.TODAYMONEY; + // //今日發電金額 計算方式: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 = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB); - var sumLeaseRate = 0.00; - var avgLeaseRate = 0.00; + // ////總發電金額 計算方式:totalkWh * 授電費率 + // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; + // //calcPowerStation.Total_Money = history.TOTALMONEY; + // break; + // case (int)SolarTypeEnum.HireSold: //租建躉售 + // //找出該電站的所有土地房屋資訊 + // var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB); + // var sumLeaseRate = 0.00; + // var avgLeaseRate = 0.00; - foreach (var landBuilding in landBuildings) - { - sumLeaseRate += landBuilding.LeaseRate; - } - //avgLeaseRate = sumLeaseRate / landBuildings.Count(); + // foreach (var landBuilding in landBuildings) + // { + // sumLeaseRate += landBuilding.LeaseRate; + // } + // //avgLeaseRate = sumLeaseRate / landBuildings.Count(); - //if (lastmoneyhistorybyhour != null) - //{ - // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; + // //if (lastmoneyhistorybyhour != null) + // //{ + // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; - // //今日發電金額計算方式:todaykWh * 出借費率(各個土地房屋租借比率平均) - // calcPowerStation.Today_Money = lastmoneyhistorybyhour.TODAYMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); - // //總發電金額 計算方式:totalkWh * 授電費率 - // calcPowerStation.Total_Money = lastmoneyhistorybyhour.TOTALMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); - //} - //else - //{ - // history.TODAYMONEY = history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = history.KWH * powerStation.PowerRate; + // // //今日發電金額計算方式:todaykWh * 出借費率(各個土地房屋租借比率平均) + // // calcPowerStation.Today_Money = lastmoneyhistorybyhour.TODAYMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); + // // //總發電金額 計算方式:totalkWh * 授電費率 + // // calcPowerStation.Total_Money = lastmoneyhistorybyhour.TOTALMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); + // //} + // //else + // //{ + // // history.TODAYMONEY = history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = history.KWH * powerStation.PowerRate; - // calcPowerStation.Today_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; - // calcPowerStation.Total_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; - //} + // // calcPowerStation.Today_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; + // // calcPowerStation.Total_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; + // //} - calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; - calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; + // calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; + // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; - break; - case (int)SolarTypeEnum.SelfUse: //自建自用 + // break; + // case (int)SolarTypeEnum.SelfUse: //自建自用 - //if (lastmoneyhistorybyhour != null) - //{ - // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; - //} - //else - //{ - // history.TODAYMONEY = history.KWH * powerStation.PowerRate; - // history.TOTALMONEY = history.KWH * powerStation.PowerRate; - //} + // //if (lastmoneyhistorybyhour != null) + // //{ + // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; + // //} + // //else + // //{ + // // history.TODAYMONEY = history.KWH * powerStation.PowerRate; + // // history.TOTALMONEY = history.KWH * powerStation.PowerRate; + // //} - //今日發電金額 計算方式:todaykWh * 授電費率 - //calcPowerStation.Today_Money = history.TODAYMONEY; - calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate; + // //今日發電金額 計算方式: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; - } + // //總發電金額 計算方式:totalkWh * 授電費率 + // //calcPowerStation.Total_Money = history.TOTALMONEY; + // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; + // break; + //} #endregion #region kWh/kWp - //直接填寫 - calcPowerStation.Today_kwhkwp = history.KWHKWP; + ////直接填寫 + //calcPowerStation.Today_kwhkwp = history.KWHKWP; #endregion #region PR //直接填寫 - calcPowerStation.Today_PR = history.PR; + //calcPowerStation.Today_PR = history.PR; #endregion #region 減碳量 @@ -252,19 +255,123 @@ namespace SolarPower.Quartz.Jobs //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] //calcPowerStation.Today_Carbon = history.TODAYCARBON; - calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate; + //calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate; //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; - calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; + //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; #endregion #region 發電時間 - calcPowerStation.SolarHour = history.SolarHour; + //calcPowerStation.SolarHour = history.SolarHour; #endregion #endregion + #region 計算單一電站每小時發電量、發電金額等資料 for calcPowerStation + var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");//取當天 + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation); + var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name); + if (history_for_powerStation == null) + { + logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料 for calcPowerStation;發電量、發電金額等資料設定為0】", powerStation.Code, dateTimeforPowerStation); + 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 + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation); + #region 發電量 + //每小時發電量(直接填寫 + calcPowerStation.kwh = history_for_powerStation.KWH; + //今日發電量(直接填寫 + calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh; + //總發電量(直接填寫 + calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH; + #endregion + + #region 發電金額 + history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate; + history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate; + history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate; + + //即時發電金額 + switch (powerStation.SolarType) + { + case (int)SolarTypeEnum.SelfSold: //自建躉售 + //今日發電金額 計算方式:todaykWh * 授電費率 + calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; + + ////總發電金額 計算方式:totalkWh * 授電費率 + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; + break; + case (int)SolarTypeEnum.HireSold: //租建躉售 + //找出該電站的所有土地房屋資訊 + var landBuildings = await powerStationRepository.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_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; + + break; + case (int)SolarTypeEnum.SelfUse: //自建自用 + + //今日發電金額 計算方式:todaykWh * 授電費率 + calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; + + //總發電金額 計算方式:totalkWh * 授電費率 + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; + break; + } + #endregion + + #region kWh/kWp + ////直接填寫 + calcPowerStation.Today_kwhkwp = history_for_powerStation.KWHKWP; + #endregion + + #region PR + //直接填寫 + calcPowerStation.Today_PR = history_for_powerStation.PR; + #endregion + + #region 減碳量 + carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate")); + history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate; + history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate; + history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate; + + //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] + calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate; + + //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] + calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate; + #endregion + + #region 發電時間 + calcPowerStation.SolarHour = history_for_powerStation.SolarHour; + #endregion + + #region 取拿到資料的時間 + calcPowerStationTime = history_for_powerStation.Timestamp; + #endregion + } + #endregion + powerStationHistoriesHour.Add(history); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); @@ -299,10 +406,19 @@ namespace SolarPower.Quartz.Jobs { logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); var pyrheliometerHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); - + string dateTimeForCalc; + if (calcPowerStationTime != "") + { + dateTimeForCalc = calcPowerStationTime; + } + else + { + dateTimeForCalc = dateTime; + } + var pyrheliometerHistory_for_calcPowerStation = await powerStationRepository.CalcSensorHistoryPerHour(dateTimeForCalc, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); if (pyrheliometerHistory != null) { - calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; + calcPowerStation.Today_irradiance = pyrheliometerHistory_for_calcPowerStation.Irradiance; sensorHistory.Irradiance = pyrheliometerHistory.Irradiance; @@ -489,13 +605,13 @@ namespace SolarPower.Quartz.Jobs var TPYHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, TPYdeviceInfos, Convert.ToInt32(SensorTypeEnum.TPY)); if (TPYHistory != null) { - sensorHistory.IrrDay = TPYHistory.IrrDay; + sensorHistory.IrrDay = TPYHistory.IrrDay; logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); - var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); + var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); if (ss != null) { - sensorHistory.IrrDayHour = double.Parse( ss); + sensorHistory.IrrDayHour = double.Parse(ss); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); } @@ -508,30 +624,6 @@ namespace SolarPower.Quartz.Jobs 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); } @@ -672,9 +764,9 @@ namespace SolarPower.Quartz.Jobs double p2 = Convert.ToDouble(powerLocation[1].Replace("°", string.Empty)); double dLat = Convert.ToDouble(Location.Lat); double dLon = Convert.ToDouble(Location.Lon); - double x = Math.Pow(p1 - dLat, 2) ; + double x = Math.Pow(p1 - dLat, 2); double y = Math.Pow(p2 - dLon, 2); - var nowLocation = Math.Sqrt(x + y); + var nowLocation = Math.Sqrt(x + y); //var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0]) // - Convert.ToDouble(Location.Lat), 2) // + Math.Pow(Convert.ToDouble(powerLocation[1]) @@ -732,7 +824,7 @@ namespace SolarPower.Quartz.Jobs } } #endregion - + if (!this.environment.IsDevelopment()) { #region step3. 將historiers INSERT 到 power_station_history_hour 資料表 @@ -980,5 +1072,99 @@ namespace SolarPower.Quartz.Jobs } } } + + public async Task setHistoryPerHourForPowerStation(string dateTime, string full_table_name, PowerStation powerStation) + { + var calcPowerStation = new PowerStation(); + calcPowerStation.Id = powerStation.Id; + var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTime, full_table_name); + if (history_for_powerStation == null) + { + //logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); + //每小時發電量(直接填寫 + calcPowerStation.kwh = 0; + //今日發電量(直接填寫 + calcPowerStation.Today_kWh = 0; + //總發電量(直接填寫 + calcPowerStation.Total_kWh = 0; + } + else + { + //每小時發電量(直接填寫 + calcPowerStation.kwh = history_for_powerStation.KWH; + //今日發電量(直接填寫 + calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh; + //總發電量(直接填寫 + calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH; + + #region 發電金額 + + history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate; + history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate; + history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate; + + //即時發電金額 + switch (powerStation.SolarType) + { + case (int)SolarTypeEnum.SelfSold: //自建躉售 + + //今日發電金額 計算方式:todaykWh * 授電費率 + calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; + + ////總發電金額 計算方式:totalkWh * 授電費率 + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; + break; + case (int)SolarTypeEnum.HireSold: //租建躉售 + //找出該電站的所有土地房屋資訊 + var landBuildings = await powerStationRepository.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_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; + + break; + case (int)SolarTypeEnum.SelfUse: //自建自用 + + //今日發電金額 計算方式:todaykWh * 授電費率 + calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; + + //總發電金額 計算方式:totalkWh * 授電費率 + calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; + break; + } + #endregion + + #region PR + //直接填寫 + calcPowerStation.Today_PR = history_for_powerStation.PR; + #endregion + + #region 減碳量 + carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate")); + + history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate; + history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate; + history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate; + + //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] + calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate; + + //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] + calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate; + + #endregion + + #region 發電時間 + calcPowerStation.SolarHour = history_for_powerStation.SolarHour; + #endregion + } + + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index ecb6390..48dddaf 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2189,6 +2189,33 @@ namespace SolarPower.Repository.Implement } } + public async Task GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name) + { + PowerStationHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + 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 = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }, commandTimeout: 600);//加上時間 + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + public async Task CalcAvgPowerStationHistory30day(string nowDay, string table_name) { AvgPowerStationHistory result; diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 7e9ff54..7ee71f8 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -633,5 +633,6 @@ namespace SolarPower.Repository.Interface Task> GetAllNoStatusAsync(); Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); + Task GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name); } }