feat : version 0.3.6.5

add new filter for shiftplan
master
Amir Hossein Khademi 2024-02-21 20:36:55 +03:30
parent 70f83b627b
commit a6ebce4b8f
9 changed files with 108 additions and 28 deletions

View File

@ -1 +1 @@
0.2.5.1
0.3.6.5

View File

@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<AssemblyVersion>0.2.5.1</AssemblyVersion>
<FileVersion>0.2.5.1</FileVersion>
<AssemblyVersion>0.3.6.5</AssemblyVersion>
<FileVersion>0.3.6.5</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -14,7 +14,7 @@ public class ReportController : ICarterModule
.WithDisplayName("Get Tasks Report")
.HasApiVersion(1.0);
group.MapGet("shit/plan/{shiftPLanId}", GetShiftPlanReportAsync)
group.MapGet("shift/plan/{shiftPLanId}", GetShiftPlanReportAsync)
.WithDisplayName("Get ShiftPlan Report")
.HasApiVersion(1.0);
}

View File

@ -1,4 +1,6 @@
namespace Brizco.Api.Controllers;
using Brizco.Domain.Enums;
namespace Brizco.Api.Controllers;
public class ShiftPlanController : ICarterModule
{
@ -37,8 +39,8 @@ public class ShiftPlanController : ICarterModule
// GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, ISender sender, CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0), cancellationToken));
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, [FromQuery] DateTimeQueryFilter? dateFilter , ISender sender, CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0 , DateTimeQueryFilter: dateFilter), cancellationToken));
// GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, ISender sender, CancellationToken cancellationToken)

View File

@ -91,6 +91,11 @@ builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
.Create(typeof(DomainConfig).Assembly)
.WithAllOpenGenericHandlerTypesRegistered()
.Build());
builder.RegisterMediatR(MediatRConfigurationBuilder
.Create(typeof(CoreConfig).Assembly)
.WithAllOpenGenericHandlerTypesRegistered()
.Build());
});
var app = builder.Build();

View File

@ -27,7 +27,7 @@ public class ShiftPlanReportCommandHandler : IRequestHandler<ShiftPlanReportComm
var workbook = new XSSFWorkbook();
var sheet = workbook.CreateSheet($"شیفت {shiftPlan.ShiftTitle} - {shiftPlan.PlanFor.ToPersianDateTime().ToLongDateString()}");
var sheet = workbook.CreateSheet($"{shiftPlan.ShiftTitle} - {shiftPlan.PlanFor.ToPersianDateTime().ToString("yyyyMMMMdd")}");
sheet.IsRightToLeft = true;
int selectedRow = 1;
CreateHeader(sheet, workbook);

View File

@ -1,6 +1,6 @@
namespace Brizco.Domain.CommandQueries.Queries;
public sealed record GetShiftPlansQuery(int Page = 0 , long SelectedDate = 0) :
public sealed record GetShiftPlansQuery(int Page = 0 , long SelectedDate = 0 , DateTimeQueryFilter? DateTimeQueryFilter = DateTimeQueryFilter.CustomDate) :
IRequest<List<ShiftPlanSDto>>;
public sealed record GetShiftPlanQuery(Guid Id) :

View File

@ -0,0 +1,12 @@
namespace Brizco.Domain.Enums;
public enum DateTimeQueryFilter
{
CustomDate = 0,
Today = 1,
Yesterday = 2,
PastWeek = 10,
NextWeek = 11,
PastMonth = 20,
NextMonth = 21
}

View File

@ -14,41 +14,102 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
}
public async Task<List<ShiftPlanSDto>> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken)
{
List<ShiftPlanSDto> shiftPlans;
if (request.SelectedDate > 0)
if (_currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
IQueryable<Domain.Entities.Shift.ShiftPlan> baseQuery = _repositoryWrapper.SetRepository<Domain.Entities.Shift.ShiftPlan>()
.TableNoTracking
.OrderByDescending(s => s.CreatedAt)
.Where(s => s.ComplexId == complexId);
List<ShiftPlanSDto> shiftPlans = new List<ShiftPlanSDto>();
if (request.SelectedDate == 0)
{
var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
shiftPlans = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.ShiftPlan>()
.TableNoTracking
.Where(s => s.PlanFor.Date == selectedDate.Date)
.OrderByDescending(s => s.CreatedAt)
return await baseQuery
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
}
else if (request.SelectedDate > 0)
{
if (request.SelectedDate > 0)
{
var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == selectedDate.Date)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
}
else
{
switch (request.DateTimeQueryFilter)
{
case DateTimeQueryFilter.Today:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == DateTime.Now.Date)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.Yesterday:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == DateTime.Now.AddDays(-1).Date)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.PastWeek:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.AddDays(-7).Date)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.NextWeek:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.Date && s.PlanFor.Date <= DateTime.Today.AddDays(+7))
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.PastMonth:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.AddDays(-31).Date)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.NextMonth:
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.Date && s.PlanFor.Date <= DateTime.Today.AddDays(+31))
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case null:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
foreach (var shiftPlan in shiftPlans)
{
var activitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
.TableNoTracking
.CountAsync(a => a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
.CountAsync(a => a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
var doneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
.TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
.CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
var undoneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
.TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
.CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
shiftPlan.UndoneActivitiesCount = undoneActivitiesCount;
shiftPlan.DoneActivitiesCount = doneActivitiesCount;
shiftPlan.TotalActivitiesCount = activitiesCount;
}
}
else
{
shiftPlans = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.ShiftPlan>().TableNoTracking
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
}
return shiftPlans;