179 lines
6.7 KiB
C#
179 lines
6.7 KiB
C#
using System.Text.Json.Serialization;
|
|
using UtopiaCanteenSystem.Models;
|
|
using UtopiaCanteenSystem.Services;
|
|
|
|
namespace UtopiaCanteenSystem.Api;
|
|
|
|
public sealed class RfidScanRequestDto
|
|
{
|
|
public string CardId { get; set; } = string.Empty;
|
|
public string DeviceId { get; set; } = string.Empty;
|
|
public string SiteId { get; set; } = string.Empty;
|
|
public string? IpAddress { get; set; }
|
|
}
|
|
|
|
public sealed class HrmsEmployeeInfoDto
|
|
{
|
|
public string ParentDocumentId { get; set; } = string.Empty;
|
|
public string EmployeeId { get; set; } = string.Empty;
|
|
public string UindSerial { get; set; } = string.Empty;
|
|
public int FunctionId { get; set; }
|
|
public int DepartmentId { get; set; }
|
|
public DateTime? TagCreatedAtUtc { get; set; }
|
|
public string TagCreatedBy { get; set; } = string.Empty;
|
|
public string FirstName { get; set; } = string.Empty;
|
|
public string MiddleName { get; set; } = string.Empty;
|
|
public string DepartmentTitle { get; set; } = string.Empty;
|
|
public string DepartmentType { get; set; } = string.Empty;
|
|
public string LocationSiteId { get; set; } = string.Empty;
|
|
public string GradeType { get; set; } = string.Empty;
|
|
|
|
public static HrmsEmployeeInfoDto? FromModel(HrmsEmployeeInfo? e)
|
|
{
|
|
if (e == null) return null;
|
|
return new HrmsEmployeeInfoDto
|
|
{
|
|
ParentDocumentId = e.ParentDocumentId,
|
|
EmployeeId = e.EmployeeId,
|
|
UindSerial = e.UindSerial,
|
|
FunctionId = e.FunctionId,
|
|
DepartmentId = e.DepartmentId,
|
|
TagCreatedAtUtc = e.TagCreatedAtUtc,
|
|
TagCreatedBy = e.TagCreatedBy,
|
|
FirstName = e.FirstName,
|
|
MiddleName = e.MiddleName,
|
|
DepartmentTitle = e.DepartmentTitle,
|
|
DepartmentType = e.DepartmentType,
|
|
LocationSiteId = e.LocationSiteId,
|
|
GradeType = e.GradeType
|
|
};
|
|
}
|
|
|
|
public HrmsEmployeeInfo ToModel() => new()
|
|
{
|
|
ParentDocumentId = ParentDocumentId ?? string.Empty,
|
|
EmployeeId = EmployeeId ?? string.Empty,
|
|
UindSerial = UindSerial ?? string.Empty,
|
|
FunctionId = FunctionId,
|
|
DepartmentId = DepartmentId,
|
|
TagCreatedAtUtc = TagCreatedAtUtc,
|
|
TagCreatedBy = TagCreatedBy ?? string.Empty,
|
|
FirstName = FirstName ?? string.Empty,
|
|
MiddleName = MiddleName ?? string.Empty,
|
|
DepartmentTitle = DepartmentTitle ?? string.Empty,
|
|
DepartmentType = DepartmentType ?? string.Empty,
|
|
LocationSiteId = LocationSiteId ?? string.Empty,
|
|
GradeType = GradeType ?? string.Empty
|
|
};
|
|
}
|
|
|
|
public sealed class RfidScanResponseDto
|
|
{
|
|
public bool Success { get; set; }
|
|
public string Message { get; set; } = string.Empty;
|
|
public int CooldownSecondsRemaining { get; set; }
|
|
public HrmsEmployeeInfoDto? Employee { get; set; }
|
|
public int MealSession { get; set; }
|
|
public string? EmployeeSiteId { get; set; }
|
|
public string? CurrentSiteId { get; set; }
|
|
public string? MealLabel { get; set; }
|
|
public string? MealItems { get; set; }
|
|
public double TotalPrice { get; set; }
|
|
|
|
public static RfidScanResponseDto FromScanResult(ScanResult r, string? mealLabel = null, string? mealItems = null, double totalPrice = 0)
|
|
{
|
|
return new RfidScanResponseDto
|
|
{
|
|
Success = r.Success,
|
|
Message = r.Message,
|
|
CooldownSecondsRemaining = r.CooldownSecondsRemaining,
|
|
Employee = HrmsEmployeeInfoDto.FromModel(r.EmployeeInfo),
|
|
MealSession = (int)r.MealSession,
|
|
EmployeeSiteId = r.EmployeeSiteId,
|
|
CurrentSiteId = r.CurrentSiteId,
|
|
MealLabel = mealLabel,
|
|
MealItems = mealItems,
|
|
TotalPrice = totalPrice
|
|
};
|
|
}
|
|
}
|
|
|
|
public sealed class ScanRecordDto
|
|
{
|
|
public int Id { get; set; }
|
|
public string CardId { get; set; } = string.Empty;
|
|
public DateTime ScanTime { get; set; }
|
|
public bool IsSynced { get; set; }
|
|
public string SiteId { get; set; } = string.Empty;
|
|
public string DeviceId { get; set; } = string.Empty;
|
|
public string IpAddress { get; set; } = string.Empty;
|
|
public int MealSessionCode { get; set; }
|
|
public string ParentDocumentId { get; set; } = string.Empty;
|
|
public string EmployeeId { get; set; } = string.Empty;
|
|
public string UindSerial { get; set; } = string.Empty;
|
|
public int FunctionId { get; set; }
|
|
public int DepartmentId { get; set; }
|
|
public DateTime? TagCreatedAtUtc { get; set; }
|
|
public string TagCreatedBy { get; set; } = string.Empty;
|
|
public string EmployeeName { get; set; } = string.Empty;
|
|
public string Department { get; set; } = string.Empty;
|
|
public string DepartmentType { get; set; } = string.Empty;
|
|
public string MealLabel { get; set; } = string.Empty;
|
|
public string MealItems { get; set; } = string.Empty;
|
|
public double TotalPrice { get; set; }
|
|
[JsonPropertyName("grade_type")]
|
|
public string GradeType { get; set; } = string.Empty;
|
|
|
|
public static ScanRecordDto FromEntity(ScanRecord r) => new()
|
|
{
|
|
Id = r.Id,
|
|
CardId = r.CardId,
|
|
ScanTime = r.ScanTime,
|
|
IsSynced = r.IsSynced,
|
|
SiteId = r.SiteId,
|
|
DeviceId = r.DeviceId,
|
|
IpAddress = r.IpAddress,
|
|
MealSessionCode = r.MealSessionCode,
|
|
ParentDocumentId = r.ParentDocumentId,
|
|
EmployeeId = r.EmployeeId,
|
|
UindSerial = r.UindSerial,
|
|
FunctionId = r.FunctionId,
|
|
DepartmentId = r.DepartmentId,
|
|
TagCreatedAtUtc = r.TagCreatedAtUtc,
|
|
TagCreatedBy = r.TagCreatedBy,
|
|
EmployeeName = r.EmployeeName,
|
|
Department = r.Department,
|
|
DepartmentType = r.DepartmentType,
|
|
MealLabel = r.MealLabel,
|
|
MealItems = r.MealItems,
|
|
TotalPrice = r.TotalPrice,
|
|
GradeType = r.grade_type
|
|
};
|
|
|
|
public ScanRecord ToEntity() => new()
|
|
{
|
|
Id = Id,
|
|
CardId = CardId ?? string.Empty,
|
|
ScanTime = ScanTime,
|
|
IsSynced = IsSynced,
|
|
SiteId = SiteId ?? string.Empty,
|
|
DeviceId = DeviceId ?? string.Empty,
|
|
IpAddress = IpAddress ?? string.Empty,
|
|
MealSessionCode = MealSessionCode,
|
|
ParentDocumentId = ParentDocumentId ?? string.Empty,
|
|
EmployeeId = EmployeeId ?? string.Empty,
|
|
UindSerial = UindSerial ?? string.Empty,
|
|
FunctionId = FunctionId,
|
|
DepartmentId = DepartmentId,
|
|
TagCreatedAtUtc = TagCreatedAtUtc,
|
|
TagCreatedBy = TagCreatedBy ?? string.Empty,
|
|
EmployeeName = EmployeeName ?? string.Empty,
|
|
Department = Department ?? string.Empty,
|
|
DepartmentType = DepartmentType ?? string.Empty,
|
|
MealLabel = MealLabel ?? string.Empty,
|
|
MealItems = MealItems ?? string.Empty,
|
|
TotalPrice = TotalPrice,
|
|
grade_type = GradeType ?? string.Empty
|
|
};
|
|
}
|