fix : Optimize Query

This commit is contained in:
Suphonchai Phoonsawat 2024-07-07 09:59:37 +07:00
parent 89ef146c19
commit a911648907
9 changed files with 168 additions and 232 deletions

View file

@ -15,8 +15,10 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Newtonsoft.Json;
using OfficeOpenXml;
using RabbitMQ.Client;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
using System.Text;
namespace BMA.EHR.Insignia.Service.Controllers
{
@ -36,10 +38,10 @@ namespace BMA.EHR.Insignia.Service.Controllers
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly string Royal_Type = "Royal";
private readonly UserProfileRepository _userProfileRepository;
private readonly RabbitMQProducer _producer;
private const string INSIGNIA_QUEUE = "bma_insignia_request";
private readonly InsigniaPeriodsRepository _insigniaPeriodRepository;
private readonly IConfiguration _configuration;
/// <summary>
///
@ -61,7 +63,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
IHttpContextAccessor httpContextAccessor,
UserProfileRepository userProfileRepository,
InsigniaPeriodsRepository insigniaPeriodRepository,
RabbitMQProducer producer)
IConfiguration configuration)
{
_context = context;
_documentService = documentService;
@ -71,7 +73,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
_hostingEnvironment = hostingEnvironment;
_userProfileRepository = userProfileRepository;
_insigniaPeriodRepository = insigniaPeriodRepository;
_producer = producer;
_configuration = configuration;
}
#region " Properties "
@ -320,21 +322,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
// }
#endregion
#region " ทดสอบ RabbitMQ "
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet("rabbit")]
[AllowAnonymous]
public ActionResult<ResponseObject> CallRabbitMQ()
{
_producer.SendMessage("test send");
return Success();
}
#endregion
#region " จัดทำรายชื่อครูที่มีสิทธิในการยืนขอเครื่องราชฯ "
@ -603,9 +591,30 @@ namespace BMA.EHR.Insignia.Service.Controllers
[HttpGet("queue/{insigniaPeriodId:length(36)}")]
public ActionResult<ResponseObject> InsigniaRequestCalculate(Guid insigniaPeriodId)
{
_producer.CalculateInsignia(insigniaPeriodId);
return Success();
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
};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: INSIGNIA_QUEUE, durable: false, exclusive: false, autoDelete: false, arguments: null);
var body = Encoding.UTF8.GetBytes(insigniaPeriodId.ToString("D"));
channel.BasicPublish(exchange: "", routingKey: INSIGNIA_QUEUE, basicProperties: null, body: body);
return Success();
}
}
#endregion
#region " บันทึกหมายเหตุ "