新增全校車位數量計數

違規車輛 改下午5點到遭上6點
This commit is contained in:
威勝 張 2024-05-02 12:27:53 +08:00
parent 7727929df4
commit 4d9ada6731
6 changed files with 216 additions and 6 deletions

View File

@ -260,6 +260,20 @@ namespace Parking_space_WebAPI.Controllers
}
violation_car_table.create_data_time= DateTime.Now;
_context.violation_car_table.Add(violation_car_table);
// 車位數量+1
var yuntech_parking = await _context.yuntech_parking.FirstOrDefaultAsync();
if (yuntech_parking != null)
{
string now_num_str = yuntech_parking.now_num;
int now_num_int;
Int32.TryParse(now_num_str, out now_num_int);
now_num_int = now_num_int + 1;
now_num_str = now_num_int.ToString();
yuntech_parking.now_num = now_num_str;
// 保存更改
await _context.SaveChangesAsync();
}
try
{
await _context.SaveChangesAsync();
@ -339,15 +353,15 @@ namespace Parking_space_WebAPI.Controllers
await _context.SaveChangesAsync();
data.license_plate_number = license_plate_number;
if (time.Hour <= 17)
if (time.Hour >= 17 || time.Hour < 6)
{
// 如果时间早于或等于17:00则只更新车牌号码
// 如果时间晚于或等于17:00或者早于6:00则同时更新车牌号码和车辆入场图片
data.car_start_img = in_car_img;
_context.violation_car_table.Add(data);
}
else
{
// 如果时间晚于17:00则同时更新车牌号码和车辆入场图片
data.car_start_img = in_car_img;
// 如果时间早于或等于17:00则只更新车牌号码
_context.violation_car_table.Add(data);
}
@ -383,6 +397,20 @@ namespace Parking_space_WebAPI.Controllers
}
_context.violation_car_table.Add(violation_car_table);
await _context.SaveChangesAsync();
// 車位數量+1
var yuntech_parking = await _context.yuntech_parking.FirstOrDefaultAsync();
if (yuntech_parking != null)
{
string now_num_str = yuntech_parking.now_num;
int now_num_int;
Int32.TryParse(now_num_str, out now_num_int);
now_num_int = now_num_int + 1;
now_num_str = now_num_int.ToString();
yuntech_parking.now_num = now_num_str;
// 保存更改
await _context.SaveChangesAsync();
}
return Ok();
}
#endregion

View File

@ -265,6 +265,21 @@ namespace Parking_space_WebAPI.Controllers
yuntech_in_car_table.out_time = null;
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
await _context.SaveChangesAsync();
// 車位數量-1
var yuntech_parking = await _context.yuntech_parking.FirstOrDefaultAsync();
if (yuntech_parking != null)
{
string now_num_str = yuntech_parking.now_num;
int now_num_int;
Int32.TryParse(now_num_str, out now_num_int);
now_num_int = now_num_int - 1;
now_num_str=now_num_int.ToString();
yuntech_parking.now_num = now_num_str;
// 保存更改
await _context.SaveChangesAsync();
}
}
catch (DbUpdateException)
{
@ -314,6 +329,21 @@ namespace Parking_space_WebAPI.Controllers
in_car_data.out_car_img = out_car_img;
_context.yuntech_in_car_table.Add(in_car_data);
await _context.SaveChangesAsync();
// 車位數量+1
var yuntech_parking = await _context.yuntech_parking.FirstOrDefaultAsync();
if (yuntech_parking != null)
{
string now_num_str = yuntech_parking.now_num;
int now_num_int;
Int32.TryParse(now_num_str, out now_num_int);
now_num_int = now_num_int + 1;
now_num_str = now_num_int.ToString();
yuntech_parking.now_num = now_num_str;
// 保存更改
await _context.SaveChangesAsync();
}
}
else
{

View File

@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Parking_space_WebAPI.Services;
using WebApi_data_value.Models;
using Parking_space_WebAPI.Authorization;
namespace WebApi_data_value.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
[ApiExplorerSettings(GroupName = "校園大內網")]
public class Yuntech_parkingController : ControllerBase
{
private readonly SqlContext _context;
public Yuntech_parkingController(SqlContext context)
{
_context = context;
}
// GET: api/Yuntech_parking
[HttpGet]
public async Task<ActionResult<IEnumerable<Yuntech_parking>>> Getyuntech_parking()
{
if (_context.yuntech_parking == null)
{
return NotFound();
}
return await _context.yuntech_parking.ToListAsync();
}
// GET: api/Yuntech_parking/5
[HttpGet("{id}")]
public async Task<ActionResult<Yuntech_parking>> GetYuntech_parking(string id)
{
if (_context.yuntech_parking == null)
{
return NotFound();
}
var yuntech_parking = await _context.yuntech_parking.FindAsync(id);
if (yuntech_parking == null)
{
return NotFound();
}
return yuntech_parking;
}
// PUT: api/Yuntech_parking/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutYuntech_parking(string id, Yuntech_parking yuntech_parking)
{
if (id != yuntech_parking.all_num)
{
return BadRequest();
}
_context.Entry(yuntech_parking).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!Yuntech_parkingExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Yuntech_parking
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Yuntech_parking>> PostYuntech_parking(Yuntech_parking yuntech_parking)
{
if (_context.yuntech_parking == null)
{
return Problem("Entity set 'SqlContext.yuntech_parking' is null.");
}
_context.yuntech_parking.Add(yuntech_parking);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (Yuntech_parkingExists(yuntech_parking.all_num))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetYuntech_parking", new { id = yuntech_parking.all_num }, yuntech_parking);
}
// DELETE: api/Yuntech_parking/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteYuntech_parking(string id)
{
if (_context.yuntech_parking == null)
{
return NotFound();
}
var yuntech_parking = await _context.yuntech_parking.FindAsync(id);
if (yuntech_parking == null)
{
return NotFound();
}
_context.yuntech_parking.Remove(yuntech_parking);
await _context.SaveChangesAsync();
return NoContent();
}
private bool Yuntech_parkingExists(string id)
{
return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,8 @@
namespace WebApi_data_value.Models
{
public class Yuntech_parking
{
public string? all_num { get; set; }
public string? now_num { get; set; }
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Parking_space_WebAPI.Models;
using Parking_space_WebAPI.Entities;
using WebApi_data_value.Models;
namespace Parking_space_WebAPI.Services
@ -52,7 +53,7 @@ namespace Parking_space_WebAPI.Services
//雲科校內相機
public DbSet<Yuntech_cam_total_table> yuntech_cam_total_table { get; set; } = null!;
public DbSet<Yuntech_cam> yuntech_cam { get; set; } = null!;
public DbSet<Yuntech_parking> yuntech_parking { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder builder)
@ -83,6 +84,8 @@ namespace Parking_space_WebAPI.Services
builder.Entity<Yuntech_cam_total_table>().HasKey(o => new { o.location_name }); //Primary Key
builder.Entity<Yuntech_cam>().HasKey(o => new { o.ip }); //Primary Key
builder.Entity<Yuntech_parking>().HasKey(o => new { o.all_num }); //Primary Key
}

View File

@ -25,7 +25,7 @@
<PackageReference Include="JWT" Version="10.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.29" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>