水位管理修改

This commit is contained in:
GiteaAdmin 2023-02-01 00:14:12 +08:00
parent 511dccd742
commit 9202857ee4
8 changed files with 46 additions and 28 deletions

View File

@ -237,7 +237,7 @@ namespace SolarPower.Repository.Implement
{
var startDay = Convert.ToDateTime(nowDay).AddDays(-7).ToString("yyyy-MM-dd");
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData, pyr.Temperature AS TemperatureData
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.IrrDayHour AS IrradianceData, pyr.Temperature AS TemperatureData
FROM power_station_history_day ps
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d')
WHERE ps.PowerStationId = @PowerStationId
@ -262,7 +262,7 @@ namespace SolarPower.Repository.Implement
{
var startDay = Convert.ToDateTime(nowDay).ToString("yyyy-MM-01");
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData, pyr.Temperature AS TemperatureData
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.IrrDayHour AS IrradianceData, pyr.Temperature AS TemperatureData
FROM power_station_history_day ps
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d')
WHERE ps.PowerStationId = @PowerStationId
@ -288,7 +288,7 @@ namespace SolarPower.Repository.Implement
{
var startyear = Convert.ToDateTime(nowDay).ToString("yyyy");
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m') AS Label, ps.MONTHKWH AS PowerData, pyr.Irradiance AS IrradianceData, pyr.Temperature AS TemperatureData
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m') AS Label, ps.MONTHKWH AS PowerData, pyr.IrrDay AS IrradianceData, pyr.Temperature AS TemperatureData
FROM power_station_history_month ps
LEFT JOIN sensor_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(pyr.timestamp, '%Y-%m')
WHERE ps.PowerStationId = @PowerStationId

View File

@ -31,7 +31,7 @@
</div>
<div class="col-xl-3 d-flex justify-content-start">
<p class="card-text px-3"><i class="fal fa-cloud-sun-rain fa-3x" id="weather-icon"></i></p>
<p class="font-weight-bold" id="weather-temp">27°C<br>降雨率: 0%</p>
<p class="font-weight-bold" id="weather-temp">27°C<br>降雨率: 0%</p>
</div>
</div>
<ul class="nav nav-tabs mb-5" role="tablist">
@ -351,7 +351,7 @@
$('#power-station-healthStatus').html(statusicon);
$('#power-station-title').html(stationOverview.stationName);
$('#weather-temp').html(stationOverview.todayWeatherTemp + '°C <br>降雨率: ' + stationOverview.rateOfRain + '%');
$('#weather-temp').html(stationOverview.todayWeatherTemp + '°C <br>降雨率: ' + stationOverview.rateOfRain + '%');
$('#weather-icon')[0].setAttribute("class", 'fal fa-' + stationOverview.todayWeather + ' fa-3x');
$('#breadcrumbname').html(stationOverview.stationName);
$('#breadcrumbcity').html(stationOverview.cityName);

View File

@ -6,6 +6,7 @@ using solarApp.Model;
using System.Configuration;
using Dapper;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace solarApp.Service
{
@ -30,11 +31,18 @@ namespace solarApp.Service
public string _siteID01 { get; set; }
public string _powerStationID { get; set; }
/// <summary>
/// 要搬動的月份
/// </summary>
public string move_month { get; set; }
public bool archiveData(string siteID)
{
bool result = false;
// string yyyymm = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM");
_siteID = siteID;
//搬移的月份
move_month = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM");
//_date1 = date1;
get_siteInfo();
checkTable();
@ -42,6 +50,8 @@ namespace solarApp.Service
moveData_station();
moveData_inv();
moveData_sensor();
result = true;
return result;
@ -86,14 +96,14 @@ namespace solarApp.Service
try
{
//先判斷是否存在 DB
//string ss = $@"SELECT * FROM information_schema.SCHEMATA where SCHEMA_NAME='" + _siteDB + "'; ";
//List<string> ds_db = conn.Query<string>(ss, new { siteDB = _siteDB }).AsList<string>();
string ss = $@"SELECT * FROM information_schema.SCHEMATA where SCHEMA_NAME= '" + _siteDB + "'; ";
List<string> ds_db = conn.Query<string>(ss, new { siteDB = _siteDB }).AsList<string>();
////如果該 DB不存在 則create
//if (ds_db.Count == 0)
//{
// string createDb = $@"CREATE SCHEMA '" + _siteDB + "' DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
//}
if (ds_db.Count == 0)
{
string createDb = $@"CREATE DATABASE " + _siteDB + " DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
}
//判斷table是否存在
string checkStationExists = $@"SELECT * FROM information_schema.tables WHERE table_schema = '{_siteDB}_history' AND table_name = 's{_siteID01}_station';";
@ -290,7 +300,7 @@ namespace solarApp.Service
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_station]的資料表向[{_siteDB}_history.s{_siteID}_station]搬移");
string for_insert_station = $@"INSERT {_siteDB}_history.s{_siteID01}_station(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime`)
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime` FROM {_siteDB}.s{_siteID01}_station
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-10'";
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
int rowCT = conn.Execute(for_insert_station, commandTimeout : 600);
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_station的七月前資料寫入至{_siteDB}_history.s{_siteID}_station【寫入成功】於{dateTime}");
@ -303,7 +313,7 @@ namespace solarApp.Service
//刪除原本的資料
string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '2022-10'";
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
rowCT = conn.Execute(for_delete_station, commandTimeout: 600);
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_station.ToString()} 筆");
duration = DateTime.Now - dt_start1;
@ -343,10 +353,14 @@ namespace solarApp.Service
{
#region inv搬移
dt_start1 = DateTime.Now;
if (_powerStationID == "19")
{
//MessageBox.Show("here");
}
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_inv]的資料表向[{_siteDB}_history.s{_siteID}_inv]搬移");
string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime`)
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime` FROM {_siteDB}.s{_siteID01}_inv
WHERE LEFT(crdTime, 7) < '2022-10'";
WHERE LEFT(crdTime, 7) < '{move_month}'";
int rowCT = conn.Execute(for_insert_inv, commandTimeout: 6000);
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_inv的七月前資料寫入至{_siteDB}_history.s{_siteID}_inv【寫入成功】於{dateTime}");
// log
@ -356,7 +370,7 @@ namespace solarApp.Service
dt_start1 = DateTime.Now;
string for_delete_inv = $@"DELETE FROM {_siteDB}.s{_siteID01}_inv
WHERE LEFT(crdTime, 7) < '2022-10'";
WHERE LEFT(crdTime, 7) < '{move_month}'";
rowCT = conn.Execute(for_delete_inv, commandTimeout: 6000);
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_inv.ToString()} 筆");
duration = DateTime.Now - dt_start1;
@ -390,15 +404,16 @@ namespace solarApp.Service
dt_start1 = DateTime.Now;
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_sensoravg]的資料表向[{_siteDB}_history.s{_siteID}_sensoravg]搬移");
string for_insert_sensoravg = $@"INSERT {_siteDB}_history.s{_siteID01}_sensoravg(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`)
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime` FROM {_siteDB}.s{_siteID01}_sensoravg
WHERE LEFT(crdTime, 7) < '2022-10'";
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`
FROM {_siteDB}.s{_siteID01}_sensoravg
WHERE LEFT(crdTime, 7) < '{move_month}'";
int rowCT = conn.Execute(for_insert_sensoravg, commandTimeout: 600);
// log
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null);
dt_start1 = DateTime.Now;
string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '2022-10'";
string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '{move_month}'";
rowCT = conn.Execute(for_delete_sensoravg, commandTimeout: 600);
duration = DateTime.Now - dt_start1;

View File

@ -559,6 +559,10 @@ namespace solarApp.Service
return result;
}
/// <summary>
/// 累計日照計算
/// </summary>
/// <returns></returns>
bool insert_sensor_for_history_hour()
{
procArchiveLog arclog = new procArchiveLog();
@ -581,9 +585,9 @@ namespace solarApp.Service
if (isFirst)
{
sql = $@"DROP TEMPORARY TABLE IF EXISTS `temp_s1`;
create TEMPORARY TABLE temp_s1
select powerstationID, `TIMESTAMP`, irrday
from sensor_history_hour a
Create TEMPORARY TABLE temp_s1
Select powerstationID, `TIMESTAMP`, irrday
From sensor_history_hour a
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}';
ALTER TABLE `temp_s1` ADD INDEX `temp_indexs1` (powerstationID, `TIMESTAMP`);";
dt_start2 = DateTime.Now;
@ -598,8 +602,7 @@ namespace solarApp.Service
(select powerstationID, LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday from temp_s1 ) b
on LEFT(a.`TIMESTAMP`, 13) = hour_1 and a.powerstationID = b.powerstationID
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
and a.powerstationID = {_powerStationID} ";
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}' and a.powerstationID = {_powerStationID} ";
dt_start2 = DateTime.Now;
cmd.CommandText = sql;
int rowCT2 = cmd.ExecuteNonQuery();

View File

@ -312,6 +312,7 @@ namespace solarApp
procInvSvc invSvc = new procInvSvc();
procStationSvc siteSvc = new procStationSvc();
foreach (var item in site_list)
{
//RadioButton rb = new RadioButton();

View File

@ -14,7 +14,6 @@
<ItemGroup>
<EmbeddedResource Remove="fmExcel.resx" />
<EmbeddedResource Remove="fmTest.resx" />
</ItemGroup>
<ItemGroup>