merge from master
This commit is contained in:
@@ -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<AutoPendingFullTimeTaskSectionsCommand>
|
||||
{
|
||||
private readonly ITaskSectionRepository _taskSectionRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public AutoPendingFullTimeTaskSectionsCommandHandler(
|
||||
ITaskSectionRepository taskSectionRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_taskSectionRepository = taskSectionRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Command to change a task priority.
|
||||
/// </summary>
|
||||
public record ChangeTaskPriorityCommand(Guid TaskId, TaskPriority Priority) : IBaseCommand;
|
||||
|
||||
public class ChangeTaskPriorityCommandHandler : IBaseCommandHandler<ChangeTaskPriorityCommand>
|
||||
{
|
||||
private readonly IProjectTaskRepository _taskRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public ChangeTaskPriorityCommandHandler(IProjectTaskRepository taskRepository, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_taskRepository = taskRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,10 +365,26 @@ public class SetTimeProjectCommandHandler : IBaseCommandHandler<SetTimeProjectCo
|
||||
|
||||
section.ClearAdditionalTimes();
|
||||
// افزودن زمانهای اضافی
|
||||
bool hasAdditionalTime = false;
|
||||
foreach (var additionalTime in sectionItem.AdditionalTime)
|
||||
{
|
||||
var additionalTimeSpan = TimeSpan.FromHours(additionalTime.Hours).Add(TimeSpan.FromMinutes(additionalTime.Minutes));
|
||||
section.AddAdditionalTime(additionalTimeSpan, additionalTime.Description, addedByUserId);
|
||||
hasAdditionalTime = true;
|
||||
}
|
||||
|
||||
// تغییر status به Incomplete فقط اگر زمان اضافی اضافه شده باشد و در وضعیتی غیر از ReadyToStart باشد
|
||||
if (hasAdditionalTime && section.Status != TaskSectionStatus.ReadyToStart)
|
||||
{
|
||||
// اگر سکشن درحال انجام است، باید متوقف شود قبل از تغییر status
|
||||
if (section.Status == TaskSectionStatus.InProgress)
|
||||
{
|
||||
section.StopWork(TaskSectionStatus.Incomplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
section.UpdateStatus(TaskSectionStatus.Incomplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
|
||||
SpentTime = spentTime,
|
||||
RemainingTime = remainingTime,
|
||||
Sections = sectionDtos,
|
||||
Priority = task.Priority
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -15,6 +15,7 @@ public class GetTaskDto
|
||||
// Task-specific fields
|
||||
public TimeSpan SpentTime { get; init; }
|
||||
public TimeSpan RemainingTime { get; init; }
|
||||
public TaskPriority Priority { get; set; }
|
||||
public List<GetTaskSectionDto> Sections { get; init; }
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,9 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler<ProjectBoardListQu
|
||||
.ToDictionaryAsync(x => 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 =>
|
||||
{
|
||||
|
||||
@@ -270,7 +270,7 @@ public class TaskSection : EntityBase<Guid>
|
||||
// متوقف کردن فعالیت با EndDate دقیق شده
|
||||
activeActivity.StopWorkWithSpecificTime(adjustedEndDate, "متوقف خودکار - بیش از تایم تعیین شده");
|
||||
|
||||
UpdateStatus(TaskSectionStatus.Incomplete);
|
||||
UpdateStatus(TaskSectionStatus.PendingForCompletion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,7 @@ public interface ITaskSectionRepository: IRepository<Guid,TaskSection>
|
||||
Task<List<TaskSection>> GetAssignedToUserAsync(long userId);
|
||||
Task<List<TaskSection>> GetActiveSectionsIncludeAllAsync(CancellationToken cancellationToken);
|
||||
Task<bool> HasUserAnyInProgressSectionAsync(long userId, CancellationToken cancellationToken = default);
|
||||
|
||||
// جدید: دریافت سکشنهایی که هنوز Completed یا PendingForCompletion نشدهاند با اطلاعات کامل
|
||||
Task<List<TaskSection>> GetAllNotCompletedOrPendingIncludeAllAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -53,4 +53,13 @@ public class TaskSectionRepository:RepositoryBase<Guid,TaskSection>,ITaskSection
|
||||
.AnyAsync(x => x.CurrentAssignedUserId == userId && x.Status == TaskSectionStatus.InProgress,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public Task<List<TaskSection>> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<ActionResult<OperationResult>> ChangePriority([FromBody] ChangeTaskPriorityCommand command)
|
||||
{
|
||||
var res = await _mediator.Send(command);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user