Revert "[前台] 修改即時告警table render 問題"

This reverts commit 40ba482d70.
This commit is contained in:
dev02 2023-06-07 12:17:09 +08:00
parent 40ba482d70
commit 7f010ddb97
3 changed files with 89 additions and 138 deletions

View File

@ -18,10 +18,10 @@
"Port": "js2LutKe+rdjzdxMPQUrvQ==", "Port": "js2LutKe+rdjzdxMPQUrvQ==",
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
//"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome "Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
//"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office
"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
"Password": "FVAPxztxpY4gJJKQ/se4bQ==" "Password": "FVAPxztxpY4gJJKQ/se4bQ=="
}, },

View File

@ -55,20 +55,13 @@ namespace BackendWorkerService.Quartz.Jobs
EDFunction ed = new EDFunction(); EDFunction ed = new EDFunction();
XmlDocument xmlDocument = new XmlDocument(); XmlDocument xmlDocument = new XmlDocument();
ServicePointManager.DefaultConnectionLimit = 10;
var sqlArchive = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'archiveConfig'"; var sqlArchive = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'archiveConfig'";
var saveToMSDB = await backgroundServiceRepository.GetOneAsync<string>("select system_value from variable where system_type = 'save_to_ms_db' and deleted = 0"); var saveToMSDB = await backgroundServiceRepository.GetOneAsync<string>("select system_value from variable where system_type = 'save_to_ms_db' and deleted = 0");
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive); var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
var electricMeterGuid = variableArchive.Where(x => x.Name == "ElectricMeterGuid").Select(x => x.Value).FirstOrDefault(); var electricMeterGuid = variableArchive.Where(x => x.Name == "ElectricMeterGuid").Select(x => x.Value).FirstOrDefault();
var waterMeterGuid = variableArchive.Where(x => x.Name == "WaterMeterGuid").Select(x => x.Value).FirstOrDefault(); var waterMeterGuid = variableArchive.Where(x => x.Name == "WaterMeterGuid").Select(x => x.Value).FirstOrDefault();
#region http variable
HttpWebRequest archiveRequest = null;
HttpWebResponse archiveResponse = null;
string archiveResponseContent = null;
string archiveJson = null;
JObject archiveJsonResult = new JObject();
#endregion
#region #region
var sWhere = "deleted = 0 AND device_name_tag = @sub_system_guid"; var sWhere = "deleted = 0 AND device_name_tag = @sub_system_guid";
var electricMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere, new { sub_system_guid = electricMeterGuid }); var electricMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere, new { sub_system_guid = electricMeterGuid });
@ -154,29 +147,26 @@ namespace BackendWorkerService.Quartz.Jobs
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveDayRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveDayRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveDayRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveDayResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]{0}", archiveDayJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]{0}", archiveDayJsonResult);
@ -188,7 +178,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveDayRawData.Add("@is_complete", 0); archiveDayRawData.Add("@is_complete", 0);
archiveDayRawData.Add("@repeat_times", 0); archiveDayRawData.Add("@repeat_times", 0);
archiveDayRawData.Add("@fail_reason", archiveJson); archiveDayRawData.Add("@fail_reason", archiveDayJson);
archiveDayRawData.Add("@count_rawdata", 0); archiveDayRawData.Add("@count_rawdata", 0);
archiveDayRawData.Add("@min_rawdata", 0); archiveDayRawData.Add("@min_rawdata", 0);
@ -200,9 +190,9 @@ namespace BackendWorkerService.Quartz.Jobs
electericArchiveDayRawDatas.Add(archiveDayRawData); electericArchiveDayRawDatas.Add(archiveDayRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
electericArchiveDayRawDatas.AddRange(ArrangeRawDatas); electericArchiveDayRawDatas.AddRange(ArrangeRawDatas);
@ -212,29 +202,26 @@ namespace BackendWorkerService.Quartz.Jobs
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveDayRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveDayRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveDayRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveDayResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]{0}", archiveDayJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]{0}", archiveDayJsonResult);
@ -246,7 +233,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveDayRawData.Add("@is_complete", 0); archiveDayRawData.Add("@is_complete", 0);
archiveDayRawData.Add("@repeat_times", 0); archiveDayRawData.Add("@repeat_times", 0);
archiveDayRawData.Add("@fail_reason", archiveJson); archiveDayRawData.Add("@fail_reason", archiveDayJson);
archiveDayRawData.Add("@count_rawdata", 0); archiveDayRawData.Add("@count_rawdata", 0);
archiveDayRawData.Add("@min_rawdata", 0); archiveDayRawData.Add("@min_rawdata", 0);
@ -258,9 +245,9 @@ namespace BackendWorkerService.Quartz.Jobs
waterArchiveDayRawDatas.Add(archiveDayRawData); waterArchiveDayRawDatas.Add(archiveDayRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
waterArchiveDayRawDatas.AddRange(ArrangeRawDatas); waterArchiveDayRawDatas.AddRange(ArrangeRawDatas);
@ -586,14 +573,6 @@ namespace BackendWorkerService.Quartz.Jobs
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】"); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】");
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】[Exception]{0}", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】[Exception]{0}", exception.ToString());
} }
finally
{
if (archiveResponse != null)
{
archiveResponse.Dispose();
archiveResponse.Close();
}
}
} }
#endregion #endregion
@ -623,29 +602,26 @@ namespace BackendWorkerService.Quartz.Jobs
List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveWeekRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveWeekRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveWeekRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveWeekResponse = (HttpWebResponse)archiveWeekRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveWeekResponseContent = new StreamReader(archiveWeekResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveWeekResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveWeekJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveWeekJsonResult = (JObject)JsonConvert.DeserializeObject(archiveWeekJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveWeekJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]{0}", archiveWeekJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]{0}", archiveWeekJsonResult);
@ -657,7 +633,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveWeekRawData.Add("@is_complete", 0); archiveWeekRawData.Add("@is_complete", 0);
archiveWeekRawData.Add("@repeat_times", 0); archiveWeekRawData.Add("@repeat_times", 0);
archiveWeekRawData.Add("@fail_reason", archiveJson); archiveWeekRawData.Add("@fail_reason", archiveWeekJson);
archiveWeekRawData.Add("@count_rawdata", 0); archiveWeekRawData.Add("@count_rawdata", 0);
archiveWeekRawData.Add("@min_rawdata", 0); archiveWeekRawData.Add("@min_rawdata", 0);
@ -669,9 +645,9 @@ namespace BackendWorkerService.Quartz.Jobs
electricArchiveWeekRawDatas.Add(archiveWeekRawData); electricArchiveWeekRawDatas.Add(archiveWeekRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveWeekJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveWeekJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
electricArchiveWeekRawDatas.AddRange(ArrangeRawDatas); electricArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
@ -680,29 +656,26 @@ namespace BackendWorkerService.Quartz.Jobs
} }
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveWeekRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveWeekRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveWeekRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveWeekResponse = (HttpWebResponse)archiveWeekRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveWeekResponseContent = new StreamReader(archiveWeekResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveWeekResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveWeekJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveWeekJsonResult = (JObject)JsonConvert.DeserializeObject(archiveWeekJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveWeekJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]{0}", archiveWeekJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]{0}", archiveWeekJsonResult);
@ -714,7 +687,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveWeekRawData.Add("@is_complete", 0); archiveWeekRawData.Add("@is_complete", 0);
archiveWeekRawData.Add("@repeat_times", 0); archiveWeekRawData.Add("@repeat_times", 0);
archiveWeekRawData.Add("@fail_reason", archiveJson); archiveWeekRawData.Add("@fail_reason", archiveWeekJson);
archiveWeekRawData.Add("@count_rawdata", 0); archiveWeekRawData.Add("@count_rawdata", 0);
archiveWeekRawData.Add("@min_rawdata", 0); archiveWeekRawData.Add("@min_rawdata", 0);
@ -726,9 +699,9 @@ namespace BackendWorkerService.Quartz.Jobs
waterArchiveWeekRawDatas.Add(archiveWeekRawData); waterArchiveWeekRawDatas.Add(archiveWeekRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveWeekJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveWeekJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
waterArchiveWeekRawDatas.AddRange(ArrangeRawDatas); waterArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
@ -950,14 +923,6 @@ namespace BackendWorkerService.Quartz.Jobs
logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】"); logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】");
logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】[Exception]{0}", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】[Exception]{0}", exception.ToString());
} }
finally
{
if (archiveResponse != null)
{
archiveResponse.Dispose();
archiveResponse.Close();
}
}
} }
#endregion #endregion
@ -989,29 +954,26 @@ namespace BackendWorkerService.Quartz.Jobs
List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveMonthRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveMonthRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveMonthRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveMonthResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]{0}", archiveMonthJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]{0}", archiveMonthJsonResult);
@ -1023,7 +985,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveMonthRawData.Add("@is_complete", 0); archiveMonthRawData.Add("@is_complete", 0);
archiveMonthRawData.Add("@repeat_times", 0); archiveMonthRawData.Add("@repeat_times", 0);
archiveMonthRawData.Add("@fail_reason", archiveJson); archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
archiveMonthRawData.Add("@count_rawdata", 0); archiveMonthRawData.Add("@count_rawdata", 0);
archiveMonthRawData.Add("@min_rawdata", 0); archiveMonthRawData.Add("@min_rawdata", 0);
@ -1035,9 +997,9 @@ namespace BackendWorkerService.Quartz.Jobs
electricArchiveMonthRawDatas.Add(archiveMonthRawData); electricArchiveMonthRawDatas.Add(archiveMonthRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas); electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
@ -1046,29 +1008,26 @@ namespace BackendWorkerService.Quartz.Jobs
} }
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveMonthRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveMonthRequest.PreAuthenticate = true;
archiveRequest.Timeout = 3000;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveRequest.GetRequestStream()) using (Stream reqStream = archiveMonthRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); reqStream.Write(byteArray, 0, byteArray.Length);
} }
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse(); HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd(); var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
archiveResponse.Dispose();
archiveResponse.Close();
xmlDocument.LoadXml(archiveResponseContent); xmlDocument.LoadXml(archiveMonthResponseContent);
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument); string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson); JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤 if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
{ {
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】"); //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]{0}", archiveMonthJsonResult); //logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]{0}", archiveMonthJsonResult);
@ -1080,7 +1039,7 @@ namespace BackendWorkerService.Quartz.Jobs
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19)); archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
archiveMonthRawData.Add("@is_complete", 0); archiveMonthRawData.Add("@is_complete", 0);
archiveMonthRawData.Add("@repeat_times", 0); archiveMonthRawData.Add("@repeat_times", 0);
archiveMonthRawData.Add("@fail_reason", archiveJson); archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
archiveMonthRawData.Add("@count_rawdata", 0); archiveMonthRawData.Add("@count_rawdata", 0);
archiveMonthRawData.Add("@min_rawdata", 0); archiveMonthRawData.Add("@min_rawdata", 0);
@ -1092,9 +1051,9 @@ namespace BackendWorkerService.Quartz.Jobs
waterArchiveMonthRawDatas.Add(archiveMonthRawData); waterArchiveMonthRawDatas.Add(archiveMonthRawData);
} }
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容 if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{ {
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult); var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas); waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
@ -1309,14 +1268,6 @@ namespace BackendWorkerService.Quartz.Jobs
logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【任務失敗】"); logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【任務失敗】");
logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【任務失敗】[Exception]{0}", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【任務失敗】[Exception]{0}", exception.ToString());
} }
finally
{
if (archiveResponse != null)
{
archiveResponse.Dispose();
archiveResponse.Close();
}
}
} }
#endregion #endregion
@ -1326,7 +1277,7 @@ namespace BackendWorkerService.Quartz.Jobs
{ {
try try
{ {
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Compensate", "補償機制任務開始"); await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Compensate", "任務開始");
ProcEletricMeterService procEletricMeterService = new ProcEletricMeterService(backgroundServiceRepository, backgroundServiceMsSqlRepository); ProcEletricMeterService procEletricMeterService = new ProcEletricMeterService(backgroundServiceRepository, backgroundServiceMsSqlRepository);
await procEletricMeterService.ArchiveData(); await procEletricMeterService.ArchiveData();
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Compensate", "任務完成"); await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Compensate", "任務完成");

View File

@ -875,7 +875,7 @@
{ {
"title": "設備名稱", "title": "設備名稱",
"data": "sourceName_zh", "data": "sourceName_zh",
"render" : function (data) { render: (data) => {
return allDevices.find(d => d.device_number === data)?.full_name || "" return allDevices.find(d => d.device_number === data)?.full_name || ""
} }
}, },