From 1324baa9c70e5b5324490b3ad36b41631f499cfa Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sat, 24 Jan 2026 14:48:35 +0330 Subject: [PATCH] GetContractsAndIncludeDataDataToCreateCheckout changes --- .../CheckoutAgg/ICheckoutRepository.cs | 3 +- .../Checkout/ICheckoutApplication.cs | 2 +- .../CheckoutApplication.cs | 6 +-- .../Repository/CheckoutRepository.cs | 45 ++++++++++++++----- .../Admin/Controllers/CheckoutController.cs | 2 +- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index e9a0125a..23a6b262 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -112,9 +112,10 @@ public interface ICheckoutRepository : IRepository /// /// /// + /// /// Task> GetContractsAndIncludeDataDataToCreateCheckout( - List ids, string month); + List ids, string month, long workshopId); #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index 2a74d2dd..d10e24e1 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -113,7 +113,7 @@ public interface ICheckoutApplication /// /// /// - Task CreateCheckoutApi(List ids, string year, string month); + Task CreateCheckoutApi(List ids, string year, string month, long workshopId); #endregion } diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 240b5668..3da6033c 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -789,7 +789,7 @@ public class CheckoutApplication : ICheckoutApplication } - public async Task CreateCheckoutApi(List ids, string year, string month) + public async Task CreateCheckoutApi(List ids, string year, string month, long workshopId) { var op = new OperationResult(); @@ -829,8 +829,8 @@ public class CheckoutApplication : ICheckoutApplication #endregion - var getContcatsData = - _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month); + var getContcatsData = await + _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month, workshopId); return op.Succcedded(); } #endregion diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 97ee960a..8d4a491a 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -2762,23 +2762,25 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return employees; } - public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month) + public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month, long workshopId) { var op = new OperationResult(); - var watch = new Stopwatch(); - watch.Start(); + var watcher = new Stopwatch(); + watcher.Start(); //دریافت قراداد ها - var contracts =await _context.Contracts.Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); - if (!contracts.Any()) + var getContracts =await _context.Contracts.Include(x=>x.Employee).Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); + if (!getContracts.Any()) return op.Failed("قرادادی یافت نشد"); - var employeeIds = contracts.Select(x => x.EmployeeId).ToList(); - var workshopId = contracts.First().WorkshopIds; + var employeeIds = getContracts.Select(x => x.EmployeeId).ToList(); + //دریافت اطلاعات کارگاه var workshop = await _context.Workshops.FirstAsync(x => x.id == workshopId); - + var GetContractsTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); //دریافت اطلاعات پرسنل ها - var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync(); + // var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync(); //دریافت اطلاعت ساعت کاری #region WorkingHours var getWorkingHours = await _context.WorkingHoursSet.Where(x => ids.Contains(x.ContractId)) @@ -3894,6 +3896,10 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + + var workingHoursTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); //دریافت اطلاعات شروع بکار/ترک کار #region LeftWorks @@ -3903,12 +3909,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + var leftWorkTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); + //جداسازی شروع و پایان فیش از قراداد با توجه به شروع بکار و ترک کار #region Separation + var timer = new Stopwatch(); + timer.Start(); var separation = new List(); - foreach (var item in contracts) + foreach (var item in getContracts) { bool hasLeft = false; var ContractEnd = item.ContractEnd; @@ -4192,6 +4204,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + + var SeparationTime = timer.Elapsed; + + var optionTimer = new Stopwatch(); + optionTimer.Start(); //دریافت تنظیمات فنی پرسنل ها #region EmployeeOptions @@ -4207,8 +4224,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos }).AsNoTracking().ToListAsync(); #endregion - - Console.WriteLine("GetContractsAndIncludeDataDataToCreateCheckout : " + watch.Elapsed); + Console.WriteLine("GetContracts - employeeIds - workshop: " + GetContractsTime); + Console.WriteLine("workingHours " + workingHoursTime); + Console.WriteLine("leftWork " + leftWorkTime); + Console.WriteLine("Separation " + SeparationTime); + Console.WriteLine("EmployeeOptions : " + optionTimer.Elapsed); + Console.WriteLine("===================== sum : " + (GetContractsTime + workingHoursTime + leftWorkTime + SeparationTime + optionTimer.Elapsed) + "==================="); return op.Succcedded(new GetContractAndIncludesDataToCreateDto()); } diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index 77706420..67968610 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -122,7 +122,7 @@ public class CheckoutController : AdminBaseController #region testCreate var ids = result.Data.Where(x => x.CreateCheckoutStatus == CreateCheckoutStatus.ReadyToCreate).Select(x => x.Id).ToList(); - var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month); + var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month,workshopId); #endregion