using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Parking_space_WebAPI.Models;
using Parking_space_WebAPI.Services;
using Parking_space_WebAPI.ViewModel;
using Parking_space_WebAPI.Authorization;
using OfficeOpenXml;
using System.Web;
namespace Parking_space_WebAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
[ApiExplorerSettings(GroupName = "校園大內網")]
public class Yuntech_in_car_tableController : ControllerBase
{
private readonly SqlContext _context;
public Yuntech_in_car_tableController(SqlContext context)
{
_context = context;
}
#region 獲取進入雲科的所有資料
///
/// 獲取進入雲科的所有資料
///
// GET: api/Yuntech_in_car_table
[HttpGet]
public async Task>> Getyuntech_in_car_table()
{
var in_car_table = await (from c in _context.yuntech_in_car_table
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location=c.out_location,
}
).ToListAsync();
return in_car_table;
}
#endregion
#region 獲取進入雲科的100筆資料
///
/// 獲取進入雲科的100筆資料
///
// GET: api/Yuntech_in_car_table
[HttpGet("Amount-{num}")]
public async Task>> Getyuntech_in_car_100_table(int num)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}
).Skip(num).Take(100).ToListAsync();
return in_car_table;
}
#endregion
#region 獲取進入的單獨地區的所有資料
///
/// 獲取進入的單獨地區的所有資料
///
/// 哪個門口
///
// GET: api/Yuntech_in_car_table/5
[HttpGet("location-{id}")]
public async Task> GetYuntech_in_car_table(string id)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.location == id
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).Skip(0).Take(500).ToListAsync();
return in_car_table;
}
#endregion
#region 獲取時間內的車輛
///
/// 獲取時間內的車輛
///
/// 位置名稱
/// 起始時間
/// 結束時間
///
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
public async Task> GetYuntech_in_car_table_date(string id, DateTime start_time, DateTime end_time)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.location == id
where c.in_time >= start_time
where c.in_time <= end_time
orderby c.in_time descending // 按進入時間降序排列
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
return in_car_table;
}
#endregion
#region 透過車牌號碼搜尋所有資料
///
/// 透過車牌號碼搜尋所有資料
///
/// 車牌號碼 ex:ABC4321
///
[HttpGet("license_plate_number-{id}")]
public async Task> Getlicense_plate_number(string id)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.license_plate_number == id
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
return in_car_table;
}
#endregion
#region 獲取進入的單獨地區的單筆資料
///
/// 獲取進入的單獨地區的單筆資料
///
/// 地區
/// 進入時間 ex:2024-02-05T12:21:48.395Z
///
// GET: api/Yuntech_in_car_table/5
[HttpGet("location_name-{id}-time-{time}")]
public async Task> One_data(string id, DateTime time)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.location == id
where c.in_time == time
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
car_img = c.car_img,
location = c.location,
out_car_img = c.out_car_img,
out_location= c.out_location,
}).FirstAsync();
return in_car_table;
}
#endregion
#region 尋找規定時間內每日進入人數
///
/// 尋找規定時間內每日進入人數
///
///
[HttpGet("get_day_in_car-{day}")]
public async Task> Getdayvalue(int day)
{
// 取得今日日期
DateTime today = DateTime.Today;
// 取得 30 天前的日期
DateTime DaysAgo = today.AddDays(-day);
var dateValue = new List