新增找尋進出校園的位置

This commit is contained in:
leo 2024-02-21 15:29:01 +08:00
parent cd0b1ed9fa
commit 1563577166
2 changed files with 36 additions and 15 deletions

View File

@ -108,7 +108,7 @@ namespace WebApi_data_value.Controllers
/// <param name="end_time">結束時間</param>
/// <returns></returns>
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table_date(string id,DateTime start_time, DateTime end_time)
public async Task<IEnumerable<Yuntech_in_car_table>> 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
@ -170,7 +170,7 @@ namespace WebApi_data_value.Controllers
where c.in_time == time
select new Yuntech_in_car_table
{
license_plate_number= c.license_plate_number,
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
car_img = c.car_img,
@ -197,12 +197,12 @@ namespace WebApi_data_value.Controllers
DateTime DaysAgo = today.AddDays(-day);
var dateValue = new List<object>();
// 使用 for 迴圈逐日計算次數
for (int i = 1;i<= day; i++)
for (int i = 1; i <= day; i++)
{
DateTime date_1 = DaysAgo;
date_1 = date_1.AddDays(i);
DateTime date_2 = DaysAgo;
date_2 = date_2.AddDays(i+1);
date_2 = date_2.AddDays(i + 1);
var dailyCount = await _context.yuntech_in_car_table
.Where(c => c.in_time >= date_1.Date) // 只選擇指定日期的資料
.Where(c => c.in_time <= date_2.Date) // 只選擇指定日期的資料
@ -218,6 +218,27 @@ namespace WebApi_data_value.Controllers
}
#endregion
#region
///<summary>
///尋找所有進出校園的地點
/// </summary>
/// <returns></returns>
[HttpGet("location_name")]
public async Task<IEnumerable<object>> Get_in_Yuntech_location_name()
{
var location_name_table = await _context.yuntech_in_car_table
.GroupBy(c=>c.location)
.Select(group => new
{
location_name = group.Key,
})
.ToListAsync();
return location_name_table;
}
#endregion
#region
/// <summary>

View File

@ -17,8 +17,8 @@ builder.Services.AddCors();
builder.Services.AddControllers();
// 連線PostgreSQL資料庫
//var connectionString = "Server=140.125.20.183;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
var connectionString = "Server=127.0.0.1;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
var connectionString = "Server=140.125.20.183;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
//var connectionString = "Server=127.0.0.1;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
builder.Services.AddDbContext<SqlContext>(opt => opt.UseNpgsql(connectionString));