每天歸檔的資料需要先做 四捨五入
This commit is contained in:
parent
48a90ece43
commit
4f762c4201
@ -266,9 +266,9 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
var sql = $@" SET FOREIGN_KEY_CHECKS = 1;
|
||||
UPDATE archive_electric_meter_day_{dbDateName} SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
kwh_result = @max_rawdata - @min_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
@ -299,9 +299,9 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@max_rawdata - @min_rawdata,
|
||||
round(@min_rawdata, 2),
|
||||
round(@max_rawdata, 2) ,
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@ -351,9 +351,9 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
UPDATE archive_electric_meter_day_{dbDateName} SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
kwh_result = @max_rawdata - @min_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2) ,
|
||||
kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
@ -386,9 +386,9 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@max_rawdata - @min_rawdata
|
||||
round(@min_rawdata, 2),
|
||||
round(@max_rawdata, 2) ,
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@ -602,400 +602,400 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
#endregion 天歸檔
|
||||
|
||||
#region 週歸檔
|
||||
if (await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "Week"))
|
||||
{
|
||||
try
|
||||
{
|
||||
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Week", "水電表周任務開始");
|
||||
int week = Convert.ToInt32(actionDay.DayOfWeek);
|
||||
week = week == 0 ? 7 : week;
|
||||
//if (await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "Week"))
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Week", "水電表周任務開始");
|
||||
// int week = Convert.ToInt32(actionDay.DayOfWeek);
|
||||
// week = week == 0 ? 7 : week;
|
||||
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", actionDay.AddDays(1 - week).ToString("yyyy-MM-dd"));
|
||||
//var endTimestamp = string.Format("{0}T23:59:59.000+08:00", actionDay.AddDays(7 - week).ToString("yyyy-MM-dd"));
|
||||
var endTimestamp = string.Format("{0}T00:00:01.000+08:00", actionDay.AddDays(7 - week).ToString("yyyy-MM-dd"));
|
||||
// var startTimestamp = string.Format("{0}T00:00:00.000+08:00", actionDay.AddDays(1 - week).ToString("yyyy-MM-dd"));
|
||||
// //var endTimestamp = string.Format("{0}T23:59:59.000+08:00", actionDay.AddDays(7 - week).ToString("yyyy-MM-dd"));
|
||||
// var endTimestamp = string.Format("{0}T00:00:01.000+08:00", actionDay.AddDays(7 - week).ToString("yyyy-MM-dd"));
|
||||
|
||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
<abstime name='start' val='{startTimestamp}' />
|
||||
<abstime name='end' val='{endTimestamp}' />
|
||||
<reltime name='interval' val = 'PT8D' />
|
||||
</obj>";
|
||||
// var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||
// <abstime name='start' val='{startTimestamp}' />
|
||||
// <abstime name='end' val='{endTimestamp}' />
|
||||
// <reltime name='interval' val = 'PT8D' />
|
||||
// </obj>";
|
||||
|
||||
//Stopwatch stopWatch = new Stopwatch();
|
||||
//stopWatch.Start();
|
||||
// //Stopwatch stopWatch = new Stopwatch();
|
||||
// //stopWatch.Start();
|
||||
|
||||
//抓取每個設備的資料
|
||||
List<Dictionary<string, object>> electricArchiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
//電錶結果收集
|
||||
procEletricMeterService.obixData_collect(xmlDocument, electricDeviceNumberPoints, obixApiConfig, encoded, startTimestamp, endTimestamp, historyQueryFilter, electricArchiveWeekRawDatas);
|
||||
// //抓取每個設備的資料
|
||||
// List<Dictionary<string, object>> electricArchiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
// List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
// //電錶結果收集
|
||||
// procEletricMeterService.obixData_collect(xmlDocument, electricDeviceNumberPoints, obixApiConfig, encoded, startTimestamp, endTimestamp, historyQueryFilter, electricArchiveWeekRawDatas);
|
||||
|
||||
//水錶結果收集
|
||||
procEletricMeterService.obixData_collect(xmlDocument, waterDeviceNumberPoints, obixApiConfig, encoded, startTimestamp, endTimestamp, historyQueryFilter, waterArchiveWeekRawDatas);
|
||||
#region old request niagara obix data
|
||||
// //水錶結果收集
|
||||
// procEletricMeterService.obixData_collect(xmlDocument, waterDeviceNumberPoints, obixApiConfig, encoded, startTimestamp, endTimestamp, historyQueryFilter, waterArchiveWeekRawDatas);
|
||||
// #region old request niagara obix data
|
||||
|
||||
//foreach (var deviceNumberPoint in electricDeviceNumberPoints)
|
||||
//{
|
||||
// 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;
|
||||
// if (string.IsNullOrEmpty(station))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
// //HttpWebRequest archiveWeekRequest = (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;
|
||||
// //foreach (var deviceNumberPoint in electricDeviceNumberPoints)
|
||||
// //{
|
||||
// // 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;
|
||||
// // if (string.IsNullOrEmpty(station))
|
||||
// // {
|
||||
// // continue;
|
||||
// // }
|
||||
// // archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
// // //HttpWebRequest archiveWeekRequest = (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())
|
||||
// {
|
||||
// reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
// }
|
||||
// // byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
// // using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
// // {
|
||||
// // reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
// // }
|
||||
|
||||
// archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
// archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
// archiveResponse.Dispose();
|
||||
// archiveResponse.Close();
|
||||
// // archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
// // archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
// // archiveResponse.Dispose();
|
||||
// // archiveResponse.Close();
|
||||
|
||||
// xmlDocument.LoadXml(archiveResponseContent);
|
||||
// archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
// archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
// // xmlDocument.LoadXml(archiveResponseContent);
|
||||
// // archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
// // archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
|
||||
// if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
// {
|
||||
// //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
|
||||
// //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveWeekJsonResult);
|
||||
// // if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
// // {
|
||||
// // //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
|
||||
// // //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveWeekJsonResult);
|
||||
|
||||
// Dictionary<string, object> archiveWeekRawData = new Dictionary<string, object>();
|
||||
// archiveWeekRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
// archiveWeekRawData.Add("@point", deviceNumberPoint.Point);
|
||||
// archiveWeekRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// archiveWeekRawData.Add("@is_complete", 0);
|
||||
// archiveWeekRawData.Add("@repeat_times", 0);
|
||||
// archiveWeekRawData.Add("@fail_reason", archiveJson);
|
||||
// // Dictionary<string, object> archiveWeekRawData = new Dictionary<string, object>();
|
||||
// // archiveWeekRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
// // archiveWeekRawData.Add("@point", deviceNumberPoint.Point);
|
||||
// // archiveWeekRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// // archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// // archiveWeekRawData.Add("@is_complete", 0);
|
||||
// // archiveWeekRawData.Add("@repeat_times", 0);
|
||||
// // archiveWeekRawData.Add("@fail_reason", archiveJson);
|
||||
|
||||
// archiveWeekRawData.Add("@count_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@min_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@max_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@avg_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@sum_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
// // archiveWeekRawData.Add("@count_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@min_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@max_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@avg_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@sum_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
// electricArchiveWeekRawDatas.Add(archiveWeekRawData);
|
||||
// }
|
||||
// // electricArchiveWeekRawDatas.Add(archiveWeekRawData);
|
||||
// // }
|
||||
|
||||
// if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
// {
|
||||
// var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||
// if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
// {
|
||||
// electricArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||
//{
|
||||
// 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;
|
||||
// archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
// //HttpWebRequest archiveWeekRequest = (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;
|
||||
// // if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
// // {
|
||||
// // var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||
// // if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
// // {
|
||||
// // electricArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
// //foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||
// //{
|
||||
// // 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;
|
||||
// // archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||
// // //HttpWebRequest archiveWeekRequest = (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())
|
||||
// {
|
||||
// reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
// }
|
||||
// // byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
// // using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
// // {
|
||||
// // reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
// // }
|
||||
|
||||
// archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
// archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
// archiveResponse.Dispose();
|
||||
// archiveResponse.Close();
|
||||
// // archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
// // archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
// // archiveResponse.Dispose();
|
||||
// // archiveResponse.Close();
|
||||
|
||||
// xmlDocument.LoadXml(archiveResponseContent);
|
||||
// archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
// archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
// // xmlDocument.LoadXml(archiveResponseContent);
|
||||
// // archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
// // archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
|
||||
// if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
// {
|
||||
// //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
|
||||
// //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveWeekJsonResult);
|
||||
// // if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
// // {
|
||||
// // //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】");
|
||||
// // //logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveWeekJsonResult);
|
||||
|
||||
// Dictionary<string, object> archiveWeekRawData = new Dictionary<string, object>();
|
||||
// archiveWeekRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
// archiveWeekRawData.Add("@point", deviceNumberPoint.Point);
|
||||
// archiveWeekRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// archiveWeekRawData.Add("@is_complete", 0);
|
||||
// archiveWeekRawData.Add("@repeat_times", 0);
|
||||
// archiveWeekRawData.Add("@fail_reason", archiveJson);
|
||||
// // Dictionary<string, object> archiveWeekRawData = new Dictionary<string, object>();
|
||||
// // archiveWeekRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||
// // archiveWeekRawData.Add("@point", deviceNumberPoint.Point);
|
||||
// // archiveWeekRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// // archiveWeekRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||
// // archiveWeekRawData.Add("@is_complete", 0);
|
||||
// // archiveWeekRawData.Add("@repeat_times", 0);
|
||||
// // archiveWeekRawData.Add("@fail_reason", archiveJson);
|
||||
|
||||
// archiveWeekRawData.Add("@count_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@min_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@max_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@avg_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@sum_rawdata", 0);
|
||||
// archiveWeekRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
// // archiveWeekRawData.Add("@count_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@min_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@max_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@avg_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@sum_rawdata", 0);
|
||||
// // archiveWeekRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
// waterArchiveWeekRawDatas.Add(archiveWeekRawData);
|
||||
// }
|
||||
// // waterArchiveWeekRawDatas.Add(archiveWeekRawData);
|
||||
// // }
|
||||
|
||||
// if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
// {
|
||||
// var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||
// if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
// {
|
||||
// waterArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
// // if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
// // {
|
||||
// // var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||
// // if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
// // {
|
||||
// // waterArchiveWeekRawDatas.AddRange(ArrangeRawDatas);
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
// #endregion
|
||||
|
||||
//stopWatch.Stop();
|
||||
//logger.LogInformation("【ArchiveElectricMeterDayJob】【週歸檔】【效能檢驗】[取得資料花費時間]{0} 毫秒", stopWatch.ElapsedMilliseconds);
|
||||
// //stopWatch.Stop();
|
||||
// //logger.LogInformation("【ArchiveElectricMeterDayJob】【週歸檔】【效能檢驗】[取得資料花費時間]{0} 毫秒", stopWatch.ElapsedMilliseconds);
|
||||
|
||||
if (electricArchiveWeekRawDatas.Count() > 0)
|
||||
{
|
||||
var sql = $@"
|
||||
UPDATE archive_electric_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2)
|
||||
max_rawdata = round(@max_rawdata, 2)
|
||||
kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
// if (electricArchiveWeekRawDatas.Count() > 0)
|
||||
// {
|
||||
// var sql = $@"
|
||||
// UPDATE archive_electric_meter_week SET
|
||||
// count_rawdata = @count_rawdata,
|
||||
// min_rawdata = round(@min_rawdata, 2)
|
||||
// max_rawdata = round(@max_rawdata, 2)
|
||||
// kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// avg_rawdata = @avg_rawdata,
|
||||
// sum_rawdata = @sum_rawdata,
|
||||
// is_complete = @is_complete,
|
||||
// repeat_times = @repeat_times,
|
||||
// fail_reason = @fail_reason,
|
||||
// updated_at = @updated_at
|
||||
// WHERE device_number = @device_number
|
||||
// AND point = @point
|
||||
// AND start_timestamp = @start_timestamp;
|
||||
|
||||
|
||||
INSERT INTO archive_electric_meter_week (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
kwh_result,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
round(@min_rawdata, 2),
|
||||
round(@max_rawdata, 2),
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;
|
||||
";
|
||||
// INSERT INTO archive_electric_meter_week (
|
||||
// device_number,
|
||||
// point,
|
||||
// start_timestamp,
|
||||
// end_timestamp,
|
||||
// count_rawdata,
|
||||
// min_rawdata,
|
||||
// max_rawdata,
|
||||
// kwh_result,
|
||||
// avg_rawdata,
|
||||
// sum_rawdata,
|
||||
// is_complete,
|
||||
// repeat_times,
|
||||
// fail_reason)
|
||||
// SELECT
|
||||
// @device_number,
|
||||
// @point,
|
||||
// @start_timestamp,
|
||||
// @end_timestamp,
|
||||
// @count_rawdata,
|
||||
// round(@min_rawdata, 2),
|
||||
// round(@max_rawdata, 2),
|
||||
// round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// @avg_rawdata,
|
||||
// @sum_rawdata,
|
||||
// @is_complete,
|
||||
// @repeat_times,
|
||||
// @fail_reason
|
||||
// WHERE ROW_COUNT() = 0;
|
||||
// ";
|
||||
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
// var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_electric_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
kwh_result = round(@min_rawdata, 2) - round(@max_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
// UPDATE archive_electric_meter_week SET
|
||||
// count_rawdata = @count_rawdata,
|
||||
// min_rawdata = round(@min_rawdata, 2),
|
||||
// max_rawdata = round(@max_rawdata, 2),
|
||||
// kwh_result = round(@min_rawdata, 2) - round(@max_rawdata, 2),
|
||||
// avg_rawdata = @avg_rawdata,
|
||||
// sum_rawdata = @sum_rawdata,
|
||||
// is_complete = @is_complete,
|
||||
// repeat_times = @repeat_times,
|
||||
// fail_reason = @fail_reason,
|
||||
// updated_at = @updated_at
|
||||
// WHERE device_number = @device_number
|
||||
// AND point = @point
|
||||
// AND start_timestamp = @start_timestamp;
|
||||
|
||||
IF @@ROWCOUNT = 0
|
||||
BEGIN
|
||||
INSERT INTO archive_electric_meter_week (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
kwh_result,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
VALUES (
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
round(@min_rawdata, 2),
|
||||
round(@max_rawdata, 2),
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason)
|
||||
END
|
||||
// IF @@ROWCOUNT = 0
|
||||
// BEGIN
|
||||
// INSERT INTO archive_electric_meter_week (
|
||||
// device_number,
|
||||
// point,
|
||||
// start_timestamp,
|
||||
// end_timestamp,
|
||||
// count_rawdata,
|
||||
// min_rawdata,
|
||||
// max_rawdata,
|
||||
// kwh_result,
|
||||
// avg_rawdata,
|
||||
// sum_rawdata,
|
||||
// is_complete,
|
||||
// repeat_times,
|
||||
// fail_reason)
|
||||
// VALUES (
|
||||
// @device_number,
|
||||
// @point,
|
||||
// @start_timestamp,
|
||||
// @end_timestamp,
|
||||
// @count_rawdata,
|
||||
// round(@min_rawdata, 2),
|
||||
// round(@max_rawdata, 2),
|
||||
// round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// @avg_rawdata,
|
||||
// @sum_rawdata,
|
||||
// @is_complete,
|
||||
// @repeat_times,
|
||||
// @fail_reason)
|
||||
// END
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveWeekRawDatas);
|
||||
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||
{
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveWeekRawDatas);
|
||||
}
|
||||
// COMMIT TRANSACTION;";
|
||||
// await backgroundServiceRepository.ExecuteSql(sql, electricArchiveWeekRawDatas);
|
||||
// if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||
// {
|
||||
// await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveWeekRawDatas);
|
||||
// }
|
||||
|
||||
}
|
||||
if (waterArchiveWeekRawDatas.Count() > 0)
|
||||
{
|
||||
var sql = $@" UPDATE archive_water_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
kwh_result = round(@min_rawdata, 2) - round(@max_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
// }
|
||||
// if (waterArchiveWeekRawDatas.Count() > 0)
|
||||
// {
|
||||
// var sql = $@" UPDATE archive_water_meter_week SET
|
||||
// count_rawdata = @count_rawdata,
|
||||
// min_rawdata = round(@min_rawdata, 2),
|
||||
// max_rawdata = round(@max_rawdata, 2),
|
||||
// kwh_result = round(@min_rawdata, 2) - round(@max_rawdata, 2),
|
||||
// avg_rawdata = @avg_rawdata,
|
||||
// sum_rawdata = @sum_rawdata,
|
||||
// is_complete = @is_complete,
|
||||
// repeat_times = @repeat_times,
|
||||
// fail_reason = @fail_reason,
|
||||
// updated_at = @updated_at
|
||||
// WHERE device_number = @device_number
|
||||
// AND point = @point
|
||||
// AND start_timestamp = @start_timestamp;
|
||||
|
||||
|
||||
INSERT INTO archive_water_meter_week (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
kwh_result,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
round(@min_rawdata, 2),
|
||||
round(@max_rawdata, 2),
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;
|
||||
";
|
||||
// INSERT INTO archive_water_meter_week (
|
||||
// device_number,
|
||||
// point,
|
||||
// start_timestamp,
|
||||
// end_timestamp,
|
||||
// count_rawdata,
|
||||
// min_rawdata,
|
||||
// max_rawdata,
|
||||
// kwh_result,
|
||||
// avg_rawdata,
|
||||
// sum_rawdata,
|
||||
// is_complete,
|
||||
// repeat_times,
|
||||
// fail_reason)
|
||||
// SELECT
|
||||
// @device_number,
|
||||
// @point,
|
||||
// @start_timestamp,
|
||||
// @end_timestamp,
|
||||
// @count_rawdata,
|
||||
// round(@min_rawdata, 2),
|
||||
// round(@max_rawdata, 2),
|
||||
// round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// @avg_rawdata,
|
||||
// @sum_rawdata,
|
||||
// @is_complete,
|
||||
// @repeat_times,
|
||||
// @fail_reason
|
||||
// WHERE ROW_COUNT() = 0;
|
||||
// ";
|
||||
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
// var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_water_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = round(@min_rawdata, 2),
|
||||
max_rawdata = round(@max_rawdata, 2),
|
||||
kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
// UPDATE archive_water_meter_week SET
|
||||
// count_rawdata = @count_rawdata,
|
||||
// min_rawdata = round(@min_rawdata, 2),
|
||||
// max_rawdata = round(@max_rawdata, 2),
|
||||
// kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// avg_rawdata = @avg_rawdata,
|
||||
// sum_rawdata = @sum_rawdata,
|
||||
// is_complete = @is_complete,
|
||||
// repeat_times = @repeat_times,
|
||||
// fail_reason = @fail_reason,
|
||||
// updated_at = @updated_at
|
||||
// WHERE device_number = @device_number
|
||||
// AND point = @point
|
||||
// AND start_timestamp = @start_timestamp;
|
||||
|
||||
IF @@ROWCOUNT = 0
|
||||
BEGIN
|
||||
INSERT INTO archive_water_meter_week (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
kwh_result,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
VALUES (
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
round(@min_rawdata,2) ,
|
||||
round(@max_rawdata,2) ,
|
||||
round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason)
|
||||
END
|
||||
// IF @@ROWCOUNT = 0
|
||||
// BEGIN
|
||||
// INSERT INTO archive_water_meter_week (
|
||||
// device_number,
|
||||
// point,
|
||||
// start_timestamp,
|
||||
// end_timestamp,
|
||||
// count_rawdata,
|
||||
// min_rawdata,
|
||||
// max_rawdata,
|
||||
// kwh_result,
|
||||
// avg_rawdata,
|
||||
// sum_rawdata,
|
||||
// is_complete,
|
||||
// repeat_times,
|
||||
// fail_reason)
|
||||
// VALUES (
|
||||
// @device_number,
|
||||
// @point,
|
||||
// @start_timestamp,
|
||||
// @end_timestamp,
|
||||
// @count_rawdata,
|
||||
// round(@min_rawdata,2) ,
|
||||
// round(@max_rawdata,2) ,
|
||||
// round(@max_rawdata, 2) - round(@min_rawdata, 2),
|
||||
// @avg_rawdata,
|
||||
// @sum_rawdata,
|
||||
// @is_complete,
|
||||
// @repeat_times,
|
||||
// @fail_reason)
|
||||
// END
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveWeekRawDatas);
|
||||
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||
{
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveWeekRawDatas);
|
||||
}
|
||||
}
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Week", "任務完成");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Week", exception.ToString());
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】");
|
||||
logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】[Exception]:{0}", exception.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (archiveResponse != null)
|
||||
{
|
||||
archiveResponse.Dispose();
|
||||
archiveResponse.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
// COMMIT TRANSACTION;";
|
||||
// await backgroundServiceRepository.ExecuteSql(sql, waterArchiveWeekRawDatas);
|
||||
// if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||
// {
|
||||
// await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveWeekRawDatas);
|
||||
// }
|
||||
// }
|
||||
// await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Week", "任務完成");
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Week", exception.ToString());
|
||||
// logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】");
|
||||
// logger.LogError("【ArchiveElectricMeterDayJob】【週歸檔】【任務失敗】[Exception]:{0}", exception.ToString());
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// if (archiveResponse != null)
|
||||
// {
|
||||
// archiveResponse.Dispose();
|
||||
// archiveResponse.Close();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion 週歸檔
|
||||
|
||||
#region 月歸檔
|
||||
|
@ -306,9 +306,17 @@ namespace BackendWorkerService.Services.Implement
|
||||
//var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
|
||||
//var startTimestamp = string.Format("{0}+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
|
||||
var endTimestamp = "";
|
||||
//var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
|
||||
var endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Parse(error_day.End_timestamp).AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
if (DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd") == DateTime.Parse(error_day.End_timestamp).ToString("yyyy-MM-dd"))
|
||||
{
|
||||
//同一天為 舊有格式 採用 endtime
|
||||
endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Parse(error_day.End_timestamp).AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
|
||||
}
|
||||
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}' />
|
||||
@ -334,42 +342,52 @@ namespace BackendWorkerService.Services.Implement
|
||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
}
|
||||
|
||||
HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse();
|
||||
var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
|
||||
|
||||
xmlDocument.LoadXml(archiveDayResponseContent);
|
||||
string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
|
||||
|
||||
if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
|
||||
archiveDayRawData.Add("@device_number", error_day.Device_number);
|
||||
archiveDayRawData.Add("@point", error_day.Point);
|
||||
archiveDayRawData.Add("@start_timestamp", DateTime.Parse(error_day.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveDayRawData.Add("@end_timestamp", DateTime.Parse(error_day.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveDayRawData.Add("@is_complete", 0);
|
||||
archiveDayRawData.Add("@repeat_times", ++error_day.Repeat_times);
|
||||
archiveDayRawData.Add("@fail_reason", archiveDayJson);
|
||||
HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse();
|
||||
var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
|
||||
|
||||
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"));
|
||||
xmlDocument.LoadXml(archiveDayResponseContent);
|
||||
string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
|
||||
electricArchiveDayRawDatas.Add(archiveDayRawData);
|
||||
}
|
||||
// logger.LogInformation( Environment.NewLine + " json = " + archiveDayJson + Environment.NewLine);
|
||||
|
||||
if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
{
|
||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
|
||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
|
||||
if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤
|
||||
{
|
||||
electricArchiveDayRawDatas.AddRange(ArrangeRawDatas);
|
||||
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
|
||||
archiveDayRawData.Add("@device_number", error_day.Device_number);
|
||||
archiveDayRawData.Add("@point", error_day.Point);
|
||||
archiveDayRawData.Add("@start_timestamp", DateTime.Parse(error_day.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveDayRawData.Add("@end_timestamp", DateTime.Parse(error_day.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveDayRawData.Add("@is_complete", 0);
|
||||
archiveDayRawData.Add("@repeat_times", ++error_day.Repeat_times);
|
||||
archiveDayRawData.Add("@fail_reason", archiveDayJson);
|
||||
|
||||
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"));
|
||||
|
||||
electricArchiveDayRawDatas.Add(archiveDayRawData);
|
||||
}
|
||||
|
||||
if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||
{
|
||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
|
||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||
{
|
||||
electricArchiveDayRawDatas.AddRange(ArrangeRawDatas);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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)
|
||||
@ -917,7 +935,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
logger.LogError("【ProcEletricMeterService】【補償機制 - 任務失敗】");
|
||||
logger.LogError("【ProcEletricMeterService】【補償機制 - 任務失敗】[Exception]:{0} {1}", exception.ToString());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -16,7 +16,7 @@
|
||||
"RegularUpdateDBTableJob": "0 0 2 * * ?",
|
||||
"ParkingJob": "0 0 2 * * ?",
|
||||
"ArchiveElectricMeterHourJob": "0 0 2 * * ?",
|
||||
"ArchiveElectricMeterDayJob": "0/5 * * * * ?", //每 5分鐘
|
||||
"ArchiveElectricMeterDayJob": "0/2 * * * * ?", //每 5分鐘
|
||||
"WeatherAPIJob": "0 0 2 * * ?"
|
||||
},
|
||||
"DBConfig": {
|
||||
|
@ -269,6 +269,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
RowPosition = 0;
|
||||
lastDeviceItem = d.type;
|
||||
sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}{"_" + d.type}");
|
||||
//sheet = workbook.CreateSheet($"{d.deviceName}{"_" + d.type}");
|
||||
#region set cell
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||
|
@ -132,6 +132,13 @@ namespace FrontendWebApi.ApiControllers
|
||||
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
|
||||
var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})";
|
||||
var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date";
|
||||
string date_yyyymmdd = "";
|
||||
switch (input.tableType)
|
||||
{
|
||||
case "day": date_yyyymmdd = @$" date(aemm.start_timestamp) = {aemmStaDate}"; break;
|
||||
case "month": date_yyyymmdd = @$" aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} "; break;
|
||||
case "year": date_yyyymmdd = @$" aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} "; break;
|
||||
}
|
||||
var sql = $@"set @i = -1;
|
||||
select fd.device_number, case when aemm.avg_rawdata = -1.0 then 'NaN' when aemm.avg_rawdata is null then 0.00 else aemm.avg_rawdata end as avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
|
||||
from (
|
||||
@ -156,7 +163,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
from {table}
|
||||
where start_timestamp >= '{startTime}' and end_timestamp < '{endTime}' and point = 'KWH' {buildingSql}
|
||||
{sqlWhere} {sqlGroup}
|
||||
) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number
|
||||
) aemm on {date_yyyymmdd} and aemm.device_number = fd.device_number
|
||||
join device dc on fd.device_number = dc.device_number
|
||||
where dc.deleted = 0
|
||||
order by fd.device_number, fd.date";
|
||||
@ -500,7 +507,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
if (r.Count > 0)
|
||||
{
|
||||
string buildingName = r.Select(x => x.building_name).FirstOrDefault();
|
||||
var sheet = workbook.CreateSheet($"{r.Select( x=> x.device_full_name).FirstOrDefault()} 電表報表");
|
||||
var sheet = workbook.CreateSheet($"{buildingName}");
|
||||
int RowPosition = 0;
|
||||
#region set cell
|
||||
IRow row = sheet.CreateRow(RowPosition);
|
||||
@ -603,7 +610,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
ms.Flush();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
return File(ms, "application/vnd.ms", @$"{building}_電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx");
|
||||
return File(ms, "application/vnd.ms", @$"電表報表_{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
Loading…
Reference in New Issue
Block a user