From 5f92b0c5363df7a2d24c3b6cb57fbd83ed661817 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 13 Dec 2024 21:14:01 +0700 Subject: [PATCH] query by node --- .../ProcessUserTimeStampRepository.cs | 19 +++++++++++++++++-- .../Controllers/LeaveReportController.cs | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs index b83a19fb..ee897d88 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs @@ -139,12 +139,27 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants return data; } - public async Task> GetTimestampByDateLateAsync(string type) + public async Task> GetTimestampByDateLateAsync(string type, string role, string nodeId, int node) { - var data = await _dbContext.Set() + var _nodeId = Guid.Parse(nodeId); + var data = new List(); + if (role == "OWNER" || role == "CHILD") + { + data = await _dbContext.Set().AsQueryable() .Where(x => x.CheckInStatus == "LATE") .Where(x => x.ProfileType == type.Trim().ToUpper()) + .Where(x => node == 4 ? x.Child4Id == _nodeId : (node == 3 ? x.Child3Id == _nodeId : (node == 2 ? x.Child2Id == _nodeId : (node == 1 ? x.Child1Id == _nodeId : (node == 0 ? x.RootId == _nodeId : true))))) .ToListAsync(); + } + else + { + data = await _dbContext.Set().AsQueryable() + .Where(x => x.CheckInStatus == "LATE") + .Where(x => x.ProfileType == type.Trim().ToUpper()) + .Where(x => node == 4 ? x.Child4Id == _nodeId : (node == 3 ? x.Child3Id == _nodeId : (node == 2 ? x.Child2Id == _nodeId : (node == 1 ? x.Child1Id == _nodeId : (node == 0 ? x.RootId == _nodeId : true))))) + .Where(x => node == 0 ? x.Child1Id == null : (node == 1 ? x.Child2Id == null : (node == 2 ? x.Child3Id == null : (node == 3 ? x.Child4Id == null : true)))) + .ToListAsync(); + } return data; } diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 95a690c5..e968ed66 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -1171,7 +1171,7 @@ namespace BMA.EHR.Leave.Service.Controllers var employees = new List(); var count = 1; - var userTimeStamps = await _processUserTimeStampRepository.GetTimestampByDateLateAsync(type.Trim().ToUpper()); + var userTimeStamps = await _processUserTimeStampRepository.GetTimestampByDateLateAsync(type.Trim().ToUpper(), jsonData["result"]?.ToString(), req.nodeId, req.node); foreach (var p in userTimeStamps) { var fullName = $"{p.Prefix}{p.FirstName} {p.LastName}";