[BackendWorkerService]修改水電月歸檔最後一天沒紀錄的問題
This commit is contained in:
parent
6c50bdb071
commit
0929c6f21a
@ -188,8 +188,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
// 每日資料製作
|
||||
await day_proc(procEletricMeterService, saveToMSDB, archiveResponse, electricDeviceNumberPoints, waterDeviceNumberPoints, obixApiConfig, encoded, startDay, endDay, dbDateName);
|
||||
|
||||
//}
|
||||
|
||||
//}
|
||||
//}
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "任務完成0927");
|
||||
}
|
||||
@ -207,8 +207,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
archiveResponse.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion 天歸檔
|
||||
@ -646,7 +646,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
//抓取每個設備的資料
|
||||
List<Dictionary<string, object>> electricArchiveMonthRawDatas = new List<Dictionary<string, object>>();
|
||||
List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
|
||||
|
||||
|
||||
|
||||
//收集 niagara 電錶 Data
|
||||
procEletricMeterService.obixData_collect_range(xmlDocument, electricDeviceNumberPoints, obixApiConfig, encoded, electricArchiveMonthRawDatas);
|
||||
@ -799,6 +799,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
{
|
||||
var sql = $@"
|
||||
UPDATE archive_electric_meter_month SET
|
||||
start_timestamp = @start_timestamp,
|
||||
end_timestamp = @end_timestamp,
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
@ -846,6 +848,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_electric_meter_month SET
|
||||
start_timestamp = @start_timestamp,
|
||||
end_timestamp = @end_timestamp,
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
@ -892,7 +896,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
@fail_reason)
|
||||
END
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
COMMIT TRANSACTION;";
|
||||
|
||||
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveMonthRawDatas);
|
||||
|
||||
@ -906,6 +910,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
{
|
||||
var sql = $@"
|
||||
UPDATE archive_water_meter_month SET
|
||||
start_timestamp = @start_timestamp,
|
||||
end_timestamp = @end_timestamp,
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
@ -952,6 +958,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_water_meter_month SET
|
||||
start_timestamp = @start_timestamp,
|
||||
end_timestamp = @end_timestamp,
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
@ -998,7 +1006,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
@fail_reason)
|
||||
END
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
COMMIT TRANSACTION;";
|
||||
|
||||
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveMonthRawDatas);
|
||||
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||
@ -1059,10 +1067,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
private async Task day_proc( ProcEletricMeterService procEletricMeterService, string saveToMSDB, HttpWebResponse archiveResponse, List<DeviceNumberPoint> electricDeviceNumberPoints, List<DeviceNumberPoint> waterDeviceNumberPoints, ObixApiConfig obixApiConfig, string encoded, DateTime startDay, DateTime endDay, string dbDateName)
|
||||
{
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
|
||||
// --------- 需要變成指定日期 ----------------
|
||||
|
||||
|
||||
// PT2D 需要設定超過1天
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@ -1178,7 +1186,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
//異常設備 update
|
||||
string sql2 = string.Empty;
|
||||
foreach (var kv in dicError)
|
||||
{
|
||||
{
|
||||
sql2 += $@"update device set archive_lastDate = '{kv.Value}', archive_lastActionDate = now() where device_number = '{kv.Key}' ;";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sql2))
|
||||
@ -1188,7 +1196,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
logger.LogInformation("run sql electericArchiveDayRawDatas.Count() = " + electericArchiveDayRawDatas.Count());
|
||||
|
||||
|
||||
|
||||
foreach (var row in electericArchiveDayRawDatas)
|
||||
{
|
||||
row.TryGetValue("@start_timestamp", out var yyyymmData);
|
||||
@ -1329,7 +1337,11 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
#endregion
|
||||
}
|
||||
if (waterArchiveDayRawDatas.Count() > 0)
|
||||
{
|
||||
foreach (var row in waterArchiveDayRawDatas)
|
||||
{
|
||||
row.TryGetValue("@start_timestamp", out var yyyymmData);
|
||||
dbDateName = System.DateTime.Parse(yyyymmData.ToString()).ToString("yyyyMM");
|
||||
var sql = $@" UPDATE archive_water_meter_day_{dbDateName} SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
@ -1470,7 +1482,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveDayRawDatas);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1558,7 +1571,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
// #endregion 水電錶作業 save to DB end
|
||||
//}
|
||||
|
||||
private bool initWork(string dbDateName)
|
||||
private bool initWork(string dbDateName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -1603,9 +1616,9 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("【initWork】【任務失敗】");
|
||||
logger.LogError("【initWork】【任務失敗】[Exception]:{0}", exception.ToString());
|
||||
}
|
||||
|
||||
logger.LogError("【initWork】【任務失敗】[Exception]:{0}", exception.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ using BackendWorkerService.Quartz.Jobs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
|
||||
namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
@ -319,7 +320,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
else
|
||||
{ //不同天為新格式 採用 Start_timestamp
|
||||
endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Parse(error_day.Start_timestamp).AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
}
|
||||
}
|
||||
|
||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
<abstime name='start' val='{startTimestamp}' />
|
||||
@ -390,7 +391,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 天】【任務失敗】Device_number=" + error_day.Device_number + " point = " + error_day.Point + " date =" + error_day + " startTimestamp" + startTimestamp + " endTimestamp =" + endTimestamp);
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 天】【任務失敗】[Exception]:{0}", ex.ToString() + Environment.NewLine );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (electricArchiveDayRawDatas.Count() > 0)
|
||||
@ -410,7 +411,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
//先清空 該月份的數據
|
||||
string sql = @$"update archive_electric_meter_month set count_rawdata = 0, kwh_result = 0, max_rawdata = 0,
|
||||
min_rawdata = 0, repeat_times = 0, is_complete = 0, fail_reason = null, updated_at = null
|
||||
where `point` = 'KWH' and date(start_timestamp) = CONCAT('{yyyy}-{mm}', '-01'); ";
|
||||
where `point` = 'KWH' and date(start_timestamp) = CONCAT('{yyyy}-{mm}', '-01'); ";
|
||||
|
||||
try
|
||||
{
|
||||
@ -436,8 +437,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
//await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Compensate", ex.ToString());
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 月總計】【任務失敗】");
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 月總計】【任務失敗】[Exception]:{0}", ex.ToString() + Environment.NewLine + sql);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -567,7 +568,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
//var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_week.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
|
||||
//var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
|
||||
var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
//var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("dd/MM/yyyy").Replace(" ", "T"));
|
||||
@ -661,7 +662,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
//var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
|
||||
//var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_week.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_week.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
<abstime name='start' val='{startTimestamp}' />
|
||||
@ -757,7 +758,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
// //var startTimestamp = string.Format("{0}+08:00", error_month.Start_timestamp.Replace(" ", "T"));
|
||||
// //var endTimestamp = string.Format("{0}+08:00", error_month.End_timestamp.Replace(" ", "T"));
|
||||
// var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_month.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
|
||||
// var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_month.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
// var startDateTime = Convert.ToDateTime(error_month.Start_timestamp);
|
||||
@ -995,8 +996,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
//logger.LogInformation(@$"obix query for {deviceNumberPoint.DeviceNumber} day = {day.ToString("yyyy-MM-dd")}");
|
||||
|
||||
var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
var eDay = string.Format("{0}T00:00:10.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
var eDay = string.Format("{0}T00:01:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
|
||||
string historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
<abstime name='start' val='{sDay}' />
|
||||
@ -1019,7 +1020,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
// logger.LogInformation($@"url= {$"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/" + Environment.NewLine} {device_number} station = {station} task= {startDay} ~ {endDay} action ={sDay} ~ {eDay}"); // ----------- log
|
||||
// logger.LogInformation($@"url= {$"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/" + Environment.NewLine} {device_number} station = {station} task= {startDay} ~ {endDay} action ={sDay} ~ {eDay}"); // ----------- log
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
@ -1043,7 +1044,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveDayJsonResult); archiveJsonResult
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveJsonResult);
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveJsonResult);
|
||||
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
|
||||
archiveDayRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
archiveDayRawData.Add("@point", deviceNumberPoint.Point);
|
||||
@ -1085,9 +1086,9 @@ namespace BackendWorkerService.Services.Implement
|
||||
if (!dicError.ContainsKey(deviceNumberPoint.DeviceNumber))
|
||||
{
|
||||
dicError.Add(deviceNumberPoint.DeviceNumber, day.ToString("yyyy-MM-dd")); //記錄異常設備與日期
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1126,96 +1127,105 @@ namespace BackendWorkerService.Services.Implement
|
||||
var endDay = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||
|
||||
logger.LogInformation($@"before startDay = {startDay} endDay={endDay}"); // ----------- log
|
||||
|
||||
|
||||
#region
|
||||
//foreach (DateTime day in EachMonth(startDay , endDay))
|
||||
//{
|
||||
// 需要比原定日期增加 1天:因 Niagara 內部判斷為 < lastData, 並未包含結束當天 add by jiahao @2023-09-16
|
||||
//var dayInMonth = DateTime.DaysInMonth(day.Year, day.Month) +1; 、、(DateTime.Now - DateTime.Parse(startDay)).Days
|
||||
DateTime today = DateTime.Now;
|
||||
var dayInMonth = (DateTime.Now - DateTime.Parse(today.ToString("yyyy-MM-") + "01")).Days + 1;
|
||||
// 需要比原定日期增加 1天:因 Niagara 內部判斷為 < lastData, 並未包含結束當天 add by jiahao @2023-09-16
|
||||
//var dayInMonth = DateTime.DaysInMonth(day.Year, day.Month) +1; 、、(DateTime.Now - DateTime.Parse(startDay)).Days
|
||||
DateTime today = DateTime.Now;
|
||||
|
||||
var preDay = today.AddDays(-1); //取得前一天
|
||||
|
||||
var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month);
|
||||
var FirstDay = new DateTime(preDay.Year, preDay.Month, 1);
|
||||
var LastDay = today;
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
||||
var endTimestamp = string.Format("{0}T00:01:00.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||
|
||||
//var dayInMonth = (DateTime.Now - DateTime.Parse(today.ToString("yyyy-MM-") + "01")).Days + 1;
|
||||
|
||||
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", today.ToString("yyyy-MM-") + "01");
|
||||
//var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||
//var endTimestamp = string.Format("{0}T00:00:10.000+08:00", day.AddMonths(1).ToString("yyyy-MM-") + "01"); // by jiahao @2023-09-26
|
||||
var endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Now.ToString("yyyy-MM-dd")); // by jiahao @2023-10-03
|
||||
//var startTimestamp = string.Format("{0}T00:00:00.000+08:00", today.ToString("yyyy-MM-") + "01");
|
||||
////var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||
////var endTimestamp = string.Format("{0}T00:00:10.000+08:00", day.AddMonths(1).ToString("yyyy-MM-") + "01"); // by jiahao @2023-09-26
|
||||
//var endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Now.ToString("yyyy-MM-dd")); // by jiahao @2023-10-03
|
||||
|
||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
<abstime name='start' val='{startTimestamp}' />
|
||||
<abstime name='end' val='{endTimestamp}' />
|
||||
<reltime name='interval' val = 'PT{dayInMonth.ToString()}D' />
|
||||
<reltime name='interval' val = 'PT{(dayInMonth+1).ToString()}D' />
|
||||
</obj>";
|
||||
|
||||
|
||||
string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
|
||||
var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
||||
|
||||
string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
|
||||
var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
||||
device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}'
|
||||
and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}'
|
||||
and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
|
||||
and device_point_name = '{device_number.Split("_")[8]}'").Result;
|
||||
HttpWebRequest archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
HttpWebRequest archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
}
|
||||
|
||||
var archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
var archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
archiveResponse.Dispose();
|
||||
archiveResponse.Close();
|
||||
|
||||
//logger.LogInformation(@$"【ArchiveElectricMeterMonth】{device_number} startTimestamp={startTimestamp} endTimestamp= {endTimestamp} interval = PT{dayInMonth.ToString()}D url = {$"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"}");
|
||||
|
||||
|
||||
xmlDocument.LoadXml(archiveResponseContent);
|
||||
var archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
var archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
|
||||
|
||||
//if (device_number == "NTPC_D8_EE_E4_RF_Total_WHT_N1" || device_number == "NTPC_D8_EE_E4_RF_H2_WHT_N1")
|
||||
//{
|
||||
logger.LogError(@$"{device_number} json = {archiveJsonResult}");
|
||||
//}
|
||||
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
{
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveDayJsonResult);
|
||||
|
||||
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
|
||||
archiveDayRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
archiveDayRawData.Add("@point", deviceNumberPoint.Point);
|
||||
archiveDayRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
archiveDayRawData.Add("@is_complete", 0);
|
||||
archiveDayRawData.Add("@repeat_times", 0);
|
||||
archiveDayRawData.Add("@fail_reason", archiveJson);
|
||||
|
||||
archiveDayRawData.Add("@count_rawdata", 0);
|
||||
archiveDayRawData.Add("@min_rawdata", 0);
|
||||
archiveDayRawData.Add("@max_rawdata", 0);
|
||||
archiveDayRawData.Add("@avg_rawdata", 0);
|
||||
archiveDayRawData.Add("@sum_rawdata", 0);
|
||||
archiveDayRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
resultArchiveDayRawDatas.Add(archiveDayRawData);
|
||||
}
|
||||
|
||||
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
{
|
||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult, ref dicError);
|
||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
{
|
||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
}
|
||||
|
||||
var archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
var archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
archiveResponse.Dispose();
|
||||
archiveResponse.Close();
|
||||
|
||||
//logger.LogInformation(@$"【ArchiveElectricMeterMonth】{device_number} startTimestamp={startTimestamp} endTimestamp= {endTimestamp} interval = PT{dayInMonth.ToString()}D url = {$"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"}");
|
||||
|
||||
|
||||
xmlDocument.LoadXml(archiveResponseContent);
|
||||
var archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
var archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
|
||||
|
||||
//if (device_number == "NTPC_D8_EE_E4_RF_Total_WHT_N1" || device_number == "NTPC_D8_EE_E4_RF_H2_WHT_N1")
|
||||
//{
|
||||
logger.LogError(@$"{device_number} json = {archiveJsonResult}");
|
||||
//}
|
||||
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
{
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
|
||||
//logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveDayJsonResult);
|
||||
|
||||
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
|
||||
archiveDayRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
archiveDayRawData.Add("@point", deviceNumberPoint.Point);
|
||||
archiveDayRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
archiveDayRawData.Add("@is_complete", 0);
|
||||
archiveDayRawData.Add("@repeat_times", 0);
|
||||
archiveDayRawData.Add("@fail_reason", archiveJson);
|
||||
|
||||
archiveDayRawData.Add("@count_rawdata", 0);
|
||||
archiveDayRawData.Add("@min_rawdata", 0);
|
||||
archiveDayRawData.Add("@max_rawdata", 0);
|
||||
archiveDayRawData.Add("@avg_rawdata", 0);
|
||||
archiveDayRawData.Add("@sum_rawdata", 0);
|
||||
archiveDayRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
resultArchiveDayRawDatas.Add(archiveDayRawData);
|
||||
}
|
||||
|
||||
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
{
|
||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult, ref dicError);
|
||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
{
|
||||
resultArchiveDayRawDatas.AddRange(ArrangeRawDatas);
|
||||
}
|
||||
resultArchiveDayRawDatas.AddRange(ArrangeRawDatas);
|
||||
}
|
||||
}
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
@ -1307,7 +1317,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
arrangeRawData.Add("@is_complete", 1);
|
||||
arrangeRawData.Add("@repeat_times", 0);
|
||||
arrangeRawData.Add("@fail_reason", null);
|
||||
@ -1407,7 +1417,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
/// <param name="thru"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<DateTime> EachDay(string from, string thru)
|
||||
{
|
||||
{
|
||||
var strtday = DateTime.Parse(from).AddDays(-1); //每次重做 2天
|
||||
var endday = DateTime.Parse(thru);
|
||||
for (var day = strtday.Date; day.Date <= endday.Date; day = day.AddDays(1))
|
||||
|
Loading…
Reference in New Issue
Block a user