diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectListDto.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectListDto.cs index 91a82c28..9157ec1d 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectListDto.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectListDto.cs @@ -10,8 +10,10 @@ public class GetProjectItemDto public int Percentage { get; init; } public ProjectHierarchyLevel Level { get; init; } public Guid? ParentId { get; init; } - public int TotalHours { get; set; } - public int Minutes { get; set; } + + public TimeSpan TotalTime { get; init; } + + public TimeSpan RemainingTime { get; init; } public AssignmentStatus Front { get; set; } public AssignmentStatus Backend { get; set; } public AssignmentStatus Design { get; set; } diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectsListQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectsListQueryHandler.cs index a982caf3..5c4af255 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectsListQueryHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectsList/GetProjectsListQueryHandler.cs @@ -16,7 +16,8 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler> Handle(GetProjectsListQuery request, CancellationToken cancellationToken) + public async Task> Handle(GetProjectsListQuery request, + CancellationToken cancellationToken) { var projects = new List(); var phases = new List(); @@ -51,13 +52,14 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler(); } + var entities = await query .OrderByDescending(p => p.CreationDate) .ToListAsync(cancellationToken); var result = new List(); foreach (var project in entities) { - var (percentage, totalTime) = await CalculateProjectPercentage(project, cancellationToken); + var (percentage, totalTime,remainingTime) = await CalculateProjectPercentage(project, cancellationToken); result.Add(new GetProjectDto { Id = project.Id, @@ -65,10 +67,11 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler x.ProjectId == parentId); } + var entities = await query .OrderByDescending(p => p.CreationDate) .ToListAsync(cancellationToken); var result = new List(); foreach (var phase in entities) { - var (percentage, totalTime) = await CalculatePhasePercentage(phase, cancellationToken); + var (percentage, totalTime,remainingTime) = await CalculatePhasePercentage(phase, cancellationToken); result.Add(new GetPhaseDto { Id = phase.Id, @@ -93,10 +97,11 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler x.PhaseId == parentId); } + var entities = await query .OrderByDescending(t => t.CreationDate) .ToListAsync(cancellationToken); @@ -118,7 +124,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler s.Activities) .Include(s => s.Skill) @@ -140,13 +146,12 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler s.Activities.Sum(a => a.GetTimeSpent().Ticks))); - var remainingTime = totalTime - spentTime; // ساخت section DTOs برای تمام Skills var sectionDtos = allSkills.Select(skill => { var section = sections.FirstOrDefault(s => s.SkillId == skill.Id); - + if (section == null) { // اگر section وجود نداشت، یک DTO با وضعیت Unassigned برمی‌گردانیم @@ -192,10 +197,12 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler(List items, CancellationToken cancellationToken) where TItem : GetProjectItemDto + private async Task SetSkillFlags(List items, CancellationToken cancellationToken) + where TItem : GetProjectItemDto { if (!items.Any()) return; @@ -213,7 +220,8 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler(List items, List projectIds, CancellationToken cancellationToken) where TItem : GetProjectItemDto + private async Task SetSkillFlagsForProjects(List items, List projectIds, + CancellationToken cancellationToken) where TItem : GetProjectItemDto { // For projects: gather all phases, then tasks, then sections var phases = await _context.ProjectPhases @@ -243,7 +251,8 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler(List items, List phaseIds, CancellationToken cancellationToken) where TItem : GetProjectItemDto + private async Task SetSkillFlagsForPhases(List items, List phaseIds, + CancellationToken cancellationToken) where TItem : GetProjectItemDto { // For phases: gather tasks, then sections var tasks = await _context.ProjectTasks @@ -269,68 +278,81 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler CalculateProjectPercentage(Project project, CancellationToken cancellationToken) + private async Task<(int Percentage, TimeSpan TotalTime,TimeSpan RemainingTime)> CalculateProjectPercentage(Project project, + CancellationToken cancellationToken) { var phases = await _context.ProjectPhases .Where(ph => ph.ProjectId == project.Id) .ToListAsync(cancellationToken); if (!phases.Any()) - return (0, TimeSpan.Zero); + return (0, TimeSpan.Zero,TimeSpan.Zero); var phasePercentages = new List(); var totalTime = TimeSpan.Zero; + var remainingTime = TimeSpan.Zero; foreach (var phase in phases) { - var (phasePercentage, phaseTime) = await CalculatePhasePercentage(phase, cancellationToken); + var (phasePercentage, phaseTime,phaseRemainingTime) = await CalculatePhasePercentage(phase, cancellationToken); phasePercentages.Add(phasePercentage); totalTime += phaseTime; + remainingTime += phaseRemainingTime; } + var averagePercentage = phasePercentages.Any() ? (int)phasePercentages.Average() : 0; - return (averagePercentage, totalTime); + return (averagePercentage, totalTime,remainingTime); } - private async Task<(int Percentage, TimeSpan TotalTime)> CalculatePhasePercentage(ProjectPhase phase, CancellationToken cancellationToken) + private async Task<(int Percentage, TimeSpan TotalTime,TimeSpan RemainingTime)> CalculatePhasePercentage(ProjectPhase phase, + CancellationToken cancellationToken) { var tasks = await _context.ProjectTasks .Where(t => t.PhaseId == phase.Id) .ToListAsync(cancellationToken); if (!tasks.Any()) - return (0, TimeSpan.Zero); + return (0, TimeSpan.Zero,TimeSpan.Zero); var taskPercentages = new List(); var totalTime = TimeSpan.Zero; + var remainingTime = TimeSpan.Zero; foreach (var task in tasks) { - var (taskPercentage, taskTime) = await CalculateTaskPercentage(task, cancellationToken); + var (taskPercentage, taskTime,taskRemainingTime) = await CalculateTaskPercentage(task, cancellationToken); taskPercentages.Add(taskPercentage); totalTime += taskTime; + remainingTime += taskRemainingTime; } + var averagePercentage = taskPercentages.Any() ? (int)taskPercentages.Average() : 0; - return (averagePercentage, totalTime); + return (averagePercentage, totalTime,remainingTime); } - private async Task<(int Percentage, TimeSpan TotalTime)> CalculateTaskPercentage(ProjectTask task, CancellationToken cancellationToken) + private async Task<(int Percentage, TimeSpan TotalTime, TimeSpan RemainingTime)> CalculateTaskPercentage( + ProjectTask task, CancellationToken cancellationToken) { var sections = await _context.TaskSections .Include(s => s.Activities) - .Include(x=>x.AdditionalTimes) + .Include(x => x.AdditionalTimes) .Where(s => s.TaskId == task.Id) .ToListAsync(cancellationToken); if (!sections.Any()) - return (0, TimeSpan.Zero); + return (0, TimeSpan.Zero, TimeSpan.Zero); var sectionPercentages = new List(); var totalTime = TimeSpan.Zero; + var spentTime = TimeSpan.Zero; foreach (var section in sections) { var (sectionPercentage, sectionTime) = CalculateSectionPercentage(section); + var sectionSpent = TimeSpan.FromTicks(section.Activities.Sum(x => x.GetTimeSpent().Ticks)); sectionPercentages.Add(sectionPercentage); totalTime += sectionTime; + spentTime += sectionSpent; } + var remainingTime = totalTime - spentTime; var averagePercentage = sectionPercentages.Any() ? (int)sectionPercentages.Average() : 0; - return (averagePercentage, totalTime); + return (averagePercentage, totalTime, remainingTime); } private static (int Percentage, TimeSpan TotalTime) CalculateSectionPercentage(TaskSection section) { - return ((int)section.GetProgressPercentage(),section.FinalEstimatedHours); + return ((int)section.GetProgressPercentage(), section.FinalEstimatedHours); } private static AssignmentStatus GetAssignmentStatus(TaskSection? section) @@ -341,7 +363,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler 0; - + // بررسی وجود time (InitialEstimatedHours بزرگتر از صفر باشد) bool hasTime = section.InitialEstimatedHours > TimeSpan.Zero; @@ -356,5 +378,4 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler