From 0b407f3c68940b253beb74d6df6ca925adf6de55 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 7 May 2025 14:05:08 +0700 Subject: [PATCH] =?UTF-8?q?change=20insigniaTypeId=20=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B9=87=E0=B8=99=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/InsigniaManageController.cs | 37 +++-- .../Controllers/InsigniaRequestController.cs | 146 ++++++++++-------- .../Requests/GetReclaimListRequest.cs | 9 ++ .../Requests/InsigniaNoteSearchRequest.cs | 2 +- 4 files changed, 116 insertions(+), 78 deletions(-) create mode 100644 BMA.EHR.Insignia/Requests/GetReclaimListRequest.cs diff --git a/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs b/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs index f02b9025..0e8e94e2 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs @@ -4,8 +4,10 @@ using BMA.EHR.Application.Requests; using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Models.Insignias; +using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; +using BMA.EHR.Insignia.Service.Requests; using Elasticsearch.Net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -583,8 +585,8 @@ namespace BMA.EHR.Insignia.Service.Controllers /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("reclaim/{year}/{insigniaTypeId:length(36)}")] - public async Task> ListReclaimInsignia(int year, Guid insigniaTypeId) + [HttpPost("reclaim-list")] + public async Task> ListReclaimInsignia([FromBody] GetReclaimListRequest req) { var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM"); var jsonData = JsonConvert.DeserializeObject(getPermission); @@ -592,10 +594,16 @@ namespace BMA.EHR.Insignia.Service.Controllers { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } - var insigniaType = await _context.InsigniaTypes - .FirstOrDefaultAsync(x => x.Id == insigniaTypeId); - if (insigniaType == null) - return Error(GlobalMessages.InsigniaTypeNotFound); + + InsigniaType? insigniaType = null; + if (req.InsigniaTypeId != null) + { + insigniaType = await _context.InsigniaTypes + .FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); + if (insigniaType == null) + return Error(GlobalMessages.InsigniaTypeNotFound); + } + string role = jsonData["result"]; var nodeId = string.Empty; @@ -623,8 +631,11 @@ namespace BMA.EHR.Insignia.Service.Controllers var node = profileAdmin?.Node; var rawData = await _context.InsigniaReclaimProfiles.AsQueryable() - .Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) - .Where(x => year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == year) + .Include(x => x.InsigniaNoteProfile) + .ThenInclude(x => x.RequestInsignia) + .ThenInclude(x => x.InsigniaType) + //.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) + .Where(x => req.Year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == req.Year) .OrderByDescending(x => x.CreatedAt) .Select(p => new { @@ -668,9 +679,15 @@ namespace BMA.EHR.Insignia.Service.Controllers Child3DnaId = p.InsigniaNoteProfile.Child3DnaId, Child4DnaId = p.InsigniaNoteProfile.Child4DnaId, + InsigniaTypeId = p.InsigniaNoteProfile.RequestInsignia.InsigniaType.Id }).ToListAsync(); - + + if (req.InsigniaTypeId != null) + { + rawData = rawData.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList(); + } + if (role == "OWNER") { @@ -946,7 +963,7 @@ namespace BMA.EHR.Insignia.Service.Controllers }) .ToListAsync(); - if(role == "OWNER") + if (role == "OWNER") { node = null; } diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index 1e91d64a..68b72eff 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -7,6 +7,7 @@ using BMA.EHR.Application.Responses.Organizations; 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.Shared; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Insignia.Service.Requests; @@ -1079,8 +1080,8 @@ namespace BMA.EHR.Insignia.Service.Controllers pf = _userProfileRepository.GetEmployeeProfileById(profileOld.ProfileId, AccessToken); var orgSend = ""; - var orgRecv = ""; - + var orgRecv = ""; + if (profileOld.Child4 != null || profileOld.Child4 != "") orgSend += $"{profileOld.Child4}"; if (profileOld.Child3 != null || profileOld.Child3 != "") @@ -1099,7 +1100,7 @@ namespace BMA.EHR.Insignia.Service.Controllers var kk = pf.Keycloak == null ? Guid.Empty : pf.Keycloak.Value; var pfData = await _userProfileRepository.GetProfileByKeycloakIdAsync(kk, AccessToken); if (pfData != null) - { + { if (pfData.Child4 != null || pfData.Child4 != "") orgRecv += $"{pfData.Child4}"; if (pfData.Child3 != null || pfData.Child3 != "") @@ -1113,7 +1114,7 @@ namespace BMA.EHR.Insignia.Service.Controllers orgRecv = orgRecv.Trim(); - } + } } @@ -1126,10 +1127,10 @@ namespace BMA.EHR.Insignia.Service.Controllers ProfileId = profileOld.ProfileId, RequestInsignia = profileOld.RequestInsignia, - + OrganizationOrganizationSend = orgSend, OrganizationOrganizationReceive = orgRecv, - + InsigniaNote = insigniaNote, CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", @@ -1417,17 +1418,23 @@ namespace BMA.EHR.Insignia.Service.Controllers .FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId); if (insigniaNote == null) return Error(GlobalMessages.InsigniaRequestNotFound); - var insigniaType = await _context.InsigniaTypes - .FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); - if (insigniaType == null) - return Error(GlobalMessages.InsigniaTypeNotFound); + + InsigniaType? insigniaType = null; + if (req.InsigniaTypeId != null) + { + insigniaType = await _context.InsigniaTypes + .FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); + if (insigniaType == null) + return Error(GlobalMessages.InsigniaTypeNotFound); + } var rawNoteProfiles = await _context.InsigniaNoteProfiles .Where(x => x.InsigniaNote == insigniaNote) - .Where(x => x.RequestInsignia.InsigniaType == insigniaType) + //.Where(x => x.RequestInsignia.InsigniaType == insigniaType) .Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId)) .Select(x => new { + InsigniaTypeId = x.RequestInsignia.InsigniaType.Id, Id = x.Id, x.CitizenId, x.Prefix, @@ -1465,6 +1472,11 @@ namespace BMA.EHR.Insignia.Service.Controllers }) .ToListAsync(); + if (req.InsigniaTypeId != null) + { + rawNoteProfiles = rawNoteProfiles.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList(); + } + var insigniaNoteProfiles = rawNoteProfiles .Select(x => new { @@ -1659,68 +1671,68 @@ namespace BMA.EHR.Insignia.Service.Controllers if (profileInsignia == null) { - var insigniaNoteProfile = new InsigniaNoteProfile - { - Salary = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, - IsApprove = true, - Status = "PENDING", - ProfileId = profile.Id, - Issue = req.Issue, - Number = req.Number, - DateReceive = req.DateReceive, - Date = req.Date, - VolumeNo = req.VolumeNo, - Section = req.Section, - Page = req.Page, - No = req.No, - DatePayment = req.DatePayment, - TypePayment = req.TypePayment, - Address = req.Address, - RequestInsignia = insignia, - OrganizationOrganizationReceive = req.OrganizationOrganizationReceive, - OrganizationOrganizationSend = req.OrganizationOrganizationSend, - InsigniaNote = insigniaNote, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - CreatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, + var insigniaNoteProfile = new InsigniaNoteProfile + { + Salary = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, + IsApprove = true, + Status = "PENDING", + ProfileId = profile.Id, + Issue = req.Issue, + Number = req.Number, + DateReceive = req.DateReceive, + Date = req.Date, + VolumeNo = req.VolumeNo, + Section = req.Section, + Page = req.Page, + No = req.No, + DatePayment = req.DatePayment, + TypePayment = req.TypePayment, + Address = req.Address, + RequestInsignia = insignia, + OrganizationOrganizationReceive = req.OrganizationOrganizationReceive, + OrganizationOrganizationSend = req.OrganizationOrganizationSend, + InsigniaNote = insigniaNote, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, - Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, - CitizenId = profile.CitizenId, - DateAppoint = profile.DateAppoint, - Prefix = profile.Prefix, - FirstName = profile.FirstName, - LastName = profile.LastName, - Gender = profile.Gender, - PosLevelName = profile.PosLevel, - PosNo = profile.PosNo, - PosTypeName = profile.PosType, - Position = profile.Position, - ProfileType = profile.ProfileType, - PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount, + Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, + CitizenId = profile.CitizenId, + DateAppoint = profile.DateAppoint, + Prefix = profile.Prefix, + FirstName = profile.FirstName, + LastName = profile.LastName, + Gender = profile.Gender, + PosLevelName = profile.PosLevel, + PosNo = profile.PosNo, + PosTypeName = profile.PosType, + Position = profile.Position, + ProfileType = profile.ProfileType, + PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount, - Root = profile.Root, - RootId = profile.RootId, - RootDnaId = profile.RootDnaId, - Child1 = profile.Child1, - Child1Id = profile.Child1Id, - Child1DnaId = profile.Child1DnaId, - Child2 = profile.Child2, - Child2Id = profile.Child2Id, - Child2DnaId = profile.Child2DnaId, - Child3 = profile.Child3, - Child3Id = profile.Child3Id, - Child3DnaId = profile.Child3DnaId, - Child4 = profile.Child4, - Child4Id = profile.Child4Id, - Child4DnaId = profile.Child4DnaId, + Root = profile.Root, + RootId = profile.RootId, + RootDnaId = profile.RootDnaId, + Child1 = profile.Child1, + Child1Id = profile.Child1Id, + Child1DnaId = profile.Child1DnaId, + Child2 = profile.Child2, + Child2Id = profile.Child2Id, + Child2DnaId = profile.Child2DnaId, + Child3 = profile.Child3, + Child3Id = profile.Child3Id, + Child3DnaId = profile.Child3DnaId, + Child4 = profile.Child4, + Child4Id = profile.Child4Id, + Child4DnaId = profile.Child4DnaId, - }; + }; insigniaNote.InsigniaNoteProfiles.Add(insigniaNoteProfile); diff --git a/BMA.EHR.Insignia/Requests/GetReclaimListRequest.cs b/BMA.EHR.Insignia/Requests/GetReclaimListRequest.cs new file mode 100644 index 00000000..0ff8e6e6 --- /dev/null +++ b/BMA.EHR.Insignia/Requests/GetReclaimListRequest.cs @@ -0,0 +1,9 @@ +namespace BMA.EHR.Insignia.Service.Requests +{ + public class GetReclaimListRequest + { + public int Year { get; set; } = 0; + + public Guid? InsigniaTypeId { get; set; } + } +} diff --git a/BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs b/BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs index fca5c598..f457a70d 100644 --- a/BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs +++ b/BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs @@ -5,7 +5,7 @@ namespace BMA.EHR.Insignia.Service.Requests { public class InsigniaNoteSearchRequest { - public Guid InsigniaTypeId { get; set; } + public Guid? InsigniaTypeId { get; set; } public Guid InsigniaNoteId { get; set; } public Guid? InsigniaId { get; set; } }