From c7ac3ac7cbb56873e181e600636e46ec5ac8f509 Mon Sep 17 00:00:00 2001 From: SamSys Date: Mon, 12 May 2025 21:14:26 +0330 Subject: [PATCH] BreakTime Merged --- .../DomainService/IRollCallDomainService.cs | 14 ++++ Company.Domain/RollCallAgg/RollCall.cs | 69 +++++++++++-------- .../RollCall/IRollCallMandatoryApplication.cs | 2 +- .../RollCall/RollCallViewModel.cs | 4 ++ .../RollCallApplication.cs | 6 +- ...omizeWorkshopEmployeeSettingsRepository.cs | 5 ++ .../Repository/RollCallMandatoryRepository.cs | 48 ++++++++----- .../Repository/RollCallRepository.cs | 12 ++-- .../Pages/Company/AndroidApk/Index.cshtml.cs | 17 +++-- 9 files changed, 118 insertions(+), 59 deletions(-) diff --git a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs index 01f923c4..3084f5c4 100644 --- a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs +++ b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs @@ -32,6 +32,9 @@ public interface IRollCallDomainService (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection rotatingShifts); (DateTime start, DateTime end) FindRotatingShift(List<(DateTime StartDate, DateTime EndDate)> rollcalls, ICollection rotatingShifts); + + BreakTime GetBreakTime(long employeeId, long workshopId); + } public class RollCallDomainService : IRollCallDomainService @@ -672,6 +675,17 @@ public class RollCallDomainService : IRollCallDomainService return (overlapChosenShift.Shift.Start, end); } + public BreakTime GetBreakTime(long employeeId, long workshopId) + { + var employeeSettings = _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, + employeeId); + if (employeeSettings == null) + { + return new BreakTime(false, TimeOnly.MinValue); + } + + return employeeSettings.BreakTime; + } private DateTime CalculateRegularShiftDate(DateTime startDate, TimeOnly offset) { DateTime nextOffSetDateTime; diff --git a/Company.Domain/RollCallAgg/RollCall.cs b/Company.Domain/RollCallAgg/RollCall.cs index 35204c1c..8436eeae 100644 --- a/Company.Domain/RollCallAgg/RollCall.cs +++ b/Company.Domain/RollCallAgg/RollCall.cs @@ -4,6 +4,8 @@ using System; using Company.Domain.RollCallAgg.DomainService; using System.Linq; using _0_Framework.Exceptions; +using Company.Domain.EmployeeAgg; +using Company.Domain.WorkshopAgg; namespace Company.Domain.RollCallAgg { @@ -34,10 +36,10 @@ namespace Company.Domain.RollCallAgg { throw new NotFoundException("اطلاعات گروهبندی شخص نامعتبر است"); } - + SetBreakTime(service, employeeId, workshopId); //if (endDate.HasValue) //{ - // Edit(StartDate.Value,endDate.Value,service); + // Edit(StartDate.Value,endDate.Value,service); //} } @@ -198,30 +200,7 @@ namespace Company.Domain.RollCallAgg - /// - /// Truncates the TimeSpan to only include days, hours, and minutes. - /// Removes seconds, milliseconds, and smaller units. - /// - /// The original TimeSpan value. - /// A truncated TimeSpan with only days, hours, and minutes. - private TimeSpan TruncateTimeSpan(TimeSpan time) - { - return new TimeSpan(time.Days, time.Hours, time.Minutes, 0); - } - - /// - /// Truncates the DateTime to only include Years,Month,days,Hours and Minutes. - /// Removes seconds, milliseconds, and smaller units. - /// - /// The original DateTime value. - /// A truncated DateTime with only days, hours, and minutes. - private DateTime TruncateDateTime(DateTime dateTime) - { - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, - dateTime.Minute, 0); - } - - + public void SetEndDateTime(DateTime endDate, IRollCallDomainService service) { @@ -238,7 +217,7 @@ namespace Company.Domain.RollCallAgg ////محاسبه اختلاف زمانی(تاخیر و تعجیل)ء service.CalculateTimeDifferences(this); - + SetBreakTime(service, EmployeeId, WorkshopId); } @@ -259,6 +238,8 @@ namespace Company.Domain.RollCallAgg //محاسبه اختلاف زمانی(تاخیر و تعجیل)ء service.CalculateTimeDifferences(this); + SetBreakTime(service, EmployeeId, WorkshopId); + } @@ -331,6 +312,40 @@ namespace Company.Domain.RollCallAgg } } + + + public void SetBreakTime(IRollCallDomainService rollCallDomainService, long employeeId, long workshopId) + { + var breakTime = rollCallDomainService.GetBreakTime(employeeId, workshopId); + + if (breakTime.BreakTimeType == BreakTimeType.WithTime) + BreakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); + + + } + + /// + /// Truncates the TimeSpan to only include days, hours, and minutes. + /// Removes seconds, milliseconds, and smaller units. + /// + /// The original TimeSpan value. + /// A truncated TimeSpan with only days, hours, and minutes. + private TimeSpan TruncateTimeSpan(TimeSpan time) + { + return new TimeSpan(time.Days, time.Hours, time.Minutes, 0); + } + + /// + /// Truncates the DateTime to only include Years,Month,days,Hours and Minutes. + /// Removes seconds, milliseconds, and smaller units. + /// + /// The original DateTime value. + /// A truncated DateTime with only days, hours, and minutes. + private DateTime TruncateDateTime(DateTime dateTime) + { + return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, + dateTime.Minute, 0); + } //private static (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection rotatingShifts) //{ diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs index a7f43bf8..68e3dcf7 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs @@ -8,7 +8,7 @@ namespace CompanyManagment.App.Contracts.RollCall; public interface IRollCallMandatoryApplication { bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart); - ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking); + ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout); /// /// گزارش نوبت کاری حضور غیاب diff --git a/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs b/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs index d1fa157d..4bfd8968 100644 --- a/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs @@ -61,4 +61,8 @@ public class RollCallViewModel /// مقدار تایم شیفت (مدت زمان شیفت کاری) /// public TimeSpan ShiftDurationTimeSpan { get; set; } + /// + /// مدت زمان استراحت + /// + public TimeSpan BreakTimeSpan { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index c470f86f..03879c1b 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -793,17 +793,17 @@ public class RollCallApplication : IRollCallApplication { List fromDates = commands.Select(x => x.FromDate.ToGeorgianDateTime()).ToList(); var employeeIds = commands.Select(x => x.EmployeeId).ToList(); - if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش رسمی است"); } - if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی نهایی است"); } - if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی موقت است"); } diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs index fff9d80d..33bcd3df 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs @@ -191,6 +191,11 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC return true; } + if (command.BreakTime.BreakTimeValue != employeeSettings.BreakTime.BreakTimeValue || command.BreakTime.HasBreakTimeValue != employeeSettings.BreakTime.HasBreakTimeValue) + { + return true; + } + switch (employeeSettings.WorkshopShiftStatus) { case WorkshopShiftStatus.Irregular: diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index d9fcb853..9276e8db 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -135,16 +135,19 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll EndDate = x.EndDate, ShiftSpan = (x.EndDate.Value - x.StartDate.Value), CreationDate = x.ShiftDate, - }).ToList(); + BreakTimeSpan = x.BreakTimeSpan + }).ToList(); + groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => new GroupedRollCalls() { CreationDate = x.Key, ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)), - - SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(breakTime, + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), + }).OrderBy(x => x.CreationDate).ToList(); } @@ -853,18 +856,24 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll #endregion } - public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan) + //public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan) + //{ + // if (breakTime.BreakTimeType != BreakTimeType.WithTime) + // return new TimeSpan(); + + // var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); + + // if (breakTimeSpan * 2 >= sumOneDaySpan) + // return new TimeSpan(); + + // return breakTimeSpan; ; + + //} + public static TimeSpan CalculateBreakTime(TimeSpan breakTimeSpan, TimeSpan sumOneDaySpan) { - if (breakTime.BreakTimeType != BreakTimeType.WithTime) - return new TimeSpan(); - - var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); - if (breakTimeSpan * 2 >= sumOneDaySpan) return new TimeSpan(); - return breakTimeSpan; ; - } public TimeSpan AfterSubtract(CreateWorkingHoursTemp command, TimeSpan sumOneDaySpan, DateTime creationDate) @@ -2319,6 +2328,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll EndDate = x.EndDate, ShiftSpan = (x.EndDate.Value - x.StartDate.Value), CreationDate = x.CreationDate, + BreakTimeSpan = x.BreakTimeSpan }).ToList(); @@ -2330,10 +2340,10 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), HasFriday = x.Any(s => s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value.DayOfWeek == DayOfWeek.Friday), - SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), - BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))) + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))) }).ToList(); @@ -2946,8 +2956,10 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll LateEntryDuration = x.LateEntryDuration, EarlyExitDuration = x.EarlyExitDuration, LateExitDuration = x.LateExitDuration, - ShiftDurationTimeSpan = x.ShiftDurationTimeSpan - }).ToList(); + ShiftDurationTimeSpan = x.ShiftDurationTimeSpan, + BreakTimeSpan = x.BreakTimeSpan + + }).ToList(); @@ -2963,16 +2975,16 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll EarlyEntryDuration = s.EarlyEntryDuration, EarlyExitDuration = s.EarlyExitDuration, LateEntryDuration = s.LateEntryDuration, - LateExitDuration = s.LateExitDuration + LateExitDuration = s.LateExitDuration, }).ToList(), HasFriday = x.Any(s => s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value.DayOfWeek == DayOfWeek.Friday), SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime( - customizeWorkshopEmployeeSettings.BreakTime, + x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), - BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), ShiftDate = x.Key, TotalEarlyEntryDuration = new TimeSpan(x.Sum(rollCall => rollCall.EarlyEntryDuration.Ticks)), diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 34f6fdc2..2f384a23 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -154,13 +154,13 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //گرفتن ساعت استراحت پرسنل از تنظیمات #region breakTime - BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery().FirstOrDefault(x => - x.WorkshopId == workshopId && x.EmployeeId == employeeId); - //اگر ساعت استراحت پرسنل وجود نداشت صفر است - var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime; + //BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery().FirstOrDefault(x => + // x.WorkshopId == workshopId && x.EmployeeId == employeeId); + ////اگر ساعت استراحت پرسنل وجود نداشت صفر است + //var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime; #endregion - var rollCalls = _context.RollCalls.Where(x => + var rollCalls = _context.RollCalls.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && x.ShiftDate.Date >= startMonthDay && x.ShiftDate.Date <= endMonthDay).ToList(); @@ -223,7 +223,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var rollCallTimeSpanPerDay = new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)); - var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(breakTime, rollCallTimeSpanPerDay); + var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(x.First().BreakTimeSpan, rollCallTimeSpanPerDay); return new CheckoutDailyRollCallViewModel() { diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index 3e2a8b3b..9ea8a133 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -65,15 +65,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk public IActionResult OnPostShiftDateNew() { var startRollCall = new DateTime(2025, 4, 21); - var employees = _context.CustomizeWorkshopEmployeeSettings - .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList(); + //var employees = _context.CustomizeWorkshopEmployeeSettings + // .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList(); - var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null &&employees.Contains(x.EmployeeId)).ToList(); + var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList(); var r1 = rollCalls.ToList(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("endStep 1 ============"); - SetRollCall(r1); + SetBreakTime(r1); ViewData["message"] = "تومام یک"; @@ -444,6 +444,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk } + private void SetBreakTime(List r1) + { + foreach (var rollCall in r1) + { + rollCall.SetBreakTime(_rollCallDomainService,rollCall.EmployeeId,rollCall.WorkshopId); + } + + _context.SaveChanges(); + } private void SetRollCall(List r1) {