From 9a0e68b0f8a986c53081a9342a82de2a02549f75 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Sun, 20 Aug 2023 07:46:52 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=AA=E0=B8=A3=E0=B8=A3=E0=B9=80?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=87=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/InsigniaPeriodsRepository.cs | 18 ++- .../Requests/InsigniaRequestItem.cs | 1 + BMA.EHR.Domain/Shared/GlobalMessages.cs | 2 + .../Controllers/InsigniaRequestController.cs | 132 +++++++++++++++++- .../Requests/AddUserRequestInsigniaRequest.cs | 12 ++ .../UpdateUserRequestInsigniaRequest.cs | 10 ++ 6 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 BMA.EHR.Insignia.Service/Requests/AddUserRequestInsigniaRequest.cs create mode 100644 BMA.EHR.Insignia.Service/Requests/UpdateUserRequestInsigniaRequest.cs diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index 9a3851d9..95f9fb85 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -4965,6 +4965,7 @@ namespace BMA.EHR.Application.Repositories .ToList() .Select(h => new InsigniaRequestItem { + Id = h.Id, ProfileId = h.Profile.Id, FullName = $"{h.Profile.FirstName} {h.Profile.LastName}", Position = h.Profile.Position.Name, @@ -5109,7 +5110,13 @@ namespace BMA.EHR.Application.Repositories Period = period, Organization = oc, RequestStatus = "st1", - RequestNote = "" + RequestNote = "", + CreatedUserId = FullName ?? "", + CreatedFullName = UserId ?? "System Administrator", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, }; foreach (var item in items) @@ -5126,8 +5133,13 @@ namespace BMA.EHR.Application.Repositories RequestInsignia = req_insignia, Salary = item.Salary == null ? null : item.Salary, RequestDate = DateTime.Now, - MatchingConditions = System.Text.Json.JsonSerializer.Serialize(item.MatchingConditions) // serialize to string - + MatchingConditions = System.Text.Json.JsonSerializer.Serialize(item.MatchingConditions), // serialize to string + CreatedUserId = FullName ?? "", + CreatedFullName = UserId ?? "System Administrator", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, }); } } diff --git a/BMA.EHR.Application/Requests/InsigniaRequestItem.cs b/BMA.EHR.Application/Requests/InsigniaRequestItem.cs index f39b7460..762b353a 100644 --- a/BMA.EHR.Application/Requests/InsigniaRequestItem.cs +++ b/BMA.EHR.Application/Requests/InsigniaRequestItem.cs @@ -2,6 +2,7 @@ { public class InsigniaRequestItem { + public Guid Id { get; set; } public Guid ProfileId { get; set; } public string FullName { get; set; } public string Position { get; set; } diff --git a/BMA.EHR.Domain/Shared/GlobalMessages.cs b/BMA.EHR.Domain/Shared/GlobalMessages.cs index ba7c1e39..18c458f5 100644 --- a/BMA.EHR.Domain/Shared/GlobalMessages.cs +++ b/BMA.EHR.Domain/Shared/GlobalMessages.cs @@ -78,6 +78,8 @@ public static readonly string InsigniaDupicate = "มีการยื่นรอบรอบนี้ในปีนี้ไว้อยู่แล้ว"; public static readonly string InsigniaManageDupicate = "มีการกำหนดจัดสรรเครื่องราชย์ฯ รอบนี้ในปีนี้ไว้อยู่แล้ว"; public static readonly string InsigniaRequestNotFound = "ไม่พบข้อมูลการยื่นขอพระราชทานเครื่องราชย์ฯ ของหน่วยงานที่ระบุ!!"; + public static readonly string InsigniaRequestProfileNotFound = "ไม่พบข้อมูลการยื่นขอพระราชทานเครื่องราชย์ฯ ของบุคคลนี้!!"; + public static readonly string InsigniaRequestProfileDupicate = "มีการกำหนดจัดสรรเครื่องราชย์ฯ บุคคลนี้ไว้อยู่แล้ว"; public static readonly string InsigniaPeriodNotFound = "ไม่พบรอบการยื่นขอพระราชทานเครื่องราชย์อิสริยาภรณ์ฯ "; public static readonly string InsigniaManageNotFound = "ไม่พบจัดสรรเครื่องราชย์ฯ ที่ระบุ"; public static readonly string CoinPeriodNotFound = "ไม่พบรอบการขอพระราชทานเหรียญจักรพรรดิมาลาที่ระบุ!!"; diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs index 50389268..6139a930 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs @@ -5,6 +5,7 @@ using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; +using BMA.EHR.Insignia.Service.Requests; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -441,7 +442,7 @@ namespace BMA.EHR.Insignia.Service.Controllers } /// - /// คำนวนราชชื่อผู้ได้รับเครื่องราช + /// คำนวณราชชื่อผู้ได้รับเครื่องราช /// /// Id รอบเครื่องราช /// @@ -591,6 +592,9 @@ namespace BMA.EHR.Insignia.Service.Controllers if (insigniaRequestProfile == null) return Error(GlobalMessages.InsigniaPeriodNotFound); insigniaRequestProfile.Status = "REJECT"; + insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator"; + insigniaRequestProfile.LastUpdateUserId = UserId ?? ""; + insigniaRequestProfile.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } @@ -615,6 +619,9 @@ namespace BMA.EHR.Insignia.Service.Controllers if (insigniaRequestProfile == null) return Error(GlobalMessages.InsigniaPeriodNotFound); insigniaRequestProfile.Status = "DELETE"; + insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator"; + insigniaRequestProfile.LastUpdateUserId = UserId ?? ""; + insigniaRequestProfile.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } @@ -682,5 +689,128 @@ namespace BMA.EHR.Insignia.Service.Controllers return Success(); } + /// + /// หน่วยงานที่อยู่ปัจจุบัน + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("agency")] + public async Task> GetOrgAgency() + { + var profile = await _context.Profiles.AsQueryable() + .FirstOrDefaultAsync(x => x.KeycloakId == (UserId != null && UserId != "" ? Guid.Parse(UserId) : Guid.Parse("00000000-0000-0000-0000-000000000000"))); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + var orgProfile = await _context.ProfilePositions + .Where(x => x.Profile == profile) + .Where(x => x.OrganizationPosition != null) + .Where(x => x.OrganizationPosition.Organization != null) + .Where(x => x.OrganizationPosition.Organization.OrganizationAgencyId != null) + .Select(x => x.OrganizationPosition.Organization.OrganizationAgencyId) + .FirstOrDefaultAsync(); + + return Success(orgProfile); + } + + /// + /// เพิ่มราชชื่อผู้ได้รับเครื่องราช + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost()] + public async Task> AddUserToRequestInsignia([FromBody] AddUserRequestInsigniaRequest req) + { + var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == req.insigniaPeriodId); + if (insigniaPeriod == null) + return Error(GlobalMessages.InsigniaRequestNotFound); + var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.Id == req.ProfileId); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + var insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Id == req.insigniaId); + if (insignia == null) + return Error(GlobalMessages.InsigniaNotFound); + var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Profile == profile && x.Request.Period == insigniaPeriod); + if (insigniaRequestProfile != null) + return Error(GlobalMessages.InsigniaRequestProfileDupicate); + var insigniaRequest = await _context.InsigniaRequests.FirstOrDefaultAsync(x => x.Period == insigniaPeriod); + if (insigniaRequest == null) + { + var orgProfile = await _context.ProfilePositions + .Where(x => x.Profile == profile) + .Where(x => x.OrganizationPosition != null) + .Where(x => x.OrganizationPosition.Organization != null) + .Where(x => x.OrganizationPosition.Organization.OrganizationAgencyId != null) + .Select(x => x.OrganizationPosition.Organization.OrganizationAgencyId) + .FirstOrDefaultAsync(); + var org = await _context.Organizations + .FirstOrDefaultAsync(x => x.Id == orgProfile); + if (org == null) + return Error(GlobalMessages.OrganizationNotFound); + insigniaRequest = new InsigniaRequest + { + Period = insigniaPeriod, + Organization = org, + RequestStatus = "st1", + RequestNote = "", + CreatedUserId = FullName ?? "", + CreatedFullName = UserId ?? "System Administrator", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + }; + } + + await _context.AddAsync(new InsigniaRequestProfile + { + Status = "PENDING", + Profile = profile, + RequestInsignia = insignia, + Request = insigniaRequest, + RequestDate = DateTime.Now, + MatchingConditions = System.Text.Json.JsonSerializer.Serialize(new List()), // serialize to string + CreatedUserId = FullName ?? "", + CreatedFullName = UserId ?? "System Administrator", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + }); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// แก้ไขราชชื่อผู้ได้รับเครื่องราช + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("{insigniaRequestProfileId:length(36)}")] + public async Task> UpdateUserToRequestInsignia([FromBody] UpdateUserRequestInsigniaRequest req, Guid insigniaRequestProfileId) + { + var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Id == insigniaRequestProfileId); + if (insigniaRequestProfile == null) + return Error(GlobalMessages.InsigniaRequestProfileNotFound); + var insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Id == req.insigniaId); + if (insignia == null) + return Error(GlobalMessages.InsigniaNotFound); + + insigniaRequestProfile.RequestInsignia = insignia; + insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator"; + insigniaRequestProfile.LastUpdateUserId = UserId ?? ""; + insigniaRequestProfile.LastUpdatedAt = DateTime.Now; + await _context.SaveChangesAsync(); + return Success(); + } + } } diff --git a/BMA.EHR.Insignia.Service/Requests/AddUserRequestInsigniaRequest.cs b/BMA.EHR.Insignia.Service/Requests/AddUserRequestInsigniaRequest.cs new file mode 100644 index 00000000..df5c5772 --- /dev/null +++ b/BMA.EHR.Insignia.Service/Requests/AddUserRequestInsigniaRequest.cs @@ -0,0 +1,12 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Insignia.Service.Requests +{ + public class AddUserRequestInsigniaRequest + { + public Guid ProfileId { get; set; } + public Guid insigniaId { get; set; } + public Guid insigniaPeriodId { get; set; } + } +} \ No newline at end of file diff --git a/BMA.EHR.Insignia.Service/Requests/UpdateUserRequestInsigniaRequest.cs b/BMA.EHR.Insignia.Service/Requests/UpdateUserRequestInsigniaRequest.cs new file mode 100644 index 00000000..1b75a8ea --- /dev/null +++ b/BMA.EHR.Insignia.Service/Requests/UpdateUserRequestInsigniaRequest.cs @@ -0,0 +1,10 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Insignia.Service.Requests +{ + public class UpdateUserRequestInsigniaRequest + { + public Guid insigniaId { get; set; } + } +} \ No newline at end of file