fix ยืมคืนเครื่องราชย?มาใช้่ RootDnaId แทน rootId
This commit is contained in:
parent
65e85b7194
commit
14fd93ae95
9 changed files with 21340 additions and 22 deletions
|
|
@ -1126,6 +1126,29 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
}
|
||||
|
||||
public async Task PostInsigniaMessageToSocket(string message, string userId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var apiPath = $"{_configuration["API"]}/org/through-socket/notify";
|
||||
var apiKey = _configuration["API_KEY"];
|
||||
|
||||
var body = new
|
||||
{
|
||||
message = message,
|
||||
userId = userId
|
||||
};
|
||||
|
||||
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body, apiKey);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task PostProfileEmpInsigniaAsync(PostProfileEmpInsigniaDto body, string? accessToken)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -37,5 +37,11 @@ namespace BMA.EHR.Application.Responses.Organizations
|
|||
public string? Child4 { get; set; }
|
||||
|
||||
public string? Child4ShortName { get; set; }
|
||||
|
||||
public Guid? RootDnaId { get; set; }
|
||||
public Guid? Child1DnaId { get; set; }
|
||||
public Guid? Child2DnaId { get; set; }
|
||||
public Guid? Child3DnaId { get; set; }
|
||||
public Guid? Child4DnaId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,7 @@ namespace BMA.EHR.Domain.Models.Insignias
|
|||
[Comment("Fk Table InsigniaManage")]
|
||||
public InsigniaManage InsigniaManage { get; set; }
|
||||
public virtual List<InsigniaManageProfile> InsigniaManageProfiles { get; set; } = new List<InsigniaManageProfile>();
|
||||
|
||||
public Guid? RootDnaId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,9 @@ namespace BMA.EHR.Infrastructure.MessageQueue
|
|||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly InsigniaPeriodsRepository _insigniaPeriodsRepository;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private const string INSIGNIA_QUEUE = "bma_insignia_request";
|
||||
|
||||
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
private IConnection _connection;
|
||||
|
|
@ -30,33 +28,29 @@ namespace BMA.EHR.Infrastructure.MessageQueue
|
|||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public RabbitMQConsumer(UserProfileRepository userProfileRepository,
|
||||
InsigniaPeriodsRepository insigniaPeriodsRepository,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
public RabbitMQConsumer(IHttpContextAccessor httpContextAccessor,
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
_configuration = configuration;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
_insigniaPeriodsRepository = insigniaPeriodsRepository;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
|
||||
var host = _configuration["RabbitMQ:URL"];
|
||||
var userName = _configuration["RabbitMQ:UserName"];
|
||||
var password = _configuration["RabbitMQ:Password"];
|
||||
|
||||
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = host,
|
||||
UserName = userName,
|
||||
Password = password
|
||||
};
|
||||
|
||||
|
||||
_connection = factory.CreateConnection();
|
||||
_channel = _connection.CreateModel();
|
||||
_channel.QueueDeclare(queue: INSIGNIA_QUEUE, durable: false, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
|
@ -85,19 +79,19 @@ namespace BMA.EHR.Infrastructure.MessageQueue
|
|||
var userRepo = scope.ServiceProvider.GetRequiredService<UserProfileRepository>();
|
||||
var insigniaRepo = scope.ServiceProvider.GetRequiredService<InsigniaPeriodsRepository>();
|
||||
|
||||
var selectPeriod = await _insigniaPeriodsRepository.GetByIdAsync(periodId);
|
||||
var selectPeriod = await insigniaRepo.GetByIdAsync(periodId);
|
||||
if (selectPeriod == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
||||
}
|
||||
|
||||
|
||||
var organizations = await userRepo.GetActiveRootAsync(AccessToken, selectPeriod.RevisionId);
|
||||
|
||||
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
if (organization == null)
|
||||
continue;
|
||||
|
||||
|
||||
var result = await insigniaRepo.GetInsigniaRequest(periodId, organization.Id);
|
||||
if (result != null)
|
||||
{
|
||||
|
|
|
|||
21246
BMA.EHR.Infrastructure/Migrations/20251121023046_Add rootdna to InsigniaMagOrg Table.Designer.cs
generated
Normal file
21246
BMA.EHR.Infrastructure/Migrations/20251121023046_Add rootdna to InsigniaMagOrg Table.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddrootdnatoInsigniaMagOrgTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "RootDnaId",
|
||||
table: "InsigniaManageOrganiations",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RootDnaId",
|
||||
table: "InsigniaManageOrganiations");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5832,6 +5832,9 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
.HasColumnType("char(36)")
|
||||
.HasComment("รหัสหน่วยงาน");
|
||||
|
||||
b.Property<Guid?>("RootDnaId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<int>("Total")
|
||||
.HasColumnType("int")
|
||||
.HasComment("จำนวนทั้งหมด");
|
||||
|
|
|
|||
|
|
@ -330,7 +330,10 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
var total = insigniaManage.InsigniaManageOrganiations.Where(x => x.OrganizationId != req.OrganizationOrganizationId).Sum(x => x.Total);
|
||||
if (req.Total + total > insigniaManage.Total)
|
||||
return Error(GlobalMessages.InsigniaManageOrgLimit);
|
||||
var root = _userProfileRepository.GetOc(req.OrganizationOrganizationId, 0, AccessToken)?.Root ?? null;
|
||||
|
||||
var ocData = _userProfileRepository.GetOc(req.OrganizationOrganizationId, 0, AccessToken);
|
||||
var root = ocData?.Root ?? null;
|
||||
var rootDnaId = ocData?.RootDnaId ?? null;
|
||||
await _context.InsigniaManageOrganiations.AddAsync(
|
||||
new InsigniaManageOrganiation
|
||||
{
|
||||
|
|
@ -344,6 +347,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
RootDnaId = rootDnaId
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
|
@ -791,7 +795,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
|
||||
var insigniaManageOrganiation = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.Include(x => x.InsigniaManageProfiles)
|
||||
.FirstOrDefaultAsync(x => x.OrganizationId == insigniaNoteProfile.RootId && x.InsigniaManage.Id == insigniaManage.Id); // แก้เป็นหาจากหน่วยงานยืมเพิม manage id
|
||||
.FirstOrDefaultAsync(x => x.RootDnaId == insigniaNoteProfile.RootDnaId && x.InsigniaManage.Id == insigniaManage.Id); // แก้เป็นหาจากหน่วยงานยืมเพิม manage id
|
||||
if (insigniaManageOrganiation == null)
|
||||
return Error(GlobalMessages.InsigniaManageOrgNotFound);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Insignia.Service.Configuration;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Insignia.Service.Configuration;
|
||||
using SocketIOClient;
|
||||
using System.Security.Claims;
|
||||
|
||||
|
|
@ -9,16 +10,17 @@ public class InsigniaRequestProcessService : BackgroundService
|
|||
{
|
||||
private readonly IBackgroundTaskQueue _queue;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
|
||||
|
||||
public InsigniaRequestProcessService(
|
||||
IBackgroundTaskQueue queue,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
_queue = queue;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
|
@ -73,6 +75,14 @@ public class InsigniaRequestProcessService : BackgroundService
|
|||
var endTime = DateTime.Now;
|
||||
var duration = endTime - startTime;
|
||||
|
||||
// Resolve repository from a scope because DbContext is scoped/transient.
|
||||
using var scope = _serviceScopeFactory.CreateScope();
|
||||
var userProfileRepository = (UserProfileRepository)scope.ServiceProvider.GetService(typeof(UserProfileRepository));
|
||||
if (userProfileRepository != null)
|
||||
{
|
||||
await userProfileRepository.PostInsigniaMessageToSocket("Task completed", UserId ?? "", AccessToken);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue