異常同步 更新 site_id SQL 語法
This commit is contained in:
parent
a189bcc2f4
commit
ff213eba6e
@ -34,7 +34,7 @@ namespace solarApp.Service
|
|||||||
{
|
{
|
||||||
DateTime dt_start = DateTime.Now;
|
DateTime dt_start = DateTime.Now;
|
||||||
conn.Open();
|
conn.Open();
|
||||||
#region 同步最新狀態 改到 trigger
|
#region 更新 Normal time
|
||||||
dt_start = DateTime.Now;
|
dt_start = DateTime.Now;
|
||||||
string sql = $@" update`err_main` a join alarmorion_orionalarmrecord b on a.id = b.id set
|
string sql = $@" update`err_main` a join alarmorion_orionalarmrecord b on a.id = b.id set
|
||||||
a.`sourcestate` = b.`sourcestate`,
|
a.`sourcestate` = b.`sourcestate`,
|
||||||
@ -43,19 +43,19 @@ namespace solarApp.Service
|
|||||||
a.`normaltime` = b.`normaltime`,
|
a.`normaltime` = b.`normaltime`,
|
||||||
a.`acktime` = b.`acktime`,
|
a.`acktime` = b.`acktime`,
|
||||||
a.`lastupdate` = b.`lastupdate`
|
a.`lastupdate` = b.`lastupdate`
|
||||||
where a.sourcestate =1 and a.site_id is not null "; // b.datestamp >= '{ System.DateTime.Now.AddDays(-90).ToString("yyyy-mm-dd")}' ;";
|
where a.sourcestate = 1 and b.datestamp >= '{ System.DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd")}'";// and a.site_id is not null "; // ;";
|
||||||
int rowCount = conn.Execute(sql);
|
int rowCount = conn.Execute(sql);
|
||||||
TimeSpan durationSec = DateTime.Now - dt_start;
|
TimeSpan durationSec = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s2 normaltime", durationSec.TotalSeconds, "orionAlarmRecord", "err_main", "0", "", rowCount.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s0 normaltime", durationSec.TotalSeconds, "orionAlarmRecord", "err_main", "0", "", rowCount.ToString(), conn, null);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 取得 昨天到今天的尚未同步的異常資料
|
#region 取得 昨天到今天的尚未同步的異常資料
|
||||||
//sql = $@" select * from alarmorion_orionalarmrecord
|
sql = $@" select * from alarmorion_orionalarmrecord
|
||||||
// where id not in (select id from err_main )
|
where id not in (select id from err_main )
|
||||||
// and datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}'";
|
and datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}'";
|
||||||
sql = $@"select * from err_main
|
//sql = $@"select * from err_main
|
||||||
where site_id is null and datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}'";
|
// where site_id is null and datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}'";
|
||||||
var ds = conn.Query<errMain_model>(sql).AsList<errMain_model>();
|
var ds = conn.Query<errMain_model>(sql).AsList<errMain_model>();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
bool isfirst = true;
|
bool isfirst = true;
|
||||||
@ -74,16 +74,17 @@ namespace solarApp.Service
|
|||||||
if (ds.Count > 0)
|
if (ds.Count > 0)
|
||||||
{
|
{
|
||||||
#region 新增異常值 err_main
|
#region 新增異常值 err_main
|
||||||
//string sql_header = "INSERT INTO `err_main`(`id`, `timestamp`, `datestamp`, `uuidHash`, `uuid`, `isOpen`, `sourceState`, `ackState`, `ackRequired`, `alarmClass`, `priority`, `normalTime`, `ackTime`, `userAccount`, `alarmTransition`, `lastUpdate`) ";
|
sql = "";
|
||||||
//foreach (var item in ds)
|
string sql_header = "INSERT INTO `err_main`(`id`, `timestamp`, `datestamp`, `uuidHash`, `uuid`, `isOpen`, `sourceState`, `ackState`, `ackRequired`, `alarmClass`, `priority`, `normalTime`, `ackTime`, `userAccount`, `alarmTransition`, `lastUpdate`) ";
|
||||||
//{
|
foreach (var item in ds)
|
||||||
// sql = sql_header + $@" VALUES ({item.id}, {item.timestamp}, '{item.datestamp}', {item.uuidHash}, {item.uuid}, {item.isOpen}, {item.sourceState}
|
{ // //{item.uuidHash}, '{Convert.ToBase64String(item.uuid)}'
|
||||||
// , {item.ackState}, {item.ackRequired}, {item.alarmClass}, {item.priority}, {item.normalTime}, {item.ackTime}
|
sql += sql_header + $@" VALUES ({item.id}, {item.timestamp}, '{DateTime.Parse(item.datestamp).ToString("yyyy-MM-dd")}', 0, 0
|
||||||
// , '{item.userAccount}', {item.alarmTransition}, {item.lastUpdate}); ";
|
, {item.isOpen}, {item.sourceState}, {item.ackState}, {item.ackRequired}, {item.alarmClass}, {item.priority}, {item.normalTime}, {item.ackTime}
|
||||||
//}
|
, '{item.userAccount}', {item.alarmTransition}, {item.lastUpdate}); ";
|
||||||
//int rowCT = conn.Execute(sql);
|
}
|
||||||
//TimeSpan duration = DateTime.Now - dt_start;
|
int rowCT = conn.Execute(sql);
|
||||||
//arclog.insert_log("0", "syncError s1", duration.TotalSeconds, "orionAlarmRecord", "err_main", "0", "", rowCT.ToString(), conn, null);
|
TimeSpan duration = DateTime.Now - dt_start;
|
||||||
|
arclog.insert_log("0", "syncError s1", duration.TotalSeconds, "orionAlarmRecord", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region update site_id, inverterID
|
#region update site_id, inverterID
|
||||||
@ -94,35 +95,38 @@ namespace solarApp.Service
|
|||||||
SUBSTRING_INDEX(`value`, '@', 1) # @前面所有string --> e:7
|
SUBSTRING_INDEX(`value`, '@', 1) # @前面所有string --> e:7
|
||||||
, ':', -1)
|
, ':', -1)
|
||||||
where facetName = 4 and alarm in ({sb.ToString()});";
|
where facetName = 4 and alarm in ({sb.ToString()});";
|
||||||
int rowCT = conn.Execute(sql);
|
rowCT = conn.Execute(sql);
|
||||||
TimeSpan duration = DateTime.Now - dt_start;
|
duration = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s3 errValue", duration.TotalSeconds, "facetvalue4", "err_main", "0", "", rowCT.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s2 errValue", duration.TotalSeconds, "facetvalue4", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region update device_id
|
#region update site_id, device_id
|
||||||
dt_start = DateTime.Now;
|
dt_start = DateTime.Now;
|
||||||
sql = $@"update err_main a join alarmorion_orionalarmfacetvalue b on a.id = b.alarm
|
sql = $@"update err_main a join alarmorion_orionalarmfacetvalue b on a.id = b.alarm
|
||||||
set err_valuekind = left(`value`, 1),
|
set err_valuekind = left(`value`, 1),
|
||||||
errDevice = SUBSTRING_INDEX(SUBSTRING_INDEX(`value`, ':', -1) # : 後面所有string
|
errDevice = SUBSTRING_INDEX(SUBSTRING_INDEX(`value`, ':', -1) # : 後面所有string
|
||||||
,'S', -1)
|
,'S', -1),
|
||||||
where facetName = 8 and alarm in ({sb.ToString()});";
|
a.site_id = substring(
|
||||||
|
SUBSTRING_INDEX(SUBSTRING_INDEX(`value`, ':', -1) # : 後面所有string
|
||||||
|
,'S', -1)
|
||||||
|
, 1, 9)
|
||||||
|
where facetName = 8 and errDevice is null and a.datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}';";
|
||||||
rowCT = conn.Execute(sql);
|
rowCT = conn.Execute(sql);
|
||||||
duration = DateTime.Now - dt_start;
|
duration = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s4 errDevice", duration.TotalSeconds, "facetValue8", "err_main", "0", "", rowCT.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s3 errDevice", duration.TotalSeconds, "facetValue8", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region update site_id, 設備廠牌
|
#region update 設備廠牌
|
||||||
dt_start = DateTime.Now;
|
dt_start = DateTime.Now;
|
||||||
sql = $@"update err_main a join v_company_inv b on a.errDevice = b.INVERTERID set
|
sql = $@"update err_main a join v_company_inv b on a.errDevice = b.INVERTERID set
|
||||||
site_id = substring(errDevice , 1, 9),
|
|
||||||
errDeviceBrand = b.brand,
|
errDeviceBrand = b.brand,
|
||||||
errDeviceModel = b.Model
|
errDeviceModel = b.Model
|
||||||
where errDevice is not null and id in ({sb.ToString()});";
|
where errDevice is not null and datestamp >= '{System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}';";
|
||||||
rowCT = conn.Execute(sql);
|
rowCT = conn.Execute(sql);
|
||||||
duration = DateTime.Now - dt_start;
|
duration = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s5 site_id", duration.TotalSeconds, "v_company_inv", "err_main", "0", "", rowCT.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s4 site_id", duration.TotalSeconds, "v_company_inv", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 更新全部的燈號
|
#region 更新全部的燈號
|
||||||
@ -152,7 +156,7 @@ namespace solarApp.Service
|
|||||||
set a.healthstatus = b.healthstatus;";
|
set a.healthstatus = b.healthstatus;";
|
||||||
rowCT = conn.Execute(sql);
|
rowCT = conn.Execute(sql);
|
||||||
duration = DateTime.Now - dt_start;
|
duration = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s6 site health", duration.TotalSeconds, "temp_healthstatus", "err_main", "0", "", rowCT.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s5 site health", duration.TotalSeconds, "temp_healthstatus", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -169,7 +173,7 @@ namespace solarApp.Service
|
|||||||
set status = errStatus;";
|
set status = errStatus;";
|
||||||
rowCT = conn.Execute(sql);
|
rowCT = conn.Execute(sql);
|
||||||
duration = DateTime.Now - dt_start;
|
duration = DateTime.Now - dt_start;
|
||||||
arclog.insert_log("0", "syncError s7 inv health", duration.TotalSeconds, "", "err_main", "0", "", rowCT.ToString(), conn, null);
|
arclog.insert_log("0", "syncError s6 inv health", duration.TotalSeconds, "", "err_main", "0", "", rowCT.ToString(), conn, null);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,9 +116,11 @@ namespace solarApp
|
|||||||
//異常處理 每 5分鐘跑一次
|
//異常處理 每 5分鐘跑一次
|
||||||
if ((DateTime.Now.Minute % 5) == 0 && autoTask == false)
|
if ((DateTime.Now.Minute % 5) == 0 && autoTask == false)
|
||||||
{
|
{
|
||||||
lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
|
|
||||||
btSyncErr.PerformClick();
|
|
||||||
autoTask = true;
|
autoTask = true;
|
||||||
|
lbMsgTitle.Text = "異常處理 " + DateTime.Now.ToString() + " timer start";
|
||||||
|
btSyncErr.PerformClick();
|
||||||
|
lbMsgTitle.Text = "異常處理 done" + DateTime.Now.ToString() ;
|
||||||
|
autoTask = false;
|
||||||
//bt_archive_Click.PerformClick();
|
//bt_archive_Click.PerformClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,24 +138,24 @@ namespace solarApp
|
|||||||
|
|
||||||
|
|
||||||
//水位管理
|
//水位管理
|
||||||
if (System.DateTime.Now.Hour == 03 && DateTime.Now.Minute == 30
|
//if (System.DateTime.Now.Hour == 03 && DateTime.Now.Minute == 30
|
||||||
&& (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10)
|
// && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10)
|
||||||
&& autoTask == false)
|
// && autoTask == false)
|
||||||
{
|
//{
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
var site_list = stationSvc.get_station_list();
|
// var site_list = stationSvc.get_station_list();
|
||||||
|
|
||||||
archiveLowData archiveData = new archiveLowData();
|
// archiveLowData archiveData = new archiveLowData();
|
||||||
autoTask = true;
|
// autoTask = true;
|
||||||
foreach (var item in site_list)
|
// foreach (var item in site_list)
|
||||||
{
|
// {
|
||||||
archiveData.archiveData(item.SiteID.Substring(0, 9));
|
// archiveData.archiveData(item.SiteID.Substring(0, 9));
|
||||||
|
|
||||||
i++;
|
// i++;
|
||||||
}
|
// }
|
||||||
autoTask = false;
|
// autoTask = false;
|
||||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
|
// lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rb_site_CheckedChanged(object sender, EventArgs e)
|
private void rb_site_CheckedChanged(object sender, EventArgs e)
|
||||||
@ -714,8 +716,9 @@ namespace solarApp
|
|||||||
|
|
||||||
private void btSyncErr_Click(object sender, EventArgs e)
|
private void btSyncErr_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
autoTask = true;
|
||||||
svc.syncErrData();
|
svc.syncErrData();
|
||||||
|
autoTask = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//test for email format
|
//test for email format
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user