透過時間 使進入車輛在1分鐘內不會被重福登記
透過時間 使出去車輛必須與進入時間相隔30秒才會算出去
This commit is contained in:
parent
4d9ada6731
commit
35822c4079
@ -261,6 +261,20 @@ namespace Parking_space_WebAPI.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
//比對1分鐘內有無重複記錄到
|
||||
DateTime now_time = DateTime.Now;
|
||||
// 取得 59秒前的時間
|
||||
DateTime time_59s_ago = now_time.AddSeconds(-59);
|
||||
var in_car_data = await (from c in _context.yuntech_in_car_table
|
||||
where c.license_plate_number == yuntech_in_car_table.license_plate_number
|
||||
where c.out_time == null
|
||||
orderby c.in_time descending
|
||||
select c).FirstOrDefaultAsync();
|
||||
if (in_car_data != null && in_car_data.in_time > time_59s_ago)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
// 新增資料
|
||||
yuntech_in_car_table.in_time = DateTime.Now;
|
||||
yuntech_in_car_table.out_time = null;
|
||||
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
|
||||
@ -320,7 +334,10 @@ namespace Parking_space_WebAPI.Controllers
|
||||
where c.out_time ==null
|
||||
orderby c.in_time descending
|
||||
select c).FirstOrDefaultAsync();
|
||||
if (in_car_data != null)
|
||||
DateTime now_time = DateTime.Now;
|
||||
// 取得 30秒前的時間
|
||||
DateTime time_30s_ago = now_time.AddSeconds(-30);
|
||||
if (in_car_data != null && in_car_data.in_time<time_30s_ago)
|
||||
{
|
||||
// 处理找到记录的情况
|
||||
_context.yuntech_in_car_table.Remove(in_car_data);
|
||||
|
Loading…
Reference in New Issue
Block a user