From 98a8bef754f8f89fe1a1f2380f1c1c52081df059 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Mon, 21 Apr 2025 15:42:30 +0330 Subject: [PATCH] fix rollcall shiftdate bug --- .../RollCallAgg/DomainService/IRollCallDomainService.cs | 8 ++++---- Company.Domain/RollCallAgg/RollCall.cs | 6 +++--- CompanyManagment.Application/RollCallApplication.cs | 4 ++-- .../AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs index b4b6cfe4..0abe6b9b 100644 --- a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs +++ b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs @@ -25,7 +25,7 @@ public interface IRollCallDomainService long workshopId); TimeOnly GetEmployeeOffSetForRegularSettings(long employeeId, long workshopId); - DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId, DateTime rollCallStartDate); + DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId, DateTime rollCallStartDate,DateTime rollCallEndDate); void CalculateTimeDifferences(RollCall rollCall); @@ -173,16 +173,16 @@ public class RollCallDomainService : IRollCallDomainService } public DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId, - DateTime rollCallStartDate) + DateTime rollCallStartDate,DateTime rollCallEndDate) { var shiftDetails = GetEmployeeShiftDetails(employeeId, workshopId); - + var offset = GetEmployeeOffSetForRegularSettings(employeeId, workshopId); return shiftDetails.shiftType switch { WorkshopShiftStatus.Regular => CalculateRegularShiftDate(rollCallStartDate, offset), - WorkshopShiftStatus.Rotating => rollCallStartDate.Date, + WorkshopShiftStatus.Rotating => FindRotatingShift(rollCallEndDate,rollCallEndDate,shiftDetails.rotatingShifts).start.Date, WorkshopShiftStatus.Irregular => rollCallStartDate.Date, _ => throw new ArgumentOutOfRangeException() }; diff --git a/Company.Domain/RollCallAgg/RollCall.cs b/Company.Domain/RollCallAgg/RollCall.cs index 0da53d46..38a083c9 100644 --- a/Company.Domain/RollCallAgg/RollCall.cs +++ b/Company.Domain/RollCallAgg/RollCall.cs @@ -27,8 +27,6 @@ namespace Company.Domain.RollCallAgg Month = month; RollCallModifyType = rollCallModifyType; - SetShiftDate(service); - var shiftDetails = service.GetEmployeeShiftDetails(employeeId, workshopId); if (shiftDetails is { shiftType: WorkshopShiftStatus.Irregular, irregularShift: null } or @@ -229,6 +227,8 @@ namespace Company.Domain.RollCallAgg { EndDate = endDate; + SetShiftDate(service); + ShiftDurationTimeSpan = CalculateShiftDuration(StartDate!.Value, EndDate.Value, service); NightWorkTimeSpan = CalculateNightWorkDuration(StartDate.Value, endDate); @@ -278,7 +278,7 @@ namespace Company.Domain.RollCallAgg private void SetShiftDate(IRollCallDomainService service) { - ShiftDate = service.GetEmployeeShiftDateByRollCallStartDate(WorkshopId, EmployeeId, StartDate!.Value); + ShiftDate = service.GetEmployeeShiftDateByRollCallStartDate(WorkshopId, EmployeeId, StartDate!.Value,EndDate.Value); } private TimeSpan CalculateShiftDuration(DateTime startRollCall, DateTime endRollCall, IRollCallDomainService service) diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index e24a4368..62f786ab 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -447,7 +447,7 @@ public class RollCallApplication : IRollCallApplication { x.ShiftDate = _rollCallDomainService.GetEmployeeShiftDateByRollCallStartDate(command.WorkshopId, command.EmployeeId, - x.StartDate!.Value); + x.StartDate!.Value,x.EndDate!.Value); }); if (newRollCallDates.Any(x => x.ShiftDate.Date != date.Date)) @@ -618,7 +618,7 @@ public class RollCallApplication : IRollCallApplication { x.ShiftDate = _rollCallDomainService.GetEmployeeShiftDateByRollCallStartDate(command.WorkshopId, command.EmployeeId, - x.StartDate!.Value); + x.StartDate!.Value,x.EndDate!.Value); }); if (newRollCallDates.Any(x => x.ShiftDate.Date != date.Date)) { diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index 9076d5ac..22bb1f92 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -51,15 +51,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk //var notEndedRollCalls = rollCalls.Where(x => x.EndDate == null).ToList(); //RefactorAllTheRollCallsOnEsfand(endedRollCalls, notEndedRollCalls); - CreateRewardForKebabMahdi().GetAwaiter().GetResult(); + //CreateRewardForKebabMahdi().GetAwaiter().GetResult(); ViewData["message"] = "ایجاد شد"; return Page(); } public IActionResult OnPostShiftDateNew() { - var startRollCall = new DateTime(2025, 2, 19); - var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.WorkshopId == 170).ToList(); + var startRollCall = new DateTime(2025, 3, 21); + var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.WorkshopId == 170 ).ToList(); var r1 = rollCalls.Take(3000).ToList(); Console.ForegroundColor = ConsoleColor.DarkRed;