新增30天內紀錄次數查詢API
This commit is contained in:
parent
8f881bf0cf
commit
51f4bafb9f
@ -179,7 +179,7 @@ namespace WebApi_data_value.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region
|
||||
#region 尋找違規次數最多
|
||||
/// <summary>
|
||||
/// 尋找違規次數最多
|
||||
/// </summary>
|
||||
@ -204,6 +204,39 @@ namespace WebApi_data_value.Controllers
|
||||
#endregion
|
||||
|
||||
|
||||
#region 尋找規定時間內每日違規人數
|
||||
/// <summary>
|
||||
/// 尋找規定時間內每日違規人數
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("get_day_violation-{day}")]
|
||||
public async Task<IEnumerable<object>> Getdayvalue(int day)
|
||||
{
|
||||
// 取得今日日期
|
||||
DateTime today = DateTime.Today;
|
||||
|
||||
// 取得 30 天前的日期
|
||||
DateTime DaysAgo = today.AddDays(-day);
|
||||
var dateValue = new List<object>();
|
||||
// 使用 for 迴圈逐日計算次數
|
||||
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);
|
||||
var dailyCount = await _context.violation_car_table
|
||||
.Where(c => c.create_data_time >= date_1.Date) // 只選擇指定日期的資料
|
||||
.Where(c => c.create_data_time <= date_2.Date) // 只選擇指定日期的資料
|
||||
.CountAsync(); // 計算該日期的次數
|
||||
|
||||
dateValue.Add(new { Date = date_1.Date, Occurrences = dailyCount });
|
||||
}
|
||||
|
||||
return dateValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 新增違規車輛
|
||||
/// <summary>
|
||||
/// 新增違規車輛
|
||||
|
@ -155,6 +155,41 @@ namespace WebApi_data_value.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 尋找規定時間內每日進入人數
|
||||
/// <summary>
|
||||
/// 尋找規定時間內每日進入人數
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("get_day_in_car-{day}")]
|
||||
public async Task<IEnumerable<object>> Getdayvalue(int day)
|
||||
{
|
||||
// 取得今日日期
|
||||
DateTime today = DateTime.Today;
|
||||
|
||||
// 取得 30 天前的日期
|
||||
DateTime DaysAgo = today.AddDays(-day);
|
||||
var dateValue = new List<object>();
|
||||
// 使用 for 迴圈逐日計算次數
|
||||
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);
|
||||
var dailyCount = await _context.yuntech_in_car_table
|
||||
.Where(c => c.in_time >= date_1.Date) // 只選擇指定日期的資料
|
||||
.Where(c => c.in_time <= date_2.Date) // 只選擇指定日期的資料
|
||||
.CountAsync(); // 計算該日期的次數
|
||||
|
||||
dateValue.Add(new { Date = date_1, Occurrences = dailyCount });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return dateValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 新增資料
|
||||
|
Loading…
Reference in New Issue
Block a user