workflow - rollcallEdit - grouping...

This commit is contained in:
SamSys
2024-12-24 21:59:16 +03:30
parent 79a38c31a8
commit 166ccadfba
33 changed files with 1095 additions and 482 deletions

View File

@@ -7,31 +7,32 @@ namespace WorkFlow.Application.Contracts.WorkFlow;
public interface IWorkFlowApplication
{
OperationResult CreateRollCallConfirmedAbsence(CreateRollCallConfirmedAbsence command);
OperationResult CreateRollCallConfirmedWithoutLunchBreak(CreateRollCallConfirmedWithoutLunchBreak command);
Task<OperationResult> CreateRollCallConfirmedAbsence(CreateRollCallConfirmedAbsence command);
Task<OperationResult> CreateRollCallConfirmedWithoutLunchBreak(CreateRollCallConfirmedWithoutLunchBreak command);
int GetCountAllWorkFlows(long workshopId);
int GetRollCallAbsentsWorkFlows(long workshopId);
int GetCountCutRollCallByBgService(long workshopId);
int GetAllWorkFlowCount(long workshopId);
Task<int> GetCountAllWorkFlows(long workshopId);
Task<int> GetRollCallAbsentsWorkFlows(long workshopId);
Task<int> GetCountCutRollCallByBgService(long workshopId);
Task<int> GetAllWorkFlowCount(long workshopId);
Task<int> GetAllWorkFlowCountAsync(long workshopId);
DailyRollCallWorkFlowViewModel GetAbsentRollCallWorkFlowsByDate(long workshopId, DateTime date);
DailyRollCallConfirmedWithoutLunchBreakViewModel GetEmployeesWithoutLunchBreakByDate(long workshopId, DateTime date);
DailyRollCallWorkFlowViewModel GetRollCallWorkFlowsCutByBgServiceByDate(long workshopId, DateTime date);
DailyRollCallWorkFlowViewModel GetUndefinedRollCallsByDate(long workshopId, DateTime date);
Task<DailyRollCallWorkFlowViewModel> GetAbsentRollCallWorkFlowsByDate(long workshopId, DateTime date);
Task<DailyRollCallConfirmedWithoutLunchBreakViewModel> GetEmployeesWithoutLunchBreakByDate(long workshopId, DateTime date);
Task<DailyRollCallWorkFlowViewModel> GetRollCallWorkFlowsCutByBgServiceByDate(long workshopId, DateTime date);
Task<DailyRollCallWorkFlowViewModel> GetUndefinedRollCallsByDate(long workshopId, DateTime date);
DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel GetRollCallsOverlappingLeaveByDate(long workshopId,
DateTime date);
Task<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel> GetRollCallsOverlappingLeaveByDate(long workshopId,
DateTime date);
List<RollCallConfirmAbsenceViewModel> GetConfirmAbsencesBy(long workshopId, DateTime start, DateTime end);
List<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel> GetRollCallsOverlappingLeaves(long workshopId);
List<DailyRollCallWorkFlowViewModel> GetRollCallWorkFlowsCutByBgService(long workshopId);
List<DailyRollCallWorkFlowViewModel> GetAbsentRollCallWorkFlows(long workshopId);
List<DailyRollCallWorkFlowViewModel> GetUndefinedRollCalls(long workshopId);
Task<List<RollCallConfirmAbsenceViewModel>> GetConfirmAbsencesBy(long workshopId, DateTime start, DateTime end);
Task<List<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel>> GetRollCallsOverlappingLeaves(long workshopId);
Task<List<DailyRollCallWorkFlowViewModel>> GetRollCallWorkFlowsCutByBgService(long workshopId);
Task<List<DailyRollCallWorkFlowViewModel>> GetAbsentRollCallWorkFlows(long workshopId);
Task<List<DailyRollCallWorkFlowViewModel>> GetUndefinedRollCalls(long workshopId);
List<DailyRollCallConfirmedWithoutLunchBreakViewModel> GetEmployeesWithoutLunchBreak(long workshopId);
List<(long Id, string Name)> GetEmployeesWithoutGroup(long workshopId);
Task<List<DailyRollCallConfirmedWithoutLunchBreakViewModel>> GetEmployeesWithoutLunchBreak(long workshopId);
Task<List<(long Id, string Name)>> GetEmployeesWithoutGroup(long workshopId);
}

View File

@@ -28,7 +28,7 @@ public class WorkFlowApplication : IWorkFlowApplication
_rollCallConfirmedWithoutLunchBreakRepository = rollCallConfirmedWithoutLunchBreakRepository;
}
public OperationResult CreateRollCallConfirmedAbsence(CreateRollCallConfirmedAbsence command)
public async Task<OperationResult> CreateRollCallConfirmedAbsence(CreateRollCallConfirmedAbsence command)
{
OperationResult op = new OperationResult();
if (!command.AbsenceDate.TryToGeorgianDateTime(out var absenceDateGe))
@@ -39,11 +39,11 @@ public class WorkFlowApplication : IWorkFlowApplication
command.ConfirmedByAccountId);
_absenceRepository.Create(entity);
_absenceRepository.SaveChanges();
await _absenceRepository.SaveChangesAsync();
return op.Succcedded();
}
public OperationResult CreateRollCallConfirmedWithoutLunchBreak(CreateRollCallConfirmedWithoutLunchBreak command)
public async Task<OperationResult> CreateRollCallConfirmedWithoutLunchBreak(CreateRollCallConfirmedWithoutLunchBreak command)
{
OperationResult op = new();
var entity = _rollCallACL.GetDetails(command.RollCallId);
@@ -54,30 +54,30 @@ public class WorkFlowApplication : IWorkFlowApplication
var newEntity = new RollCallConfirmedWithoutLunchBreak(command.RollCallId, entity.EmployeeId, entity.WorkshopId, entity.RollCallDate);
_rollCallConfirmedWithoutLunchBreakRepository.Create(newEntity);
_rollCallConfirmedWithoutLunchBreakRepository.SaveChanges();
await _rollCallConfirmedWithoutLunchBreakRepository.SaveChangesAsync();
return op.Succcedded();
}
public int GetCountAllWorkFlows(long workshopId)
public async Task<int> GetCountAllWorkFlows(long workshopId)
{
int count = 0;
count += GetAllWorkFlowCount(workshopId);
count += await GetAllWorkFlowCount(workshopId);
return count;
}
public int GetRollCallAbsentsWorkFlows(long workshopId)
public Task<int> GetRollCallAbsentsWorkFlows(long workshopId)
{
var now = DateTime.Now;
DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo);
return _rollCallACL.GetRollCallAbsentsWorkFlowsCount(workshopId, now, twoMonthsAgo);
return Task.FromResult(_rollCallACL.GetRollCallAbsentsWorkFlowsCount(workshopId, now, twoMonthsAgo));
}
public int GetCountCutRollCallByBgService(long workshopId)
public async Task<int> GetCountCutRollCallByBgService(long workshopId)
{
return GetRollCallWorkFlowsCutByBgService(workshopId).Count;
return (await GetRollCallWorkFlowsCutByBgService(workshopId)).Count;
}
public int GetAllWorkFlowCount(long workshopId)
public async Task<int> GetAllWorkFlowCount(long workshopId)
{
var count = 0;
var activeServiceByWorkshopId = _rollCallACL.GetActiveServiceByWorkshopId(workshopId);
@@ -86,17 +86,22 @@ public class WorkFlowApplication : IWorkFlowApplication
return count;
}
//count += _rollCallACL.GetRollCallAbsentsWorkFlows(accId, workshopId);
count += GetAbsentRollCallWorkFlows(workshopId)?.Count ?? 0;
count += GetRollCallWorkFlowsCutByBgService(workshopId)?.Count ?? 0;
count += GetEmployeesWithoutLunchBreak(workshopId)?.Count ?? 0;
count += GetRollCallsOverlappingLeaves(workshopId)?.Count ?? 0;
count += GetUndefinedRollCalls(workshopId)?.Count ?? 0;
count += (await GetAbsentRollCallWorkFlows(workshopId))?.Count ?? 0;
count += (await GetRollCallWorkFlowsCutByBgService(workshopId))?.Count ?? 0;
count += (await GetEmployeesWithoutLunchBreak(workshopId))?.Count ?? 0;
count += (await GetRollCallsOverlappingLeaves(workshopId))?.Count ?? 0;
count += (await GetUndefinedRollCalls(workshopId))?.Count ?? 0;
return count;
}
public DailyRollCallWorkFlowViewModel GetAbsentRollCallWorkFlowsByDate(long workshopId, DateTime date)
public Task<int> GetAllWorkFlowCountAsync(long workshopId)
{
return Task.FromResult(20);
}
public async Task<DailyRollCallWorkFlowViewModel> GetAbsentRollCallWorkFlowsByDate(long workshopId, DateTime date)
{
var startOfDay = date.Date;
@@ -110,7 +115,7 @@ public class WorkFlowApplication : IWorkFlowApplication
var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, startOfDay, endOfDay);
var confirmedAbssences = GetConfirmAbsencesBy(workshopId, startOfDay, endOfDay);
var confirmedAbssences = await GetConfirmAbsencesBy(workshopId, startOfDay, endOfDay);
//var groupedConfirmedAbssencesByDate = confirmedAbssences.GroupBy(x => x.AbsenceDate.Date).ToList();
@@ -124,7 +129,7 @@ public class WorkFlowApplication : IWorkFlowApplication
var allAbsencesInDate = absences.FirstOrDefault();
if (allAbsencesInDate == null)
return new();
return await Task.FromResult(new DailyRollCallWorkFlowViewModel());
var newItem = new DailyRollCallWorkFlowViewModel()
@@ -173,7 +178,7 @@ public class WorkFlowApplication : IWorkFlowApplication
return newItem;
}
public DailyRollCallConfirmedWithoutLunchBreakViewModel GetEmployeesWithoutLunchBreakByDate(long workshopId, DateTime date)
public async Task<DailyRollCallConfirmedWithoutLunchBreakViewModel> GetEmployeesWithoutLunchBreakByDate(long workshopId, DateTime date)
{
var startOfDay = date.Date;
var endOfDay = startOfDay.AddDays(1).Date.AddTicks(-1);
@@ -209,7 +214,7 @@ public class WorkFlowApplication : IWorkFlowApplication
};
}
public DailyRollCallWorkFlowViewModel GetRollCallWorkFlowsCutByBgServiceByDate(long workshopId, DateTime date)
public async Task<DailyRollCallWorkFlowViewModel> GetRollCallWorkFlowsCutByBgServiceByDate(long workshopId, DateTime date)
{
var startOfDay = date.Date;
var endOfDay = startOfDay.AddDays(1).Date.AddTicks(-1);
@@ -241,7 +246,7 @@ public class WorkFlowApplication : IWorkFlowApplication
};
return result;
}
public DailyRollCallWorkFlowViewModel GetUndefinedRollCallsByDate(long workshopId, DateTime date)
public async Task<DailyRollCallWorkFlowViewModel> GetUndefinedRollCallsByDate(long workshopId, DateTime date)
{
var startOfDay = date.Date;
var endOfDay = startOfDay.AddDays(1).Date.AddTicks(-1);
@@ -275,7 +280,8 @@ public class WorkFlowApplication : IWorkFlowApplication
}
public DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel GetRollCallsOverlappingLeaveByDate(long workshopId, DateTime date)
public async Task<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel> GetRollCallsOverlappingLeaveByDate(long workshopId,
DateTime date)
{
var startOfDay = date.Date;
var endOfDay = startOfDay.AddDays(1).Date.AddTicks(-1);
@@ -315,50 +321,50 @@ public class WorkFlowApplication : IWorkFlowApplication
};
return result;
}
public List<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel> GetRollCallsOverlappingLeaves(long workshopId)
public async Task<List<DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel>> GetRollCallsOverlappingLeaves(long workshopId)
{
var now = DateTime.Now;
DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo);
var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now);
var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now);
var rollCalls = _rollCallACL.GetRollCallsOverlappingLeaves(workshopId, twoMonthsAgo, now);
return rollCalls
.Select(x=> new DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel()
{
Date = x.Date,
DateFa = x.DateFa,
EmployeesList = x.EmployeesList
.Where(y => !lastCheckouts.Any(z => z.EmployeeId == y.EmployeeId &&
z.CheckoutStart.Date <= x.Date.Date &&
z.CheckoutEnd.Date >= x.Date.Date ) && activeEmployees.Any(z => y.EmployeeId == z.EmployeeId))
.Select(e => new WorkFlowEmployeeWithRollCallOnLeaveViewModel()
{
EmployeeId = e.EmployeeId,
EmployeeFullName = e.EmployeeFullName,
LeaveId = e.LeaveId,
EndOfOverlapTime = e.EndOfOverlapTime,
StartOfOverlapTime = e.StartOfOverlapTime,
RollCallId = e.RollCallId,
EndOfOverlapDateFa = e.EndOfOverlapDateFa,
EndOfOverlapDateTime = e.EndOfOverlapDateTime,
StartOfOverlapDateFa = e.StartOfOverlapDateFa,
StartOfOverlapDateTime = e.StartOfOverlapDateTime
}).ToList(),
DayOfWeek = x.DayOfWeek
})
.Where(y => y.EmployeesList != null && y.EmployeesList.Any())
.OrderBy(x => x.Date).ToList();
var now = DateTime.Now;
DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo);
var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now);
var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now);
var rollCalls = _rollCallACL.GetRollCallsOverlappingLeaves(workshopId, twoMonthsAgo, now);
return rollCalls
.Select(x => new DailyWorkFlowEmployeesWithRollCallOnLeaveViewModel()
{
Date = x.Date,
DateFa = x.DateFa,
EmployeesList = x.EmployeesList
.Where(y => !lastCheckouts.Any(z => z.EmployeeId == y.EmployeeId &&
z.CheckoutStart.Date <= x.Date.Date &&
z.CheckoutEnd.Date >= x.Date.Date) && activeEmployees.Any(z => y.EmployeeId == z.EmployeeId))
.Select(e => new WorkFlowEmployeeWithRollCallOnLeaveViewModel()
{
EmployeeId = e.EmployeeId,
EmployeeFullName = e.EmployeeFullName,
LeaveId = e.LeaveId,
EndOfOverlapTime = e.EndOfOverlapTime,
StartOfOverlapTime = e.StartOfOverlapTime,
RollCallId = e.RollCallId,
EndOfOverlapDateFa = e.EndOfOverlapDateFa,
EndOfOverlapDateTime = e.EndOfOverlapDateTime,
StartOfOverlapDateFa = e.StartOfOverlapDateFa,
StartOfOverlapDateTime = e.StartOfOverlapDateTime
}).ToList(),
DayOfWeek = x.DayOfWeek
})
.Where(y => y.EmployeesList != null && y.EmployeesList.Any())
.OrderBy(x => x.Date).ToList();
}
}
public List<RollCallConfirmAbsenceViewModel> GetConfirmAbsencesBy(long workshopId, DateTime start, DateTime end)
public async Task<List<RollCallConfirmAbsenceViewModel>> GetConfirmAbsencesBy(long workshopId, DateTime start, DateTime end)
{
return _absenceRepository.GetConfirmAbsencesBy(workshopId, start, end);
}
public List<DailyRollCallWorkFlowViewModel> GetUndefinedRollCalls(long workshopId)
public async Task<List<DailyRollCallWorkFlowViewModel>> GetUndefinedRollCalls(long workshopId)
{
var now = DateTime.Now;
@@ -388,14 +394,14 @@ public class WorkFlowApplication : IWorkFlowApplication
}).Where(y => y.RollCallWorkFlowPerDayViewModels != null && y.RollCallWorkFlowPerDayViewModels.Any()).OrderBy(x => x.DateTime).ToList();
}
public List<DailyRollCallWorkFlowViewModel> GetRollCallWorkFlowsCutByBgService(long workshopId)
public async Task<List<DailyRollCallWorkFlowViewModel>> GetRollCallWorkFlowsCutByBgService(long workshopId)
{
var now = DateTime.Now;
var yesterday = now.AddDays(-1).Date;
DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo);
var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now);
var rollCalls = _rollCallACL.GetRollCallWorkFlowsCutByBgService(workshopId, twoMonthsAgo, yesterday);
var rollCalls = _rollCallACL.GetRollCallWorkFlowsCutByBgService(workshopId, twoMonthsAgo, now.AddDays(-1).Date);
var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now);
return rollCalls.Select(x => new DailyRollCallWorkFlowViewModel()
{
@@ -413,9 +419,10 @@ public class WorkFlowApplication : IWorkFlowApplication
RollCallId = e.RollCallId
}).ToList(),
DayOfWeekFa = x.DateTime.DayOfWeek.DayOfWeeKToPersian()
}).Where(y => y.RollCallWorkFlowPerDayViewModels != null && y.RollCallWorkFlowPerDayViewModels.Any()).OrderBy(x => x.DateTime).ToList();
}).Where(y => y.RollCallWorkFlowPerDayViewModels != null && y.RollCallWorkFlowPerDayViewModels.Any())
.OrderBy(x => x.DateTime).ToList();
}
public List<DailyRollCallWorkFlowViewModel> GetAbsentRollCallWorkFlows(long workshopId)
public async Task<List<DailyRollCallWorkFlowViewModel>> GetAbsentRollCallWorkFlows(long workshopId)
{
var now = DateTime.Now;
@@ -428,7 +435,7 @@ public class WorkFlowApplication : IWorkFlowApplication
var absences = _rollCallACL.GetAbsentRollCallWorkFlows(workshopId, twoMonthsAgo, now.AddDays(-1).Date);
var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now);
var confirmedAbssences = GetConfirmAbsencesBy(workshopId, twoMonthsAgo,
var confirmedAbssences = await GetConfirmAbsencesBy(workshopId, twoMonthsAgo,
now);
@@ -484,7 +491,7 @@ public class WorkFlowApplication : IWorkFlowApplication
}
return result.OrderBy(x => x.DateTime).ToList();
}
public List<DailyRollCallConfirmedWithoutLunchBreakViewModel> GetEmployeesWithoutLunchBreak(long workshopId)
public async Task<List<DailyRollCallConfirmedWithoutLunchBreakViewModel>> GetEmployeesWithoutLunchBreak(long workshopId)
{
var now = DateTime.Now.Date;
@@ -518,7 +525,7 @@ public class WorkFlowApplication : IWorkFlowApplication
}).ToList();
}
public List<(long Id, string Name)> GetEmployeesWithoutGroup(long workshopId)
public async Task<List<(long Id, string Name)>> GetEmployeesWithoutGroup(long workshopId)
{
return _customizedWorkshopSettingsACL.GetEmployeesWithoutGroup(workshopId);
}