From 35cc18a4f659df9c437e93677bf92fa14d7f8ca6 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 10:42:22 +0700 Subject: [PATCH 1/5] test SystemName = "recruiting" --- Core/RequestLoggingMiddleware.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs index 3a3b7f4..64a2741 100644 --- a/Core/RequestLoggingMiddleware.cs +++ b/Core/RequestLoggingMiddleware.cs @@ -28,7 +28,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Core Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200"; IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index"; - SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown"; + //SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown"; + SystemName = "recruiting"; } protected async Task GetExternalAPIAsync(string apiPath, string accessToken, string apiKey) From 0043097b2d744314de4ed11a400c42bdf18e1ee9 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 14:34:53 +0700 Subject: [PATCH 2/5] call api check citizen --- Services/CandidateService.cs | 41 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 168755d..8fe7f31 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -8,6 +8,9 @@ using BMA.EHR.Recurit.Exam.Service.Response; using BMA.EHR.Recurit.Exam.Service.Responses.Document; using Microsoft.EntityFrameworkCore; using System.Linq; +using Newtonsoft.Json; +using System.Net.Http.Headers; +using Newtonsoft.Json.Linq; namespace BMA.EHR.Recurit.Exam.Service.Services { @@ -20,6 +23,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services private readonly IHttpContextAccessor _httpContextAccessor; private readonly MinIOService _minioService; private readonly MailService _mailService; + private readonly IConfiguration _configuration; #endregion @@ -29,13 +33,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Services OrgDbContext contextOrg, IHttpContextAccessor httpContextAccessor, MinIOService minioService, - MailService mailService) + MailService mailService, + IConfiguration configuration) { _context = context; _contextOrg = contextOrg; _httpContextAccessor = httpContextAccessor; _minioService = minioService; _mailService = mailService; + _configuration = configuration; } #endregion @@ -43,8 +49,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services #region " Properties " 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 @@ -2601,6 +2607,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (exam == null) throw new Exception(GlobalMessages.ExamNotFound); + #region check digit (old) // if (citizenId.Length != 13) // throw new Exception(GlobalMessages.CitizenIncomplete); @@ -2629,6 +2636,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services // if (citizenIdDigits[12] != chkDigit) // throw new Exception(GlobalMessages.CitizenIncorrect); + #endregion if (positionId != "00000000-0000-0000-0000-000000000000") { @@ -2638,12 +2646,27 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (position == null) throw new Exception(GlobalMessages.PositionExamNotFound); - var candidate1 = await _context.Candidates.AsQueryable() - .Where(x => x.PeriodExam == exam && x.UserId != UserId /*&& x.PositionExam == position*/ && x.CitizenId == citizenId) - .FirstOrDefaultAsync(); - if (candidate1 != null) - throw new Exception(GlobalMessages.CitizanDupicate); - return; + //var candidate1 = await _context.Candidates.AsQueryable() + // .Where(x => x.PeriodExam == exam && x.UserId != UserId /*&& x.PositionExam == position*/ && x.CitizenId == citizenId) + // .FirstOrDefaultAsync(); + //if (candidate1 != null) + // throw new Exception(GlobalMessages.CitizanDupicate); + //return; + } + + var apiUrl = $"{_configuration["API"]}/org/dotnet/check-citizen"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrl, new + { + citizenId + }); + var _result = await _res.Content.ReadAsStringAsync(); + var jsonData = JsonConvert.DeserializeObject(_result); + if (!_res.IsSuccessStatusCode) + throw new Exception(jsonData?["message"]?.ToString()); } var candidate2 = await _context.Candidates.AsQueryable() @@ -2651,6 +2674,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services .FirstOrDefaultAsync(); if (candidate2 != null) throw new Exception(GlobalMessages.CitizanDupicate); + + return; } public async Task GetExamCandidateAsync(Guid id) From dfa9dd3b47192cd91367cd988d6c861ea5537963 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 16:11:16 +0700 Subject: [PATCH 3/5] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A=20log?= =?UTF-8?q?=20User=20=E0=B8=9A=E0=B8=B8=E0=B8=84=E0=B8=84=E0=B8=A5?= =?UTF-8?q?=E0=B8=A0=E0=B8=B2=E0=B8=A2=E0=B8=99=E0=B8=AD=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/RequestLoggingMiddleware.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs index 64a2741..7d24362 100644 --- a/Core/RequestLoggingMiddleware.cs +++ b/Core/RequestLoggingMiddleware.cs @@ -160,6 +160,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Core var token = context.Request.Headers["Authorization"]; var pf = await GetProfileByKeycloakIdAsync(Guid.Parse(keycloakId), token); + var _userFullname = string.Empty; + var _userName = string.Empty; + if (keycloakId != "00000000-0000-0000-0000-000000000000" && pf == null) + { + _userFullname = context.User?.FindFirst("name")?.Value; + _userName = context.User?.FindFirst("preferred_username")?.Value; + } await _next(context); // ดำเนินการต่อไปยัง Middleware อื่น ๆ @@ -260,8 +267,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Core output = responseBodyJson, userId = keycloakId, - userName = $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}", - user = pf?.CitizenId ?? "" + userName = pf != null ? $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}" : _userFullname ?? "", + user = pf != null ? pf?.CitizenId ?? "" : _userName ?? "" }; From 0304e0594c217d13159bcc02e5c4c19f3fcfda24 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Dec 2025 15:26:44 +0700 Subject: [PATCH 4/5] =?UTF-8?q?=E0=B8=AA=E0=B8=A1=E0=B8=B1=E0=B8=84?= =?UTF-8?q?=E0=B8=A3=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=8A=E0=B9=87?= =?UTF-8?q?=E0=B8=84=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=99=20+=20Status=20#2136?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/CandidateController.cs | 4 +- Services/CandidateService.cs | 70 +++++++++--------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs index f6852cb..751c6af 100644 --- a/Controllers/CandidateController.cs +++ b/Controllers/CandidateController.cs @@ -1559,12 +1559,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } /// - /// โหลดใบชำระเงิน + /// กรอกเลขประจำตัวประชาชน /// /// รหัสรอบสมัคร /// Id ตำแหน่งสมัครสอบ /// - /// เมื่อทำการโหลดใบชำระเงิน สำเร็จ + /// เมื่อกรอกเลขประจำตัวประชาชน สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("check/citizen/{examId:length(36)}/{positionId:length(36)}")] diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 8fe7f31..dd90ae6 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -2600,64 +2600,42 @@ namespace BMA.EHR.Recurit.Exam.Service.Services public async Task CheckCitizen(string examId, string positionId, string citizenId) { + // เช็ครอบสมัครสอบ var exam = await _context.PeriodExams.AsQueryable() .Where(p => p.CheckDisability == false) .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId)); - if (exam == null) throw new Exception(GlobalMessages.ExamNotFound); - #region check digit (old) - // if (citizenId.Length != 13) - // throw new Exception(GlobalMessages.CitizenIncomplete); - - // int[] citizenIdDigits = citizenId.Select(c => int.Parse(c.ToString())).ToArray(); - // int cal = - // citizenIdDigits[0] * 13 + - // citizenIdDigits[1] * 12 + - // citizenIdDigits[2] * 11 + - // citizenIdDigits[3] * 10 + - // citizenIdDigits[4] * 9 + - // citizenIdDigits[5] * 8 + - // citizenIdDigits[6] * 7 + - // citizenIdDigits[7] * 6 + - // citizenIdDigits[8] * 5 + - // citizenIdDigits[9] * 4 + - // citizenIdDigits[10] * 3 + - // citizenIdDigits[11] * 2; - - // int calStp2 = cal % 11; - // int chkDigit = 11 - calStp2; - - // if (chkDigit >= 10) - // { - // chkDigit = 0; - // } - - // if (citizenIdDigits[12] != chkDigit) - // throw new Exception(GlobalMessages.CitizenIncorrect); - #endregion - + // เช็คตำแหน่งที่สมัครสอบ if (positionId != "00000000-0000-0000-0000-000000000000") { var position = await _context.PositionExams.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam); - + .FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam); if (position == null) throw new Exception(GlobalMessages.PositionExamNotFound); + } + + // เช็คเลขบัตรซ้ำ + var candidate = await _context.Candidates.AsQueryable() + .Where(x => + x.PeriodExam == exam + && x.UserId != UserId + && x.CitizenId == citizenId + && ( + (exam.Fee > 0 && x.Status.Trim().ToUpper() != "REGISTER") + || (exam.Fee == 0 && x.Status.Trim().ToUpper() == "CHECKSEAT") + ) + ) + .FirstOrDefaultAsync(); + if (candidate != null) + throw new Exception(GlobalMessages.CitizanDupicate); - //var candidate1 = await _context.Candidates.AsQueryable() - // .Where(x => x.PeriodExam == exam && x.UserId != UserId /*&& x.PositionExam == position*/ && x.CitizenId == citizenId) - // .FirstOrDefaultAsync(); - //if (candidate1 != null) - // throw new Exception(GlobalMessages.CitizanDupicate); - //return; - } - + // เช็ค Digit เลขบัตร var apiUrl = $"{_configuration["API"]}/org/dotnet/check-citizen"; using (var client = new HttpClient()) { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrl, new { @@ -2669,12 +2647,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services throw new Exception(jsonData?["message"]?.ToString()); } - var candidate2 = await _context.Candidates.AsQueryable() - .Where(x => x.PeriodExam == exam && x.UserId != UserId && x.CitizenId == citizenId) - .FirstOrDefaultAsync(); - if (candidate2 != null) - throw new Exception(GlobalMessages.CitizanDupicate); - return; } From 53da74d3226994157beff9780ae632da5c746b03 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Dec 2025 16:18:51 +0700 Subject: [PATCH 5/5] =?UTF-8?q?=E0=B8=AA=E0=B8=A1=E0=B8=B1=E0=B8=84?= =?UTF-8?q?=E0=B8=A3=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=8A=E0=B9=87?= =?UTF-8?q?=E0=B8=84=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=99=20+=20Status=20(=E0=B8=82=E0=B8=B1=E0=B9=89=E0=B8=99?= =?UTF-8?q?=E0=B8=95=E0=B8=AD=E0=B8=99=E0=B8=81=E0=B8=94=E0=B8=AA=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B9=83=E0=B8=9A=E0=B8=AA=E0=B8=A1=E0=B8=B1=E0=B8=84?= =?UTF-8?q?=E0=B8=A3)=20#2136?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Services/CandidateService.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index dd90ae6..fc1ba9f 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -2025,6 +2025,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (status == "checkRegister") { + // เช็คเลขบัตรซ้ำ + var candidate2 = await _context.Candidates.AsQueryable() + .Where(x => + x.PeriodExam == exam + && x.UserId != UserId + && x.CitizenId == candidate.CitizenId + && ( + (exam.Fee > 0 && x.Status.Trim().ToUpper() != "REGISTER") + || (exam.Fee == 0 && x.Status.Trim().ToUpper() == "CHECKSEAT") + ) + ) + .FirstOrDefaultAsync(); + if (candidate2 != null) + throw new Exception(GlobalMessages.CitizanDupicate); + var subject = "แจ้งผลการสมัครสอบคัดเลือก " + exam.Name; var body = candidate.FirstName + " " + candidate.LastName + " สถานะการสมัครสอบ: ได้รับใบสมัครแล้ว"; if (candidate.Email != null && candidate.Email != "") _mailService.SendMailToUser(subject, body, candidate.Email);