change insigniaTypeId เป็น optional
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Suphonchai Phoonsawat 2025-05-07 14:05:08 +07:00
parent 8ce58201e9
commit 0b407f3c68
4 changed files with 116 additions and 78 deletions

View file

@ -4,8 +4,10 @@ using BMA.EHR.Application.Requests;
using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Models.Insignias;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Insignia.Service.Requests;
using Elasticsearch.Net; using Elasticsearch.Net;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -583,8 +585,8 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response> /// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("reclaim/{year}/{insigniaTypeId:length(36)}")] [HttpPost("reclaim-list")]
public async Task<ActionResult<ResponseObject>> ListReclaimInsignia(int year, Guid insigniaTypeId) public async Task<ActionResult<ResponseObject>> ListReclaimInsignia([FromBody] GetReclaimListRequest req)
{ {
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM"); var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission); var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
@ -592,10 +594,16 @@ namespace BMA.EHR.Insignia.Service.Controllers
{ {
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
} }
var insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId); InsigniaType? insigniaType = null;
if (insigniaType == null) if (req.InsigniaTypeId != null)
return Error(GlobalMessages.InsigniaTypeNotFound); {
insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
if (insigniaType == null)
return Error(GlobalMessages.InsigniaTypeNotFound);
}
string role = jsonData["result"]; string role = jsonData["result"];
var nodeId = string.Empty; var nodeId = string.Empty;
@ -623,8 +631,11 @@ namespace BMA.EHR.Insignia.Service.Controllers
var node = profileAdmin?.Node; var node = profileAdmin?.Node;
var rawData = await _context.InsigniaReclaimProfiles.AsQueryable() var rawData = await _context.InsigniaReclaimProfiles.AsQueryable()
.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) .Include(x => x.InsigniaNoteProfile)
.Where(x => year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == year) .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) .OrderByDescending(x => x.CreatedAt)
.Select(p => new .Select(p => new
{ {
@ -668,9 +679,15 @@ namespace BMA.EHR.Insignia.Service.Controllers
Child3DnaId = p.InsigniaNoteProfile.Child3DnaId, Child3DnaId = p.InsigniaNoteProfile.Child3DnaId,
Child4DnaId = p.InsigniaNoteProfile.Child4DnaId, Child4DnaId = p.InsigniaNoteProfile.Child4DnaId,
InsigniaTypeId = p.InsigniaNoteProfile.RequestInsignia.InsigniaType.Id
}).ToListAsync(); }).ToListAsync();
if (req.InsigniaTypeId != null)
{
rawData = rawData.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList();
}
if (role == "OWNER") if (role == "OWNER")
{ {
@ -946,7 +963,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
}) })
.ToListAsync(); .ToListAsync();
if(role == "OWNER") if (role == "OWNER")
{ {
node = null; node = null;
} }

View file

@ -7,6 +7,7 @@ using BMA.EHR.Application.Responses.Organizations;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Models.Insignias;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Insignia.Service.Requests; using BMA.EHR.Insignia.Service.Requests;
@ -1417,17 +1418,23 @@ namespace BMA.EHR.Insignia.Service.Controllers
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId); .FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId);
if (insigniaNote == null) if (insigniaNote == null)
return Error(GlobalMessages.InsigniaRequestNotFound); return Error(GlobalMessages.InsigniaRequestNotFound);
var insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); InsigniaType? insigniaType = null;
if (insigniaType == null) if (req.InsigniaTypeId != null)
return Error(GlobalMessages.InsigniaTypeNotFound); {
insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
if (insigniaType == null)
return Error(GlobalMessages.InsigniaTypeNotFound);
}
var rawNoteProfiles = await _context.InsigniaNoteProfiles var rawNoteProfiles = await _context.InsigniaNoteProfiles
.Where(x => x.InsigniaNote == insigniaNote) .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)) .Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId))
.Select(x => new .Select(x => new
{ {
InsigniaTypeId = x.RequestInsignia.InsigniaType.Id,
Id = x.Id, Id = x.Id,
x.CitizenId, x.CitizenId,
x.Prefix, x.Prefix,
@ -1465,6 +1472,11 @@ namespace BMA.EHR.Insignia.Service.Controllers
}) })
.ToListAsync(); .ToListAsync();
if (req.InsigniaTypeId != null)
{
rawNoteProfiles = rawNoteProfiles.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList();
}
var insigniaNoteProfiles = rawNoteProfiles var insigniaNoteProfiles = rawNoteProfiles
.Select(x => new .Select(x => new
{ {
@ -1659,68 +1671,68 @@ namespace BMA.EHR.Insignia.Service.Controllers
if (profileInsignia == null) if (profileInsignia == null)
{ {
var insigniaNoteProfile = new InsigniaNoteProfile var insigniaNoteProfile = new InsigniaNoteProfile
{ {
Salary = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, Salary = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount,
IsApprove = true, IsApprove = true,
Status = "PENDING", Status = "PENDING",
ProfileId = profile.Id, ProfileId = profile.Id,
Issue = req.Issue, Issue = req.Issue,
Number = req.Number, Number = req.Number,
DateReceive = req.DateReceive, DateReceive = req.DateReceive,
Date = req.Date, Date = req.Date,
VolumeNo = req.VolumeNo, VolumeNo = req.VolumeNo,
Section = req.Section, Section = req.Section,
Page = req.Page, Page = req.Page,
No = req.No, No = req.No,
DatePayment = req.DatePayment, DatePayment = req.DatePayment,
TypePayment = req.TypePayment, TypePayment = req.TypePayment,
Address = req.Address, Address = req.Address,
RequestInsignia = insignia, RequestInsignia = insignia,
OrganizationOrganizationReceive = req.OrganizationOrganizationReceive, OrganizationOrganizationReceive = req.OrganizationOrganizationReceive,
OrganizationOrganizationSend = req.OrganizationOrganizationSend, OrganizationOrganizationSend = req.OrganizationOrganizationSend,
InsigniaNote = insigniaNote, InsigniaNote = insigniaNote,
CreatedFullName = FullName ?? "System Administrator", CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "", CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now, CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator", LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "", LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount,
CitizenId = profile.CitizenId, CitizenId = profile.CitizenId,
DateAppoint = profile.DateAppoint, DateAppoint = profile.DateAppoint,
Prefix = profile.Prefix, Prefix = profile.Prefix,
FirstName = profile.FirstName, FirstName = profile.FirstName,
LastName = profile.LastName, LastName = profile.LastName,
Gender = profile.Gender, Gender = profile.Gender,
PosLevelName = profile.PosLevel, PosLevelName = profile.PosLevel,
PosNo = profile.PosNo, PosNo = profile.PosNo,
PosTypeName = profile.PosType, PosTypeName = profile.PosType,
Position = profile.Position, Position = profile.Position,
ProfileType = profile.ProfileType, ProfileType = profile.ProfileType,
PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount, PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount,
Root = profile.Root, Root = profile.Root,
RootId = profile.RootId, RootId = profile.RootId,
RootDnaId = profile.RootDnaId, RootDnaId = profile.RootDnaId,
Child1 = profile.Child1, Child1 = profile.Child1,
Child1Id = profile.Child1Id, Child1Id = profile.Child1Id,
Child1DnaId = profile.Child1DnaId, Child1DnaId = profile.Child1DnaId,
Child2 = profile.Child2, Child2 = profile.Child2,
Child2Id = profile.Child2Id, Child2Id = profile.Child2Id,
Child2DnaId = profile.Child2DnaId, Child2DnaId = profile.Child2DnaId,
Child3 = profile.Child3, Child3 = profile.Child3,
Child3Id = profile.Child3Id, Child3Id = profile.Child3Id,
Child3DnaId = profile.Child3DnaId, Child3DnaId = profile.Child3DnaId,
Child4 = profile.Child4, Child4 = profile.Child4,
Child4Id = profile.Child4Id, Child4Id = profile.Child4Id,
Child4DnaId = profile.Child4DnaId, Child4DnaId = profile.Child4DnaId,
}; };
insigniaNote.InsigniaNoteProfiles.Add(insigniaNoteProfile); insigniaNote.InsigniaNoteProfiles.Add(insigniaNoteProfile);

View file

@ -0,0 +1,9 @@
namespace BMA.EHR.Insignia.Service.Requests
{
public class GetReclaimListRequest
{
public int Year { get; set; } = 0;
public Guid? InsigniaTypeId { get; set; }
}
}

View file

@ -5,7 +5,7 @@ namespace BMA.EHR.Insignia.Service.Requests
{ {
public class InsigniaNoteSearchRequest public class InsigniaNoteSearchRequest
{ {
public Guid InsigniaTypeId { get; set; } public Guid? InsigniaTypeId { get; set; }
public Guid InsigniaNoteId { get; set; } public Guid InsigniaNoteId { get; set; }
public Guid? InsigniaId { get; set; } public Guid? InsigniaId { get; set; }
} }