diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html
index fcb44ed..cd83e93 100644
--- a/Frontend/_historyData.html
+++ b/Frontend/_historyData.html
@@ -496,6 +496,7 @@
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;
+ v.device_number = pageAct.deviceNumber;
objSendData.Data = v;
$.ajax({
diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs
index b7e5cae..0e847bc 100644
--- a/FrontendWebApi/ApiControllers/HistoryController.cs
+++ b/FrontendWebApi/ApiControllers/HistoryController.cs
@@ -1,4 +1,5 @@
using FrontendWebApi.Models;
+using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;
@@ -58,10 +59,13 @@ namespace FrontendWebApi.ApiControllers
// apiResult.Msg = "沒有資料匯入";
// return apiResult;
//}
- var fileDateName = lhe.dateType == "today" ? lhe.starttime.ToString("yyyy-MM-dd")
+ string 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";
+ string fileName = "歷史資料_" + fileDateName + ".xlsx";
+ lhe.device_number = char.IsDigit(lhe.device_number.Split("_")[1][0])
+ ? lhe.device_number.Replace(lhe.device_number.Split("_")[1], "$3" + lhe.device_number.Split("_")[1])
+ : lhe.device_number;
XSSFWorkbook workbook = new XSSFWorkbook();
try
{
@@ -79,24 +83,21 @@ namespace FrontendWebApi.ApiControllers
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 = 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;
+ var device = backendRepository.GetAllAsync($"select * from device where deleted = 0 and is_link = 1 and device_number = '{lhe.device_number}'").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 = '{lhe.device_number.Split("_")[1]}' and device_system_tag = '{lhe.device_number.Split("_")[2]}' and device_name_tag = '{lhe.device_number.Split("_")[3]}'").Result;
#endregion
List listDevicePoint = new List();
#region combine device and point
- foreach (var d in device)
+ var dp = devicePoint.Where(x => x.device_building_tag == lhe.device_number.Split("_")[1]).ToList();
+ foreach (var point in dp)
{
- var dp = devicePoint.Where(x => x.device_building_tag == d.device_building_tag).ToList();
- foreach (var point in dp)
- {
- DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
- deviceNumberPoint.DeviceNumber = d.device_number;
- deviceNumberPoint.Point = point.points;
- deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", d.device_number, point.points);
+ DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
+ deviceNumberPoint.DeviceNumber = lhe.device_number;
+ deviceNumberPoint.Point = point.points;
+ deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", lhe.device_number, point.points);
- listDevicePoint.Add(deviceNumberPoint);
- }
+ listDevicePoint.Add(deviceNumberPoint);
}
#endregion
@@ -173,12 +174,6 @@ namespace FrontendWebApi.ApiControllers
#endregion
#region export file progress
- //var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history");
-
- //if (!System.IO.Directory.Exists(filePath))
- // System.IO.Directory.CreateDirectory(filePath);
-
-
#region excel設定
IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體";
@@ -220,75 +215,59 @@ namespace FrontendWebApi.ApiControllers
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
+ var data = he.ToList();
+ ISheet sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}歷史資料");
+ 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;
}
}
}
-
-
-
-
- //using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
- //{
- //workbook.Write(fs);
-
- //}
#endregion
-
- //apiResult.Code = "0000";
- //apiResult.Data = "history/" + fileName;
}
catch (Exception exception)
{
diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs
index 81f3c52..c21b144 100644
--- a/FrontendWebApi/Models/HistoryClass.cs
+++ b/FrontendWebApi/Models/HistoryClass.cs
@@ -299,6 +299,7 @@ namespace FrontendWebApi.Models
public string dateType { get; set; }
public string type { get; set; }
public string building_tag { get; set; }
+ public string device_number { get; set; }
}
public class History_Building