From 9d09ef60f827cbfd0cf7c21e430f7df7be2b2381 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 6 Jan 2026 18:19:16 +0330 Subject: [PATCH] feat: add progress percentage calculations to project and task details --- .../GetProjectsListQueryHandler.cs | 15 +-------------- .../ProjectBoardListQueryHandler.cs | 1 + .../ProjectBoardListResponse.cs | 1 + .../ProjectDeployBoardDetailsQueryHandler.cs | 19 +++++++++++-------- .../ProjectDeployBoardListQueryHandler.cs | 4 +++- .../ProjectAgg/Entities/TaskSection.cs | 2 +- 6 files changed, 18 insertions(+), 24 deletions(-) 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 ceaf2e19..621ef025 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 @@ -296,20 +296,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler a.GetTimeSpent().TotalHours)); - - if (totalEstimatedHours <= 0) - return (0, section.FinalEstimatedHours); - - var totalSpentHours = totalSpentTime.TotalHours; - - // محاسبه درصد (حداکثر 100%) - var percentage = (totalSpentHours / totalEstimatedHours) * 100; - return (Math.Min((int)Math.Round(percentage), 100), section.FinalEstimatedHours); + return ((int)section.GetProgressPercentage(),section.FinalEstimatedHours); } } diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListQueryHandler.cs index e6502494..1157a932 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListQueryHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListQueryHandler.cs @@ -106,6 +106,7 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler a.TotalSeconds), Histories = mergedHistories }, diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListResponse.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListResponse.cs index ab38750e..688a12c0 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListResponse.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectBoardList/ProjectBoardListResponse.cs @@ -18,6 +18,7 @@ public class ProjectBoardListResponse public class ProjectProgressDto { public double CurrentSecond { get; set; } + public int Percentage { get; set; } public double CompleteSecond { get; set; } public List Histories { get; set; } } diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardDetail/ProjectDeployBoardDetailsQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardDetail/ProjectDeployBoardDetailsQueryHandler.cs index 33a1caa6..ddff2247 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardDetail/ProjectDeployBoardDetailsQueryHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardDetail/ProjectDeployBoardDetailsQueryHandler.cs @@ -12,14 +12,16 @@ public record ProjectDeployBoardDetailsResponse( public record ProjectDeployBoardDetailPhaseItem( string Name, TimeSpan TotalTimeSpan, - TimeSpan DoneTimeSpan); + TimeSpan DoneTimeSpan, + int Percentage); public record ProjectDeployBoardDetailTaskItem( string Name, TimeSpan TotalTimeSpan, TimeSpan DoneTimeSpan, + int Percentage, List Skills) - : ProjectDeployBoardDetailPhaseItem(Name, TotalTimeSpan, DoneTimeSpan); + : ProjectDeployBoardDetailPhaseItem(Name, TotalTimeSpan, DoneTimeSpan,Percentage); public record ProjectDeployBoardDetailItemSkill(string OriginalUserFullName, string SkillName, int TimePercentage); @@ -79,22 +81,20 @@ public class var skillName = s.Skill?.Name ?? "بدون مهارت"; - var totalTimeSpent = s.GetTotalTimeSpent(); - - var timePercentage = s.FinalEstimatedHours.Ticks > 0 - ? (int)((totalTimeSpent.Ticks / (double)s.FinalEstimatedHours.Ticks) * 100) - : 0; + var timePercentage = (int)s.GetProgressPercentage(); return new ProjectDeployBoardDetailItemSkill( originalUserFullName, skillName, timePercentage); }).ToList(); + var taskPercentage = (int)Math.Round(skills.Average(x => x.TimePercentage)); return new ProjectDeployBoardDetailTaskItem( t.Name, totalTime, doneTime, + taskPercentage, skills); }).ToList(); @@ -104,7 +104,10 @@ public class var doneTimeSpan = tasksRes.Aggregate(TimeSpan.Zero, (sum, next) => sum.Add(next.DoneTimeSpan)); - var phaseRes = new ProjectDeployBoardDetailPhaseItem(phase.Name, totalTimeSpan, doneTimeSpan); + var phasePercentage = tasksRes.Average(x => x.Percentage); + + var phaseRes = new ProjectDeployBoardDetailPhaseItem(phase.Name, totalTimeSpan, doneTimeSpan, + (int)phasePercentage); var res = new ProjectDeployBoardDetailsResponse(phaseRes, tasksRes); diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardList/ProjectDeployBoardListQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardList/ProjectDeployBoardListQueryHandler.cs index 6a0a7cda..d8f6e39d 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardList/ProjectDeployBoardListQueryHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectDeployBoardList/ProjectDeployBoardListQueryHandler.cs @@ -17,6 +17,7 @@ public record ProjectDeployBoardListItem() public int DoneTasks { get; set; } public TimeSpan TotalTimeSpan { get; set; } public TimeSpan DoneTimeSpan { get; set; } + public int Percentage { get; set; } public ProjectDeployStatus DeployStatus { get; set; } } public record GetProjectsDeployBoardListResponse(List Items); @@ -66,7 +67,8 @@ public class ProjectDeployBoardListQueryHandler:IBaseQueryHandler x.TaskId).Distinct().Count(), TotalTimeSpan = TimeSpan.FromTicks(g.Sum(x => x.InitialEstimatedHours.Ticks)), DoneTimeSpan = TimeSpan.FromTicks(g.Sum(x=>x.GetTotalTimeSpent().Ticks)), - DeployStatus = g.First().Task.Phase.DeployStatus + DeployStatus = g.First().Task.Phase.DeployStatus, + Percentage = (int)Math.Round(g.Average(x => x.GetProgressPercentage())) }).ToList(); var response = new GetProjectsDeployBoardListResponse(list); return OperationResult.Success(response); diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs index e506d173..072422fe 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs @@ -172,7 +172,7 @@ public class TaskSection : EntityBase return 0.0; var timeSpent = GetTotalTimeSpent(); - var percentage = (timeSpent.TotalHours / FinalEstimatedHours.TotalHours) * 100.0; + var percentage = (timeSpent.TotalMinutes / FinalEstimatedHours.TotalMinutes) * 100.0; // محدود کردن درصد به 100 (در صورتی که زمان مصرف شده بیشتر از تخمین باشد) return Math.Min(percentage, 100.0);