สมัครสอบเช็คเลขบัตรประชาชน + Status #2136

This commit is contained in:
harid 2025-12-18 15:26:44 +07:00
parent dfa9dd3b47
commit 0304e0594c
2 changed files with 23 additions and 51 deletions

View file

@ -1559,12 +1559,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
} }
/// <summary> /// <summary>
/// โหลดใบชำระเงิ /// กรอกเลขประจำตัวประชาช
/// </summary> /// </summary>
/// <param name="examId">รหัสรอบสมัคร</param> /// <param name="examId">รหัสรอบสมัคร</param>
/// <param name="positionId">Id ตำแหน่งสมัครสอบ</param> /// <param name="positionId">Id ตำแหน่งสมัครสอบ</param>
/// <returns></returns> /// <returns></returns>
/// <response code="200">เมื่อทำการโหลดใบชำระเงิน สำเร็จ</response> /// <response code="200">เมื่อกรอกเลขประจำตัวประชาชน สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("check/citizen/{examId:length(36)}/{positionId:length(36)}")] [HttpPut("check/citizen/{examId:length(36)}/{positionId:length(36)}")]

View file

@ -2600,64 +2600,42 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task CheckCitizen(string examId, string positionId, string citizenId) public async Task CheckCitizen(string examId, string positionId, string citizenId)
{ {
// เช็ครอบสมัครสอบ
var exam = await _context.PeriodExams.AsQueryable() var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false) .Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId)); .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null) if (exam == null)
throw new Exception(GlobalMessages.ExamNotFound); 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") if (positionId != "00000000-0000-0000-0000-000000000000")
{ {
var position = await _context.PositionExams.AsQueryable() 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) if (position == null)
throw new Exception(GlobalMessages.PositionExamNotFound); 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 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);
// เช็ค Digit เลขบัตร
var apiUrl = $"{_configuration["API"]}/org/dotnet/check-citizen"; var apiUrl = $"{_configuration["API"]}/org/dotnet/check-citizen";
using (var client = new HttpClient()) 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"]); client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrl, new var _res = await client.PostAsJsonAsync(apiUrl, new
{ {
@ -2669,12 +2647,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
throw new Exception(jsonData?["message"]?.ToString()); 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; return;
} }