diff --git a/.vs/BMA.EHR.Recruit.Service/DesignTimeBuild/.dtbcache.v2 b/.vs/BMA.EHR.Recruit.Service/DesignTimeBuild/.dtbcache.v2
index b41ecde..6f3db9a 100644
Binary files a/.vs/BMA.EHR.Recruit.Service/DesignTimeBuild/.dtbcache.v2 and b/.vs/BMA.EHR.Recruit.Service/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/.vs/BMA.EHR.Recruit.Service/v17/.futdcache.v2 b/.vs/BMA.EHR.Recruit.Service/v17/.futdcache.v2
index 4d5081f..b49956c 100644
Binary files a/.vs/BMA.EHR.Recruit.Service/v17/.futdcache.v2 and b/.vs/BMA.EHR.Recruit.Service/v17/.futdcache.v2 differ
diff --git a/.vs/BMA.EHR.Recruit.Service/v17/.suo b/.vs/BMA.EHR.Recruit.Service/v17/.suo
index 28be4b1..40c0a48 100644
Binary files a/.vs/BMA.EHR.Recruit.Service/v17/.suo and b/.vs/BMA.EHR.Recruit.Service/v17/.suo differ
diff --git a/BMA.EHR.Recruit.Service.csproj b/BMA.EHR.Recruit.Service.csproj
index cde6d16..d2ebf6a 100644
--- a/BMA.EHR.Recruit.Service.csproj
+++ b/BMA.EHR.Recruit.Service.csproj
@@ -38,6 +38,7 @@
+
diff --git a/BMA.EHR.Recruit.Service.csproj.user b/BMA.EHR.Recruit.Service.csproj.user
index c404400..96e63d6 100644
--- a/BMA.EHR.Recruit.Service.csproj.user
+++ b/BMA.EHR.Recruit.Service.csproj.user
@@ -1,9 +1,9 @@
-
-
-
- https
-
-
- ProjectDebugger
-
+
+
+
+ https
+
+
+ ProjectDebugger
+
\ No newline at end of file
diff --git a/Controllers/RecruitController.cs b/Controllers/RecruitController.cs
index ed6b974..552d140 100644
--- a/Controllers/RecruitController.cs
+++ b/Controllers/RecruitController.cs
@@ -1,9 +1,6 @@
using Amazon.S3.Model;
using BMA.EHR.MetaData.Service.Models;
using BMA.EHR.Profile.Service.Models.HR;
-
-
-//using BMA.EHR.Extensions;
using BMA.EHR.Recruit.Service.Core;
using BMA.EHR.Recruit.Service.Data;
using BMA.EHR.Recruit.Service.Extensions;
@@ -25,6 +22,7 @@ using Sentry;
using Swashbuckle.AspNetCore.Annotations;
using System.Data;
using System.Net;
+using System.Net.Http.Headers;
using System.Net.WebSockets;
using System.Security.Claims;
using System.Text;
@@ -50,6 +48,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
private readonly PermissionRepository _permission;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger _logger;
+ private readonly IConfiguration _configuration;
//private readonly DateTimeExtension;
#endregion
@@ -63,6 +62,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
RecruitService recruitService,
IHttpContextAccessor httpContextAccessor,
ILogger logger,
+ IConfiguration configuration,
PermissionRepository permission
//DateTimeExtension extensions
)
@@ -73,6 +73,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
_webHostEnvironment = webHostEnvironment;
_recruitService = recruitService;
_httpContextAccessor = httpContextAccessor;
+ _configuration = configuration;
_logger = logger;
_permission = permission;
//_extensions = extensions;
@@ -85,6 +86,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
+ private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
#endregion
@@ -721,7 +723,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
{
// loop from sheet2 to end
- for (int i = 1; i < c_package.Workbook.Worksheets.Count; i++)
+ for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
{
var workSheet = c_package.Workbook.Worksheets[i];
var totalRows = workSheet.Dimension.Rows;
@@ -774,7 +776,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
Road1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Road1)]?.GetValue() ?? "",
District1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.District1)]?.GetValue() ?? "",
Amphur1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Amphur1)]?.GetValue() ?? "",
- Province1 = "",
+ Province1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Province1)]?.GetValue() ?? "",
ZipCode1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ZipCode1)]?.GetValue() ?? "",
});
@@ -1055,7 +1057,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
{
// loop from sheet2 to end
- for (int i = 1; i < c_package.Workbook.Worksheets.Count; i++)
+ for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
{
var workSheet = c_package.Workbook.Worksheets[i];
var totalRows = workSheet.Dimension.Rows;
@@ -1107,7 +1109,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
Road1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Road1)]?.GetValue() ?? "",
District1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.District1)]?.GetValue() ?? "",
Amphur1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Amphur1)]?.GetValue() ?? "",
- Province1 = "",
+ Province1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Province1)]?.GetValue() ?? "",
ZipCode1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ZipCode1)]?.GetValue() ?? "",
});
@@ -1242,6 +1244,9 @@ namespace BMA.EHR.Recruit.Service.Controllers
var file = Request.Form.Files[0];
var doc = await _minioService.UploadFileAsync(file);
import_doc_id = doc.Id.ToString("D");
+
+ Console.WriteLine($"file id = {import_doc_id}");
+
var fileContent = (await _minioService.DownloadFileAsync(doc.Id)).FileContent;
// create import history
@@ -1267,7 +1272,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
using (var c_package = new ExcelPackage(new FileInfo(importFile)))
{
// loop from sheet2 to end
- for (int i = 1; i < c_package.Workbook.Worksheets.Count; i++)
+ for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
{
var workSheet = c_package.Workbook.Worksheets[i];
var totalRows = workSheet.Dimension.Rows;
@@ -1284,20 +1289,20 @@ namespace BMA.EHR.Recruit.Service.Controllers
r.ExamId = workSheet?.Cells[row, 2]?.GetValue();
r.FullA = (int)workSheet?.Cells[7, 7]?.GetValue().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
- r.SumA = workSheet?.Cells[row, 7]?.GetValue() == "ขส." ? 0 : (int)workSheet?.Cells[row, 7]?.GetValue().Replace(".00", "").ToInteger();
+ r.SumA = workSheet?.Cells[row, 7]?.GetValue() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 7]?.GetValue();
r.PercentageA = workSheet?.Cells[row, 8]?.GetValue() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 8]?.GetValue();
r.AStatus = workSheet?.Cells[row, 9]?.GetValue();
r.FullB = (int)workSheet?.Cells[7, 12]?.GetValue().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
- r.SumB = workSheet?.Cells[row, 12]?.GetValue() == "ขส." ? 0 : (int)workSheet?.Cells[row, 12]?.GetValue().Replace(".00", "").ToInteger();
+ r.SumB = workSheet?.Cells[row, 12]?.GetValue() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 12]?.GetValue();
r.PercentageB = workSheet?.Cells[row, 13]?.GetValue() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 13]?.GetValue();
r.BStatus = workSheet?.Cells[row, 14]?.GetValue();
- r.SumAB = workSheet?.Cells[row, 15]?.GetValue() == "ขส." ? 0 : (int)workSheet?.Cells[row, 15]?.GetValue().Replace(".00", "").ToInteger();
+ r.SumAB = workSheet?.Cells[row, 15]?.GetValue() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 15]?.GetValue();
r.ABStatus = workSheet?.Cells[row, 17]?.GetValue();
r.FullC = (int)workSheet?.Cells[7, 20]?.GetValue().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
- r.SumC = workSheet?.Cells[row, 20]?.GetValue() == "ขส." ? 0 : (int)workSheet?.Cells[row, 20]?.GetValue().Replace(".00", "").ToInteger();
+ r.SumC = workSheet?.Cells[row, 20]?.GetValue() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 20]?.GetValue();
r.PercentageC = workSheet?.Cells[row, 21]?.GetValue() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 21]?.GetValue();
r.CStatus = workSheet?.Cells[row, 22]?.GetValue();
@@ -1308,6 +1313,28 @@ namespace BMA.EHR.Recruit.Service.Controllers
imported.Scores.Add(r);
row++;
+ var recruit = await _context.Recruits.AsQueryable()
+ .Include(x => x.RecruitImport)
+ .Where(x => x.RecruitImport == rec_import && x.ExamId == r.ExamId)
+ .FirstOrDefaultAsync();
+ if (recruit != null)
+ {
+ var apiUrl = $"{_configuration["API"]}/org/find/head/officer";
+ using (var client = new HttpClient())
+ {
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
+ client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
+ var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
+ var _res = await client.SendAsync(_req);
+ var _result = await _res.Content.ReadAsStringAsync();
+ if (_res.IsSuccessStatusCode)
+ {
+ var org = JsonConvert.DeserializeObject(_result);
+ recruit.AuthName = org.result.name == null ? "" : org.result.name;
+ recruit.AuthPosition = org.result.position == null ? "" : org.result.position;
+ }
+ }
+ }
}
}
}
@@ -1321,7 +1348,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
}
catch (Exception ex)
{
- await _minioService.DeleteFileAsync(Guid.Parse(import_doc_id));
+ //await _minioService.DeleteFileAsync(Guid.Parse(import_doc_id));
return Error(ex);
}
finally
@@ -1547,7 +1574,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
ExamName = p.RecruitImport!.Name,
ExamOrder = p.RecruitImport.Order,
ExamYear = p.RecruitImport.Year.ToThaiYear(),
- Score = sr == null ? 0 : sr.SumA + sr.SumB + sr.SumC,
+ Score = sr == null ? 0.0 : sr.SumA + sr.SumB + sr.SumC,
Number = sr == null ? "" : sr.Number,
ExamCount = _recruitService.GetExamCount(p.CitizenId),
ScoreExpire = p.RecruitImport.AnnouncementDate == null ? "" : p.RecruitImport.AnnouncementDate.Value.AddYears(2).ToThaiShortDate(),
diff --git a/Core/DateTimeFixConverter.cs b/Core/DateTimeFixConverter.cs
new file mode 100644
index 0000000..60c8af6
--- /dev/null
+++ b/Core/DateTimeFixConverter.cs
@@ -0,0 +1,25 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace BMA.EHR.Recruit.Service.Core
+{
+ public class DateTimeFixConverter : JsonConverter
+ {
+ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ if (reader.TokenType == JsonTokenType.String)
+ {
+ if (DateTime.TryParse(reader.GetString(), out var date))
+ {
+ return date;
+ }
+ }
+ throw new JsonException("Invalid date format.");
+ }
+
+ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToString("yyyy-MM-dd"));
+ }
+ }
+}
diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs
new file mode 100644
index 0000000..fe87828
--- /dev/null
+++ b/Core/RequestLoggingMiddleware.cs
@@ -0,0 +1,272 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Configuration;
+using Nest;
+using Newtonsoft.Json;
+using System.Diagnostics;
+using System.Net.Http.Headers;
+using System.Security.Claims;
+using System.Text.Encodings.Web;
+using System.Text.Json;
+using JsonSerializer = System.Text.Json.JsonSerializer;
+
+namespace BMA.EHR.Recruit.Service.Core
+{
+ public class RequestLoggingMiddleware
+ {
+ private readonly RequestDelegate _next;
+ private readonly IConfiguration _configuration;
+
+ private string Uri = "";
+ private string IndexFormat = "";
+ private string SystemName = "";
+ private string APIKey = "";
+
+ public RequestLoggingMiddleware(RequestDelegate next, IConfiguration configuration)
+ {
+ _next = next;
+ _configuration = configuration;
+
+ Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200";
+ IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index";
+ SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown";
+ }
+
+ protected async Task GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
+ {
+ try
+ {
+ using (var client = new HttpClient())
+ {
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
+ client.DefaultRequestHeaders.Add("api_key", apiKey);
+ var _res = await client.GetAsync(apiPath);
+ if (_res.IsSuccessStatusCode)
+ {
+ var _result = await _res.Content.ReadAsStringAsync();
+
+ return _result;
+ }
+ return string.Empty;
+ }
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ public async Task GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken)
+ {
+ try
+ {
+ var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}";
+ var apiKey = _configuration["API_KEY"];
+
+ var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
+ if (apiResult != null)
+ {
+ var raw = JsonConvert.DeserializeObject(apiResult);
+ if (raw != null)
+ return raw.Result;
+ }
+
+ return null;
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ public async Task Invoke(HttpContext context)
+ {
+ var settings = new ConnectionSettings(new Uri(Uri))
+ .DefaultIndex(IndexFormat);
+
+ var client = new ElasticClient(settings);
+
+
+ var startTime = DateTime.UtcNow;
+ var stopwatch = Stopwatch.StartNew();
+ string? responseBodyJson = null;
+ string? requestBodyJson = null;
+
+ string requestBody = await ReadRequestBodyAsync(context);
+ if (requestBody != "")
+ {
+ if (context.Request.HasFormContentType)
+ {
+ var form = await context.Request.ReadFormAsync(); // อ่าน form-data
+
+ var formData = new Dictionary();
+ foreach (var field in form)
+ {
+ formData[field.Key] = field.Value.ToString();
+ }
+ // อ่านไฟล์ที่ถูกส่งมา (ถ้ามี)
+ if (form.Files.Count > 0)
+ {
+ var fileDataList = new List