From b58481a36f03605fc6be2654a58fd1e3a2543366 Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 24 Dec 2025 18:07:43 +0330 Subject: [PATCH] add employee client api --- .../EmployeeAgg/IEmployeeRepository.cs | 1 + .../Employee/IEmployeeApplication.cs | 35 ++++++ .../EmployeeAplication.cs | 5 + .../Repository/EmployeeRepository .cs | 113 +++++++++++++++++- 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs index 43a2564a..f0ecc290 100644 --- a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs +++ b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs @@ -76,6 +76,7 @@ public interface IEmployeeRepository : IRepository #region Api Task> GetSelectList(string searchText,long id); Task> GetList(GetEmployeeListSearchModel searchModel); + Task> GetClientEmployeeList(GetClientEmployeeListSearchModel searchModel, long workshopId); #endregion diff --git a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs index 396047da..bbf28757 100644 --- a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs +++ b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs @@ -94,7 +94,42 @@ public interface IEmployeeApplication /// /// Task> GetList(GetEmployeeListSearchModel searchModel); + + /// + /// لیست کل پرسنل کلاینت + /// + /// + /// + /// + Task> GetClientEmployeeList(GetClientEmployeeListSearchModel searchModel, long workshopId); #endregion +} + +public class GetClientEmployeeListSearchModel +{ +} + +public class GetClientEmployeeListViewModel +{ + public string FullName { get; set; } + public long EmployeeId { get; set; } + public long WorkshopId { get; set; } + public long PersonnelCode { get; set; } + public string MaritalStatus { get; set; } + public string NationalCode { get; set; } + public string IdNumber { get; set; } + public string DateOfBirthFa { get; set; } + public string FatherName { get; set; } + public int ChildrenCount { get; set; } + public string LastStartInsuranceWork { get; set; } + public string LastLeftInsuranceWork { get; set; } + public string LastStartContractWork { get; set; } + public string LastLeftContractWork { get; set; } + public bool HasContractLeftWork { get; set; } + public bool HasInsuranceLeftWork { get; set; } + public bool LeftWorkCompletely { get; set; } + public bool PendingStartWork { get; set; } + public bool PendingLeftWork { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/EmployeeAplication.cs b/CompanyManagment.Application/EmployeeAplication.cs index 4af00ab9..352d2173 100644 --- a/CompanyManagment.Application/EmployeeAplication.cs +++ b/CompanyManagment.Application/EmployeeAplication.cs @@ -1729,5 +1729,10 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli return await _EmployeeRepository.GetList(searchModel); } + public async Task> GetClientEmployeeList(GetClientEmployeeListSearchModel searchModel, long workshopId) + { + return await _EmployeeRepository.GetClientEmployeeList(searchModel, workshopId); + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs index bd02e8fa..74c27f31 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs +++ b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs @@ -1062,5 +1062,116 @@ public class EmployeeRepository : RepositoryBase, IEmployeeRepos } - #endregion + public Task> GetClientEmployeeList(GetClientEmployeeListSearchModel searchModel, long workshopId) + { + // var leftDate = Tools.GetUndefinedDateTime(); + // + // var personnelCodes = _context.PersonnelCodeSet.Include(x => x.Employee) + // .ThenInclude(x => x.EmployeeChildrenList).IgnoreQueryFilters().Where(x => x.WorkshopId == workshopId).ToList(); + // + // var contractLeftWork = + // _context.LeftWorkList.Where(x => x.WorkshopId == workshopId) + // .GroupBy(x => x.EmployeeId).Select(x => x.OrderByDescending(y => y.LeftWork).First()).ToList(); + // + // + // + // + // var insuranceLeftWork = _context.LeftWorkInsuranceList.Where(x => x.WorkshopId == workshopId).Select(x => new + // { + // EmployeeId = x.EmployeeId, + // FullName = x.EmployeeFullName, + // PersonnelCode = 0, + // InsurancePerson = true, + // InsuranceLeft = x.LeftWorkDate != null, + // StartWork = x.StartWorkDate, + // LeftWork = x.LeftWorkDate ?? leftDate, + // LastStartInsuranceWork = x.StartWorkDate.ToFarsi(), + // LastLeftInsuranceWork = x.LeftWorkDate != null ? x.LeftWorkDate.ToFarsi() : "-", + // LastStartContractWork = "-", + // LastLeftContractWork = "-" + // }).GroupBy(x => x.EmployeeId) + // .Select(x => x.OrderByDescending(y => y.LeftWork).First()).ToList(); + // + // var leftWorkTemp = _context.LeftWorkTemps.Where(x => x.WorkshopId == workshopId).Select(x => new + // { + // WorkshopId = x.WorkshopId, + // EmployeeId = x.EmployeeId, + // PersonnelCode = 0, + // ContractPerson = true, + // ContractLeft = x.LeftWork != leftDate, + // StartWork = x.StartWork, + // LeftWork = x.LeftWork, + // LastStartContractWork = x.StartWork.ToFarsi(), + // LastLeftContractWork = x.LeftWork != leftDate ? x.LeftWork.ToFarsi() : "-", + // LastStartInsuranceWork = "-", + // LastLeftInsuranceWork = "-", + // LefWorkTemp = x.LeftWorkType == LeftWorkTempType.LeftWork, + // CreatedByClient = x.LeftWorkType == LeftWorkTempType.StartWork + // }).ToList(); + // + // + // var employeeClientTemp = _context.EmployeeClientTemps.Where(x => x.WorkshopId == workshopId).Select(x => new + // { + // WorkshopId = x.WorkshopId, + // EmployeeId = x.EmployeeId, + // PersonnelCode = 0, + // CreatedByClient = true, + // ContractPerson = true + // }).ToList(); + // + // var resultTemp = employeeClientTemp.Concat(leftWorkTemp).ToList().GroupBy(x => x.EmployeeId); + // + // + // + // var result = contractLeftWork.Concat(insuranceLeftWork).GroupBy(x => x.EmployeeId).ToList(); + // + // result = result.Concat(resultTemp).GroupBy(x => x.First().EmployeeId).Select(x => x.First()).ToList(); + // + // var employeeClientTempList = employeeClientTemp.ToList(); + // var startWorkTempsForWorkshop = leftWorkTemp.Where(x => x.CreatedByClient).ToList(); + // var leftWorkTempsForWorkshop = leftWorkTemp.Where(x => x.LefWorkTemp).ToList(); + // + // return result.Select(x => + // { + // var insurance = x.FirstOrDefault(y => y.InsurancePerson); + // var contract = x.FirstOrDefault(y => y.ContractPerson); + // var personnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == x.Key); + // var employee = personnelCode.Employee; + // var employeeClient = employeeClientTempList.FirstOrDefault(t => t.EmployeeId == x.First().EmployeeId); + // var startWorkTemp = startWorkTempsForWorkshop.FirstOrDefault(s => s.EmployeeId == x.First().EmployeeId); + // var leftWorkTemp = leftWorkTempsForWorkshop.FirstOrDefault(s => s.EmployeeId == x.First().EmployeeId); + // + // + // return new GetClientEmployeeListViewModel() + // { + // EmployeeId = x.Key, + // FullName = employee.FullName, + // PersonnelCode = personnelCode?.PersonnelCode ?? 0, + // HasContractLeftWork = insurance != null, + // HasInsuranceLeftWork = contract != null, + // + // LeftWorkCompletely = (insurance?.InsuranceLeft ?? false) && (contract?.ContractLeft ?? false), + // + // LastStartInsuranceWork = insurance != null ? insurance.LastStartInsuranceWork : "-", + // LastLeftInsuranceWork = insurance != null ? insurance.LastLeftInsuranceWork : "-", + // LastStartContractWork = contract != null ? contract.LastStartContractWork : "-", + // LastLeftContractWork = contract != null ? contract.LastLeftContractWork : "-", + // + // NationalCode = employee.NationalCode, + // IdNumber = employee.IdNumber, + // MaritalStatus = employee.MaritalStatus, + // DateOfBirthFa = employee.DateOfBirth.ToFarsi(), + // FatherName = employee.FatherName, + // ChildrenCount = employee.EmployeeChildrenList.Count, + // + // PendingStartWork = employeeClient != null || startWorkTemp != null, + // PendingLeftWork = leftWorkTemp != null, + // + // + // }; + // }).OrderByDescending(x => x.StartWork).ToList(); +throw new NotImplementedException(); + } + + #endregion } \ No newline at end of file