From 803d74d6454cbab65c222df61de71228b70dfe44 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 29 Jun 2023 11:21:36 +0800 Subject: [PATCH 1/7] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=AD=B7=E5=8F=B2=E8=B3=87=E6=96=99=E5=8C=AF=E5=87=BA,=20?= =?UTF-8?q?=E5=BE=8C=E5=8F=B0=E5=90=8C=E6=AD=A5station=E6=9B=B4=E6=8F=9B?= =?UTF-8?q?=20[=E5=89=8D=E7=AB=AF]=20=E5=A2=9E=E5=8A=A0loading=E7=95=8C?= =?UTF-8?q?=E9=9D=A2,=20=E4=BF=AE=E6=94=B9=E9=80=81=E5=87=BAniagara=20buil?= =?UTF-8?q?ding=5Ftag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Models/Mybase.cs | 6 + .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 10 +- .../Implement/ProcEletricMeterService.cs | 138 ++++--- Frontend/_historyData.html | 56 +-- .../ApiControllers/HistoryController.cs | 381 +++++++++++++++--- FrontendWebApi/Models/HistoryClass.cs | 43 +- .../excel/history/歷史資料_2023-06-29.xlsx | Bin 0 -> 2601389 bytes 7 files changed, 481 insertions(+), 153 deletions(-) create mode 100644 FrontendWebApi/wwwroot/excel/history/歷史資料_2023-06-29.xlsx diff --git a/Backend/Models/Mybase.cs b/Backend/Models/Mybase.cs index 254ec07..6732228 100644 --- a/Backend/Models/Mybase.cs +++ b/Backend/Models/Mybase.cs @@ -88,4 +88,10 @@ namespace Backend.Models public int Value { get; set; } //通常放id public string Name { get; set; } } + + public class BuildStation + { + public string system_value { get; set; } + public string system_key { get; set; } + } } diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 79bc6db..3de882a 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -61,6 +61,7 @@ namespace BackendWorkerService.Quartz.Jobs var variableArchive = await backgroundServiceRepository.GetAllAsync(sqlArchive); 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 buildingStation = await backgroundServiceRepository.GetAllAsync("select SUBSTRING_INDEX(system_value, '/', 1) system_value, system_key from variable where system_type = 'dashboard_total_elec' and deleted = 0 and (SUBSTRING_INDEX(system_value, '/', 1) != '' and SUBSTRING_INDEX(system_value, '/', 1) is not null)"); #region http variable HttpWebRequest archiveRequest = null; @@ -127,7 +128,6 @@ namespace BackendWorkerService.Quartz.Jobs obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault(); obixApiConfig.UserName = ed.AESDecrypt(variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault()); obixApiConfig.Password = ed.AESDecrypt(variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault()); - var station = await backgroundServiceRepository.GetOneAsync($@"select system_value from variable where system_type = 'obixStatus' and deleted = 0"); String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password)); #endregion 取得obix 設定 @@ -159,7 +159,7 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveDayRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { - + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; @@ -216,7 +216,7 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { - + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; @@ -628,6 +628,7 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveWeekRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; @@ -685,6 +686,7 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; @@ -993,6 +995,7 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveMonthRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; @@ -1049,6 +1052,7 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; diff --git a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs index a574ce1..a4dea3c 100644 --- a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs +++ b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs @@ -55,6 +55,7 @@ namespace BackendWorkerService.Services.Implement var variableArchive = await backgroundServiceRepository.GetAllAsync(sqlArchive); repeatTimes = Convert.ToInt32(variableArchive.Where(x => x.Name == "RepeatTimes").Select(x => x.Value).FirstOrDefault()); var saveToMSDB = await backgroundServiceRepository.GetOneAsync("select system_value from variable where system_type = 'save_to_ms_db' and deleted = 0"); + var buildingStation = await backgroundServiceRepository.GetAllAsync("select SUBSTRING_INDEX(system_value, '/', 1) system_value, system_key from variable where system_type = 'dashboard_total_elec' and deleted = 0 and (SUBSTRING_INDEX(system_value, '/', 1) != '' and SUBSTRING_INDEX(system_value, '/', 1) is not null)"); #region 取得obix 設定 var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; @@ -63,7 +64,6 @@ namespace BackendWorkerService.Services.Implement obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault(); obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); - var station = await backgroundServiceRepository.GetOneAsync($@"select system_value from variable where system_type = 'obixStatus' and deleted = 0"); encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password)); #endregion 取得obix 設定 @@ -280,6 +280,7 @@ namespace BackendWorkerService.Services.Implement "; + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveDayRequest.Method = "POST"; @@ -354,84 +355,85 @@ namespace BackendWorkerService.Services.Implement var water_error_days = await backgroundServiceRepository.GetAllAsync(sql_error_day, new { RepeatTimes = repeatTimes }); List> waterArchiveDayRawDatas = new List>(); if (water_error_days.Count() > 0) - { - foreach (var error_day in water_error_days) { - DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint(); - deviceNumberPoint.DeviceNumber = error_day.Device_number; - deviceNumberPoint.Point = error_day.Point; - deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point); - - var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T")); - var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T")); - var historyQueryFilter = $@" - - - - "; - - HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); - //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); - archiveDayRequest.Method = "POST"; - archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded); - archiveDayRequest.PreAuthenticate = true; - - byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); - using (Stream reqStream = archiveDayRequest.GetRequestStream()) + foreach (var error_day in water_error_days) { - reqStream.Write(byteArray, 0, byteArray.Length); - } + DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint(); + deviceNumberPoint.DeviceNumber = error_day.Device_number; + deviceNumberPoint.Point = error_day.Point; + deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point); - HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse(); - var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd(); + var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T")); + var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T")); + var historyQueryFilter = $@" + + + + "; - xmlDocument.LoadXml(archiveDayResponseContent); - string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument); - JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson); + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); + HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); + archiveDayRequest.Method = "POST"; + archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded); + archiveDayRequest.PreAuthenticate = true; - if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤 - { - Dictionary archiveDayRawData = new Dictionary(); - 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")); - - waterArchiveDayRawDatas.Add(archiveDayRawData); - } - - if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容 - { - var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult); - if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) + byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter); + using (Stream reqStream = archiveDayRequest.GetRequestStream()) { - waterArchiveDayRawDatas.AddRange(ArrangeRawDatas); + 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")) //抓取錯誤 + { + Dictionary archiveDayRawData = new Dictionary(); + 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")); + + waterArchiveDayRawDatas.Add(archiveDayRawData); + } + + if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容 + { + var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult); + if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0) + { + waterArchiveDayRawDatas.AddRange(ArrangeRawDatas); + } } } - } - if (waterArchiveDayRawDatas.Count() > 0) - { - var Mysql_error_update = string.Format(MYsql_update_format, targetTable); - var sql_error_update = string.Format(sql_update_format, targetTable); - if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") + if (waterArchiveDayRawDatas.Count() > 0) { - await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveDayRawDatas); + var Mysql_error_update = string.Format(MYsql_update_format, targetTable); + var sql_error_update = string.Format(sql_update_format, targetTable); + if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") + { + await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveDayRawDatas); + } + await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas); } - await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas); } } - } #endregion 天歸檔補償 #region 週歸檔補償 @@ -458,6 +460,7 @@ namespace BackendWorkerService.Services.Implement "; + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveWeekRequest.Method = "POST"; @@ -542,6 +545,7 @@ namespace BackendWorkerService.Services.Implement "; + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveWeekRequest.Method = "POST"; @@ -632,6 +636,7 @@ namespace BackendWorkerService.Services.Implement "; + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveMonthRequest.Method = "POST"; @@ -719,6 +724,7 @@ namespace BackendWorkerService.Services.Implement "; + var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault(); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveMonthRequest.Method = "POST"; diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index ca1da80..2c959c7 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -19,10 +19,8 @@
-
+
@@ -81,11 +79,14 @@ \ No newline at end of file From d13f5930a6070986632c4cc6820f550a9777a686 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 3 Jul 2023 12:29:46 +0800 Subject: [PATCH 3/7] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=AC=84=E4=BD=8D=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrontendWebApi/ApiControllers/HistoryController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 867a1b4..792507e 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -156,7 +156,7 @@ namespace FrontendWebApi.ApiControllers hed.type = devicePoint.Where(x => x.device_building_tag == d.building_tag && x.points == ard["@point"].ToString()).Select(x => x.full_name).FirstOrDefault(); hed.deviceName = device.Where(x => x.device_number == ard["@device_number"].ToString()).Select(x => x.full_name).FirstOrDefault(); hed.value = (double)((decimal)ard["@avg_rawdata"]); - hed.timestamp = Convert.ToDateTime(ard["@end_timestamp"].ToString()); + hed.timestamp = Convert.ToDateTime(ard["@start_timestamp"].ToString()); hed.building_tag = d.building_tag; he.Add(hed); } From 6ca824e00cec910552f925649195682b71003794 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 3 Jul 2023 16:44:12 +0800 Subject: [PATCH 4/7] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B3=87=E6=96=99=E9=A1=AF=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Views/NiagaraDataSynchronize/Index.cshtml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Backend/Views/NiagaraDataSynchronize/Index.cshtml b/Backend/Views/NiagaraDataSynchronize/Index.cshtml index 7bd6a7d..98cfe79 100644 --- a/Backend/Views/NiagaraDataSynchronize/Index.cshtml +++ b/Backend/Views/NiagaraDataSynchronize/Index.cshtml @@ -111,8 +111,17 @@ } var data = rel.data; - ds = data; - console.log(ds) + ds = $.extend(true, [], data); + $.each(data, function (i, v) + { + if (v.value.includes("$3")) + { + v.value = v.value.replace("$3", ""); + v.tag_name = v.tag_name.replace("$3", ""); + v.point_name = v.point_name.replace("$3", ""); + } + }) + //console.log(ds) if (data == null || data.length == 0) { this.data = []; document.getElementById('loadDataText').innerText = ""; From 54e295628fd5d88395d9460a8461884962def1cc Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 4 Jul 2023 16:45:03 +0800 Subject: [PATCH 5/7] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=AD=B7=E5=8F=B2=E8=B3=87=E6=96=99=E4=B8=8B=E8=BC=89=E6=96=B9?= =?UTF-8?q?=E5=BC=8F,=20=E4=BF=AE=E6=94=B9=E5=A0=B1=E8=A1=A8=E5=8C=AF?= =?UTF-8?q?=E5=87=BA=E9=8C=AF=E8=AA=A4=20[=E5=89=8D=E7=AB=AF]=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=AD=B7=E5=8F=B2=E8=B3=87=E6=96=99=E6=99=82=E9=96=93?= =?UTF-8?q?=E7=99=BC=E9=80=81=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_historyData.html | 73 ++++-- .../ApiControllers/HistoryController.cs | 245 ++++++++++-------- .../ApiControllers/HydroMeterController.cs | 8 +- 3 files changed, 192 insertions(+), 134 deletions(-) diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index ab20694..b62599c 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -280,18 +280,32 @@ $('#devPointsList').html(strHtml); - if (!hisFirst) - getData(); + if (!hisFirst) { + let start = new Date($('#his_startdate').val()); + let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); + + if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); + else if (pageAct.dateType == "month") { + start = new Date($('#getmonth').val()); + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); + } + else if (pageAct.dateType != "range") + return; + + getData(formatDate(start, "date", true), formatDate(end, "date", true)); + } } ytAjax = new YourTeam.Ajax(url, objSendData, success, null, "POST").send(); } function getData(start = null, end = null) { + $(loadEle).Loading("start"); var sdt = new Date(); var edt = new Date(new Date().setDate(sdt.getDate() + 1)); start = start ?? sdt.toLocaleDateString(); end = end ?? edt.toLocaleDateString(); - callBackFromHistory(); + // callBackFromHistory(); getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem, new Date(start).getTime(), new Date(end).getTime(), @@ -329,13 +343,13 @@ let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") - end = new Date(new Date().setDate(start.getDate() + 1)); + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); else if (pageAct.dateType == "month") { start = new Date($('#getmonth').val()); - end = new Date(new Date().setDate(start.getDate() + 30)); + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); } else if (pageAct.dateType != "range") - getData(); + return; getData(formatDate(start, "date", true), formatDate(end, "date", true)); } @@ -399,10 +413,10 @@ let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1)); if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd") - end = new Date(new Date().setDate(start.getDate() + 1)); + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 1)); else if (pageAct.dateType == "month") { start = new Date($('#getmonth').val()); - end = new Date(new Date().setDate(start.getDate() + 30)); + end = new Date(new Date(start.valueOf()).setDate(start.getDate() + 30)); } else if (pageAct.dateType != "range") return; @@ -471,21 +485,48 @@ function exportExcel() { $(loadEle).Loading("start"); - let url = baseApiUrl + "/History/OpeExportExcel"; + let token = cookies.get("JWT-Authorization"); + let url = baseApiUrl + "/api/ExportHistory"; let v = {}; v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#his_startdate').val())); v.endtime = $('#his_enddate input').val() === "" ? null : new Date($('#his_enddate input').val()); v.dateType = pageAct.dateType; objSendData.Data = v; - ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { - if (rel.code == "0000") - location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + cookies.get("JWT-Authorization"); + $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(objSendData.Data), + aysnc: true, + headers: { + Authorization: "Bearer " + token, + }, + contentType: "application/json; charset=utf-8", + xhrFields: { + responseType: "blob", // to avoid binary data being mangled on charset conversion + }, + success: function (rel, text, xhr) { + if (rel) { + downloadByBlob(xhr, rel); + } + $(loadEle).Loading("close"); + }, + error: function () { + $(loadEle).Loading("close"); + }, + complete: (xhr) => { + setLoading(false); + }, + }); + // ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { + // $(loadEle).Loading("close"); + // }, function (rel) { + // if (rel) { + // downloadByBlob(xhr, rel); + // } - $(loadEle).Loading("close"); - }, () => { - $(loadEle).Loading("close"); - }, "POST", true).send(); + // $(loadEle).Loading("close"); + // }, "POST",true).send(); } //選擇棟別 diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 792507e..22b6c40 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1,9 +1,11 @@ using FrontendWebApi.Models; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NPOI.HPSF; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using Repository.BackendRepository.Interface; @@ -45,35 +47,40 @@ namespace FrontendWebApi.ApiControllers /// /// [HttpPost] - public async Task>> OpeExportExcel([FromBody] HistoryExport lhe) + [Route("api/ExportHistory")] + public FileResult OpeExportExcel([FromBody] HistoryExport lhe) { ApiResult apiResult = new ApiResult(); - if (lhe == null) - { - apiResult.Code = "0001"; - apiResult.Msg = "沒有資料匯入"; - return apiResult; - } - + //if (lhe == null) + //{ + // apiResult.Code = "0001"; + // apiResult.Msg = "沒有資料匯入"; + // return apiResult; + //} + var fileDateName = lhe.dateType == "today" ? lhe.starttime.ToString("yyyy-MM-dd") + : lhe.dateType == "month" ? lhe.starttime.ToString("yyyy-MM") + : lhe.starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.endtime).ToString("yyyy-MM-dd"); + var fileName = "歷史資料_" + fileDateName + ".xlsx"; + XSSFWorkbook workbook = new XSSFWorkbook(); try { #region 取得obix 設定 EDFunction ed = new EDFunction(); var obixApiConfig = new ObixApiConfig(); var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; - var variableObix = await backendRepository.GetAllAsync(sqlObix); + var variableObix = backendRepository.GetAllAsync(sqlObix).Result; obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault(); obixApiConfig.UserName = ed.AESDecrypt(variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault()); obixApiConfig.Password = ed.AESDecrypt(variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault()); String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password)); #endregion 取得obix 設定 - var building = await backendRepository.GetAllAsync("select * from building where deleted = 0"); - var buildStation = await backendRepository.GetAllAsync("select SUBSTRING_INDEX(system_value, '/', 1) system_value, system_key from variable where system_type = 'dashboard_total_elec' and deleted = 0 and (SUBSTRING_INDEX(system_value, '/', 1) != '' and SUBSTRING_INDEX(system_value, '/', 1) is not null)"); + var building = backendRepository.GetAllAsync("select * from building where deleted = 0").Result; + var buildStation = backendRepository.GetAllAsync("select SUBSTRING_INDEX(system_value, '/', 1) system_value, system_key from variable where system_type = 'dashboard_total_elec' and deleted = 0 and (SUBSTRING_INDEX(system_value, '/', 1) != '' and SUBSTRING_INDEX(system_value, '/', 1) is not null)").Result; #region get device and device_item(point) - var device = await backendRepository.GetAllAsync($"select * from device where deleted = 0 and is_link = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')"); - var devicePoint = await backendRepository.GetAllAsync($"select * from device_item where deleted = 0 and is_link = 1 and is_show_history = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')"); + var device = backendRepository.GetAllAsync($"select * from device where deleted = 0 and is_link = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')").Result; + var devicePoint = backendRepository.GetAllAsync($"select * from device_item where deleted = 0 and is_link = 1 and is_show_history = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')").Result; #endregion List listDevicePoint = new List(); @@ -166,130 +173,140 @@ namespace FrontendWebApi.ApiControllers #endregion #region export file progress - var fileDateName = lhe.dateType == "today" ? lhe.starttime.ToString("yyyy-MM-dd") - : lhe.dateType == "month" ? lhe.starttime.ToString("yyyy-MM") - : lhe.starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.endtime).ToString("yyyy-MM-dd"); - var fileName = "歷史資料_" + fileDateName + ".xlsx"; - var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); + //var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); - if (!System.IO.Directory.Exists(filePath)) - System.IO.Directory.CreateDirectory(filePath); + //if (!System.IO.Directory.Exists(filePath)) + // System.IO.Directory.CreateDirectory(filePath); - using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write)) + + #region excel設定 + IFont font12 = workbook.CreateFont(); + font12.FontName = "新細明體"; + font12.FontHeightInPoints = 12; + ICellStyle style12 = workbook.CreateCellStyle(); + style12.SetFont(font12); + style12.Alignment = HorizontalAlignment.Center; + style12.VerticalAlignment = VerticalAlignment.Center; + IFont font12Times = workbook.CreateFont(); + font12Times.FontName = "Times New Roman"; + font12Times.FontHeightInPoints = 12; + IFont font18 = workbook.CreateFont(); + font18.FontName = "新細明體"; + font18.FontHeightInPoints = 18; + font18.IsBold = true; + ICellStyle styleTitle18 = workbook.CreateCellStyle(); + styleTitle18.SetFont(font18); + styleTitle18.Alignment = HorizontalAlignment.Center; + styleTitle18.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLeft12 = workbook.CreateCellStyle(); + styleLeft12.SetFont(font12); + styleLeft12.Alignment = HorizontalAlignment.Left; + styleLeft12.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLine12 = workbook.CreateCellStyle(); + styleLine12.SetFont(font12); + styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; + styleLine12.VerticalAlignment = VerticalAlignment.Center; + styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + ICellStyle stylein12 = workbook.CreateCellStyle(); + stylein12.SetFont(font12Times); + stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; + stylein12.VerticalAlignment = VerticalAlignment.Center; + stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.WrapText = true; + #endregion + + foreach (var b in building) { - IWorkbook workbook = new XSSFWorkbook(); - #region excel設定 - IFont font12 = workbook.CreateFont(); - font12.FontName = "新細明體"; - font12.FontHeightInPoints = 12; - ICellStyle style12 = workbook.CreateCellStyle(); - style12.SetFont(font12); - style12.Alignment = HorizontalAlignment.Center; - style12.VerticalAlignment = VerticalAlignment.Center; - IFont font12Times = workbook.CreateFont(); - font12Times.FontName = "Times New Roman"; - font12Times.FontHeightInPoints = 12; - IFont font18 = workbook.CreateFont(); - font18.FontName = "新細明體"; - font18.FontHeightInPoints = 18; - font18.IsBold = true; - ICellStyle styleTitle18 = workbook.CreateCellStyle(); - styleTitle18.SetFont(font18); - styleTitle18.Alignment = HorizontalAlignment.Center; - styleTitle18.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLeft12 = workbook.CreateCellStyle(); - styleLeft12.SetFont(font12); - styleLeft12.Alignment = HorizontalAlignment.Left; - styleLeft12.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLine12 = workbook.CreateCellStyle(); - styleLine12.SetFont(font12); - styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; - styleLine12.VerticalAlignment = VerticalAlignment.Center; - styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - ICellStyle stylein12 = workbook.CreateCellStyle(); - stylein12.SetFont(font12Times); - stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; - stylein12.VerticalAlignment = VerticalAlignment.Center; - stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.WrapText = true; + var data = he.Where(x => x.building_tag == b.building_tag).ToList(); + ISheet sheet = workbook.CreateSheet($"{b.full_name}歷史資料"); + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("類型"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("設備名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("數值"); + cell = row.CreateCell(3); + cell.SetCellValue("記錄時間"); + cell.CellStyle = styleLine12; #endregion - foreach (var b in building) + if (data.Count > 0) { - var data = he.Where(x => x.building_tag == b.building_tag).ToList(); - ISheet sheet = workbook.CreateSheet($"{b.full_name}歷史資料"); - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("類型"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("設備名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("數值"); - cell = row.CreateCell(3); - cell.SetCellValue("記錄時間"); - cell.CellStyle = styleLine12; - #endregion - - if (data.Count > 0) + foreach (var d in data) { - foreach (var d in data) + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 4; i++) { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 4; i++) + cell = row.CreateCell(i); + if (i == 0) { - cell = row.CreateCell(i); - if (i == 0) - { - cell.SetCellValue(d.type); - } - if (i == 1) - { - cell.SetCellValue(d.deviceName); - } - if (i == 2) - { - cell.SetCellValue(d.value); - } - if (i == 3) - { - cell.SetCellValue(d.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");// - } - - cell.CellStyle = style12; + cell.SetCellValue(d.type); } + if (i == 1) + { + cell.SetCellValue(d.deviceName); + } + if (i == 2) + { + cell.SetCellValue(d.value); + } + if (i == 3) + { + cell.SetCellValue(d.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");// + } + + cell.CellStyle = style12; } } } - workbook.Write(fs); } + + + + + //using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write)) + //{ + //workbook.Write(fs); + + //} #endregion - apiResult.Code = "0000"; - apiResult.Data = "history/" + fileName; + //apiResult.Code = "0000"; + //apiResult.Data = "history/" + fileName; } catch (Exception exception) { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。 Msg: " + exception.Message; Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - return Ok(apiResult); + throw exception; } - return Ok(apiResult); + + var ms = new NpoiMemoryStream + { + AllowClose = false + }; + workbook.Write(ms); + ms.Flush(); + ms.Seek(0, SeekOrigin.Begin); + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); + return File(ms, "application/vnd.ms-excel", fileName); } /// diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index c9ffeef..93f4e02 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -462,11 +462,11 @@ namespace FrontendWebApi.ApiControllers #endregion foreach (var r in result) { - string buildingName = r.Select(x => x.building_name).FirstOrDefault(); - var sheet = workbook.CreateSheet($"{buildingName}電表報表"); - int RowPosition = 0; - if (result.Count > 0) + if (r.Count > 0) { + string buildingName = r.Select(x => x.building_name).FirstOrDefault(); + var sheet = workbook.CreateSheet($"{buildingName}電表報表"); + int RowPosition = 0; #region set cell IRow row = sheet.CreateRow(RowPosition); sheet.SetColumnWidth(0, 4 * 160 * 12); From a620eae1a811cd8b8d3c0a7333913a69186b2f6a Mon Sep 17 00:00:00 2001 From: dev02 Date: Wed, 5 Jul 2023 10:11:46 +0800 Subject: [PATCH 6/7] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=20=E4=BF=AE=E6=94=B9ch?= =?UTF-8?q?eckbox=E9=A1=94=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_accountManagement.html | 4 ++-- Frontend/css/site.css | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Frontend/_accountManagement.html b/Frontend/_accountManagement.html index ba2e04c..0d2400a 100644 --- a/Frontend/_accountManagement.html +++ b/Frontend/_accountManagement.html @@ -875,7 +875,7 @@ } function setAuthPage() { - $(`#accAuthPageTable input[type=checkbox]`).prop('disabled', false); + $(`#accAuthPageTable input[type=checkbox]`).removeClass(); $.each($(`#accAuthPageTable input[type=checkbox]:checked`), function (i, v) { $(v).click(); }); @@ -886,7 +886,7 @@ $.each(pageAct.authCode, function (i, v) { $(`#accAuthPageTable input[id=${v}]`).click(); - $(`#accAuthPageTable input[id=${v}]`).attr('disabled', true); + $(`#accAuthPageTable input[id=${v}]`).addClass("disabledBox"); }); } diff --git a/Frontend/css/site.css b/Frontend/css/site.css index a9fc63b..7871d38 100644 --- a/Frontend/css/site.css +++ b/Frontend/css/site.css @@ -45,6 +45,8 @@ input.toggle:checked { background: #97c193; } .lds-ring div:nth-child(3) { animation-delay: -0.15s; } +input.disabledBox { pointer-events: none; } + /* js-tree */ .jstree-node { padding-bottom: 3px; } .jstree-default-dark { background-color: transparent; } From 17b9f2485b569756e18624ab6af215e40bebcf3c Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 6 Jul 2023 11:42:43 +0800 Subject: [PATCH 7/7] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=A8=93=E5=B1=A4=E9=A1=AF=E7=A4=BA=E5=9C=96=E6=AA=94=E5=95=8F?= =?UTF-8?q?=E9=A1=8C,=20=E4=BF=AE=E6=94=B9=E5=88=87=E6=8F=9B=E6=A3=9F?= =?UTF-8?q?=E5=88=A5=E5=95=8F=E9=A1=8C,=20=E9=97=9C=E9=96=89=E9=BB=9E?= =?UTF-8?q?=E4=BD=8D=E6=96=B0=E5=A2=9E,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/BuildInfoController.cs | 2 +- .../Controllers/SystemCategoryController.cs | 39 +++++++++------ Backend/Views/BuildInfo/Index.cshtml | 48 +++++++++++++++---- Backend/Views/SystemCategory/Index.cshtml | 14 +++--- .../Views/SystemCategory/_SystemSub.cshtml | 4 +- .../bfa367b0-4867-4d0e-b821-bbc127b79be1.svg | 0 BackendWorkerService/Program.cs | 12 ++--- 7 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 Backend/wwwroot/upload/floor_map/bfa367b0-4867-4d0e-b821-bbc127b79be1.svg diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index c03565a..71176cd 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -468,7 +468,7 @@ namespace Backend.Controllers if (!string.IsNullOrEmpty(buildFloor.InitMapName)) { - buildFloor.MapUrl = "/upload/floor_map/" + buildFloor.Floor_guid + ".svg"; + buildFloor.MapUrl = baseURL + "upload/floor_map/" + buildFloor.Floor_map_name + ".svg"; } apiResult.Code = "0000"; diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index 9246230..e063514 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -531,24 +531,33 @@ namespace Backend.Controllers if (device_Item.id == 0) { - + var building = await backendRepository.GetAllAsync("select building_tag from building where deleted = 0;"); + var parentPath = await backendRepository.GetOneAsync("select system_value from variable where deleted = 0 and system_type = 'obixStatus'"); + List> device_iteDic = new List>(); //新增 - Dictionary Device_itemDic = new Dictionary() + foreach (var b in building) { - { "@device_system_tag", main_tag}, - { "@device_name_tag", sub_tag}, - { "@full_name", device_Item.full_name}, - { "@points", device_Item.points}, - { "@unit", device_Item.unit}, - { "@is_show", device_Item.is_show}, - { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, - { "@is_controll", device_Item.is_controll}, - { "@is_bool", device_Item.is_bool}, - { "@is_show_history", device_Item.is_show_history}, - { "@created_by", myUserInfo.Userinfo_guid}, - }; - await backendRepository.AddOneByCustomTable(Device_itemDic, "device_item"); + Dictionary Device_itemDic = new Dictionary() + { + { "@device_system_tag", main_tag}, + { "@device_name_tag", sub_tag}, + { "@full_name", device_Item.full_name}, + { "@points", device_Item.points}, + { "@unit", device_Item.unit}, + { "@device_building_tag", b}, + { "@parent_path", parentPath}, + { "@is_link", 1}, + { "@is_show", device_Item.is_show}, + { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, + { "@is_controll", device_Item.is_controll}, + { "@is_bool", device_Item.is_bool}, + { "@is_show_history", device_Item.is_show_history}, + { "@created_by", myUserInfo.Userinfo_guid}, + }; + device_iteDic.Add(Device_itemDic); + } + await backendRepository.AddMutiByCustomTable(device_iteDic, "device_item"); apiResult.Code = "0000"; apiResult.Msg = "新增成功"; } diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index a498f85..6876afe 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -108,6 +108,9 @@ //樓層設定上方選單 $("#BuildList").empty(); $.each(data, function (key, value) { + if (value.building_tag.includes("$3")) + value.building_tag = value.building_tag.replace("$3", ""); + $("#BuildList").append(``); @*if (key == 0) { selected_build_guid_top_name = value.full_name; @@ -454,7 +457,7 @@ var file = input3Dfile; var formData = new FormData(); formData.append('fileToUpload', file); - formData.append('bucketKey', "zo4zguyalhjrl5o81va39pkdgr82wamq-202305_bim");//forge上傳平台-資料夾 + formData.append('bucketKey', "zo4zguyalhjrl5o81va39pkdgr82wamq-202305_bim");//forge上傳平台-資料夾 $.ajax({ url: '/api/forge/oss/objects', @@ -530,7 +533,10 @@ var url = "/BuildInfo/EditBuildInfo"; var formData = new FormData(); - formData.append("building_tag", selected_build_guid); + if ($.isNumeric(selected_build_guid[0])) + formData.append("building_tag", "$3" + selected_build_guid); + else + formData.append("building_tag", selected_build_guid); formData.append("Full_name", $('#build_name_modal').val()); formData.append("Ip_address", $('#ip_address_modal').val()); formData.append("Ip_port", $('#ip_port_modal').val()); @@ -682,7 +688,10 @@ "url": "/BuildInfo/BuildFloorList", "type": "POST", "data": function (d) { - d.build_tag = selected_build_guid_top; + if ($.isNumeric(selected_build_guid_top[0])) + d.build_tag = selected_build_guid_top = "$3" + selected_build_guid_top; + else + d.build_tag = selected_build_guid_top; }, "dataSrc": function (rel) { if (rel.code == "9999") { @@ -762,11 +771,14 @@ return; } else { + $('#floor-modal').modal(); + $("#BuildName").html(selected_build_guid_top_name); $("#floor_name_modal").val(rel.data.full_name); - @*$("#map_file_preview_modal").attr("data-original", rel.data.mapUrl);*@ - - $('#floor-modal').modal(); + if (rel.data.mapUrl) + loadURLToInputFiled(rel.data.mapUrl, rel.data.initMapName + ".svg"); + else + $('#floor_map_file_modal')[0].value = ""; } }, 'json'); }); @@ -962,7 +974,7 @@ function translateObject(urn) { $("#forgeViewer").empty(); //if (node == null) node = $('#appBuckets').jstree(true).get_selected(true)[0]; - var bucketKey = "zo4zguyalhjrl5o81va39pkdgr82wamq-202305_bim";//forge上傳平台-資料夾 + var bucketKey = "zo4zguyalhjrl5o81va39pkdgr82wamq-202305_bim";//forge上傳平台-資料夾 var objectKey = urn; jQuery.post({ @@ -977,6 +989,26 @@ } //#endregion - + function loadURLToInputFiled(url, filesName){ + getImgURL(url, (imgBlob)=>{ + // Load img blob to input + // WIP: UTF8 character error + let fileName = filesName + let file = new File([imgBlob], fileName,{type:"image/svg+xml", lastModified:new Date().getTime()}, 'utf-8'); + let container = new DataTransfer(); + container.items.add(file); + $('#floor_map_file_modal')[0].files = container.files; + }) + } + // xmlHTTP return blob respond + function getImgURL(url, callback){ + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + callback(xhr.response); + }; + xhr.open('GET', url); + xhr.responseType = 'blob'; + xhr.send(); + } } \ No newline at end of file diff --git a/Backend/Views/SystemCategory/Index.cshtml b/Backend/Views/SystemCategory/Index.cshtml index 85c5184..2c59b31 100644 --- a/Backend/Views/SystemCategory/Index.cshtml +++ b/Backend/Views/SystemCategory/Index.cshtml @@ -594,13 +594,13 @@ //#endregion //#region 新增設備項目 - function Adddevice_item() { - //SubDeviceItemValidate.resetForm(); - selected_system_device_item_guid = ""; - $("#device-sub-modal .modal-title").html("設備項目 - 新增"); - $("#device-item-sub-form").trigger("reset"); - $("#device-sub-modal").modal(); - } + //function Adddevice_item() { + // //SubDeviceItemValidate.resetForm(); + // selected_system_device_item_guid = ""; + // $("#device-sub-modal .modal-title").html("設備項目 - 新增"); + // $("#device-item-sub-form").trigger("reset"); + // $("#device-sub-modal").modal(); + //} //#endregion $('#system_sub_table').on("click", "tbody>tr", function () { diff --git a/Backend/Views/SystemCategory/_SystemSub.cshtml b/Backend/Views/SystemCategory/_SystemSub.cshtml index 6b8d240..93ac7a9 100644 --- a/Backend/Views/SystemCategory/_SystemSub.cshtml +++ b/Backend/Views/SystemCategory/_SystemSub.cshtml @@ -32,11 +32,11 @@