From 7c79b97825e9feba71f26f1157eb87da4bc84029 Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 23 Sep 2021 13:53:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E7=B5=B1=E4=B8=80=20=E8=A8=88?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E5=BC=8F=202.=20=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=90=88=E4=BD=B5=E9=9B=BB=E7=AB=99=E8=A8=88=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 139 +++++++++--------- .../AnalysisStationCombineRepository.cs | 4 +- SolarPower/Views/StationOverview/Index.cshtml | 2 +- 3 files changed, 72 insertions(+), 73 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 23ddf88..5223923 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -84,8 +84,6 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message); observation = null; } - - #endregion #region step2. 從電站的DB及電站編號找出該電站的控制器 @@ -103,7 +101,7 @@ namespace SolarPower.Quartz.Jobs if (string.IsNullOrEmpty(exist)) { - logger.LogError("【CalcPowerStationJob】【查無電站[{0}]的s{0}01_station資料表】", powerStation.Code); + logger.LogError($"【CalcPowerStationJob】【查無電站[{powerStation.Code}]的s{powerStation.Code}01_station資料表】"); } else { @@ -139,24 +137,24 @@ namespace SolarPower.Quartz.Jobs { 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; + ////總發電金額 計算方式:totalkWh * 授電費率 + calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; + //calcPowerStation.Total_Money = history.TOTALMONEY; break; case (int)SolarTypeEnum.HireSold: //租建躉售 //找出該電站的所有土地房屋資訊 @@ -170,43 +168,49 @@ namespace SolarPower.Quartz.Jobs } //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.TodayKWh * powerStation.PowerRate * sumLeaseRate; + calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate; - calcPowerStation.Today_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; - calcPowerStation.Total_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; - } 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.TODAYMONEY; + calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate; //總發電金額 計算方式:totalkWh * 授電費率 - calcPowerStation.Total_Money = history.TOTALMONEY; + //calcPowerStation.Total_Money = history.TOTALMONEY; + calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; break; } #endregion @@ -225,29 +229,24 @@ namespace SolarPower.Quartz.Jobs carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate")); history.CARBON = history.KWH * carbonRate; - if (lastmoneyhistorybyhour != null) - { - history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate; - history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate; + //if (lastmoneyhistorybyhour != null) + //{ + // history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate; + // history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate; + //} + //else + //{ + // history.TODAYCARBON = history.KWH * carbonRate; + // history.TOTALCARBON = history.KWH * carbonRate; + //} - //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Today_Carbon = history.TODAYCARBON; + //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] + //calcPowerStation.Today_Carbon = history.TODAYCARBON; + calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate; - //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Total_Carbon = history.TOTALCARBON; - } - else - { - history.TODAYCARBON = history.KWH * carbonRate; - history.TOTALCARBON = history.KWH * carbonRate; - - //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Today_Carbon = history.TODAYCARBON; - - history.CARBON = history.KWH * carbonRate; - //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; - } + //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] + //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; + calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; #endregion @@ -269,7 +268,7 @@ namespace SolarPower.Quartz.Jobs var sensoravg_table_exist = await powerStationRepository.ExistTable(powerStation.SiteDB, sensoravg_table_name); if (string.IsNullOrEmpty(sensoravg_table_exist)) { - logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_sensoravg資料表】", powerStation.Code); + logger.LogError($"【CalcPowerStationJob】【查無電站[{powerStation.Code}]的s{powerStation.Code}01_sensoravg資料表】"); } else { @@ -534,7 +533,7 @@ namespace SolarPower.Quartz.Jobs var exist_meter_table = await powerStationRepository.ExistTable(powerStation.SiteDB, meter_table_name); if (string.IsNullOrEmpty(exist_meter_table)) { - logger.LogError("【CalcPowerStationJob】【查無電站[{0}]的s{0}01_meter資料表】", powerStation.Code); + logger.LogError($"【CalcPowerStationJob】【查無電站[{powerStation.Code}]的s{powerStation.Code}01_meter資料表】"); } else { diff --git a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs index 3ebd463..d6521d6 100644 --- a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs +++ b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs @@ -38,8 +38,8 @@ namespace SolarPower.Repository.Implement SUM(TOTALMONEY) AS All_money, SUM(TOTALKWH) AS All_kwh, SUM(TOTALCARBON) AS All_Carbon - from power_station_history_month - WHERE PowerStationId IN @ids + from (SELECT psm.PowerStationId, max(psm.TIMESTAMP) AS TIMESTAMP FROM power_station_history_month psm WHERE PowerStationId IN (8) GROUP BY PowerStationId) a + LEFT JOIN power_station_history_month psm ON a.PowerStationId = psm.PowerStationId AND a.TIMESTAMP = psm.TIMESTAMP ) AS m, ( diff --git a/SolarPower/Views/StationOverview/Index.cshtml b/SolarPower/Views/StationOverview/Index.cshtml index 7a05b9a..04221b5 100644 --- a/SolarPower/Views/StationOverview/Index.cshtml +++ b/SolarPower/Views/StationOverview/Index.cshtml @@ -432,7 +432,7 @@ @if (ViewBag.myUser.Role.Auths.Contains("ShowMoney")) { - $('#card_' + val.id).find('#PowerRate').html((val.today_kWh * val.powerRate).toFixed()); + $('#card_' + val.id).find('#PowerRate').html((val.today_Money).toFixed()); } $('#card_' + val.id).find('#PR').html(val.today_PR); From d485b2bca9dd26bc9c3ad374e29ebc8678ed33ae Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 23 Sep 2021 17:49:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E5=94=AE=E9=9B=BB?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E9=9B=BB=E7=AB=99=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/ElectricitySoldRecordController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index 0349c60..a1f9d7c 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -46,8 +46,8 @@ namespace SolarPower.Controllers where_entities.Add("Filter", filter); } - //抓出 除了自建自用 - var temp_solarType_where = $@" ps.SolarType != 2"; + + var temp_solarType_where = $@" ps.SolarType = 0"; where.Add(temp_solarType_where); var powerStations = myPowerStationService.GetMyPowerStations(myUser, 1, null, where, where_entities);