diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index e9e184cc..5af3a4ce 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -6,6 +6,7 @@ using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Notifications; +using BMA.EHR.Domain.Models.OrganizationEmployee; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Models.Retirement; @@ -136,6 +137,9 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-20": result = await GetReceiver20Async(command); break; + case "C-PM-21": + result = await GetReceiver21Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -1377,6 +1381,63 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver21Async(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-21") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + #endregion #region " Execute and Deploy " diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 42b86e83..6de87780 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -2436,6 +2436,106 @@ namespace BMA.EHR.Command.Service.Controllers #endregion + #region " C-PM-21 " + + /// + /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-21 + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("c-pm-21/detail")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostType21Async([FromBody] CreateCommandGroup7Request req) + { + try + { + var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); + + var inserted = new Domain.Models.Commands.Core.Command + { + CommandNo = req.orderNo, + CommandYear = req.orderYear.ToString(), + CommandSubject = req.orderTitle, + CommandTypeId = req.orderTypeValue, + IssuerOrganizationId = req.orderBy, + IssuerOrganizationName = req.orderByOrganizationName, + AuthorizedUserFullName = req.signatoryBy, + AuthorizedPosition = req.signatoryPosition, + + CommandAffectDate = req.orderDate, + OwnerGovId = OcId, + + PlacementCommandIssuer = req.placementCommandIssuer, + PlacementCommandNo = req.placementCommandNo, + PlacementCommandDate = req.placementCommandDate, + + }; + + var result = await _repository.AddAsync(inserted); + + return Success(result); + } + catch + { + throw; + } + } + + /// + /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-21 + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("c-pm-21/detail/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PutType21Async(Guid orderId, [FromBody] CreateCommandGroup7Request req) + { + try + { + var order = await _repository.GetByIdAsync(orderId); + if (order == null) + throw new Exception(GlobalMessages.CommandNotFound); + + + var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); + var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); + + order.CommandNo = req.orderNo; + order.CommandYear = req.orderYear.ToString(); + order.CommandSubject = req.orderTitle; + order.CommandType = commandType!; + order.IssuerOrganizationId = req.orderBy; + order.IssuerOrganizationName = req.orderByOrganizationName; + order.AuthorizedUserFullName = req.signatoryBy; + order.AuthorizedPosition = req.signatoryPosition; + order.CommandStatus = status!; + order.CommandAffectDate = req.orderDate; + + order.PlacementCommandIssuer = req.placementCommandIssuer; + order.PlacementCommandNo = req.placementCommandNo; + order.PlacementCommandDate = req.placementCommandDate; + + var result = await _repository.UpdateAsync(order); + + return Success(result); + } + catch + { + throw; + } + } + + #endregion + #endregion /// diff --git a/BMA.EHR.Command.Service/SeedCommand.xlsx b/BMA.EHR.Command.Service/SeedCommand.xlsx index c06d6684..ac512431 100644 Binary files a/BMA.EHR.Command.Service/SeedCommand.xlsx and b/BMA.EHR.Command.Service/SeedCommand.xlsx differ diff --git a/BMA.EHR.Domain/Models/Commands/Core/Command.cs b/BMA.EHR.Domain/Models/Commands/Core/Command.cs index 343d1cca..c2758883 100644 --- a/BMA.EHR.Domain/Models/Commands/Core/Command.cs +++ b/BMA.EHR.Domain/Models/Commands/Core/Command.cs @@ -103,7 +103,7 @@ namespace BMA.EHR.Domain.Models.Commands.Core #endregion - #region " C-PM-10,C-PM-11,C-PM-12 " + #region " C-PM-10,C-PM-11,C-PM-12,C-PM-21 " [Comment("หน่วยงานที่ออกคำสั่งบรรจุ")] public string? PlacementCommandIssuer { get; set; }