solar_App: 增加功能,查詢異常是否送至寄信的資料表

This commit is contained in:
wanling040@gmail.com 2022-08-18 19:24:54 +08:00
parent 09fc3c9d9b
commit 19f6a8e1df
4 changed files with 624 additions and 445 deletions

View File

@ -31,4 +31,61 @@ namespace solarApp.Model
public string errDeviceBrand { get; set; } public string errDeviceBrand { get; set; }
public string errDeviceModel { get; set; } public string errDeviceModel { get; set; }
} }
public class ExceptionEmailInfo
{
public int id { get; set; }//Id編號
public string site_id { get; set; }//電站編號
public string alarmClassName { get; set; }//異常類別
public string errDevice { get; set; }//設備編號
public string errValue { get; set; }//原始值
public string dev_time { get; set; }//發生時間
public string errMsg { get; set; }//錯誤原因
public string PowerStationName { get; set; }//電站名稱
public int PowerStationId { get; set; }//電站流水號
public string normalTime { get; set; }//賦歸時間
public string errMsgT { get; set; } //errMsgType
public int priority { get; set; }//priority
public int sourceState { get; set; }//異常狀態
public string emailTime { get; set; }//送到寄信資料表的時間
}
public class NoticeInfo
{
public int Id { get; set; }//Id編號
public int Type { get; set; }//設備類型
public string RecipientName { get; set; }//收件人
public string RecipientEmail { get; set; }//收件Email
public string Subject { get; set; }//主旨
public string Content { get; set; }//內容
public int ExceptionId { get; set; }//異常id
public int IsDelivery { get; set; }//是否已寄出信件
public string DeliveryAt { get; set; }//寄出時間
public string CreatedAt { get; set; } //製造時間
}
public class AlarmorionInfo
{
public int id { get; set; }
public string site_id { get; set; }
public string timestamp2 { get; set; }
public string datestamp { get; set; }
public int uuidHash { get; set; }
//public Byte[] uuid { get; set; }
public string isOpen { get; set; }
public string sourceState { get; set; }
public string ackState { get; set; }
public Int16 ackRequired { get; set; }
public int alarmClass { get; set; }
public int priority { get; set; }
public Int64 normalTime { get; set; }
public Int64 ackTime { get; set; }
public string userAccount { get; set; }
public int alarmTransition { get; set; }
public Int64 lastUpdate { get; set; }
public string siteID { get; set; }
public string deviceID { get; set; }
public string errMsg { get; set; }
}
} }

View File

@ -187,5 +187,100 @@ namespace solarApp.Service
} }
return result; return result;
} }
public List<ExceptionEmailInfo> QueryExceptionData()
{
try
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = $@"SELECT a.`*`,ns.Id,
case priority when 1 then DATE_ADD(dev_time, INTERVAL 24 HOUR)
when 2 then DATE_ADD(dev_time, INTERVAL 12 HOUR)
else dev_time end emailTime
FROM
(
select pr.FormId as FormId, pr.Id as ErrorID, priority, a.id, site_id, `timestamp`, a.sourceState,
FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
a.alarmClass, b.alarmClass as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
case when c.errMsg_tw is null then
case when err_valueKind = 'b' then d.errMsg_tw
when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
when d.errMsg_tw is null then a.errValue
when a.errValue is null then d.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
else
case when err_valueKind = 'b' then c.errMsg_tw
when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
when c.errMsg_tw is null then a.errValue
when a.errValue is null then c.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
end errMsg
#, a.errDeviceBrand , d.brend , a.errDeviceModel, d.model , a.errValue , d.errCode
from err_main a
left join alarmorion_orionalarmclass b on a.alarmclass = b.id
left join ref_err_device c on trim(b.alarmClass) = c.deviceType
left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
left join power_station ps on ps.`Code` = site_id
left join operation_record pr on pr.ErrorCode = a.id
where sourceState = 1 and datestamp > '{System.DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd")}' and ps.`Code` is not null
) a LEFT JOIN notice_schedule ns ON a.id = ns.ExceptionId
WHERE ns.Id IS NULL
order by a.id desc limit 1000";
List<ExceptionEmailInfo> ds = conn.Query<ExceptionEmailInfo>(sql, commandTimeout: 600).AsList<ExceptionEmailInfo>();
conn.Close();
return ds;
}
}
catch (Exception ex)
{
throw ex;
}
}
public List<NoticeInfo> QueryNoticeData()
{
try
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = $@"select * from notice_schedule order by 1 desc limit 1000";
List<NoticeInfo> ds = conn.Query<NoticeInfo>(sql, commandTimeout: 600).AsList<NoticeInfo>();
conn.Close();
return ds;
}
}
catch (Exception ex)
{
throw ex;
}
}
public List<AlarmorionInfo> QueryAlarmorion_orionalarmrecordData()
{
try
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = $@"select a.*, FROM_UNIXTIME((a.`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') timestamp2
from alarmorion_orionalarmrecord a
order by 1 desc limit 1000";
List<AlarmorionInfo> ds = conn.Query<AlarmorionInfo>(sql, commandTimeout: 600).AsList<AlarmorionInfo>();
conn.Close();
return ds;
}
}
catch (Exception ex)
{
throw ex;
}
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@ namespace solarApp
get_inv_svc inv_svc = new get_inv_svc(); get_inv_svc inv_svc = new get_inv_svc();
getStationSvc stationSvc = new getStationSvc(); getStationSvc stationSvc = new getStationSvc();
getSensorSvc sensorSvc = new getSensorSvc(); getSensorSvc sensorSvc = new getSensorSvc();
procSyncError errorSvc = new procSyncError(); // 異常資料
public fmMain() public fmMain()
{ {
InitializeComponent(); InitializeComponent();
@ -28,12 +29,12 @@ namespace solarApp
//string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd"); //string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd");
string date1 = dtselect_inv.Value.AddDays(-7).ToString("yyyy-MM-dd"); string date1 = dtselect_inv.Value.AddDays(-7).ToString("yyyy-MM-dd");
gv_fic_inv_raw.DataSource = ""; gv_fic_inv_raw.DataSource = "";
gv_fic_inv_hour.DataSource = ""; //gv_fic_inv_hour.DataSource = "";
try try
{ {
gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(date2, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text); gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(date2, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(date2, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text); //gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(date2, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -155,18 +156,18 @@ namespace solarApp
private void gv_fic_inv_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) private void gv_fic_inv_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{ {
//int rowindex = e.RowIndex; e.ColumnIndex ////int rowindex = e.RowIndex; e.ColumnIndex
if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString())) //if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString()))
{
if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12")
{
gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
}
}
//else
//{ //{
// gv_fic_inv_hour.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = gv_fic_inv_hour.DefaultCellStyle; // if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12")
// {
// gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
// }
//} //}
////else
////{
//// gv_fic_inv_hour.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = gv_fic_inv_hour.DefaultCellStyle;
////}
} }
@ -214,11 +215,11 @@ namespace solarApp
//string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd"); //string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd");
string date1 = dtSelect_sensor1.Value.AddDays(-7).ToString("yyyy-MM-dd"); string date1 = dtSelect_sensor1.Value.AddDays(-7).ToString("yyyy-MM-dd");
gv_fic_sensor_raw.DataSource = ""; gv_fic_sensor_raw.DataSource = "";
gv_fic_sensor_hour.DataSource = ""; //gv_fic_sensor_hour.DataSource = "";
try try
{ {
gv_fic_sensor_raw.DataSource = sensorSvc.get_sensor_raw(date2, lbSiteDB_inv.Text, lbSiteID_inv.Text); gv_fic_sensor_raw.DataSource = sensorSvc.get_sensor_raw(date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_sensor_hour.DataSource = sensorSvc.get_sensor_raw_hour(date2, lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 11)); //gv_fic_sensor_hour.DataSource = sensorSvc.get_sensor_raw_hour(date2, lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 11));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -246,13 +247,13 @@ namespace solarApp
private void gv_fic_sensor_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) private void gv_fic_sensor_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{ {
if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString())) //if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString()))
{ //{
if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12") // if (gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12")
{ // {
gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; // gv_fic_sensor_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
} // }
} //}
} }
private void gv_web_inv_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) private void gv_web_inv_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
@ -298,5 +299,46 @@ namespace solarApp
} }
} }
} }
private void button1_Click_1(object sender, EventArgs e)
{
gv_all_data.DataSource = "";
gv_notice_data.DataSource = "";
try
{
gv_all_data.DataSource = errorSvc.QueryExceptionData();
gv_notice_data.DataSource = errorSvc.QueryNoticeData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void gv_notice_test_data_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//if (gv_notice_test_data.Rows[e.RowIndex].Cells[0].Value != null && !string.IsNullOrWhiteSpace(gv_notice_test_data.Rows[e.RowIndex].Cells[0].Value.ToString()))
//{
// if (gv_notice_test_data.Rows[e.RowIndex].Cells[0].Value.ToString() != "0")
// {
// gv_notice_test_data.Rows[e.RowIndex].Cells[0].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
// }
//}
}
private void button1_Click_2(object sender, EventArgs e)
{
if(label13.Text == "solar_master.notice_schedule資料表")
{
gv_notice_data.DataSource = errorSvc.QueryAlarmorion_orionalarmrecordData();
label13.Text = "solar_master.notice_schedule資料表";
}
else
{
gv_notice_data.DataSource = errorSvc.QueryNoticeData();
label13.Text = "solar_master.alarmorion_orionalarmrecord資料表";
}
}
} }
} }