Revert "changes"

This reverts commit 1e18fe1067.
This commit is contained in:
MahanCh
2025-05-07 22:39:25 +03:30
parent 1e18fe1067
commit 8e8e9ef5de
3 changed files with 59 additions and 83 deletions

View File

@@ -15,7 +15,6 @@ using System.Threading.Tasks;
using _0_Framework.Application;
using OfficeOpenXml;
using OfficeOpenXml.Drawing.Chart;
using System.Collections;
namespace Company.Domain.RollCallAgg.DomainService;
@@ -26,7 +25,7 @@ public interface IRollCallDomainService
long workshopId);
TimeOnly GetEmployeeOffSetForRegularSettings(long employeeId, long workshopId);
DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId, DateTime rollCallStartDate, DateTime rollCallEndDate);
DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId, DateTime rollCallStartDate,DateTime rollCallEndDate);
void CalculateTimeDifferences(RollCall rollCall);
@@ -174,16 +173,16 @@ public class RollCallDomainService : IRollCallDomainService
}
public DateTime GetEmployeeShiftDateByRollCallStartDate(long workshopId, long employeeId,
DateTime rollCallStartDate, DateTime rollCallEndDate)
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 => FindRotatingShift(rollCallStartDate, rollCallEndDate, shiftDetails.rotatingShifts).start.Date,
WorkshopShiftStatus.Rotating => FindRotatingShift(rollCallStartDate,rollCallEndDate,shiftDetails.rotatingShifts).start.Date,
WorkshopShiftStatus.Irregular => rollCallStartDate.Date,
_ => throw new ArgumentOutOfRangeException()
};
@@ -257,7 +256,7 @@ public class RollCallDomainService : IRollCallDomainService
var lateEntryRollCall = rollCallsInShift.OrderBy(x => x.StartDate).FirstOrDefault(x => x.StartDate > employeeShift.start);
var previousShift = employeeShifts.OrderByDescending(x => x.start)
.FirstOrDefault(x => x.end < employeeShift.start);
@@ -300,7 +299,7 @@ public class RollCallDomainService : IRollCallDomainService
var lateExitRollCall = rollCallsInShift.OrderBy(x => x.EndDate).FirstOrDefault(x => x.EndDate > employeeShift.end);
// تعجیل در خروج - زود رفتن
var nextShift = employeeShifts.OrderBy(x => x.start)
@@ -375,7 +374,7 @@ public class RollCallDomainService : IRollCallDomainService
var lateEntryRollCallRotating = rollCallsInRotatingShift.OrderBy(x => x.StartDate).FirstOrDefault(x => x.StartDate > shift.start);
if (earlyEntryRollCallRotating != null)
{
@@ -406,7 +405,7 @@ public class RollCallDomainService : IRollCallDomainService
var lateExitRollCallRotating = rollCallsInRotatingShift.OrderBy(x => x.EndDate).FirstOrDefault(x => x.EndDate > shift.end);
if (earlyExitRollCallRotating != null && (rollCallsInRotatingShift.Any(x =>
x.StartDate < rotatingShiftEnd && x.StartDate > earlyExitRollCallRotating.EndDate) == false))
@@ -454,10 +453,10 @@ public class RollCallDomainService : IRollCallDomainService
DateTime startEntryWithDate = startDate.Add(startRollCall.TimeOfDay);
DateTime endEntryWithDate = endDate.Add(endRollCall.TimeOfDay);
DateTime twoHourBeforeStart = startEntryWithDate.AddHours(-2);
DateTime twoHourAfterStart = startEntryWithDate.AddHours(2);
DateTime twoHourBeforeEnd = endEntryWithDate.AddHours(-2);
DateTime twoHourAfterEnd = endEntryWithDate.AddHours(2);
DateTime oneHourBeforeStart = startEntryWithDate.AddHours(-1);
DateTime oneHourAfterStart = startEntryWithDate.AddHours(1);
DateTime oneHourBeforeEnd = endEntryWithDate.AddHours(-1);
DateTime oneHourAfterEnd = endEntryWithDate.AddHours(1);
var shiftDateTimes = rotatingShifts.SelectMany(shift =>
@@ -478,68 +477,56 @@ public class RollCallDomainService : IRollCallDomainService
#region مقایسه شروع حضور غیاب با شیفت
//var startFilteredTimes = shiftDateTimes.Where(shift =>
// (twoHourBeforeStart <= shift.Start && twoHourAfterStart >= shift.Start) ||
// (twoHourBeforeStart <= shift.End && twoHourAfterStart >= shift.End)).ToList();
var startFilteredTimes = shiftDateTimes.Where(shift =>
(oneHourBeforeStart <= shift.Start && oneHourAfterStart >= shift.Start) ||
(oneHourBeforeStart <= shift.End && oneHourAfterStart >= shift.End)).ToList();
//if (startFilteredTimes.Count == 0)
//{
// startFilteredTimes = shiftDateTimes;
//}
//else if (startFilteredTimes.Count == 1)
//{
// var startChosenShift = startFilteredTimes.First();
if (startFilteredTimes.Count == 0)
{
startFilteredTimes = shiftDateTimes;
}
else if (startFilteredTimes.Count == 1)
{
var startChosenShift = startFilteredTimes.First();
// if (startChosenShift.End < startChosenShift.Start)
// startChosenShift.End = startChosenShift.End.AddDays(1);
if (startChosenShift.End < startChosenShift.Start)
startChosenShift.End = startChosenShift.End.AddDays(1);
// return startChosenShift;
//}
return startChosenShift;
}
//#endregion
#endregion
//#region مقایسه پایان حضورغیاب با شیفت
#region مقایسه پایان حضورغیاب با شیفت
var endFilteredTimes = shiftDateTimes.Where(shift =>
(oneHourBeforeEnd <= shift.Start && oneHourAfterEnd >= shift.Start) ||
(oneHourBeforeEnd <= shift.End && oneHourAfterEnd >= shift.End)).ToList();
if (endFilteredTimes.Count == 0)
{
endFilteredTimes = startFilteredTimes;
}
else if (endFilteredTimes.Count == 1)
{
var endChosenShift = endFilteredTimes.First();
return endChosenShift;
}
//var endFilteredTimes = shiftDateTimes.Where(shift =>
// (twoHourBeforeEnd <= shift.Start && twoHourAfterEnd >= shift.Start) ||
// (twoHourBeforeEnd <= shift.End && twoHourAfterEnd >= shift.End)).ToList();
//if (endFilteredTimes.Count == 0)
//{
// endFilteredTimes = startFilteredTimes;
//}
//else if (endFilteredTimes.Count == 1)
//{
// var endChosenShift = endFilteredTimes.First();
// return endChosenShift;
//}
#endregion
#region اشتراک حضور غیاب و شیفت
var overlapShifts = shiftDateTimes
.Select(shift => new
{
Shift = shift,
Overlap = new TimeSpan(Math.Max(0,
Math.Min(shift.End.Ticks, endRollCall.Ticks) -
Math.Max(shift.Start.Ticks, startRollCall.Ticks))),
// زمان حضور فرد در شیفت (مجموع Overlap با شیفت)
TotalTimeInShift = new TimeSpan(Math.Max(0,
Math.Min(shift.End.Ticks, endRollCall.Ticks) -
Math.Max(shift.Start.Ticks, startRollCall.Ticks))),
StartDistance = Math.Abs((shift.Start - startRollCall).Ticks),
EndDistance = Math.Abs((shift.End - endRollCall).Ticks),
TotalDistance = Math.Abs((shift.Start - startRollCall).Ticks) + Math.Abs((shift.End - endRollCall).Ticks)
})
.OrderByDescending(s => s.TotalTimeInShift) // 1. بیشترین زمان حضور فرد
.ThenByDescending(s => s.Overlap) // 2. بیشترین Overlap
.ThenBy(s=>s.TotalDistance)
.ThenBy(s => s.StartDistance)
.ThenBy(x=>x.EndDistance); // 3. اگر برابر بود، Start نزدیک‌تر
var overlapShifts = endFilteredTimes.Select(shift => new
{
Shift = shift,
Overlap = new TimeSpan(Math.Max(0,
Math.Min(shift.End.Ticks, oneHourAfterEnd.Ticks) -
Math.Max(shift.Start.Ticks, oneHourBeforeStart.Ticks)))
});
var overlapChosenShift = overlapShifts.First();
var overlapChosenShift = overlapShifts.MaxBy(s => s.Overlap);
var end = overlapChosenShift.Shift.End;
if (overlapChosenShift.Shift.End < overlapChosenShift.Shift.Start)
end = overlapChosenShift.Shift.End.AddDays(1);

View File

@@ -504,12 +504,6 @@ public class RollCallApplication : IRollCallApplication
_rollCallRepository.AddRange(rollCallsAsEntityModels);
_rollCallRepository.SaveChanges();
foreach (var rollCallsAsEntityModel in rollCallsAsEntityModels)
{
rollCallsAsEntityModel.ClearTimeDiff();
rollCallsAsEntityModel.SetShiftDate(_rollCallDomainService);
}
_rollCallRepository.SaveChanges();
foreach (var rollCallsAsEntityModel in rollCallsAsEntityModels)
{
rollCallsAsEntityModel.Edit(rollCallsAsEntityModel.StartDate.Value, rollCallsAsEntityModel.EndDate.Value, _rollCallDomainService);
}

View File

@@ -59,9 +59,9 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
public IActionResult OnPostShiftDateNew()
{
var startRollCall = new DateTime(2025, 4, 21);
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null && x.WorkshopId == 344).ToList();
var r1 = rollCalls.ToList();
var startRollCall = new DateTime(2025, 3, 21);
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
var r1 = rollCalls.Take(10000).ToList();
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("endStep 1 ============");
@@ -82,9 +82,9 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
//Console.WriteLine("endStep 1 ============");
//SetRollCall(r1);
await RefactorEmployeeDocumentItem();
await ChangeIsConfirmed();
await RemoveEmployeeClientTemps();
await RefactorEmployeeDocumentItem();
await ChangeIsConfirmed();
await RemoveEmployeeClientTemps();
ViewData["message"] = "تومام دو";
return Page();
@@ -96,7 +96,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
.Include(x => x.EmployeeDocumentItemCollection)
.Where(x => x.IsConfirmed);
var employeeClientTemps = await _context.EmployeeClientTemps.Where(x => employeeDocuments.Any(a => a.WorkshopId == x.WorkshopId && a.EmployeeId == x.EmployeeId)).ToListAsync();
var employeeClientTemps = await _context.EmployeeClientTemps.Where(x=>employeeDocuments.Any(a=>a.WorkshopId == x.WorkshopId && a.EmployeeId == x.EmployeeId)).ToListAsync();
foreach (var employeeClientTemp in employeeClientTemps)
{
@@ -108,7 +108,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
private async System.Threading.Tasks.Task ChangeIsConfirmed()
{
var employeeDocuments = await _context.EmployeeDocuments.Include(x => x.EmployeeDocumentItemCollection).ToListAsync();
var employeeDocuments = await _context.EmployeeDocuments.Include(x=>x.EmployeeDocumentItemCollection).ToListAsync();
foreach (var employeeDocument in employeeDocuments)
{
employeeDocument.UpdateRequiredItemsSubmittedByClient();
@@ -294,19 +294,14 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
var endedRollCalls2 = r1.Where(x => x.EndDate != null).ToList();
var countSetTDRollCall = endedRollCalls2.Count;
var stepSetTDRollCal = 1;
foreach (var rollCall in endedRollCalls2)
{
rollCall.ClearTimeDiff();
}
_context.SaveChanges();
foreach (var endedRollCall in endedRollCalls2)
{
endedRollCall.Edit(endedRollCall.StartDate.Value, endedRollCall.EndDate.Value, _rollCallDomainService);
endedRollCall.SetShiftDate(_rollCallDomainService);
Console.WriteLine($"{stepSetTDRollCal} - {countSetTDRollCall} ended Set Time Differences{endedRollCall.id}");
stepSetTDRollCal += 1;
}
_context.SaveChanges();
_context.SaveChanges();
}