From 9e953cd5d64387aa590ceb4f09c7802f2e0e28d2 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 13 May 2025 12:27:19 +0700 Subject: [PATCH] =?UTF-8?q?fix=20=E0=B8=84=E0=B8=B3=E0=B8=99=E0=B8=A7?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=84=E0=B8=A3=E0=B8=B7=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=A2=E0=B9=8C=20?= =?UTF-8?q?=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/InsigniaPeriodsRepository.cs | 25 +++++---- .../Controllers/InsigniaRequestController.cs | 56 ++++++++++--------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index 68a3b076..e336de4f 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -7859,6 +7859,19 @@ namespace BMA.EHR.Application.Repositories result_candidate.Add(r); } + // ย้ายที่ตามที่ มอสแจ้ง + if (period.Round != 1) + { + var insigniaIdList = await _dbContext.Set() + .Include(x => x.InsigniaType) + .Where(x => x.InsigniaType!.Name == "ชั้นสายสะพาย") + .Select(x => x.Id) + .ToListAsync(); + + + result_candidate = result_candidate.Where(x => insigniaIdList.Contains(x.RequestInsignia.Id)).ToList(); + } + foreach (var r in employee_type2) { var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); @@ -7881,17 +7894,7 @@ namespace BMA.EHR.Application.Repositories // result_candidate.Add(r); //} - if (period.Round != 1) - { - var insigniaIdList = await _dbContext.Set() - .Include(x => x.InsigniaType) - .Where(x => x.InsigniaType!.Name == "ชั้นสายสะพาย") - .Select(x => x.Id) - .ToListAsync(); - - - result_candidate = result_candidate.Where(x => insigniaIdList.Contains(x.RequestInsignia.Id)).ToList(); - } + return result_candidate.OrderBy(x => x.Seq).ThenBy(x => x.Gender).ThenBy(x => x.ProfileId).ToList(); } diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index f419847a..75442ae2 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -9,6 +9,7 @@ using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Models.MetaData; +using BMA.EHR.Domain.ModelsExam.Candidate; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Insignia.Service.Requests; @@ -407,6 +408,8 @@ namespace BMA.EHR.Insignia.Service.Controllers var organizations = await _userProfileRepository.GetActiveRootAsync(AccessToken, selectPeriod.RevisionId); var allEmployeeProfileByRoot = new List(); + var candidates = new List(); + foreach (var organization in organizations) { if (organization == null) @@ -414,34 +417,37 @@ namespace BMA.EHR.Insignia.Service.Controllers if (selectPeriod != null && selectPeriod.InsigniaEmployees != null) { - var emp = - await _userProfileRepository.GetEmployeeProfileByPositionAsync(organization.Id, selectPeriod.InsigniaEmployees.Select(x => x.RefId!.ValueOrBlank()).ToArray(), AccessToken); - if (emp != null) - allEmployeeProfileByRoot.AddRange(emp); + var can = await _repository.GetInsigniaCandidateBKK(periodId, organization.Id); + //var emp = + // await _userProfileRepository.GetEmployeeProfileByPositionAsync(organization.Id, selectPeriod.InsigniaEmployees.Select(x => x.RefId!.ValueOrBlank()).ToArray(), AccessToken); + if (can != null) + candidates.AddRange(can); } } - var resultData = allEmployeeProfileByRoot.Select(x => new - { - citizenId = x.CitizenId, - fullName = $"{x.Prefix}{x.FirstName} {x.LastName}", - root = x.Root, - child1 = x.Child1 ?? "", - child2 = x.Child2 ?? "", - child3 = x.Child3 ?? "", - child4 = x.Child4 ?? "", - dateAppoint = x.DateAppoint == null ? "" : x.DateAppoint.Value.ToThaiShortDate(), - salary = x.Amount, - salaryCondition = x.ProfileSalary == null || x.ProfileSalary.Count == 0 ? 0 : - x.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(selectPeriod.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault() != null ? x.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(selectPeriod.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : - x.Amount, - insignias = x.ProfileInsignia.ToList(), - salaries = x.ProfileSalary.ToList(), - profileType = x.ProfileType - }).ToList(); + var resultData = candidates.Where(x => x.ProfileType == "EMPLOYEE").ToList(); + + //var resultData = allEmployeeProfileByRoot.Select(x => new + //{ + // citizenId = x.CitizenId, + // fullName = $"{x.Prefix}{x.FirstName} {x.LastName}", + // root = x.Root, + // child1 = x.Child1 ?? "", + // child2 = x.Child2 ?? "", + // child3 = x.Child3 ?? "", + // child4 = x.Child4 ?? "", + // dateAppoint = x.DateAppoint == null ? "" : x.DateAppoint.Value.ToThaiShortDate(), + // salary = x.Amount, + // salaryCondition = x.ProfileSalary == null || x.ProfileSalary.Count == 0 ? 0 : + // x.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(selectPeriod.Year, 4, 29)) + // .OrderByDescending(x => x.Order).FirstOrDefault() != null ? x.ProfileSalary + // .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(selectPeriod.Year, 4, 29)) + // .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + // x.Amount, + // insignias = x.ProfileInsignia.ToList(), + // salaries = x.ProfileSalary.ToList(), + // profileType = x.ProfileType + //}).ToList(); return Success(resultData);