Merge branch 'Willy'

This commit is contained in:
b110212000 2021-07-19 17:43:49 +08:00
commit cad4cbe7f0
7 changed files with 119 additions and 11 deletions

View File

@ -1753,6 +1753,23 @@ ALTER TABLE `power_station_history_month`
ADD COLUMN `MONEY` DOUBLE NULL DEFAULT NULL AFTER `SOLARHOUR`,
ADD COLUMN `CARBON` DOUBLE NULL DEFAULT NULL AFTER `MONEY`;
-- 新增累計金額及減碳量 20210719
ALTER TABLE `power_station_history_hour`
ADD COLUMN `TODAYMONEY` DOUBLE NULL DEFAULT NULL AFTER `MONEY`,
ADD COLUMN `TOTALMONEY` DOUBLE NULL DEFAULT NULL AFTER `TODAYMONEY`,
ADD COLUMN `TODAYCARBON` DOUBLE NULL DEFAULT NULL AFTER `CARBON`,
ADD COLUMN `TOTALCARBON` DOUBLE NULL DEFAULT NULL AFTER `TODAYCARBON`;
ALTER TABLE `power_station_history_day`
ADD COLUMN `TOTALMONEY` DOUBLE NULL DEFAULT NULL AFTER `MONEY`,
ADD COLUMN `TOTALCARBON` DOUBLE NULL DEFAULT NULL AFTER `CARBON`;
ALTER TABLE `power_station_history_month`
ADD COLUMN `TOTALMONEY` DOUBLE NULL DEFAULT NULL AFTER `MONEY`,
ADD COLUMN `TOTALCARBON` DOUBLE NULL DEFAULT NULL AFTER `CARBON`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

View File

@ -589,6 +589,10 @@ namespace SolarPower.Models.PowerStation
public double SolarHour { get; set; }
public double MONEY { get; set; }
public double CARBON { get; set; }
public double TODAYMONEY { get; set; }
public double TOTALMONEY { get; set; }
public double TODAYCARBON { get; set; }
public double TOTALCARBON { get; set; }
}
public class AvgPowerStationHistory
@ -612,6 +616,10 @@ namespace SolarPower.Models.PowerStation
public double SolarHour { get; set; }
public double MONEY { get; set; }
public double CARBON { get; set; }
public double TODAYMONEY { get; set; }
public double TOTALMONEY { get; set; }
public double TODAYCARBON { get; set; }
public double TOTALCARBON { get; set; }
}
public class PowerStationHistoryMonth
@ -628,6 +636,8 @@ namespace SolarPower.Models.PowerStation
public double SolarHour { get; set; }
public double MONEY { get; set; }
public double CARBON { get; set; }
public double TOTALMONEY { get; set; }
public double TOTALCARBON { get; set; }
}
public class PyrheliometerHistory
@ -809,6 +819,10 @@ namespace SolarPower.Models.PowerStation
{
public double MONEY { get; set; }
public double CARBON { get; set; }
public double TODAYMONEY { get; set; }
public double TOTALMONEY { get; set; }
public double TODAYCARBON { get; set; }
public double TOTALCARBON { get; set; }
}

View File

@ -203,12 +203,16 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的所有值的總和】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(historyDay));
var daynow = DateTime.Now.ToString("yyyy-MM-dd");
var moneyandcarbon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowDay, 1);
var lastmoneyhistory = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 1,"");
if (historyDay != null)
{
historyDay.PowerStationId = powerStation.Id;
historyDay.CARBON = moneyandcarbon.CARBON;
historyDay.MONEY = moneyandcarbon.MONEY;
//historyDay.TODAYCARBON = lastmoneyhistory.TODAYCARBON;
//historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
powerStationHistoryDays.Add(historyDay);
}
@ -244,15 +248,17 @@ namespace SolarPower.Quartz.Jobs
if (exist_history == null)
{ //新增
var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
if (historyMonth != null)
{
var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd");
historyMonth.MONEY = moneyandcarbonMon.MONEY;
historyMonth.CARBON = moneyandcarbonMon.CARBON;
historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
insertPowerStationHistoryMonths.Add(historyMonth);
}
@ -261,8 +267,14 @@ namespace SolarPower.Quartz.Jobs
else
{ //修改
var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
if (historyMonth != null)
{
historyMonth.MONEY = historyMonth.MONEY + moneyandcarbonMon.MONEY;
historyMonth.CARBON = historyMonth.CARBON + moneyandcarbonMon.CARBON;
historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
updatePowerStationHistoryMonths.Add(historyMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
@ -354,7 +366,9 @@ namespace SolarPower.Quartz.Jobs
"MP",
"SolarHour",
"MONEY",
"CARBON"
"CARBON",
"TOTALMONEY",
"TOTALCARBON"
};
await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
@ -373,7 +387,9 @@ namespace SolarPower.Quartz.Jobs
"MP",
"SolarHour",
"MONEY",
"CARBON"
"CARBON",
"TOTALMONEY",
"TOTALCARBON"
};
if (insertPowerStationHistoryMonths.Count > 0)

View File

@ -68,7 +68,7 @@ namespace SolarPower.Quartz.Jobs
var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id;
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
var dateTime = DateTimeNow.AddHours(-3).ToString("yyyy-MM-dd HH");
#region step2-1.
var table_name = String.Format("`{0}`.s{1}01_station", powerStation.SiteDB, powerStation.Code);
@ -77,6 +77,7 @@ namespace SolarPower.Quartz.Jobs
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name);
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id,0,dateTime);
if (history != null)
{
@ -158,7 +159,10 @@ namespace SolarPower.Quartz.Jobs
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
#endregion
history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate;
history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate;
history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
#endregion
powerStationHistoriesHour.Add(history);
@ -309,7 +313,11 @@ namespace SolarPower.Quartz.Jobs
"MP",
"SolarHour",
"MONEY",
"CARBON"
"CARBON",
"TODAYMONEY",
"TOTALMONEY",
"TODAYCARBON",
"TOTALCARBON"
};
await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties);

View File

@ -2187,7 +2187,11 @@ namespace SolarPower.Repository.Implement
KWHKWP=@KWHKWP,
PR=@PR,
MP=@MP,
SolarHour=@SolarHour
SolarHour=@SolarHour,
MONEY=@MONEY,
TOTALMONEY=@TOTALMONEY,
CARBON=@CARBON,
TOTALCARBON=@TOTALCARBON
WHERE PowerStationId = @PowerStationId
AND TIMESTAMP LIKE CONCAT(@TIMESTAMP, '%')
";
@ -3165,5 +3169,53 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task<MoneyAndCarbon> GetLastMoneyAndCarbonInHour (int powerstationId ,int type,string time)
{
MoneyAndCarbon result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
var tablename = "";
if (type == 0)
{
tablename = "power_station_history_hour";
}
else if(type == 1)
{
tablename = "power_station_history_day";
}
else
{
tablename = "power_station_history_month";
}
try
{
var sql = "";
if(type == 0)
{
var time2 = time.Split(' ');
sql = $@"SELECT(SELECT TODAYMONEY FROM power_station_history_hour WHERE PowerStationId = {powerstationId} AND DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = '{time2[0]}' order by TIMESTAMP desc limit 1) AS TODAYMONEY,
TOTALMONEY,
(SELECT TODAYCARBON FROM power_station_history_hour WHERE PowerStationId = {powerstationId} AND DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = '{time2[0]}' order by TIMESTAMP desc limit 1) AS TODAYCARBON,
TOTALCARBON
FROM power_station_history_hour WHERE PowerStationId = {powerstationId} order by TIMESTAMP desc limit 1";
}
else
{
sql = $@"SELECT TOTALMONEY,TOTALCARBON FROM {tablename}
WHERE PowerStationId = {powerstationId} order by TIMESTAMP desc limit 1";
}
result = await conn.QueryFirstOrDefaultAsync<MoneyAndCarbon>(sql);
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
}
}

View File

@ -534,5 +534,6 @@ namespace SolarPower.Repository.Interface
Task AddWeatherForecast(List<WeatherForecast> entity, List<string> properties);
Task<NowWeather> SelectNowWeather(int CityId);
Task<MoneyAndCarbon> GetMoneyAndCarbonWithHistoryHour(int powerstationId, string dateTime, int type);
Task<MoneyAndCarbon> GetLastMoneyAndCarbonInHour(int powerstationId,int type,string time);
}
}

View File

@ -22,7 +22,7 @@
// "Password": "8WMHBEWuT0XoAB4kzduQHA=="
//},
"BackgroundServiceCron": {
"CalcPowerStationJob": "0/10 * * * * ?",
"CalcPowerStationJob": "0 5 * * * ?",
"CalcAvgPowerStationJob": "0 0 2 * * ?",
"OperationScheduleJob": "0 0 2 * * ?",
"CalcInverter15minJob": "0 2/15 * * * ?"