Second upload

This commit is contained in:
qi_0527 2024-10-03 18:19:31 +08:00
parent 3964510f8f
commit a0102de0b0

View File

@ -118,24 +118,25 @@ namespace WebApi_data_value.Controllers
}
}
// 下載 Excel 檔案
[HttpGet("DownloadExcel")]
public async Task<IActionResult> DownloadExcel(DateTime startDate, DateTime endDate, string interval)
{
// 確保日期有效
if (startDate == default || endDate == default)
{
return BadRequest(new { message = "日期無效。" });
}
// 確保開始時間早於結束時間
if (startDate >= endDate)
{
return BadRequest(new { message = "結束日期必須晚於開始日期。" });
}
// 調用 GetHourlyParkingLogs 方法以獲取停車紀錄
var parkingLogsResult = await GetHourlyParkingLogs(startDate, endDate, interval);
// 調用 GetHourlyParkingLogs 方法以獲取所有停車紀錄
var parkingLogsResult = await GetHourlyParkingLogs(startDate, endDate, interval, 1, int.MaxValue);
if (parkingLogsResult is NotFoundResult)
{
@ -156,6 +157,7 @@ namespace WebApi_data_value.Controllers
worksheet.Cell(1, 6).Value = "臨停車位";
worksheet.Cell(1, 7).Value = "下載日期";
for (int i = 0; i < records.Count; i++)
{
var log = records[i];
@ -165,8 +167,7 @@ namespace WebApi_data_value.Controllers
worksheet.Cell(i + 2, 4).Value = log.RemainingSpaces;
worksheet.Cell(i + 2, 5).Value = log.MonthlyRentSpaces;
worksheet.Cell(i + 2, 6).Value = log.TemporaryRentSpaces;
worksheet.Cell(2, 7).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss dddd");
worksheet.Cell(i + 2, 7).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss dddd");
}
@ -183,7 +184,6 @@ namespace WebApi_data_value.Controllers
workbook.SaveAs(stream);
var content = stream.ToArray();
string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
string weekDay = DateTime.Now.ToString("dddd", new CultureInfo("zh-TW"));
@ -193,8 +193,6 @@ namespace WebApi_data_value.Controllers
}
}
}
// 獲取停車紀錄
private async Task<IActionResult> GetParkingLogs(DateTime startDate, DateTime endDate, int pageNumber, int pageSize)
{
@ -282,8 +280,6 @@ namespace WebApi_data_value.Controllers
// 將 interval 轉換為整數
int hourInterval = int.Parse(interval);
var formattedLogs = new List<object>();
// 從 startDate 開始,每次加 hourInterval 小時,直到 endDate
for (DateTime currentTime = startDate; currentTime <= endDate; currentTime = currentTime.AddHours(hourInterval))
{
// 查找該時間的停車紀錄