新增找尋進出校園的位置

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> /// <param name="end_time">結束時間</param>
/// <returns></returns> /// <returns></returns>
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")] [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 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 where c.in_time == time
select new Yuntech_in_car_table 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, in_time = c.in_time,
out_time = c.out_time, out_time = c.out_time,
car_img = c.car_img, car_img = c.car_img,
@ -197,12 +197,12 @@ namespace WebApi_data_value.Controllers
DateTime DaysAgo = today.AddDays(-day); DateTime DaysAgo = today.AddDays(-day);
var dateValue = new List<object>(); var dateValue = new List<object>();
// 使用 for 迴圈逐日計算次數 // 使用 for 迴圈逐日計算次數
for (int i = 1;i<= day; i++) for (int i = 1; i <= day; i++)
{ {
DateTime date_1 = DaysAgo; DateTime date_1 = DaysAgo;
date_1 = date_1.AddDays(i); date_1 = date_1.AddDays(i);
DateTime date_2 = DaysAgo; 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 var dailyCount = await _context.yuntech_in_car_table
.Where(c => c.in_time >= date_1.Date) // 只選擇指定日期的資料 .Where(c => c.in_time >= date_1.Date) // 只選擇指定日期的資料
.Where(c => c.in_time <= date_2.Date) // 只選擇指定日期的資料 .Where(c => c.in_time <= date_2.Date) // 只選擇指定日期的資料
@ -218,6 +218,27 @@ namespace WebApi_data_value.Controllers
} }
#endregion #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 #region
/// <summary> /// <summary>

View File

@ -17,8 +17,8 @@ builder.Services.AddCors();
builder.Services.AddControllers(); builder.Services.AddControllers();
// 連線PostgreSQL資料庫 // 連線PostgreSQL資料庫
//var connectionString = "Server=140.125.20.183;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"; //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)); builder.Services.AddDbContext<SqlContext>(opt => opt.UseNpgsql(connectionString));