From 8ce58201e9cc2ea4f4102e974e59fed721fcf37f Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 7 May 2025 12:55:30 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=95?= =?UTF-8?q?=E0=B8=B2=E0=B8=A1=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4?= =?UTF-8?q?=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/InsigniaManageController.cs | 111 +++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs b/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs index 5c01d053..f02b9025 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaManageController.cs @@ -1,10 +1,12 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; 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.Shared; using BMA.EHR.Infrastructure.Persistence; +using Elasticsearch.Net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -595,6 +597,30 @@ namespace BMA.EHR.Insignia.Service.Controllers if (insigniaType == null) return Error(GlobalMessages.InsigniaTypeNotFound); + string role = jsonData["result"]; + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + + var node = profileAdmin?.Node; var rawData = await _context.InsigniaReclaimProfiles.AsQueryable() .Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) @@ -635,8 +661,36 @@ namespace BMA.EHR.Insignia.Service.Controllers p.InsigniaNoteProfile.Address, p.InsigniaNoteProfile.Number, p.InsigniaNoteProfile.Salary, - }) - .ToListAsync(); + + RootDnaId = p.InsigniaNoteProfile.RootDnaId, + Child1DnaId = p.InsigniaNoteProfile.Child1DnaId, + Child2DnaId = p.InsigniaNoteProfile.Child2DnaId, + Child3DnaId = p.InsigniaNoteProfile.Child3DnaId, + Child4DnaId = p.InsigniaNoteProfile.Child4DnaId, + + + }).ToListAsync(); + + + if (role == "OWNER") + { + node = null; + } + if (role == "OWNER" || role == "CHILD") + { + rawData = rawData + .Where(x => node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true)))))).ToList(); + } + else if (role == "ROOT") + { + rawData = rawData + .Where(x => x.RootDnaId == Guid.Parse(nodeId!)).ToList(); + } + else if (role == "NORMAL") + { + rawData = rawData + .Where(x => node == 0 ? x.Child1DnaId == null : (node == 1 ? x.Child2DnaId == null : (node == 2 ? x.Child3DnaId == null : (node == 3 ? x.Child4DnaId == null : true)))).ToList(); + } var data = rawData .Select(p => new @@ -810,6 +864,31 @@ namespace BMA.EHR.Insignia.Service.Controllers if (insigniaType == null) return Error(GlobalMessages.InsigniaTypeNotFound); + string role = jsonData["result"]; + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + + var node = profileAdmin?.Node; + var rawData = await _context.InsigniaManageProfiles.AsQueryable() .Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) @@ -856,9 +935,37 @@ namespace BMA.EHR.Insignia.Service.Controllers p.InsigniaNoteProfile.Address, p.InsigniaNoteProfile.Number, p.InsigniaNoteProfile.Salary, + + + RootDnaId = p.InsigniaNoteProfile.RootDnaId, + Child1DnaId = p.InsigniaNoteProfile.Child1DnaId, + Child2DnaId = p.InsigniaNoteProfile.Child2DnaId, + Child3DnaId = p.InsigniaNoteProfile.Child3DnaId, + Child4DnaId = p.InsigniaNoteProfile.Child4DnaId, + }) .ToListAsync(); + if(role == "OWNER") + { + node = null; + } + if (role == "OWNER" || role == "CHILD") + { + rawData = rawData + .Where(x => node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true)))))).ToList(); + } + else if (role == "ROOT") + { + rawData = rawData + .Where(x => x.RootDnaId == Guid.Parse(nodeId!)).ToList(); + } + else if (role == "NORMAL") + { + rawData = rawData + .Where(x => node == 0 ? x.Child1DnaId == null : (node == 1 ? x.Child2DnaId == null : (node == 2 ? x.Child3DnaId == null : (node == 3 ? x.Child4DnaId == null : true)))).ToList(); + } + var data = rawData .Select(p => new {