From 9b3efd898153ebbc49ab104709c3900b988156a9 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 28 Aug 2023 16:44:31 +0700 Subject: [PATCH] Get command Receiver For C-PM-03 , C-PM-04 --- .../Commands/CommandRepository.cs | 137 ++++++++++++++++++ .../Repositories/GenericRepository.cs | 19 ++- 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index fdc8be31..b20e9dc4 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -76,6 +76,12 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-02": result = await GetReceiver02Async(command); break; + case "C-PM-03": + result = await GetReceiver03Async(command); + break; + case "C-PM-04": + result = await GetReceiver04Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -211,6 +217,137 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver03Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") + .Where(x => x.Draft! == true) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + .OrderBy(x => x.ExamNumber) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); + if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id == profile_oc) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver04Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") + .Where(x => x.Draft! == true) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + .OrderBy(x => x.ExamNumber) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); + if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id != profile_oc) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + } + + return result; + } + catch + { + throw; + } + } #endregion diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index 6ba9c059..44503ad2 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -43,7 +43,24 @@ namespace BMA.EHR.Application.Repositories #region " Methods " - public async Task CheckIsActiveOfficer(string citizenId) + public async Task GetProfileOrganizationAsync(string citizenId) + { + try + { + var pf = await _dbContext.Set() + .Where(x => x.CitizenId == citizenId) + .Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave) + .FirstOrDefaultAsync(); + + return pf == null || pf.Oc == null ? Guid.Empty : pf.OcId!.Value; + } + catch + { + throw; + } + } + + public async Task CheckIsActiveOfficerAsync(string citizenId) { try {