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.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
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("reclaim/{year}/{insigniaTypeId:length(36)}")]
public async Task<ActionResult<ResponseObject>> ListReclaimInsignia(int year, Guid insigniaTypeId)
[HttpPost("reclaim-list")]
public async Task<ActionResult<ResponseObject>> ListReclaimInsignia([FromBody] GetReclaimListRequest req)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM");
var jsonData = JsonConvert.DeserializeObject<JObject>(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;
}

View file

@ -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);

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 Guid InsigniaTypeId { get; set; }
public Guid? InsigniaTypeId { get; set; }
public Guid InsigniaNoteId { get; set; }
public Guid? InsigniaId { get; set; }
}