sensor_history 更改資料庫名稱
This commit is contained in:
parent
68d7d98e52
commit
eb6d6165c4
@ -984,7 +984,7 @@ ALTER TABLE `power_station`
|
|||||||
ADD COLUMN `HealthStatus` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1:設備正常 2:設備斷線 3:設備異常' AFTER `AreaId`;
|
ADD COLUMN `HealthStatus` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1:設備正常 2:設備斷線 3:設備異常' AFTER `AreaId`;
|
||||||
|
|
||||||
-- 各電站每天日照度的平均值 20210708
|
-- 各電站每天日照度的平均值 20210708
|
||||||
CREATE TABLE `pyrheliometer_history_day` (
|
CREATE TABLE `sensor_history_day` (
|
||||||
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
||||||
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
||||||
@ -998,7 +998,7 @@ ENGINE=InnoDB
|
|||||||
;
|
;
|
||||||
|
|
||||||
-- 各電站每小時日照度的平均值 20210708
|
-- 各電站每小時日照度的平均值 20210708
|
||||||
CREATE TABLE `pyrheliometer_history_hour` (
|
CREATE TABLE `sensor_history_hour` (
|
||||||
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
||||||
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
||||||
@ -1012,7 +1012,7 @@ ENGINE=InnoDB
|
|||||||
;
|
;
|
||||||
|
|
||||||
-- 各電站每月日照度的平均值 20210708
|
-- 各電站每月日照度的平均值 20210708
|
||||||
CREATE TABLE `pyrheliometer_history_month` (
|
CREATE TABLE `sensor_history_month` (
|
||||||
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
|
||||||
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
|
||||||
@ -1096,13 +1096,13 @@ ENGINE=InnoDB
|
|||||||
|
|
||||||
|
|
||||||
-- 新增模組溫度計溫度 20210712
|
-- 新增模組溫度計溫度 20210712
|
||||||
ALTER TABLE `pyrheliometer_history_day`
|
ALTER TABLE `sensor_history_day`
|
||||||
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每日平均模組溫度計溫度' AFTER `Irradiance`;
|
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每日平均模組溫度計溫度' AFTER `Irradiance`;
|
||||||
|
|
||||||
ALTER TABLE `pyrheliometer_history_hour`
|
ALTER TABLE `sensor_history_hour`
|
||||||
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '即時模組溫度計溫度' AFTER `Irradiance`;
|
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '即時模組溫度計溫度' AFTER `Irradiance`;
|
||||||
|
|
||||||
ALTER TABLE `pyrheliometer_history_month`
|
ALTER TABLE `sensor_history_month`
|
||||||
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每月平均模組溫度計溫度' AFTER `Irradiance`;
|
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每月平均模組溫度計溫度' AFTER `Irradiance`;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -211,7 +211,7 @@ namespace SolarPower.Quartz.Jobs
|
|||||||
await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties);
|
await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region step4. 將Pyrheliometer History INSERT 到 pyrheliometer_history_hour 資料表
|
#region step4. 將Pyrheliometer History INSERT 到 sensor_history_hour 資料表
|
||||||
List<string> pyrheliometer_history_properties = new List<string>()
|
List<string> pyrheliometer_history_properties = new List<string>()
|
||||||
{
|
{
|
||||||
"PowerStationId",
|
"PowerStationId",
|
||||||
|
|||||||
@ -200,7 +200,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') AS Label, ps.KWH AS PowerData, pyr.Irradiance AS IrradianceData
|
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') AS Label, ps.KWH AS PowerData, pyr.Irradiance AS IrradianceData
|
||||||
FROM power_station_history_hour ps
|
FROM power_station_history_hour ps
|
||||||
LEFT JOIN pyrheliometer_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
|
LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
|
||||||
WHERE ps.PowerStationId = @PowerStationId
|
WHERE ps.PowerStationId = @PowerStationId
|
||||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay";
|
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay";
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
||||||
FROM power_station_history_day ps
|
FROM power_station_history_day ps
|
||||||
LEFT JOIN pyrheliometer_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
|
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
|
||||||
WHERE ps.PowerStationId = @PowerStationId
|
WHERE ps.PowerStationId = @PowerStationId
|
||||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
|
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
||||||
FROM power_station_history_day ps
|
FROM power_station_history_day ps
|
||||||
LEFT JOIN pyrheliometer_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
|
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
|
||||||
WHERE ps.PowerStationId = @PowerStationId
|
WHERE ps.PowerStationId = @PowerStationId
|
||||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
|
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m') AS Label, ps.MONTHKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m') AS Label, ps.MONTHKWH AS PowerData, pyr.Irradiance AS IrradianceData
|
||||||
FROM power_station_history_month ps
|
FROM power_station_history_month ps
|
||||||
LEFT JOIN pyrheliometer_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m')
|
LEFT JOIN sensor_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m')
|
||||||
WHERE ps.PowerStationId = @PowerStationId
|
WHERE ps.PowerStationId = @PowerStationId
|
||||||
AND DATE_FORMAT(ps.timestamp, '%Y') = @Year";
|
AND DATE_FORMAT(ps.timestamp, '%Y') = @Year";
|
||||||
|
|
||||||
@ -490,28 +490,28 @@ namespace SolarPower.Repository.Implement
|
|||||||
case 0:
|
case 0:
|
||||||
kwh = "C.KWH";
|
kwh = "C.KWH";
|
||||||
usedb = "power_station_history_hour";
|
usedb = "power_station_history_hour";
|
||||||
pyrdb = "pyrheliometer_history_hour";
|
pyrdb = "sensor_history_hour";
|
||||||
timeGroup = "%Y-%m-%d %H:%M:%S";
|
timeGroup = "%Y-%m-%d %H:%M:%S";
|
||||||
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m-%d') = '{post.HistoryRange}'";
|
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m-%d') = '{post.HistoryRange}'";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
kwh = "C.TODAYKWH";
|
kwh = "C.TODAYKWH";
|
||||||
usedb = "power_station_history_day";
|
usedb = "power_station_history_day";
|
||||||
pyrdb = "pyrheliometer_history_day";
|
pyrdb = "sensor_history_day";
|
||||||
timeGroup = "%Y-%m-%d";
|
timeGroup = "%Y-%m-%d";
|
||||||
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m') = '{post.HistoryRange}'";
|
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m') = '{post.HistoryRange}'";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
kwh = "C.MONTHKWH";
|
kwh = "C.MONTHKWH";
|
||||||
usedb = "power_station_history_month";
|
usedb = "power_station_history_month";
|
||||||
pyrdb = "pyrheliometer_history_month";
|
pyrdb = "sensor_history_month";
|
||||||
timeGroup = "%Y-%m";
|
timeGroup = "%Y-%m";
|
||||||
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y') = '{post.HistoryRange}'";
|
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y') = '{post.HistoryRange}'";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
kwh = "C.TOTALKWH";
|
kwh = "C.TOTALKWH";
|
||||||
usedb = "power_station_history_month";
|
usedb = "power_station_history_month";
|
||||||
pyrdb = "pyrheliometer_history_month";
|
pyrdb = "sensor_history_month";
|
||||||
timeGroup = "%Y-%m";
|
timeGroup = "%Y-%m";
|
||||||
range = "";
|
range = "";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -2281,7 +2281,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_hour");
|
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_hour");
|
||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
@ -2312,7 +2312,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = GenerateUpdateQueryWithCustomTableAndWHERE(properties, "pyrheliometer_history_hour", "PowerStationId = @PowerStationId AND TIMESTAMP = @Timestamp");
|
string sql = GenerateUpdateQueryWithCustomTableAndWHERE(properties, "sensor_history_hour", "PowerStationId = @PowerStationId AND TIMESTAMP = @Timestamp");
|
||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
@ -2343,7 +2343,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
var startDay = Convert.ToDateTime(nowDay).AddDays(-30).ToString("yyyy-MM-dd");
|
var startDay = Convert.ToDateTime(nowDay).AddDays(-30).ToString("yyyy-MM-dd");
|
||||||
|
|
||||||
var sql = $@"SELECT AVG(p.Irradiance) AS AvgIrradiance
|
var sql = $@"SELECT AVG(p.Irradiance) AS AvgIrradiance
|
||||||
FROM pyrheliometer_history_hour p
|
FROM sensor_history_hour p
|
||||||
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDay AND @EndDay
|
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDay AND @EndDay
|
||||||
AND p.Irradiance != 0
|
AND p.Irradiance != 0
|
||||||
AND PowerStationId = @PowerStationId
|
AND PowerStationId = @PowerStationId
|
||||||
@ -2372,7 +2372,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
|
DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
|
||||||
AVG(p.Irradiance) AS Irradiance,
|
AVG(p.Irradiance) AS Irradiance,
|
||||||
AVG(p.Temperature) AS Temperature
|
AVG(p.Temperature) AS Temperature
|
||||||
FROM pyrheliometer_history_hour p
|
FROM sensor_history_hour p
|
||||||
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay
|
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay
|
||||||
AND p.Irradiance != 0
|
AND p.Irradiance != 0
|
||||||
AND PowerStationId = @PowerStationId
|
AND PowerStationId = @PowerStationId
|
||||||
@ -2399,7 +2399,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_day");
|
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_day");
|
||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
@ -2432,7 +2432,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
DATE_FORMAT(p.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
|
DATE_FORMAT(p.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
|
||||||
AVG(p.Irradiance) AS Irradiance,
|
AVG(p.Irradiance) AS Irradiance,
|
||||||
AVG(p.Temperature) AS Temperature
|
AVG(p.Temperature) AS Temperature
|
||||||
FROM pyrheliometer_history_hour p
|
FROM sensor_history_hour p
|
||||||
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m') = @Month
|
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m') = @Month
|
||||||
AND p.Irradiance != 0
|
AND p.Irradiance != 0
|
||||||
AND PowerStationId = @PowerStationId
|
AND PowerStationId = @PowerStationId
|
||||||
@ -2456,7 +2456,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sql = $@"SELECT * FROM pyrheliometer_history_month WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId";
|
var sql = $@"SELECT * FROM sensor_history_month WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId";
|
||||||
|
|
||||||
result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, new { Month = month, PowerStationId = powerStationId });
|
result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, new { Month = month, PowerStationId = powerStationId });
|
||||||
}
|
}
|
||||||
@ -2478,7 +2478,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_month");
|
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_month");
|
||||||
|
|
||||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
@ -2509,7 +2509,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = @"UPDATE pyrheliometer_history_month SET
|
string sql = @"UPDATE sensor_history_month SET
|
||||||
Irradiance=@Irradiance,
|
Irradiance=@Irradiance,
|
||||||
Temperature=@Temperature
|
Temperature=@Temperature
|
||||||
WHERE PowerStationId = @PowerStationId
|
WHERE PowerStationId = @PowerStationId
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user