diff --git a/.gitignore b/.gitignore index 674512f1..aa9d4d68 100644 --- a/.gitignore +++ b/.gitignore @@ -362,3 +362,5 @@ MigrationBackup/ # # Fody - auto-generated XML schema # FodyWeavers.xsd .idea +/ServiceHost/appsettings.Development.json +/ServiceHost/appsettings.json diff --git a/CompanyManagment.Application/WorkshopAppliction.cs b/CompanyManagment.Application/WorkshopAppliction.cs index a6efd5de..c2110263 100644 --- a/CompanyManagment.Application/WorkshopAppliction.cs +++ b/CompanyManagment.Application/WorkshopAppliction.cs @@ -407,6 +407,10 @@ public class WorkshopAppliction : IWorkshopApplication public EditWorkshop GetDetails(long id) { var workshop = _workshopRepository.GetDetails(id); + if (workshop == null) + { + return null; + } if (workshop.IsClassified) { workshop.CreatePlan = _workshopPlanApplication.GetWorkshopPlanByWorkshopId(id); diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 44cd56e9..34c71438 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -2002,7 +2002,7 @@ public class InstitutionContractRepository : RepositoryBase +{ + private readonly ITaskSectionRepository _taskSectionRepository; + private readonly IUnitOfWork _unitOfWork; + private readonly IAuthHelper _authHelper; + + public ApproveTaskSectionCompletionCommandHandler( + ITaskSectionRepository taskSectionRepository, + IUnitOfWork unitOfWork, + IAuthHelper authHelper) + { + _taskSectionRepository = taskSectionRepository; + _unitOfWork = unitOfWork; + _authHelper = authHelper; + } + + public async Task Handle(ApproveTaskSectionCompletionCommand request, CancellationToken cancellationToken) + { + var currentUserId = _authHelper.GetCurrentUserId() + ?? throw new UnAuthorizedException(" ? "); + + var section = await _taskSectionRepository.GetByIdAsync(request.TaskSectionId, cancellationToken); + if (section == null) + { + return OperationResult.NotFound(" ? "); + } + + if (section.Status != TaskSectionStatus.PendingForCompletion) + { + return OperationResult.Failure(" ԝ?? ʘ? ?? ? "); + } + + if (request.IsApproved) + { + section.UpdateStatus(TaskSectionStatus.Completed); + } + else + { + section.UpdateStatus(TaskSectionStatus.Incomplete); + } + + await _unitOfWork.SaveChangesAsync(cancellationToken); + + return OperationResult.Success(); + } +} diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ApproveTaskSectionCompletion/ApproveTaskSectionCompletionCommandValidator.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ApproveTaskSectionCompletion/ApproveTaskSectionCompletionCommandValidator.cs new file mode 100644 index 00000000..c12a43c3 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ApproveTaskSectionCompletion/ApproveTaskSectionCompletionCommandValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.ApproveTaskSectionCompletion; + +public class ApproveTaskSectionCompletionCommandValidator : AbstractValidator +{ + public ApproveTaskSectionCompletionCommandValidator() + { + RuleFor(c => c.TaskSectionId) + .NotEmpty() + .NotNull() + .WithMessage(" ? ? "); + } +} diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeStatusSection/ChangeStatusSectionCommandHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeStatusSection/ChangeStatusSectionCommandHandler.cs index 9e6803f5..178a0257 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeStatusSection/ChangeStatusSectionCommandHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/ChangeStatusSection/ChangeStatusSectionCommandHandler.cs @@ -52,7 +52,10 @@ public class ChangeStatusSectionCommandHandler : IBaseCommandHandler> { { TaskSectionStatus.ReadyToStart, [TaskSectionStatus.InProgress] }, - { TaskSectionStatus.InProgress, [TaskSectionStatus.Incomplete, TaskSectionStatus.Completed] }, - { TaskSectionStatus.Incomplete, [TaskSectionStatus.InProgress, TaskSectionStatus.Completed] }, - { TaskSectionStatus.Completed, [TaskSectionStatus.InProgress, TaskSectionStatus.Incomplete] }, // Can return to InProgress or Incomplete + { TaskSectionStatus.InProgress, [TaskSectionStatus.Incomplete, TaskSectionStatus.PendingForCompletion] }, + { TaskSectionStatus.Incomplete, [TaskSectionStatus.InProgress, TaskSectionStatus.PendingForCompletion] }, + { TaskSectionStatus.PendingForCompletion, [TaskSectionStatus.InProgress, TaskSectionStatus.Incomplete] }, // Can return to InProgress or Incomplete { TaskSectionStatus.NotAssigned, [TaskSectionStatus.InProgress, TaskSectionStatus.ReadyToStart] } }; diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommand.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommand.cs index 230754b5..b7ed7859 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommand.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Commands/SetTimeProject/SetTimeProjectCommand.cs @@ -4,10 +4,15 @@ using GozareshgirProgramManager.Domain.ProjectAgg.Enums; namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.SetTimeProject; -public record SetTimeProjectCommand(List SectionItems, Guid Id, ProjectHierarchyLevel Level):IBaseCommand; +public record SetTimeProjectCommand( + List SkillItems, + Guid Id, + ProjectHierarchyLevel Level, + bool CascadeToChildren) : IBaseCommand; public class SetTimeSectionTime { public string Description { get; set; } public int Hours { get; set; } + public int Minutes { get; set; } } \ No newline at end of file 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 f6e9bafa..fdbadc28 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 @@ -6,6 +6,8 @@ using GozareshgirProgramManager.Domain._Common.Exceptions; using GozareshgirProgramManager.Domain.ProjectAgg.Entities; using GozareshgirProgramManager.Domain.ProjectAgg.Enums; using GozareshgirProgramManager.Domain.ProjectAgg.Repositories; +using GozareshgirProgramManager.Domain.SkillAgg.Repositories; +using GozareshgirProgramManager.Domain.UserAgg.Repositories; namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.SetTimeProject; @@ -15,21 +17,33 @@ public class SetTimeProjectCommandHandler : IBaseCommandHandler SetTimeForProject(SetTimeProjectCommand request, - CancellationToken cancellationToken) + private async Task AssignProject(SetTimeProjectCommand request) { var project = await _projectRepository.GetWithFullHierarchyAsync(request.Id); - if (project == null) + if (project is null) { return OperationResult.NotFound("پروژه یافت نشد"); - return OperationResult.NotFound("���� ���� ���"); } - long? addedByUserId = _userId; + var skillItems = request.SkillItems.Where(x=>x.UserId is > 0).ToList(); + + // حذف ProjectSections که در validSkills نیستند + var validSkillIds = skillItems.Select(x => x.SkillId).ToList(); + var sectionsToRemove = project.ProjectSections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var section in sectionsToRemove) + { + project.RemoveProjectSection(section.SkillId); + } + + // تخصیص در سطح پروژه + foreach (var item in skillItems) + { + var skill = await _skillRepository.GetByIdAsync(item.SkillId); + if (skill is null) + { + return OperationResult.NotFound($"مهارت با شناسه {item.SkillId} یافت نشد"); + } - // تنظیم زمان برای تمام sections در تمام فازها و تسک‌های پروژه + // بررسی و به‌روزرسانی یا اضافه کردن ProjectSection + var existingSection = project.ProjectSections.FirstOrDefault(s => s.SkillId == item.SkillId); + if (existingSection != null) + { + // اگر وجود داشت، فقط userId را به‌روزرسانی کن + existingSection.UpdateUser(item.UserId.Value); + } + else + { + // اگر وجود نداشت، اضافه کن + var newSection = new ProjectSection(project.Id, item.UserId.Value, item.SkillId); + await _projectSectionRepository.CreateAsync(newSection); + } + } + + // حالا برای تمام فازها و تسک‌ها cascade کن foreach (var phase in project.Phases) { - foreach (var task in phase.Tasks) + // اگر CascadeToChildren true است یا فاز override ندارد + if (request.CascadeToChildren || !phase.HasAssignmentOverride) { - foreach (var section in task.Sections) + // حذف PhaseSections که در validSkills نیستند + var phaseSectionsToRemove = phase.PhaseSections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var section in phaseSectionsToRemove) { - var sectionItem = request.SectionItems.FirstOrDefault(si => si.SectionId == section.Id); - if (sectionItem != null) + phase.RemovePhaseSection(section.SkillId); + } + + // برای phase هم باید section‌ها را به‌روزرسانی کنیم + foreach (var item in skillItems ) + { + var existingSection = phase.PhaseSections.FirstOrDefault(s => s.SkillId == item.SkillId); + if (existingSection != null) { - SetSectionTime(section, sectionItem, addedByUserId); + existingSection.Update(item.UserId.Value, item.SkillId); + } + else + { + var newPhaseSection = new PhaseSection(phase.Id, item.UserId.Value, item.SkillId); + await _phaseSectionRepository.CreateAsync(newPhaseSection); + } + } + + foreach (var task in phase.Tasks) + { + // اگر CascadeToChildren true است یا تسک override ندارد + if (request.CascadeToChildren || !task.HasAssignmentOverride) + { + // حذف TaskSections که در validSkills نیستند + var taskSectionsToRemove = task.Sections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var section in taskSectionsToRemove) + { + task.RemoveSection(section.Id); + } + + foreach (var item in skillItems) + { + var section = task.Sections.FirstOrDefault(s => s.SkillId == item.SkillId); + if (section != null) + { + // استفاده از TransferToUser + if (section.CurrentAssignedUserId != item.UserId) + { + if (section.CurrentAssignedUserId > 0) + { + section.TransferToUser(section.CurrentAssignedUserId, item.UserId.Value); + } + else + { + section.AssignToUser(item.UserId.Value); + } + } + } + else + { + var newTaskSection = new TaskSection(task.Id, item.SkillId, item.UserId.Value); + await _taskSectionRepository.CreateAsync(newTaskSection); + } + } } } } } - await _unitOfWork.SaveChangesAsync(cancellationToken); + await _unitOfWork.SaveChangesAsync(); return OperationResult.Success(); } - private async Task SetTimeForProjectPhase(SetTimeProjectCommand request, - CancellationToken cancellationToken) + private async Task AssignProjectPhase(SetTimeProjectCommand request) { var phase = await _projectPhaseRepository.GetWithTasksAsync(request.Id); - if (phase == null) + if (phase is null) { return OperationResult.NotFound("فاز پروژه یافت نشد"); - return OperationResult.NotFound("��� ���� ���� ���"); } - long? addedByUserId = _userId; + // تخصیص در سطح فاز + foreach (var item in request.SkillItems) + { + var skill = await _skillRepository.GetByIdAsync(item.SkillId); + if (skill is null) + { + return OperationResult.NotFound($"مهارت با شناسه {item.SkillId} یافت نشد"); + } + } - // تنظیم زمان برای تمام sections در تمام تسک‌های این فاز + // علامت‌گذاری که این فاز نسبت به parent متمایز است + phase.MarkAsOverridden(); + + var skillItems = request.SkillItems.Where(x=>x.UserId is > 0).ToList(); + + // حذف PhaseSections که در validSkills نیستند + var validSkillIds = skillItems.Select(x => x.SkillId).ToList(); + var sectionsToRemove = phase.PhaseSections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var section in sectionsToRemove) + { + phase.RemovePhaseSection(section.SkillId); + } + + // به‌روزرسانی یا اضافه کردن PhaseSection + foreach (var item in skillItems) + { + var existingSection = phase.PhaseSections.FirstOrDefault(s => s.SkillId == item.SkillId); + if (existingSection != null) + { + // اگر وجود داشت، فقط userId را به‌روزرسانی کن + existingSection.Update(item.UserId!.Value, item.SkillId); + } + else + { + // اگر وجود نداشت، اضافه کن + var newPhaseSection = new PhaseSection(phase.Id, item.UserId!.Value, item.SkillId); + await _phaseSectionRepository.CreateAsync(newPhaseSection); + } + } + + // cascade به تمام تسک‌ها foreach (var task in phase.Tasks) { - foreach (var section in task.Sections) + // اگر CascadeToChildren true است یا تسک override ندارد + if (request.CascadeToChildren || !task.HasAssignmentOverride) { - var sectionItem = request.SectionItems.FirstOrDefault(si => si.SectionId == section.Id); - if (sectionItem != null) + // حذف TaskSections که در validSkills نیستند + var taskSectionsToRemove = task.Sections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var section in taskSectionsToRemove) { - SetSectionTime(section, sectionItem, addedByUserId); + task.RemoveSection(section.Id); + } + + foreach (var item in skillItems) + { + var section = task.Sections.FirstOrDefault(s => s.SkillId == item.SkillId); + if (section != null) + { + // استفاده از TransferToUser + if (section.CurrentAssignedUserId != item.UserId) + { + if (section.CurrentAssignedUserId > 0) + { + section.TransferToUser(section.CurrentAssignedUserId, item.UserId!.Value); + } + else + { + section.AssignToUser(item.UserId!.Value); + } + } + } + else + { + var newTaskSection = new TaskSection(task.Id, item.SkillId, item.UserId!.Value); + await _taskSectionRepository.CreateAsync(newTaskSection); + } } } } - await _unitOfWork.SaveChangesAsync(cancellationToken); + await _unitOfWork.SaveChangesAsync(); return OperationResult.Success(); } + private async Task SetTimeForProjectTask(SetTimeProjectCommand request, CancellationToken cancellationToken) { @@ -116,24 +296,64 @@ public class SetTimeProjectCommandHandler : IBaseCommandHandlerx.UserId is > 0).ToList(); + + // حذف سکشن‌هایی که در validSkills نیستند + var validSkillIds = validSkills.Select(x => x.SkillId).ToList(); + var sectionsToRemove = task.Sections + .Where(s => !validSkillIds.Contains(s.SkillId)) + .ToList(); + + foreach (var sectionToRemove in sectionsToRemove) { - var sectionItem = request.SectionItems.FirstOrDefault(si => si.SectionId == section.Id); - if (sectionItem != null) - { - SetSectionTime(section, sectionItem, addedByUserId); - } + task.RemoveSection(sectionToRemove.Id); } + + foreach (var skillItem in validSkills) + { + var section = task.Sections.FirstOrDefault(s => s.SkillId == skillItem.SkillId); + if (!_userRepository.Exists(x=>x.Id == skillItem.UserId!.Value)) + { + throw new BadRequestException("کاربر با شناسه یافت نشد."); + } + + if (section == null) + { + var taskSection = new TaskSection(task.Id, + skillItem.SkillId, skillItem.UserId!.Value); + + task.AddSection(taskSection); + section = taskSection; + } + else + { + if (section.CurrentAssignedUserId != skillItem.UserId) + { + if (section.CurrentAssignedUserId > 0) + { + section.TransferToUser(section.CurrentAssignedUserId, skillItem.UserId!.Value); + } + else + { + section.AssignToUser(skillItem.UserId!.Value); + } + } + } + + SetSectionTime(section, skillItem, addedByUserId); + + } await _unitOfWork.SaveChangesAsync(cancellationToken); return OperationResult.Success(); } - private void SetSectionTime(TaskSection section, SetTimeProjectSectionItem sectionItem, long? addedByUserId) + private void SetSectionTime(TaskSection section, SetTimeProjectSkillItem sectionItem, long? addedByUserId) { var initData = sectionItem.InitData; - var initialTime = TimeSpan.FromHours(initData.Hours); + var initialTime = TimeSpan.FromHours(initData.Hours) + .Add(TimeSpan.FromMinutes(initData.Minutes)); if (initialTime <= TimeSpan.Zero) { @@ -147,7 +367,7 @@ public class SetTimeProjectCommandHandler : IBaseCommandHandler x.SectionItems) - .SetValidator(command => new SetTimeProjectSectionItemValidator()); - - RuleFor(x => x.SectionItems) - .Must(sectionItems => sectionItems.Any(si => si.InitData?.Hours > 0)) - .WithMessage("حداقل یکی از بخش‌ها باید مقدار ساعت معتبری داشته باشد."); + RuleForEach(x => x.SkillItems) + .SetValidator(command => new SetTimeProjectSkillItemValidator()); } } -public class SetTimeProjectSectionItemValidator:AbstractValidator +public class SetTimeProjectSkillItemValidator:AbstractValidator { - public SetTimeProjectSectionItemValidator() + public SetTimeProjectSkillItemValidator() { - RuleFor(x=>x.SectionId) + RuleFor(x=>x.SkillId) .NotEmpty() .NotNull() .WithMessage("شناسه بخش نمی‌تواند خالی باشد."); @@ -47,6 +43,18 @@ public class AdditionalTimeDataValidator: AbstractValidator .GreaterThanOrEqualTo(0) .WithMessage("ساعت نمی‌تواند منفی باشد."); + RuleFor(x => x.Hours) + .LessThan(1_000) + .WithMessage("ساعت باید کمتر از 1000 باشد."); + + RuleFor(x => x.Minutes) + .GreaterThanOrEqualTo(0) + .WithMessage("دقیقه نمی‌تواند منفی باشد."); + + RuleFor(x => x.Minutes) + .LessThan(60) + .WithMessage("دقیقه باید بین 0 تا 59 باشد."); + RuleFor(x=>x.Description) .MaximumLength(500) .WithMessage("توضیحات نمی‌تواند بیشتر از 500 کاراکتر باشد."); diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/DTOs/SetTimeProjectSectionItem.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/DTOs/SetTimeProjectSectionItem.cs index 04566e4e..75fdaaf8 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/DTOs/SetTimeProjectSectionItem.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/DTOs/SetTimeProjectSectionItem.cs @@ -2,9 +2,10 @@ using GozareshgirProgramManager.Application.Modules.Projects.Commands.SetTimePro namespace GozareshgirProgramManager.Application.Modules.Projects.DTOs; -public class SetTimeProjectSectionItem +public class SetTimeProjectSkillItem { - public Guid SectionId { get; set; } + public Guid SkillId { get; set; } + public long? UserId { get; set; } public SetTimeSectionTime InitData { get; set; } public List AdditionalTime { get; set; } = []; } \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQuery.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQuery.cs new file mode 100644 index 00000000..8e9e292d --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQuery.cs @@ -0,0 +1,11 @@ +using GozareshgirProgramManager.Application._Common.Interfaces; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; + +/// +/// درخواست جستجو در سراسر سلسله‌مراتب پروژه (پروژه، فاز، تسک). +/// نتایج با اطلاعات مسیر سلسله‌مراتب برای پشتیبانی از ناوبری درخت در رابط کاربری بازگردانده می‌شود. +/// +public record GetProjectSearchQuery( + string SearchQuery) : IBaseQuery; + \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryHandler.cs new file mode 100644 index 00000000..e9cb3c25 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryHandler.cs @@ -0,0 +1,132 @@ +using GozareshgirProgramManager.Application._Common.Interfaces; +using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; +using Microsoft.EntityFrameworkCore; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; + +/// +/// Handler برای درخواست جستجوی سراسری در سلسله‌مراتب پروژه. +/// این handler در تمام سطح‌های پروژه، فاز و تسک جستجو می‌کند و از تمام فیلدهای متنی (نام، توضیحات) استفاده می‌کند. +/// همچنین در زیرمجموعه‌های هر سطح (ProjectSections، PhaseSections، TaskSections) جستجو می‌کند. +/// +public class GetProjectSearchQueryHandler : IBaseQueryHandler +{ + private readonly IProgramManagerDbContext _context; + private const int MaxResults = 50; + + public GetProjectSearchQueryHandler(IProgramManagerDbContext context) + { + _context = context; + } + + public async Task> Handle( + GetProjectSearchQuery request, + CancellationToken cancellationToken) + { + var searchQuery = request.SearchQuery.ToLower(); + var results = new List(); + + // جستجو در پروژه‌ها و ProjectSections + var projects = await SearchProjects(searchQuery, cancellationToken); + results.AddRange(projects); + + // جستجو در فازها و PhaseSections + var phases = await SearchPhases(searchQuery, cancellationToken); + results.AddRange(phases); + + // جستجو در تسک‌ها و TaskSections + var tasks = await SearchTasks(searchQuery, cancellationToken); + results.AddRange(tasks); + + // مرتب‌سازی نتایج: ابتدا بر اساس سطح سلسله‌مراتب (پروژه → فاز → تسک)، سپس بر اساس نام + var sortedResults = results + .OrderBy(r => r.Level) + .ThenBy(r => r.Title) + .Take(MaxResults) + .ToList(); + + var response = new GetProjectSearchResponse(sortedResults); + return OperationResult.Success(response); + } + + /// + /// جستجو در جدول پروژه‌ها (نام، توضیحات) و ProjectSections (نام مهارت، توضیحات اولیه) + /// + private async Task> SearchProjects( + string searchQuery, + CancellationToken cancellationToken) + { + var projects = await _context.Projects + .Where(p => + p.Name.ToLower().Contains(searchQuery) || + (p.Description != null && p.Description.ToLower().Contains(searchQuery))) + .Select(p => new ProjectHierarchySearchResultDto + { + Id = p.Id, + Title = p.Name, + Level = ProjectHierarchyLevel.Project, + ProjectId = null, + PhaseId = null + }) + .ToListAsync(cancellationToken); + + return projects; + } + + /// + /// جستجو در جدول فازهای پروژه (نام، توضیحات) و PhaseSections + /// + private async Task> SearchPhases( + string searchQuery, + CancellationToken cancellationToken) + { + var phases = await _context.ProjectPhases + .Where(ph => + ph.Name.ToLower().Contains(searchQuery) || + (ph.Description != null && ph.Description.ToLower().Contains(searchQuery))) + .Select(ph => new ProjectHierarchySearchResultDto + { + Id = ph.Id, + Title = ph.Name, + Level = ProjectHierarchyLevel.Phase, + ProjectId = ph.ProjectId, + PhaseId = null + }) + .ToListAsync(cancellationToken); + + return phases; + } + + /// + /// جستجو در جدول تسک‌های پروژه (نام، توضیحات) و TaskSections (نام مهارت، توضیح اولیه، اطلاعات اضافی) + /// + private async Task> SearchTasks( + string searchQuery, + CancellationToken cancellationToken) + { + var tasks = await _context.ProjectTasks + .Include(t => t.Sections) + .Include(t => t.Phase) + .Where(t => + t.Name.ToLower().Contains(searchQuery) || + (t.Description != null && t.Description.ToLower().Contains(searchQuery)) || + t.Sections.Any(s => + (s.InitialDescription != null && s.InitialDescription.ToLower().Contains(searchQuery)) || + s.AdditionalTimes.Any(at => at.Reason != null && at.Reason.ToLower().Contains(searchQuery)))) + .Select(t => new ProjectHierarchySearchResultDto + { + Id = t.Id, + Title = t.Name, + Level = ProjectHierarchyLevel.Task, + ProjectId = t.Phase.ProjectId, + PhaseId = t.PhaseId + }) + .ToListAsync(cancellationToken); + + return tasks; + } + +} + + diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryValidator.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryValidator.cs new file mode 100644 index 00000000..70c25241 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchQueryValidator.cs @@ -0,0 +1,18 @@ +using FluentValidation; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; + +/// +/// اعتبارسنج برای درخواست جستجوی سراسری +/// +public class GetProjectSearchQueryValidator : AbstractValidator +{ + public GetProjectSearchQueryValidator() + { + RuleFor(x => x.SearchQuery) + .NotEmpty().WithMessage("متن جستجو نمی‌تواند خالی باشد.") + .MinimumLength(2).WithMessage("متن جستجو باید حداقل 2 حرف باشد.") + .MaximumLength(500).WithMessage("متن جستجو نمی‌تواند بیش از 500 حرف باشد."); + } +} + diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchResponse.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchResponse.cs new file mode 100644 index 00000000..288206f7 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/GetProjectSearchResponse.cs @@ -0,0 +1,8 @@ +namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; + +/// +/// پوسته‌ی پاسخ برای نتایج جستجوی سراسری +/// +public record GetProjectSearchResponse( + List Results); + diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/ProjectHierarchySearchResultDto.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/ProjectHierarchySearchResultDto.cs new file mode 100644 index 00000000..036d3a8b --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/GetProjectHierarchySearch/ProjectHierarchySearchResultDto.cs @@ -0,0 +1,36 @@ +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; + +namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; + +/// +/// DTO برای نتایج جستجوی سراسری در سلسله‌مراتب پروژه. +/// حاوی اطلاعات کافی برای بازسازی مسیر سلسله‌مراتب و بسط درخت در رابط کاربری است. +/// +public record ProjectHierarchySearchResultDto +{ + /// + /// شناسه آیتم (پروژه، فاز یا تسک) + /// + public Guid Id { get; init; } + + /// + /// نام/عنوان آیتم + /// + public string Title { get; init; } = string.Empty; + + /// + /// سطح سلسله‌مراتب این آیتم + /// + public ProjectHierarchyLevel Level { get; init; } + + /// + /// شناسه پروژه - همیشه برای فاز و تسک پر شده است، برای پروژه با شناسه خود پر می‌شود + /// + public Guid? ProjectId { get; init; } + + /// + /// شناسه فاز - فقط برای تسک پر شده است، برای پروژه و فاز خالی است + /// + public Guid? PhaseId { get; init; } +} + 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 e79b7fe4..ceaf2e19 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 @@ -272,6 +272,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler s.Activities) + .Include(x=>x.AdditionalTimes) .Where(s => s.TaskId == task.Id) .ToListAsync(cancellationToken); 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 69e82940..e6502494 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,68 +53,82 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler x.Id, x => x.FullName, cancellationToken); - var result = data.Select(x => - { - // محاسبه یکبار برای هر Activity و Cache کردن نتیجه - var activityTimeData = x.Activities.Select(a => + var result = data .OrderByDescending(x => x.CurrentAssignedUserId == currentUserId) + .ThenBy(x => GetStatusOrder(x.Status)) + .Select(x => { - var timeSpent = a.GetTimeSpent(); - return new + // محاسبه یکبار برای هر Activity و Cache کردن نتیجه + var activityTimeData = x.Activities.Select(a => { - Activity = a, - TimeSpent = timeSpent, - TotalSeconds = timeSpent.TotalSeconds, - FormattedTime = timeSpent.ToString(@"hh\:mm") + var timeSpent = a.GetTimeSpent(); + return new + { + Activity = a, + TimeSpent = timeSpent, + TotalSeconds = timeSpent.TotalSeconds, + FormattedTime = timeSpent.ToString(@"hh\:mm") + }; + }).ToList(); + + // ادغام پشت سر هم فعالیت‌های یک کاربر + var mergedHistories = new List(); + foreach (var activityData in activityTimeData) + { + var lastHistory = mergedHistories.LastOrDefault(); + + // اگر آخرین history برای همین کاربر باشد، زمان‌ها را جمع می‌کنیم + if (lastHistory != null && lastHistory.UserId == activityData.Activity.UserId) + { + var totalTimeSpan = lastHistory.WorkedTimeSpan + activityData.TimeSpent; + lastHistory.WorkedTimeSpan = totalTimeSpan; + lastHistory.WorkedTime = totalTimeSpan.ToString(@"hh\:mm"); + } + else + { + // در غیر این صورت، یک history جدید اضافه می‌کنیم + mergedHistories.Add(new ProjectProgressHistoryDto() + { + UserId = activityData.Activity.UserId, + IsCurrentUser = activityData.Activity.UserId == currentUserId, + Name = users.GetValueOrDefault(activityData.Activity.UserId, "ناشناس"), + WorkedTime = activityData.FormattedTime, + WorkedTimeSpan = activityData.TimeSpent, + }); + } + } + return new ProjectBoardListResponse() + { + Id = x.Id, + PhaseName = x.Task.Phase.Name, + ProjectName = x.Task.Phase.Project.Name, + TaskName = x.Task.Name, + SectionStatus = x.Status, + Progress = new ProjectProgressDto() + { + CompleteSecond = x.FinalEstimatedHours.TotalSeconds, + CurrentSecond = activityTimeData.Sum(a => a.TotalSeconds), + Histories = mergedHistories + }, + OriginalUser = users.GetValueOrDefault(x.OriginalAssignedUserId, "ناشناس"), + AssignedUser = x.CurrentAssignedUserId == x.OriginalAssignedUserId ? null + : users.GetValueOrDefault(x.CurrentAssignedUserId, "ناشناس"), + SkillName = x.Skill?.Name??"-", }; }).ToList(); - // ادغام پشت سر هم فعالیت‌های یک کاربر - var mergedHistories = new List(); - foreach (var activityData in activityTimeData) - { - var lastHistory = mergedHistories.LastOrDefault(); - - // اگر آخرین history برای همین کاربر باشد، زمان‌ها را جمع می‌کنیم - if (lastHistory != null && lastHistory.UserId == activityData.Activity.UserId) - { - var totalTimeSpan = lastHistory.WorkedTimeSpan + activityData.TimeSpent; - lastHistory.WorkedTimeSpan = totalTimeSpan; - lastHistory.WorkedTime = totalTimeSpan.ToString(@"hh\:mm"); - } - else - { - // در غیر این صورت، یک history جدید اضافه می‌کنیم - mergedHistories.Add(new ProjectProgressHistoryDto() - { - UserId = activityData.Activity.UserId, - IsCurrentUser = activityData.Activity.UserId == currentUserId, - Name = users.GetValueOrDefault(activityData.Activity.UserId, "ناشناس"), - WorkedTime = activityData.FormattedTime, - WorkedTimeSpan = activityData.TimeSpent, - }); - } - } - - return new ProjectBoardListResponse() - { - Id = x.Id, - PhaseName = x.Task.Phase.Name, - ProjectName = x.Task.Phase.Project.Name, - TaskName = x.Task.Name, - SectionStatus = x.Status, - Progress = new ProjectProgressDto() - { - CompleteSecond = x.FinalEstimatedHours.TotalSeconds, - CurrentSecond = activityTimeData.Sum(a => a.TotalSeconds), - Histories = mergedHistories - }, - OriginalUser = users.GetValueOrDefault(x.OriginalAssignedUserId, "ناشناس"), - AssignedUser = x.CurrentAssignedUserId == x.OriginalAssignedUserId ? null - : users.GetValueOrDefault(x.CurrentAssignedUserId, "ناشناس"), - SkillName = x.Skill?.Name??"-", - }; - }).ToList(); - return OperationResult>.Success(result); } + + private static int GetStatusOrder(TaskSectionStatus status) + { + return status switch + { + TaskSectionStatus.InProgress => 0, + TaskSectionStatus.Incomplete => 1, + TaskSectionStatus.NotAssigned => 2, + TaskSectionStatus.ReadyToStart => 2, + TaskSectionStatus.PendingForCompletion => 3, + _ => 99 + }; + } } \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQuery.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQuery.cs index 4b2c08b9..a3ac883d 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQuery.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQuery.cs @@ -3,21 +3,22 @@ using GozareshgirProgramManager.Domain.ProjectAgg.Enums; namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectSetTimeDetails; -public record ProjectSetTimeDetailsQuery(Guid TaskId) +public record ProjectSetTimeDetailsQuery(Guid Id, ProjectHierarchyLevel Level) : IBaseQuery; public record ProjectSetTimeResponse( - List SectionItems, + List SkillItems, Guid Id, ProjectHierarchyLevel Level); -public record ProjectSetTimeResponseSections +public record ProjectSetTimeResponseSkill { + public Guid SkillId { get; init; } public string SkillName { get; init; } - public string UserName { get; init; } - public int InitialTime { get; set; } + public long UserId { get; set; } + public string UserFullName { get; init; } + public int InitialHours { get; set; } + public int InitialMinutes { get; set; } public string InitialDescription { get; set; } - public int TotalEstimateTime { get; init; } - public int TotalAdditionalTime { get; init; } public string InitCreationTime { get; init; } public List AdditionalTimes { get; init; } public Guid SectionId { get; set; } @@ -25,6 +26,8 @@ public record ProjectSetTimeResponseSections public class ProjectSetTimeResponseSectionAdditionalTime { - public int Time { get; init; } + public int Hours { get; init; } + public int Minutes { get; init; } public string Description { get; init; } + public string CreationDate { get; set; } } diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryHandler.cs index f99f3370..aee31370 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryHandler.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryHandler.cs @@ -22,17 +22,30 @@ public class ProjectSetTimeDetailsQueryHandler public async Task> Handle(ProjectSetTimeDetailsQuery request, CancellationToken cancellationToken) + { + return request.Level switch + { + ProjectHierarchyLevel.Task => await GetTaskSetTimeDetails(request.Id, request.Level, cancellationToken), + ProjectHierarchyLevel.Phase => await GetPhaseSetTimeDetails(request.Id, request.Level, cancellationToken), + ProjectHierarchyLevel.Project => await GetProjectSetTimeDetails(request.Id, request.Level, cancellationToken), + _ => OperationResult.Failure("سطح معادل نامعتبر است") + }; + } + + private async Task> GetTaskSetTimeDetails(Guid id, ProjectHierarchyLevel level, + CancellationToken cancellationToken) { var task = await _context.ProjectTasks - .Where(p => p.Id == request.TaskId) + .Where(p => p.Id == id) .Include(x => x.Sections) .ThenInclude(x => x.AdditionalTimes).AsNoTracking() .FirstOrDefaultAsync(cancellationToken); if (task == null) { - return OperationResult.NotFound("Project not found"); + return OperationResult.NotFound("تسک یافت نشد"); } + var userIds = task.Sections.Select(x => x.OriginalAssignedUserId) .Distinct().ToList(); @@ -40,40 +53,142 @@ public class ProjectSetTimeDetailsQueryHandler .Where(x => userIds.Contains(x.Id)) .AsNoTracking() .ToListAsync(cancellationToken); - var skillIds = task.Sections.Select(x => x.SkillId) - .Distinct().ToList(); - var skills = await _context.Skills - .Where(x => skillIds.Contains(x.Id)) + var skills = await _context.Skills .AsNoTracking() .ToListAsync(cancellationToken); var res = new ProjectSetTimeResponse( - task.Sections.Select(ts => + skills.Select(skill => + { + var section = task.Sections + .FirstOrDefault(x => x.SkillId == skill.Id); + var user = users.FirstOrDefault(x => x.Id == section?.OriginalAssignedUserId); + return new ProjectSetTimeResponseSkill { - var user = users.FirstOrDefault(x => x.Id == ts.OriginalAssignedUserId); - var skill = skills.FirstOrDefault(x => x.Id == ts.SkillId); - return new ProjectSetTimeResponseSections - { - AdditionalTimes = ts.AdditionalTimes - .Select(x => new ProjectSetTimeResponseSectionAdditionalTime - { - Description = x.Reason ?? "", - Time = (int)x.Hours.TotalHours - }).ToList(), - InitCreationTime = ts.CreationDate.ToFarsi(), - SkillName = skill?.Name ?? "", - TotalAdditionalTime = (int)ts.GetTotalAdditionalTime().TotalHours, - TotalEstimateTime = (int)ts.FinalEstimatedHours.TotalHours, - UserName = user?.UserName ?? "", - SectionId = ts.Id, - InitialDescription = ts.InitialDescription ?? "", - InitialTime = (int)ts.InitialEstimatedHours.TotalHours - }; - }).ToList(), - task.Id, - ProjectHierarchyLevel.Task); + AdditionalTimes = section?.AdditionalTimes + .Select(x => new ProjectSetTimeResponseSectionAdditionalTime + { + Description = x.Reason ?? "", + Hours = (int)x.Hours.TotalHours, + Minutes = x.Hours.Minutes, + CreationDate = x.CreationDate.ToFarsi() + }).OrderBy(x => x.CreationDate).ToList() ?? [], + InitCreationTime = section?.CreationDate.ToFarsi() ?? "", + SkillName = skill.Name ?? "", + UserFullName = user?.FullName ?? "", + SectionId = section?.Id ?? Guid.Empty, + InitialDescription = section?.InitialDescription ?? "", + InitialHours = (int)(section?.InitialEstimatedHours.TotalHours ?? 0), + InitialMinutes = section?.InitialEstimatedHours.Minutes ?? 0, + UserId = section?.OriginalAssignedUserId ?? 0, + SkillId = skill.Id, + }; + }).OrderBy(x => x.SkillId).ToList(), + task.Id, + level); + return OperationResult.Success(res); + } + + private async Task> GetPhaseSetTimeDetails(Guid id, ProjectHierarchyLevel level, + CancellationToken cancellationToken) + { + var phase = await _context.ProjectPhases + .Where(p => p.Id == id) + .Include(x => x.PhaseSections).AsNoTracking() + .FirstOrDefaultAsync(cancellationToken); + + if (phase == null) + { + return OperationResult.NotFound("فاز یافت نشد"); + } + + var userIds = phase.PhaseSections.Select(x => x.UserId) + .Distinct().ToList(); + + var users = await _context.Users + .Where(x => userIds.Contains(x.Id)) + .AsNoTracking() + .ToListAsync(cancellationToken); + + var skills = await _context.Skills + .AsNoTracking() + .ToListAsync(cancellationToken); + + var res = new ProjectSetTimeResponse( + skills.Select(skill => + { + var section = phase.PhaseSections + .FirstOrDefault(x => x.SkillId == skill.Id); + var user = users.FirstOrDefault(x => x.Id == section?.UserId); + return new ProjectSetTimeResponseSkill + { + AdditionalTimes = [], + InitCreationTime = "", + SkillName = skill.Name ?? "", + UserFullName = user?.FullName ?? "", + SectionId = section?.Id ?? Guid.Empty, + InitialDescription = "", + InitialHours = 0, + InitialMinutes = 0, + UserId = section?.UserId ?? 0, + SkillId = skill.Id, + }; + }).OrderBy(x => x.SkillId).ToList(), + phase.Id, + level); + + return OperationResult.Success(res); + } + + private async Task> GetProjectSetTimeDetails(Guid id, ProjectHierarchyLevel level, + CancellationToken cancellationToken) + { + var project = await _context.Projects + .Where(p => p.Id == id) + .Include(x => x.ProjectSections).AsNoTracking() + .FirstOrDefaultAsync(cancellationToken); + + if (project == null) + { + return OperationResult.NotFound("پروژه یافت نشد"); + } + + var userIds = project.ProjectSections.Select(x => x.UserId) + .Distinct().ToList(); + + var users = await _context.Users + .Where(x => userIds.Contains(x.Id)) + .AsNoTracking() + .ToListAsync(cancellationToken); + + var skills = await _context.Skills + .AsNoTracking() + .ToListAsync(cancellationToken); + + var res = new ProjectSetTimeResponse( + skills.Select(skill => + { + var section = project.ProjectSections + .FirstOrDefault(x => x.SkillId == skill.Id); + var user = users.FirstOrDefault(x => x.Id == section?.UserId); + return new ProjectSetTimeResponseSkill + { + AdditionalTimes = [], + InitCreationTime = "", + SkillName = skill.Name ?? "", + UserFullName = user?.FullName ?? "", + SectionId = section?.Id ?? Guid.Empty, + InitialDescription = "", + InitialHours = 0, + InitialMinutes = 0, + UserId = section?.UserId ?? 0, + SkillId = skill.Id, + }; + }).OrderBy(x => x.SkillId).ToList(), + project.Id, + level); return OperationResult.Success(res); } diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryValidator.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryValidator.cs index 13952f46..bd2c0dbe 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryValidator.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Projects/Queries/ProjectSetTimeDetails/ProjectSetTimeDetailsQueryValidator.cs @@ -1,13 +1,18 @@ using FluentValidation; +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectSetTimeDetails; -public class ProjectSetTimeDetailsQueryValidator:AbstractValidator +public class ProjectSetTimeDetailsQueryValidator : AbstractValidator { public ProjectSetTimeDetailsQueryValidator() { - RuleFor(x => x.TaskId) + RuleFor(x => x.Id) .NotEmpty() - .WithMessage("شناسه پروژه نمی‌تواند خالی باشد."); + .WithMessage("شناسه نمی‌تواند خالی باشد."); + + RuleFor(x => x.Level) + .IsInEnum() + .WithMessage("سطح معادل نامعتبر است."); } } \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/Project.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/Project.cs index dc2bfa15..8e8e2b31 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/Project.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/Project.cs @@ -74,6 +74,15 @@ public class Project : ProjectHierarchyNode } } + public void RemoveProjectSection(Guid skillId) + { + var section = _projectSections.FirstOrDefault(s => s.SkillId == skillId); + if (section != null) + { + _projectSections.Remove(section); + } + } + public void ClearProjectSections() { _projectSections.Clear(); diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectPhase.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectPhase.cs index 3534c50f..60b98df9 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectPhase.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectPhase.cs @@ -87,6 +87,15 @@ public class ProjectPhase : ProjectHierarchyNode } } + public void RemovePhaseSection(Guid skillId) + { + var section = _phaseSections.FirstOrDefault(s => s.SkillId == skillId); + if (section != null) + { + _phaseSections.Remove(section); + } + } + public void ClearPhaseSections() { _phaseSections.Clear(); diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectTask.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectTask.cs index 863e332f..71de7615 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectTask.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/ProjectTask.cs @@ -246,4 +246,9 @@ public class ProjectTask : ProjectHierarchyNode } #endregion + + public void ClearTaskSections() + { + _sections.Clear(); + } } diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs index b4a4c5dd..487991a8 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionRepository.cs @@ -13,4 +13,5 @@ public interface ITaskSectionRepository: IRepository Task> GetAssignedToUserAsync(long userId); Task> GetActiveSectionsIncludeAllAsync(CancellationToken cancellationToken); + Task HasUserAnyInProgressSectionAsync(long userId, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/ProjectPhaseRepository.cs b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/ProjectPhaseRepository.cs index 81306c82..f00d4512 100644 --- a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/ProjectPhaseRepository.cs +++ b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/ProjectPhaseRepository.cs @@ -19,6 +19,7 @@ public class ProjectPhaseRepository : RepositoryBase, IProje public Task GetWithTasksAsync(Guid phaseId) { return _context.ProjectPhases + .Include(x=>x.PhaseSections) .Include(p => p.Tasks) .ThenInclude(t => t.Sections) .ThenInclude(s => s.Skill) diff --git a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs index 89fb05fd..1b29e154 100644 --- a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs +++ b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Persistence/Repositories/TaskSectionRepository.cs @@ -45,4 +45,11 @@ public class TaskSectionRepository:RepositoryBase,ITaskSection .Include(x => x.AdditionalTimes) .ToListAsync(cancellationToken); } + + public async Task HasUserAnyInProgressSectionAsync(long userId, CancellationToken cancellationToken = default) + { + return await _context.TaskSections + .AnyAsync(x => x.CurrentAssignedUserId == userId && x.Status == TaskSectionStatus.InProgress, + 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 e13bcc97..95d6da94 100644 --- a/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs +++ b/ServiceHost/Areas/Admin/Controllers/ProgramManager/ProjectController.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Application.Modules.Projects.Commands.ApproveTaskSectionCompletion; using GozareshgirProgramManager.Application.Modules.Projects.Commands.AssignProject; using GozareshgirProgramManager.Application.Modules.Projects.Commands.AutoStopOverTimeTaskSections; using GozareshgirProgramManager.Application.Modules.Projects.Commands.AutoUpdateDeployStatus; @@ -17,6 +18,7 @@ using GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectBoar using GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectDeployBoardDetail; using GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectDeployBoardList; using GozareshgirProgramManager.Application.Modules.Projects.Queries.ProjectSetTimeDetails; +using GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectHierarchySearch; using MediatR; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -40,6 +42,15 @@ public class ProjectController : ProgramManagerBaseController return res; } + [HttpGet("search")] + public async Task>> Search( + [FromQuery] string search) + { + var searchQuery = new GetProjectSearchQuery(search); + var res = await _mediator.Send(searchQuery); + return res; + } + [HttpPost] public async Task> Create([FromBody] CreateProjectCommand command) { @@ -147,4 +158,11 @@ public class ProjectController : ProgramManagerBaseController var res = await _mediator.Send(command); return res; } + + [HttpPost("approve-completion")] + public async Task> ApproveTaskSectionCompletion([FromBody] ApproveTaskSectionCompletionCommand command) + { + var res = await _mediator.Send(command); + return res; + } } \ No newline at end of file diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Ticket/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/Ticket/Index.cshtml.cs index bf33a3ed..11b18fd1 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Ticket/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Ticket/Index.cshtml.cs @@ -80,7 +80,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.Ticket public IActionResult OnGetShowDetailTicketByAdmin(long ticketID) { var res = _ticketApplication.GetDetails(ticketID); - res.WorkshopName = _workshopApplication.GetDetails(res.WorkshopId).WorkshopFullName; + res.WorkshopName = _workshopApplication.GetDetails(res.WorkshopId)?.WorkshopFullName??""; return Partial("DetailTicketModal", res); } diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 921656cd..73ff3d88 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -63,16 +63,10 @@ if (!Directory.Exists(logDirectory)) Directory.CreateDirectory(logDirectory); } +// فقط برای فایل از Serilog استفاده می‌شود +// تنظیمات MinimumLevel از appsettings.json خوانده می‌شود Log.Logger = new LoggerConfiguration() - //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() + .Enrich.FromLogContext() .WriteTo.File( path: Path.Combine(logDirectory, "gozareshgir_log.txt"), rollingInterval: RollingInterval.Day, @@ -379,7 +373,30 @@ builder.Services.AddParbad().ConfigureGateways(gateways => }); -builder.Host.UseSerilog(); +// فقط Serilog برای File استفاده می‌شه، کنسول از لاگر پیش‌فرض ASP.NET استفاده می‌کنه +builder.Host.UseSerilog((context, services, configuration) => +{ + var logConfig = configuration + .ReadFrom.Configuration(context.Configuration) + .ReadFrom.Services(services) + .Enrich.FromLogContext(); + + // در محیط Development، EF Core Commands را هم لاگ می‌کنیم + if (context.HostingEnvironment.IsDevelopment()) + { + logConfig + .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Information); + } + + logConfig.WriteTo.File( + path: Path.Combine(logDirectory, "gozareshgir_log.txt"), + rollingInterval: RollingInterval.Day, + retainedFileCountLimit: 30, + shared: true, + outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}" + ); +}, writeToProviders: true); // این باعث میشه کنسول پیش‌فرض هم کار کنه + Log.Information("SERILOG STARTED SUCCESSFULLY"); var app = builder.Build(); diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index 788962e4..f5214c2b 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -19,7 +19,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5006", "jsWebView2Debugging": false, "hotReloadEnabled": true }, @@ -44,7 +44,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5006;", "jsWebView2Debugging": false, "hotReloadEnabled": true } diff --git a/ServiceHost/ServiceHost.csproj b/ServiceHost/ServiceHost.csproj index 8eb8a743..a6eb425b 100644 --- a/ServiceHost/ServiceHost.csproj +++ b/ServiceHost/ServiceHost.csproj @@ -10,6 +10,7 @@ true + a6049acf-0286-4947-983a-761d06d65f36