parent
							
								
									70f83b627b
								
							
						
					
					
						commit
						a6ebce4b8f
					
				| 
						 | 
					@ -6,8 +6,8 @@
 | 
				
			||||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
					    <ImplicitUsings>enable</ImplicitUsings>
 | 
				
			||||||
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
 | 
					    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
 | 
				
			||||||
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
 | 
					    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
 | 
				
			||||||
    <AssemblyVersion>0.2.5.1</AssemblyVersion>
 | 
					    <AssemblyVersion>0.3.6.5</AssemblyVersion>
 | 
				
			||||||
    <FileVersion>0.2.5.1</FileVersion>
 | 
					    <FileVersion>0.3.6.5</FileVersion>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	<ItemGroup>
 | 
						<ItemGroup>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ public class ReportController : ICarterModule
 | 
				
			||||||
            .WithDisplayName("Get Tasks Report")
 | 
					            .WithDisplayName("Get Tasks Report")
 | 
				
			||||||
            .HasApiVersion(1.0);
 | 
					            .HasApiVersion(1.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        group.MapGet("shit/plan/{shiftPLanId}", GetShiftPlanReportAsync)
 | 
					        group.MapGet("shift/plan/{shiftPLanId}", GetShiftPlanReportAsync)
 | 
				
			||||||
            .WithDisplayName("Get ShiftPlan Report")
 | 
					            .WithDisplayName("Get ShiftPlan Report")
 | 
				
			||||||
            .HasApiVersion(1.0);
 | 
					            .HasApiVersion(1.0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,6 @@
 | 
				
			||||||
namespace Brizco.Api.Controllers;
 | 
					using Brizco.Domain.Enums;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Brizco.Api.Controllers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ShiftPlanController : ICarterModule
 | 
					public class ShiftPlanController : ICarterModule
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -37,8 +39,8 @@ public class ShiftPlanController : ICarterModule
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // GET:Get All Entity
 | 
					    // GET:Get All Entity
 | 
				
			||||||
    public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, ISender sender, CancellationToken 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), cancellationToken));
 | 
					        => TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0 , DateTimeQueryFilter: dateFilter), cancellationToken));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // GET:Get An Entity By Id
 | 
					    // GET:Get An Entity By Id
 | 
				
			||||||
    public async Task<IResult> GetAsync(Guid id, ISender sender, CancellationToken cancellationToken)
 | 
					    public async Task<IResult> GetAsync(Guid id, ISender sender, CancellationToken cancellationToken)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -91,6 +91,11 @@ builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
 | 
				
			||||||
        .Create(typeof(DomainConfig).Assembly)
 | 
					        .Create(typeof(DomainConfig).Assembly)
 | 
				
			||||||
        .WithAllOpenGenericHandlerTypesRegistered()
 | 
					        .WithAllOpenGenericHandlerTypesRegistered()
 | 
				
			||||||
        .Build());
 | 
					        .Build());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    builder.RegisterMediatR(MediatRConfigurationBuilder
 | 
				
			||||||
 | 
					        .Create(typeof(CoreConfig).Assembly)
 | 
				
			||||||
 | 
					        .WithAllOpenGenericHandlerTypesRegistered()
 | 
				
			||||||
 | 
					        .Build());
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var app = builder.Build();
 | 
					var app = builder.Build();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ public class ShiftPlanReportCommandHandler : IRequestHandler<ShiftPlanReportComm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var workbook = new XSSFWorkbook();
 | 
					        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;
 | 
					        sheet.IsRightToLeft = true;
 | 
				
			||||||
        int selectedRow = 1;
 | 
					        int selectedRow = 1;
 | 
				
			||||||
        CreateHeader(sheet, workbook);
 | 
					        CreateHeader(sheet, workbook);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
namespace Brizco.Domain.CommandQueries.Queries;
 | 
					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>>;
 | 
					    IRequest<List<ShiftPlanSDto>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public sealed record GetShiftPlanQuery(Guid Id) :
 | 
					public sealed record GetShiftPlanQuery(Guid Id) :
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -14,41 +14,102 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    public async Task<List<ShiftPlanSDto>> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken)
 | 
					    public async Task<List<ShiftPlanSDto>> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        List<ShiftPlanSDto> shiftPlans;
 | 
					        if (_currentUserService.ComplexId == null)
 | 
				
			||||||
        if (request.SelectedDate > 0)
 | 
					            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);
 | 
					            return await baseQuery
 | 
				
			||||||
            shiftPlans = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.ShiftPlan>()
 | 
					 | 
				
			||||||
                .TableNoTracking
 | 
					 | 
				
			||||||
                .Where(s => s.PlanFor.Date == selectedDate.Date)
 | 
					 | 
				
			||||||
                .OrderByDescending(s => s.CreatedAt)
 | 
					 | 
				
			||||||
                .Skip(request.Page * 15).Take(15)
 | 
					                .Skip(request.Page * 15).Take(15)
 | 
				
			||||||
                .Select(ShiftPlanMapper.ProjectToSDto)
 | 
					                .Select(ShiftPlanMapper.ProjectToSDto)
 | 
				
			||||||
                .ToListAsync(cancellationToken);
 | 
					                .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)
 | 
					            foreach (var shiftPlan in shiftPlans)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var activitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
 | 
					                var activitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
 | 
				
			||||||
                    .TableNoTracking
 | 
					                    .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>()
 | 
					                var doneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
 | 
				
			||||||
                    .TableNoTracking
 | 
					                    .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>()
 | 
					                var undoneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
 | 
				
			||||||
                    .TableNoTracking
 | 
					                    .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.UndoneActivitiesCount = undoneActivitiesCount;
 | 
				
			||||||
                shiftPlan.DoneActivitiesCount = doneActivitiesCount;
 | 
					                shiftPlan.DoneActivitiesCount = doneActivitiesCount;
 | 
				
			||||||
                shiftPlan.TotalActivitiesCount = activitiesCount;
 | 
					                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;
 | 
					        return shiftPlans;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue