變更違規車輛API 使2個演算法數據結合
This commit is contained in:
parent
59f58be250
commit
17a3de6643
@ -9,6 +9,7 @@ using Parking_space_WebAPI.Models;
|
||||
using Parking_space_WebAPI.Services;
|
||||
using Parking_space_WebAPI.ViewModel;
|
||||
using Parking_space_WebAPI.Authorization;
|
||||
using Mysqlx;
|
||||
|
||||
namespace Parking_space_WebAPI.Controllers
|
||||
{
|
||||
@ -301,6 +302,73 @@ namespace Parking_space_WebAPI.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 新增違規資料並比對10秒內
|
||||
/// <summary>
|
||||
/// 新增違規資料並比對10秒內
|
||||
/// </summary>
|
||||
/// <param name="violation_car_table"></param>
|
||||
/// <returns></returns>
|
||||
// POST: api/Violation_car_table
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[AllowAnonymous]
|
||||
[HttpPost("post_10s")]
|
||||
public async Task<ActionResult<Violation_car_table>> PostViolation_car_table_1(Violation_car_table violation_car_table)
|
||||
{
|
||||
violation_car_table.create_data_time = DateTime.Now;
|
||||
var location_name = violation_car_table.violation_location_name;
|
||||
var license_plate_number = violation_car_table.license_plate_number;
|
||||
// 取得現在時間
|
||||
DateTime time = DateTime.Now;
|
||||
// 取得 10秒前的時間
|
||||
DateTime time_10s_ago = time.AddSeconds(-10);
|
||||
var Data_list = await _context.violation_car_table
|
||||
.Where(c => c.violation_location_name == location_name)
|
||||
.Where(c => c.create_data_time >= time_10s_ago) // 只選擇指定日期的資料
|
||||
.ToListAsync();
|
||||
//判斷10秒內有多少資料
|
||||
if (Data_list.Count == 1) //只有1筆 若與全景判斷的車牌不同就替換車牌
|
||||
{
|
||||
if (Data_list[0].license_plate_number != license_plate_number)
|
||||
{
|
||||
var data = Data_list[0];
|
||||
_context.violation_car_table.Remove(Data_list[0]);
|
||||
await _context.SaveChangesAsync();
|
||||
data.license_plate_number = license_plate_number;
|
||||
_context.violation_car_table.Add(data);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
|
||||
}
|
||||
else {
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
||||
if (Data_list.Count > 1)//超過2筆
|
||||
{
|
||||
for (int i = 0; i < Data_list.Count; i++)
|
||||
{
|
||||
if (Data_list[i].license_plate_number != license_plate_number)
|
||||
{
|
||||
if (Data_list[i].create_data_time > time.AddSeconds(-10) && Data_list[i].create_data_time < time.AddSeconds(-3))
|
||||
{
|
||||
var data = Data_list[i];
|
||||
_context.violation_car_table.Remove(Data_list[0]);
|
||||
await _context.SaveChangesAsync();
|
||||
data.license_plate_number = license_plate_number;
|
||||
_context.violation_car_table.Add(data);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_context.violation_car_table.Add(violation_car_table);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool Violation_car_tableExists(string id)
|
||||
{
|
||||
return (_context.violation_car_table?.Any(e => e.violation_location_name == id)).GetValueOrDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user