[前端] 修改post value

[後端] 修改匯出流程
This commit is contained in:
dev02 2023-07-20 18:29:41 +08:00
parent 81996a1ada
commit b2a9df8922
3 changed files with 60 additions and 79 deletions

View File

@ -496,6 +496,7 @@
v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#his_startdate').val())); 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.endtime = $('#his_enddate input').val() === "" ? null : new Date($('#his_enddate input').val());
v.dateType = pageAct.dateType; v.dateType = pageAct.dateType;
v.device_number = pageAct.deviceNumber;
objSendData.Data = v; objSendData.Data = v;
$.ajax({ $.ajax({

View File

@ -1,4 +1,5 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -58,10 +59,13 @@ namespace FrontendWebApi.ApiControllers
// apiResult.Msg = "沒有資料匯入"; // apiResult.Msg = "沒有資料匯入";
// return apiResult; // 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.dateType == "month" ? lhe.starttime.ToString("yyyy-MM")
: lhe.starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.endtime).ToString("yyyy-MM-dd"); : 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(); XSSFWorkbook workbook = new XSSFWorkbook();
try try
{ {
@ -79,25 +83,22 @@ namespace FrontendWebApi.ApiControllers
var buildStation = backendRepository.GetAllAsync<BuildStation>("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; var buildStation = backendRepository.GetAllAsync<BuildStation>("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) #region get device and device_item(point)
var device = backendRepository.GetAllAsync<Device>($"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 device = backendRepository.GetAllAsync<Device>($"select * from device where deleted = 0 and is_link = 1 and device_number = '{lhe.device_number}'").Result;
var devicePoint = backendRepository.GetAllAsync<Device_item>($"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 devicePoint = backendRepository.GetAllAsync<Device_item>($"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 #endregion
List<DeviceNumberPoint> listDevicePoint = new List<DeviceNumberPoint>(); List<DeviceNumberPoint> listDevicePoint = new List<DeviceNumberPoint>();
#region combine device and point #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();
{
var dp = devicePoint.Where(x => x.device_building_tag == d.device_building_tag).ToList();
foreach (var point in dp) foreach (var point in dp)
{ {
DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint(); DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
deviceNumberPoint.DeviceNumber = d.device_number; deviceNumberPoint.DeviceNumber = lhe.device_number;
deviceNumberPoint.Point = point.points; deviceNumberPoint.Point = point.points;
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", d.device_number, point.points); deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", lhe.device_number, point.points);
listDevicePoint.Add(deviceNumberPoint); listDevicePoint.Add(deviceNumberPoint);
} }
}
#endregion #endregion
#region get data from niagara #region get data from niagara
@ -173,12 +174,6 @@ namespace FrontendWebApi.ApiControllers
#endregion #endregion
#region export file progress #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設定 #region excel設定
IFont font12 = workbook.CreateFont(); IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體"; font12.FontName = "新細明體";
@ -220,11 +215,8 @@ namespace FrontendWebApi.ApiControllers
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true; stylein12.WrapText = true;
#endregion #endregion
var data = he.ToList();
foreach (var b in building) ISheet sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}歷史資料");
{
var data = he.Where(x => x.building_tag == b.building_tag).ToList();
ISheet sheet = workbook.CreateSheet($"{b.full_name}歷史資料");
int RowPosition = 0; int RowPosition = 0;
#region set cell #region set cell
IRow row = sheet.CreateRow(RowPosition); IRow row = sheet.CreateRow(RowPosition);
@ -275,20 +267,7 @@ namespace FrontendWebApi.ApiControllers
} }
} }
} }
}
//using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
//{
//workbook.Write(fs);
//}
#endregion #endregion
//apiResult.Code = "0000";
//apiResult.Data = "history/" + fileName;
} }
catch (Exception exception) catch (Exception exception)
{ {

View File

@ -299,6 +299,7 @@ namespace FrontendWebApi.Models
public string dateType { get; set; } public string dateType { get; set; }
public string type { get; set; } public string type { get; set; }
public string building_tag { get; set; } public string building_tag { get; set; }
public string device_number { get; set; }
} }
public class History_Building public class History_Building