Thêm API Lưu Log
This commit is contained in:
parent
968e852f18
commit
eb9f0e86d3
|
@ -12,6 +12,17 @@ namespace AIParkingApplication
|
|||
private bool isHttpClientDisposabled;
|
||||
private int numberOfRetry;
|
||||
private ApiPath apiPath;
|
||||
public enum VehicleDirection
|
||||
{
|
||||
In,
|
||||
Out
|
||||
}
|
||||
|
||||
public enum ModePlate
|
||||
{
|
||||
Sqare,
|
||||
Long
|
||||
}
|
||||
|
||||
public ApiController(string baseAddress, int numberOfRetry = 5)
|
||||
{
|
||||
|
@ -37,7 +48,6 @@ namespace AIParkingApplication
|
|||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var loginResult = await response.Content.ReadAsAsync<LoginDataModel>();
|
||||
Console.WriteLine(loginResult.LoginData.StatisticsData.Moto);
|
||||
return loginResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -110,6 +120,42 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
//Neu Dicrection la Out thi logID la logID lay ve khi check the
|
||||
public async Task<SaveLogRespone> SaveLog(int direction, string cardID, string cameraID, int squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "")
|
||||
{
|
||||
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
|
||||
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
|
||||
string PlateFrameImageBase64 = Convert.ToBase64String(PlateFrameImage.ToBytes());
|
||||
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
|
||||
try
|
||||
{
|
||||
var request = new SaveLogParams
|
||||
{
|
||||
Direction = (direction == (int)VehicleDirection.In) ? "in" : "out",
|
||||
LogID = logID,
|
||||
CardID = cardID,
|
||||
TextPlate = textPlate,
|
||||
CameraID = cameraID,
|
||||
ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0",
|
||||
TimeVehicleInOrOut = timeInOrOut,
|
||||
PlateImage = plateImageBase64,
|
||||
PlateResultImage = plateImageResultBase64,
|
||||
PlateFrameImage = PlateFrameImageBase64,
|
||||
FrameImage = FrameImageBase64
|
||||
};
|
||||
|
||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/save-logs", request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
SaveLogRespone saveLogRespone = await response.Content.ReadAsAsync<SaveLogRespone>();
|
||||
return saveLogRespone;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"SendSaveLogRequest : {ex.Message}");
|
||||
return new SaveLogRespone();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (httpClient != null && !isHttpClientDisposabled)
|
||||
|
@ -120,7 +166,53 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public class SaveLogRespone
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
public bool Status { get; set; }
|
||||
|
||||
[JsonProperty("logID")]
|
||||
public int LogID { get; set; }
|
||||
|
||||
[JsonProperty("cost")]
|
||||
public string Cost { get; set; }
|
||||
}
|
||||
|
||||
public class SaveLogParams
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string CardID { get; set; }
|
||||
|
||||
[JsonProperty("plate")]
|
||||
public string TextPlate { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Direction { get; set; }
|
||||
|
||||
[JsonProperty("mod")]
|
||||
public string ModePlate { get; set; }
|
||||
|
||||
[JsonProperty("log_id")]
|
||||
public string LogID { get; set; }
|
||||
|
||||
[JsonProperty("camera")]
|
||||
public string CameraID { get; set; }
|
||||
|
||||
[JsonProperty("time")]
|
||||
public string TimeVehicleInOrOut { get; set; }
|
||||
|
||||
[JsonProperty("plateImage")]
|
||||
public string PlateImage { get; set; }
|
||||
|
||||
[JsonProperty("plateResultImage")]
|
||||
public string PlateResultImage { get; set; }
|
||||
|
||||
[JsonProperty("plateFrameImage")]
|
||||
public string PlateFrameImage { get; set; }
|
||||
|
||||
[JsonProperty("frameImage")]
|
||||
public string FrameImage { get; set; }
|
||||
}
|
||||
|
||||
public class ApiPath
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user