104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using _0_Framework.Domain;
|
|
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
|
using System;
|
|
using Company.Domain.RollCallAgg.DomainService;
|
|
using _0_Framework.Domain.CustomizeCheckoutShared.Base;
|
|
using System.Collections.Generic;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.EmployeeAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
|
|
namespace Company.Domain.RollCallAgg
|
|
{
|
|
public class RollCall : EntityBase
|
|
{
|
|
private RollCall()
|
|
{
|
|
}
|
|
public RollCall(long workshopId, long employeeId, string employeeFullName, DateTime startDate, DateTime? endDate, int year, int month,
|
|
IRollCallDomainService service, RollCallModifyType rollCallModifyType = RollCallModifyType.None)
|
|
{
|
|
WorkshopId = workshopId;
|
|
EmployeeId = employeeId;
|
|
EmployeeFullName = employeeFullName;
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
Year = year;
|
|
Month = month;
|
|
RollCallModifyType = rollCallModifyType;
|
|
|
|
SetShiftDate(service);
|
|
|
|
}
|
|
|
|
public long WorkshopId { get; private set; }
|
|
public long EmployeeId { get; private set; }
|
|
public string EmployeeFullName { get; private set; }
|
|
public DateTime? StartDate { get; private set; }
|
|
public DateTime? EndDate { get; private set; }
|
|
public int Year { get; private set; }
|
|
public int Month { get; private set; }
|
|
public RollCallModifyType RollCallModifyType { get; private set; }
|
|
|
|
public DateTime ShiftDate { get; set; }
|
|
|
|
public void SetEndDateTime(DateTime? endDate)
|
|
{
|
|
EndDate = endDate;
|
|
}
|
|
|
|
public void Edit(DateTime start, DateTime end)
|
|
{
|
|
StartDate = start;
|
|
EndDate = end;
|
|
}
|
|
|
|
public RollCall SetModifyType(RollCallModifyType modifyType)
|
|
{
|
|
RollCallModifyType = modifyType;
|
|
return this;
|
|
}
|
|
|
|
public void SetShiftDate(IRollCallDomainService service)
|
|
{
|
|
var shiftDetails = service.GetEmployeeShiftDetails(EmployeeId, WorkshopId);
|
|
|
|
var offset = service.GetEmployeeOffSetForRegularSettings(EmployeeId, WorkshopId);
|
|
|
|
ShiftDate = shiftDetails.shiftType switch
|
|
{
|
|
WorkshopShiftStatus.Regular => CalculateRegularShiftDate(StartDate!.Value, offset),
|
|
WorkshopShiftStatus.Rotating => StartDate!.Value.Date,
|
|
WorkshopShiftStatus.Irregular => StartDate!.Value.Date,
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
}
|
|
|
|
private DateTime CalculateRegularShiftDate(DateTime startDate, TimeOnly offset)
|
|
{
|
|
DateTime nextOffSetDateTime;
|
|
if (startDate.TimeOfDay >= offset.ToTimeSpan())
|
|
{
|
|
nextOffSetDateTime = startDate.AddDays(1).Date + offset.ToTimeSpan();
|
|
}
|
|
else
|
|
nextOffSetDateTime = startDate.Date + offset.ToTimeSpan();
|
|
|
|
if (nextOffSetDateTime.TimeOfDay >= TimeSpan.FromHours(12))
|
|
return nextOffSetDateTime.Date;
|
|
|
|
return nextOffSetDateTime.AddDays(-1).Date;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public enum RollCallModifyType
|
|
{
|
|
None,
|
|
CutByBgService,
|
|
EditByEmployer,
|
|
Undefined
|
|
}
|
|
}
|