Merge branch 'develop' into dev
* develop: สมัครสอบเช็คเลขบัตรประชาชน + Status (ขั้นตอนกดส่งใบสมัคร) #2136 สมัครสอบเช็คเลขบัตรประชาชน + Status #2136 เก็บ log User บุคคลภายนอก call api check citizen test SystemName = "recruiting"
This commit is contained in:
commit
cf04d96cd0
3 changed files with 70 additions and 50 deletions
|
|
@ -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)}")]
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Core
|
||||||
|
|
||||||
Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200";
|
Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200";
|
||||||
IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index";
|
IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index";
|
||||||
SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown";
|
//SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown";
|
||||||
|
SystemName = "recruiting";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
|
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
|
||||||
|
|
@ -159,6 +160,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Core
|
||||||
var token = context.Request.Headers["Authorization"];
|
var token = context.Request.Headers["Authorization"];
|
||||||
|
|
||||||
var pf = await GetProfileByKeycloakIdAsync(Guid.Parse(keycloakId), token);
|
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 อื่น ๆ
|
await _next(context); // ดำเนินการต่อไปยัง Middleware อื่น ๆ
|
||||||
|
|
||||||
|
|
@ -259,8 +267,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Core
|
||||||
output = responseBodyJson,
|
output = responseBodyJson,
|
||||||
|
|
||||||
userId = keycloakId,
|
userId = keycloakId,
|
||||||
userName = $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}",
|
userName = pf != null ? $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}" : _userFullname ?? "",
|
||||||
user = pf?.CitizenId ?? ""
|
user = pf != null ? pf?.CitizenId ?? "" : _userName ?? ""
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ using BMA.EHR.Recurit.Exam.Service.Response;
|
||||||
using BMA.EHR.Recurit.Exam.Service.Responses.Document;
|
using BMA.EHR.Recurit.Exam.Service.Responses.Document;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace BMA.EHR.Recurit.Exam.Service.Services
|
namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +23,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly MinIOService _minioService;
|
private readonly MinIOService _minioService;
|
||||||
private readonly MailService _mailService;
|
private readonly MailService _mailService;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -29,13 +33,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
OrgDbContext contextOrg,
|
OrgDbContext contextOrg,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
MinIOService minioService,
|
MinIOService minioService,
|
||||||
MailService mailService)
|
MailService mailService,
|
||||||
|
IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_contextOrg = contextOrg;
|
_contextOrg = contextOrg;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_minioService = minioService;
|
_minioService = minioService;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -43,8 +49,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
#region " Properties "
|
#region " Properties "
|
||||||
|
|
||||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
|
||||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||||
|
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -2019,6 +2025,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
|
|
||||||
if (status == "checkRegister")
|
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 subject = "แจ้งผลการสมัครสอบคัดเลือก " + exam.Name;
|
||||||
var body = candidate.FirstName + " " + candidate.LastName + " สถานะการสมัครสอบ: ได้รับใบสมัครแล้ว";
|
var body = candidate.FirstName + " " + candidate.LastName + " สถานะการสมัครสอบ: ได้รับใบสมัครแล้ว";
|
||||||
if (candidate.Email != null && candidate.Email != "") _mailService.SendMailToUser(subject, body, candidate.Email);
|
if (candidate.Email != null && candidate.Email != "") _mailService.SendMailToUser(subject, body, candidate.Email);
|
||||||
|
|
@ -2594,63 +2615,54 @@ 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);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
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 candidate2 = await _context.Candidates.AsQueryable()
|
// เช็คเลขบัตรซ้ำ
|
||||||
.Where(x => x.PeriodExam == exam && x.UserId != UserId && x.CitizenId == citizenId)
|
var candidate = await _context.Candidates.AsQueryable()
|
||||||
.FirstOrDefaultAsync();
|
.Where(x =>
|
||||||
if (candidate2 != null)
|
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);
|
throw new Exception(GlobalMessages.CitizanDupicate);
|
||||||
|
|
||||||
|
// เช็ค 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.Add("api_key", _configuration["API_KEY"]);
|
||||||
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
{
|
||||||
|
citizenId
|
||||||
|
});
|
||||||
|
var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
var jsonData = JsonConvert.DeserializeObject<JObject>(_result);
|
||||||
|
if (!_res.IsSuccessStatusCode)
|
||||||
|
throw new Exception(jsonData?["message"]?.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GetExamCandidateAsync(Guid id)
|
public async Task GetExamCandidateAsync(Guid id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue