diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/AutoPendingFullTimeTaskSections/AutoPendingFullTimeTaskSectionsCommand.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/AutoPendingFullTimeTaskSections/AutoPendingFullTimeTaskSectionsCommand.cs new file mode 100644 index 00000000..6e1e9802 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/AutoPendingFullTimeTaskSections/AutoPendingFullTimeTaskSectionsCommand.cs @@ -0,0 +1,62 @@ +using GozareshgirProgramManager.Application._Common.Interfaces; +using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Domain._Common; +using GozareshgirProgramManager.Domain.ProjectAgg.Repositories; +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.AutoPendingFullTimeTaskSections; + +public record AutoPendingFullTimeTaskSectionsCommand : IBaseCommand; + +public class AutoPendingFullTimeTaskSectionsCommandHandler : IBaseCommandHandler +{ + private readonly ITaskSectionRepository _taskSectionRepository; + private readonly IUnitOfWork _unitOfWork; + + public AutoPendingFullTimeTaskSectionsCommandHandler( + ITaskSectionRepository taskSectionRepository, + IUnitOfWork unitOfWork) + { + _taskSectionRepository = taskSectionRepository; + _unitOfWork = unitOfWork; + } + + public async Task Handle(AutoPendingFullTimeTaskSectionsCommand request, CancellationToken cancellationToken) + { + try + { + // تمام سکشن‌هایی که هنوز Pending یا Completed نشده‌اند را دریافت کن + var taskSections = await _taskSectionRepository.GetAllNotCompletedOrPendingIncludeAllAsync(cancellationToken); + + foreach (var section in taskSections) + { + var totalSpent = section.GetTotalTimeSpent(); + var estimate = section.FinalEstimatedHours; + + if (estimate.TotalMinutes <= 0) + continue; // تسک بدون تخمین را نادیده بگیر + + if (totalSpent >= estimate) + { + // مهم: وضعیت را مستقل از فعال/غیرفعال بودن فعالیت‌ها PendingForCompletion کنیم + if (section.IsInProgress()) + { + // اگر فعالیت فعال دارد، با وضعیت جدید متوقف شود + section.StopWork(TaskSectionStatus.PendingForCompletion, "اتمام خودکار - رسیدن به ۱۰۰٪ زمان تخمینی"); + } + else + { + section.UpdateStatus(TaskSectionStatus.PendingForCompletion); + } + } + } + + await _unitOfWork.SaveChangesAsync(cancellationToken); + return OperationResult.Success(); + } + catch (Exception ex) + { + return OperationResult.Failure($"خطا در در انتظار تکمیل قرار دادن خودکار تسک‌ها: {ex.Message}"); + } + } +} diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeTaskPriority/ChangeTaskPriorityCommand.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeTaskPriority/ChangeTaskPriorityCommand.cs new file mode 100644 index 00000000..23d23830 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeTaskPriority/ChangeTaskPriorityCommand.cs @@ -0,0 +1,41 @@ +using GozareshgirProgramManager.Application._Common.Interfaces; +using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Domain._Common; +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; +using GozareshgirProgramManager.Domain.ProjectAgg.Repositories; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.ChangeTaskPriority; + +/// +/// Command to change a task priority. +/// +public record ChangeTaskPriorityCommand(Guid TaskId, TaskPriority Priority) : IBaseCommand; + +public class ChangeTaskPriorityCommandHandler : IBaseCommandHandler +{ + private readonly IProjectTaskRepository _taskRepository; + private readonly IUnitOfWork _unitOfWork; + + public ChangeTaskPriorityCommandHandler(IProjectTaskRepository taskRepository, IUnitOfWork unitOfWork) + { + _taskRepository = taskRepository; + _unitOfWork = unitOfWork; + } + + public async Task Handle(ChangeTaskPriorityCommand request, CancellationToken cancellationToken) + { + var task = await _taskRepository.GetByIdAsync(request.TaskId, cancellationToken); + if (task is null) + return OperationResult.NotFound("تسک یافت نشد"); + + // Idempotent: if already same priority, skip extra work + if (task.Priority != request.Priority) + { + task.SetPriority(request.Priority); + } + + await _unitOfWork.SaveChangesAsync(cancellationToken); + return OperationResult.Success(); + } +} + diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommandHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommandHandler.cs index fdbadc28..a9ca3a61 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommandHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommandHandler.cs @@ -365,10 +365,26 @@ public class SetTimeProjectCommandHandler : IBaseCommandHandler Sections { get; init; } } 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 1157a932..a082f648 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 @@ -53,7 +53,9 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler x.Id, x => x.FullName, cancellationToken); - var result = data .OrderByDescending(x => x.CurrentAssignedUserId == currentUserId) + var result = data + .OrderByDescending(x => x.CurrentAssignedUserId == currentUserId) + .ThenByDescending(x=>x.Task.Priority) .ThenBy(x => GetStatusOrder(x.Status)) .Select(x => { diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs index 072422fe..83b86c23 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs @@ -270,7 +270,7 @@ public class TaskSection : EntityBase // متوقف کردن فعالیت با EndDate دقیق شده activeActivity.StopWorkWithSpecificTime(adjustedEndDate, "متوقف خودکار - بیش از تایم تعیین شده"); - UpdateStatus(TaskSectionStatus.Incomplete); + UpdateStatus(TaskSectionStatus.PendingForCompletion); } } } \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs index 487991a8..50e1a2b0 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs @@ -14,4 +14,7 @@ public interface ITaskSectionRepository: IRepository Task> GetAssignedToUserAsync(long userId); Task> GetActiveSectionsIncludeAllAsync(CancellationToken cancellationToken); Task HasUserAnyInProgressSectionAsync(long userId, CancellationToken cancellationToken = default); + + // جدید: دریافت سکشن‌هایی که هنوز Completed یا PendingForCompletion نشده‌اند با اطلاعات کامل + Task> GetAllNotCompletedOrPendingIncludeAllAsync(CancellationToken cancellationToken); } \ No newline at end of file diff --git a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs index d6d60b69..ce590dc7 100644 --- a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs +++ b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs @@ -53,4 +53,13 @@ public class TaskSectionRepository:RepositoryBase,ITaskSection .AnyAsync(x => x.CurrentAssignedUserId == userId && x.Status == TaskSectionStatus.InProgress, cancellationToken); } + + public Task> GetAllNotCompletedOrPendingIncludeAllAsync(CancellationToken cancellationToken) + { + return _context.TaskSections + .Where(x => x.Status != TaskSectionStatus.Completed && x.Status != TaskSectionStatus.PendingForCompletion) + .Include(x => x.Activities) + .Include(x => x.AdditionalTimes) + .ToListAsync(cancellationToken); + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs b/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs index 95d6da94..7be0b240 100644 --- a/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs +++ b/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs @@ -22,6 +22,8 @@ using GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectH using MediatR; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; +using GozareshgirProgramManager.Application.Modules.Projects.Commands.ChangeTaskPriority; +using GozareshgirProgramManager.Application.Modules.Projects.Commands.AutoPendingFullTimeTaskSections; namespace ServiceHost.Areas.Admin.Controllers.ProgramManager; @@ -122,6 +124,8 @@ public class ProjectController : ProgramManagerBaseController { // اجرای Command برای متوقف کردن تسک‌های overtime قبل از نمایش await _mediator.Send(new AutoStopOverTimeTaskSectionsCommand()); + // سپس تسک‌هایی که به 100% زمان تخمینی رسیده‌اند را به حالت PendingForCompletion ببریم + await _mediator.Send(new AutoPendingFullTimeTaskSectionsCommand()); var res = await _mediator.Send(query); return res; @@ -165,4 +169,12 @@ public class ProjectController : ProgramManagerBaseController var res = await _mediator.Send(command); return res; } + + [HttpPost("change-priority")] + public async Task> ChangePriority([FromBody] ChangeTaskPriorityCommand command) + { + var res = await _mediator.Send(command); + return res; + } + } \ No newline at end of file diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 012f1a0a..ee563bb8 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -63,10 +63,17 @@ if (!Directory.Exists(logDirectory)) Directory.CreateDirectory(logDirectory); } -// فقط برای فایل از Serilog استفاده می‌شود -// تنظیمات MinimumLevel از appsettings.json خوانده می‌شود Log.Logger = new LoggerConfiguration() - .Enrich.FromLogContext() + //NO EF Core log + .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) + + //NO DbCommand log + .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning) + + //NO Microsoft Public log + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + + //.MinimumLevel.Information() .WriteTo.File( path: Path.Combine(logDirectory, "gozareshgir_log.txt"), rollingInterval: RollingInterval.Day, diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index 29cf7c0a..788962e4 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -44,7 +44,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5006;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;", "jsWebView2Debugging": false, "hotReloadEnabled": true }