using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.Production; using MMDAL.Query.Production; using System.Data.Common; using static GB5Shared.GB5Constant.Constant; namespace MMDAL.CustomCode.Production { public class ResourcePunchDAL : IResourcePunchDAL { private readonly IQueryExecutor _qe; public ResourcePunchDAL(IQueryExecutor queryExecutor) => _qe = queryExecutor; public async Task SaveResourcePunch(ResourcePunchSaveDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) { string sql = login.DatabaseType switch { DBType.SQL => ResourcePunchQB.SAVE_RESOURCE_PUNCH_SQL, DBType.PostGre => ResourcePunchQB.SAVE_RESOURCE_PUNCH_PG, _ => throw new NotSupportedException("Unsupported database type") }; await _qe.ExecuteAsync(login, sql, new { dto.ResourceId, dto.EmployeeId, dto.MachineId, dto.WorkOrderId, dto.AllocationId, dto.TaskId, dto.PunchDateTime, dto.Status, dto.Quantity, dto.Remarks, dto.DeviceId, dto.GpsLat, dto.GpsLon, dto.CaptureMode }, tx, ct).ConfigureAwait(false); } public async Task> GetActivePunchesForEmployee(int employeeId, LoginDTO login, CancellationToken ct) { string sql = login.DatabaseType switch { DBType.SQL => ResourcePunchQB.GET_ACTIVE_PUNCH_FOR_EMPLOYEE_SQL, DBType.PostGre => ResourcePunchQB.GET_ACTIVE_PUNCH_FOR_EMPLOYEE_PG, _ => throw new NotSupportedException("Unsupported database type") }; return await _qe.QueryAsync(login, sql, new { EmployeeId = employeeId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false) ?? []; } public async Task> GetResourcePunchesByWO(int indentDetailId, LoginDTO login, CancellationToken ct) { string sql = login.DatabaseType switch { DBType.SQL => ResourcePunchQB.GET_RESOURCE_PUNCH_BY_WO_SQL, DBType.PostGre => ResourcePunchQB.GET_RESOURCE_PUNCH_BY_WO_PG, _ => throw new NotSupportedException("Unsupported database type") }; return await _qe.QueryAsync(login, sql, new { IndentDetailId = indentDetailId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false) ?? []; } } }