15分鐘 - 熱圖
This commit is contained in:
parent
ce83323763
commit
f2103ba957
@ -3181,6 +3181,34 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
var stratDateTime = Convert.ToDateTime(dateTime + ":00").AddMinutes(-15).ToString("yyyy-MM-dd HH:mm");
|
var stratDateTime = Convert.ToDateTime(dateTime + ":00").AddMinutes(-15).ToString("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
|
//var sql = $@"SELECT
|
||||||
|
// s.TIMESTAMP,
|
||||||
|
// s.INVERTERID,
|
||||||
|
// s.KWH,
|
||||||
|
// s.TODAYKWH,
|
||||||
|
// i.Capacity,
|
||||||
|
// s.KWH/(i.Capacity/4) AS KWHKWP
|
||||||
|
// FROM (SELECT
|
||||||
|
// MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
|
||||||
|
// sub_inv.INVERTERID,
|
||||||
|
// SUM(sub_inv.WH)/1000 AS KWH,
|
||||||
|
// MAX(sub_inv.TODAYKWH) AS TODAYKWH
|
||||||
|
// FROM {table_name} sub_inv
|
||||||
|
// WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
|
||||||
|
// AND sub_inv.INVERTERID IN @InverterIds
|
||||||
|
// GROUP BY sub_inv.INVERTERID) s
|
||||||
|
// /*LEFT JOIN (
|
||||||
|
// SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
|
||||||
|
// sub_inv.INVERTERID,
|
||||||
|
// SUM(sub_inv.WH)/1000 AS KWH
|
||||||
|
// FROM {table_name} sub_inv
|
||||||
|
// WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
|
||||||
|
// AND sub_inv.INVERTERID IN @InverterIds
|
||||||
|
// GROUP BY sub_inv.INVERTERID) a
|
||||||
|
// ON s.TIMESTAMP = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID*/
|
||||||
|
// LEFT JOIN {db_name}.inverter i ON s.INVERTERID = REPLACE(i.InverterId, 's', '');";
|
||||||
|
//result = (await conn.QueryAsync<InverterHistory>(sql, new { StartDateTime = stratDateTime, EndDateTime = dateTime, InverterIds = inverterIds }, commandTimeout: 300)).ToList();
|
||||||
|
|
||||||
var sql = $@"SELECT
|
var sql = $@"SELECT
|
||||||
s.TIMESTAMP,
|
s.TIMESTAMP,
|
||||||
s.INVERTERID,
|
s.INVERTERID,
|
||||||
@ -3194,21 +3222,11 @@ namespace SolarPower.Repository.Implement
|
|||||||
SUM(sub_inv.WH)/1000 AS KWH,
|
SUM(sub_inv.WH)/1000 AS KWH,
|
||||||
MAX(sub_inv.TODAYKWH) AS TODAYKWH
|
MAX(sub_inv.TODAYKWH) AS TODAYKWH
|
||||||
FROM {table_name} sub_inv
|
FROM {table_name} sub_inv
|
||||||
WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
|
WHERE CrdTime BETWEEN '{stratDateTime}' AND '{inverterIds}'
|
||||||
AND sub_inv.INVERTERID IN @InverterIds
|
|
||||||
GROUP BY sub_inv.INVERTERID) s
|
GROUP BY sub_inv.INVERTERID) s
|
||||||
/*LEFT JOIN (
|
LEFT JOIN {db_name}.inverter i ON s.INVERTERID = REPLACE(i.InverterId, 's', '')
|
||||||
SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
|
where Deleted = 0 and enabled = 1 ;";
|
||||||
sub_inv.INVERTERID,
|
result = (await conn.QueryAsync<InverterHistory>(sql, commandTimeout: 300)).ToList();
|
||||||
SUM(sub_inv.WH)/1000 AS KWH
|
|
||||||
FROM {table_name} sub_inv
|
|
||||||
WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
|
|
||||||
AND sub_inv.INVERTERID IN @InverterIds
|
|
||||||
GROUP BY sub_inv.INVERTERID) a
|
|
||||||
ON s.TIMESTAMP = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID*/
|
|
||||||
LEFT JOIN {db_name}.inverter i ON s.INVERTERID = REPLACE(i.InverterId, 's', '');";
|
|
||||||
|
|
||||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { StartDateTime = stratDateTime, EndDateTime = dateTime, InverterIds = inverterIds }, commandTimeout: 300)).ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"LoginExpireMinute": 60, //登入到期時間,單位(分)
|
"LoginExpireMinute": 60, //<EFBFBD>n<EFBFBD>J<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD>A<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
||||||
"GoBackDay": 1, //補償機制(背景執行(每天)),回推天數
|
"GoBackDay": 1, //<EFBFBD><EFBFBD><EFBFBD>v<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>I<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>C<EFBFBD><EFBFBD>))<EFBFBD>A<EFBFBD>^<EFBFBD><EFBFBD><EFBFBD>Ѽ<EFBFBD>
|
||||||
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;",
|
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;",
|
||||||
|
|
||||||
//"DBConfig": {
|
//"DBConfig": {
|
||||||
@ -18,7 +18,7 @@
|
|||||||
// "Root": "mWlR2HshQNhRRE34jg4kdg==",
|
// "Root": "mWlR2HshQNhRRE34jg4kdg==",
|
||||||
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
|
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
|
||||||
//},
|
//},
|
||||||
// FIC 預發佈環境
|
// FIC <EFBFBD>w<EFBFBD>o<EFBFBD>G<EFBFBD><EFBFBD><EFBFBD>
|
||||||
//"DBConfig": {
|
//"DBConfig": {
|
||||||
// "Server": "MWAxcj1mgmbZ8tB6NgApnQ==",
|
// "Server": "MWAxcj1mgmbZ8tB6NgApnQ==",
|
||||||
// "port": "CY1x+1WYXRCBab3wKnBCOQ==",
|
// "port": "CY1x+1WYXRCBab3wKnBCOQ==",
|
||||||
@ -26,7 +26,7 @@
|
|||||||
// "Root": "pBX64+ALGFnLiHGRFXNh7w==",
|
// "Root": "pBX64+ALGFnLiHGRFXNh7w==",
|
||||||
// "Password": "bOlWkSFsV3qNLkZTJ3UPog=="
|
// "Password": "bOlWkSFsV3qNLkZTJ3UPog=="
|
||||||
//},
|
//},
|
||||||
// 正式
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
"DBConfig": {
|
"DBConfig": {
|
||||||
"Server": "AVXfxd+IRlLtJ0MCi9HU1g==",
|
"Server": "AVXfxd+IRlLtJ0MCi9HU1g==",
|
||||||
"port": "CrEmevYrUsSo7Mkb7Gxn8A==",
|
"port": "CrEmevYrUsSo7Mkb7Gxn8A==",
|
||||||
@ -50,7 +50,7 @@
|
|||||||
"Password": "opuisjyxgyjbjtha", //2022-09-02 update by jiahao
|
"Password": "opuisjyxgyjbjtha", //2022-09-02 update by jiahao
|
||||||
"EnableSsl": true
|
"EnableSsl": true
|
||||||
},
|
},
|
||||||
"ExceptionTimes": 240, //異常通知時間,單位(分鐘)
|
"ExceptionTimes": 240, //<EFBFBD><EFBFBD><EFBFBD>`<EFBFBD>q<EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD>A<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||||
"ExceptionTimes_Priority1": 0,
|
"ExceptionTimes_Priority1": 0,
|
||||||
"ExceptionTimes_Priority2": 720,
|
"ExceptionTimes_Priority2": 720,
|
||||||
"ExceptionTimes_Priority3": 1440
|
"ExceptionTimes_Priority3": 1440
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.31005.135
|
VisualStudioVersion = 17.3.32901.215
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SolarPower", "SolarPower\SolarPower.csproj", "{6C88BBD7-5A1F-47B8-BF46-9CBDC73EF2E9}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SolarPower", "SolarPower\SolarPower.csproj", "{6C88BBD7-5A1F-47B8-BF46-9CBDC73EF2E9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "solarApp", "solarApp\solarApp.csproj", "{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "solarApp", "solarApp\solarApp.csproj", "{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "winService", "winService\winService.csproj", "{132A1CF9-2C64-493D-8F8E-1F86AA595D14}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -21,6 +23,10 @@ Global
|
|||||||
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3D54E7DA-4EF8-42A3-85D3-39DD08AC9A0C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{132A1CF9-2C64-493D-8F8E-1F86AA595D14}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
12
solarApp/Properties/launchSettings.json
Normal file
12
solarApp/Properties/launchSettings.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"solarApp": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"applicationUrl": "https://localhost:2904;http://localhost:2905"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,7 +13,7 @@ namespace solarApp.Service
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class getStationSvc
|
public class getStationSvc
|
||||||
{
|
{
|
||||||
string Connection1 = "";
|
public string Connection1 { get; set; }
|
||||||
public getStationSvc(string Connection_parame = null)
|
public getStationSvc(string Connection_parame = null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(Connection_parame))
|
if (!string.IsNullOrEmpty(Connection_parame))
|
||||||
|
|||||||
@ -84,11 +84,11 @@ namespace solarApp
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 自動執行
|
#region 自動執行
|
||||||
_timer = new System.Timers.Timer();
|
//_timer = new System.Timers.Timer();
|
||||||
_timer.Interval = 10000;
|
//_timer.Interval = 10000;
|
||||||
_timer.SynchronizingObject = this;
|
//_timer.SynchronizingObject = this;
|
||||||
_timer.Elapsed += _timer_Elapsed;
|
//_timer.Elapsed += _timer_Elapsed;
|
||||||
_timer.Start();
|
//_timer.Start();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// dtselect_station1.Value = DateTime.Today.AddDays(-1);
|
// dtselect_station1.Value = DateTime.Today.AddDays(-1);
|
||||||
@ -107,46 +107,46 @@ namespace solarApp
|
|||||||
|
|
||||||
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
lbMsgStatus.Text = (autoTask) ? "autoTask = true" : "autoTask = false";
|
//lbMsgStatus.Text = (autoTask) ? "autoTask = true" : "autoTask = false";
|
||||||
lbMsgStatus.Text += " timespan = " + (DateTime.Now - doTimerTaskTime).TotalMinutes.ToString();
|
//lbMsgStatus.Text += " timespan = " + (DateTime.Now - doTimerTaskTime).TotalMinutes.ToString();
|
||||||
|
|
||||||
if (DateTime.Now.Hour >= 2 && DateTime.Now.Minute == 0)
|
//if (DateTime.Now.Hour >= 2 && DateTime.Now.Minute == 0)
|
||||||
{
|
//{
|
||||||
doTimerTaskTime = DateTime.Now;
|
// doTimerTaskTime = DateTime.Now;
|
||||||
autoTask = false;
|
// autoTask = false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 凌晨 2點後,如果間隔30分鐘 沒有跑異常同步 就啟動啟動
|
//// 凌晨 2點後,如果間隔30分鐘 沒有跑異常同步 就啟動啟動
|
||||||
doTaskDuratin = DateTime.Now - doTimerTaskTime; //
|
//doTaskDuratin = DateTime.Now - doTimerTaskTime; //
|
||||||
if (DateTime.Now.Hour >= 2 && doTaskDuratin.TotalMinutes > 15 && (autoTask == true))
|
//if (DateTime.Now.Hour >= 2 && doTaskDuratin.TotalMinutes > 15 && (autoTask == true))
|
||||||
{
|
//{
|
||||||
doTimerTaskTime = DateTime.Now;
|
// doTimerTaskTime = DateTime.Now;
|
||||||
autoTask = false;
|
// autoTask = false;
|
||||||
}
|
//}
|
||||||
//每日歸檔
|
////每日歸檔
|
||||||
if (DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15 )
|
//if (DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15 )
|
||||||
{
|
//{
|
||||||
//MessageBox.Show("ok");
|
// //MessageBox.Show("ok");
|
||||||
autoTask = true;
|
// autoTask = true;
|
||||||
lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
|
// lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
|
||||||
dtSelect1.Value = System.DateTime.Now.AddDays(-1);
|
// dtSelect1.Value = System.DateTime.Now.AddDays(-1);
|
||||||
dtSelect2.Value = System.DateTime.Now.AddDays(-1);
|
// dtSelect2.Value = System.DateTime.Now.AddDays(-1);
|
||||||
bt_archive.PerformClick();
|
// bt_archive.PerformClick();
|
||||||
autoTask = false;
|
// autoTask = false;
|
||||||
//bt_archive_Click.PerformClick();
|
// //bt_archive_Click.PerformClick();
|
||||||
}
|
//}
|
||||||
|
|
||||||
//異常處理 每 5分鐘跑一次
|
////異常處理 每 5分鐘跑一次
|
||||||
if ((DateTime.Now.Minute % 5) == 0 && (DateTime.Now.Second) < 30 && (autoTask == false))
|
//if ((DateTime.Now.Minute % 5) == 0 && (DateTime.Now.Second) < 30 && (autoTask == false))
|
||||||
{
|
//{
|
||||||
doTimerTaskTime = DateTime.Now;
|
// doTimerTaskTime = DateTime.Now;
|
||||||
autoTask = true;
|
// autoTask = true;
|
||||||
lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
|
// lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
|
||||||
btSyncErr.PerformClick();
|
// btSyncErr.PerformClick();
|
||||||
lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString() ;
|
// lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString() ;
|
||||||
autoTask = false;
|
// autoTask = false;
|
||||||
//bt_archive_Click.PerformClick();
|
// //bt_archive_Click.PerformClick();
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//臨時的 累計日照
|
//臨時的 累計日照
|
||||||
@ -306,10 +306,6 @@ namespace solarApp
|
|||||||
{
|
{
|
||||||
var site_list = stationSvc.get_station_list();
|
var site_list = stationSvc.get_station_list();
|
||||||
|
|
||||||
//bt_Sensor.PerformClick();
|
|
||||||
//bt_Inv.PerformClick();
|
|
||||||
//bt_site.PerformClick();
|
|
||||||
//bt_rpt_invDay.PerformClick();
|
|
||||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||||
procSensorSvc sensorSvc = new procSensorSvc();
|
procSensorSvc sensorSvc = new procSensorSvc();
|
||||||
|
|||||||
11
winService/Program.cs
Normal file
11
winService/Program.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using winService;
|
||||||
|
|
||||||
|
IHost host = Host.CreateDefaultBuilder(args)
|
||||||
|
.UseWindowsService()
|
||||||
|
.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
services.AddHostedService<Worker>();
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await host.RunAsync();
|
||||||
11
winService/Properties/launchSettings.json
Normal file
11
winService/Properties/launchSettings.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"winService": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"DOTNET_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
114
winService/Worker.cs
Normal file
114
winService/Worker.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using solarApp.Service;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace winService
|
||||||
|
{
|
||||||
|
public class Worker : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly ILogger<Worker> _logger;
|
||||||
|
XDocument xdoc;
|
||||||
|
public XDocument Xdoc { get => xdoc; set => xdoc = value; }
|
||||||
|
|
||||||
|
getStationSvc stationSvc;
|
||||||
|
System.Timers.Timer _timer;
|
||||||
|
bool autoTask = false; //測試自動跑 irrDayHour 累計日照小時差異
|
||||||
|
procSyncError svc;
|
||||||
|
DateTime doTimerTaskTime = DateTime.Now;
|
||||||
|
TimeSpan doTaskDuratin;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Worker(ILogger<Worker> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
xdoc = XDocument.Load("../solarApp/App.config");
|
||||||
|
string conStr = Xdoc.Element("configuration").Element("connectionStrings").Element("add").Attribute("connectionString").Value;
|
||||||
|
stationSvc = new getStationSvc(conStr);
|
||||||
|
svc = new procSyncError(conStr); // 常資料同步
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
|
await Task.Delay(60000, stoppingToken); //每分鐘
|
||||||
|
if (DateTime.Now.Hour >= 2 && DateTime.Now.Minute == 0)
|
||||||
|
{
|
||||||
|
doTimerTaskTime = DateTime.Now;
|
||||||
|
autoTask = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 凌晨 2點後,如果間隔30分鐘 沒有跑異常同步 就啟動啟動
|
||||||
|
doTaskDuratin = DateTime.Now - doTimerTaskTime; //
|
||||||
|
if (DateTime.Now.Hour >= 2 && doTaskDuratin.TotalMinutes > 15 && (autoTask == true))
|
||||||
|
{
|
||||||
|
doTimerTaskTime = DateTime.Now;
|
||||||
|
autoTask = false;
|
||||||
|
}
|
||||||
|
//每日歸檔
|
||||||
|
if (DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15)
|
||||||
|
{
|
||||||
|
//MessageBox.Show("ok");
|
||||||
|
autoTask = true;
|
||||||
|
//lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
|
||||||
|
//dtSelect1.Value = System.DateTime.Now.AddDays(-1);
|
||||||
|
//dtSelect2.Value = System.DateTime.Now.AddDays(-1);
|
||||||
|
archiveAllStation();
|
||||||
|
autoTask = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//異常處理 每 5分鐘跑一次
|
||||||
|
if ((DateTime.Now.Minute % 5) == 0 && (DateTime.Now.Second) < 30 && (autoTask == false))
|
||||||
|
{
|
||||||
|
doTimerTaskTime = DateTime.Now;
|
||||||
|
autoTask = true;
|
||||||
|
svc.syncErrData();
|
||||||
|
//lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
|
||||||
|
//btSyncErr.PerformClick();
|
||||||
|
//lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString();
|
||||||
|
autoTask = false;
|
||||||
|
//bt_archive_Click.PerformClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void archiveAllStation() {
|
||||||
|
var site_list = stationSvc.get_station_list();
|
||||||
|
procSensorSvc sensorSvc = new procSensorSvc();
|
||||||
|
procInvSvc invSvc = new procInvSvc();
|
||||||
|
procStationSvc siteSvc = new procStationSvc();
|
||||||
|
string date1 = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
string date2 = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
|
||||||
|
foreach (var item in site_list)
|
||||||
|
{
|
||||||
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||||
|
{
|
||||||
|
sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||||
|
invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||||
|
siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sensorSvc.isFirst = true;
|
||||||
|
foreach (var item in site_list)
|
||||||
|
{
|
||||||
|
//for sensor_history_hour
|
||||||
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||||
|
{
|
||||||
|
sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||||
|
sensorSvc.isFirst = false;
|
||||||
|
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<DateTime> EachDay(DateTime from, DateTime thru)
|
||||||
|
{
|
||||||
|
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1))
|
||||||
|
yield return day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
winService/appsettings.Development.json
Normal file
9
winService/appsettings.Development.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;"
|
||||||
|
}
|
||||||
10
winService/appsettings.json
Normal file
10
winService/appsettings.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mySql": "server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;"
|
||||||
|
|
||||||
|
}
|
||||||
20
winService/winService.csproj
Normal file
20
winService/winService.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UserSecretsId>dotnet-winService-78282A39-DE2D-4E5B-806B-31D6FE6D57E7</UserSecretsId>
|
||||||
|
<StartupObject>SolarPower.Program</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\solarApp\solarApp.csproj" />
|
||||||
|
<ProjectReference Include="..\SolarPower\SolarPower.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
Loading…
Reference in New Issue
Block a user