ปรับระบบสรรหาสอบคัดเลือก (3)
This commit is contained in:
parent
876b085dd2
commit
efb22a9d73
5 changed files with 182 additions and 62 deletions
|
|
@ -847,6 +847,33 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ผู้สมัครทำการสมัครสอบ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="examId">รหัสรอบสมัคร</param>
|
||||||
|
/// <param name="positionId">Id ตำแหน่งสมัครสอบ</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการผู้สมัครทำการสมัครสอบ สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("register-confirm/{examId:length(36)}/{positionId:length(36)}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> RegisterCheckSeatService(string examId, string positionId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _candidateService.UserConfirmCheckSeatService(examId, positionId);
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// เจ้าหน้าที่ย้อนสถานะเป็นตรวจสอบข้อมูล
|
/// เจ้าหน้าที่ย้อนสถานะเป็นตรวจสอบข้อมูล
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Request
|
||||||
public int? Year { get; set; }
|
public int? Year { get; set; }
|
||||||
public bool Status { get; set; }
|
public bool Status { get; set; }
|
||||||
public bool SetSeat { get; set; }
|
public bool SetSeat { get; set; }
|
||||||
|
public float? Fee { get; set;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Response
|
||||||
{
|
{
|
||||||
// public Models.Prefix? Prefix { get; set; }
|
// public Models.Prefix? Prefix { get; set; }
|
||||||
public string? PrefixId { get; set; }
|
public string? PrefixId { get; set; }
|
||||||
public string? Prefix { get; set; }
|
public string? PrefixName { get; set; }
|
||||||
public string? FirstName { get; set; } = string.Empty;
|
public string? FirstName { get; set; } = string.Empty;
|
||||||
public string? LastName { get; set; } = string.Empty;
|
public string? LastName { get; set; } = string.Empty;
|
||||||
public string? Nationality { get; set; } = string.Empty;
|
public string? Nationality { get; set; } = string.Empty;
|
||||||
|
|
|
||||||
|
|
@ -741,49 +741,49 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
if (candidate == null)
|
if (candidate == null)
|
||||||
throw new Exception(GlobalMessages.ExamNotFound);
|
throw new Exception(GlobalMessages.ExamNotFound);
|
||||||
|
|
||||||
if (updated.PrefixId != null)
|
//if (updated.PrefixId != null)
|
||||||
{
|
//{
|
||||||
var prefix = await _contextOrg.prefixe.AsQueryable()
|
// var prefix = await _contextOrg.prefixe.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
|
// .FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
|
||||||
|
|
||||||
if (prefix == null)
|
// if (prefix == null)
|
||||||
throw new Exception(GlobalMessages.PrefixNotFound);
|
// throw new Exception(GlobalMessages.PrefixNotFound);
|
||||||
|
|
||||||
candidate.PrefixId = prefix.Id;
|
// candidate.PrefixId = prefix.Id;
|
||||||
candidate.PrefixName = prefix.name;
|
// candidate.PrefixName = prefix.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.Prefix))
|
if (!string.IsNullOrEmpty(updated.PrefixName))
|
||||||
{
|
{
|
||||||
candidate.PrefixName = updated.Prefix;
|
candidate.PrefixName = updated.PrefixName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated.ContactPrefixId != null)
|
//if (updated.ContactPrefixId != null)
|
||||||
{
|
//{
|
||||||
var prefix = await _contextOrg.prefixe.AsQueryable()
|
// var prefix = await _contextOrg.prefixe.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == updated.ContactPrefixId);
|
// .FirstOrDefaultAsync(x => x.Id == updated.ContactPrefixId);
|
||||||
|
|
||||||
if (prefix == null)
|
// if (prefix == null)
|
||||||
throw new Exception(GlobalMessages.PrefixNotFound);
|
// throw new Exception(GlobalMessages.PrefixNotFound);
|
||||||
|
|
||||||
candidate.ContactPrefixId = prefix.Id;
|
// candidate.ContactPrefixId = prefix.Id;
|
||||||
candidate.ContactPrefixName = prefix.name;
|
// candidate.ContactPrefixName = prefix.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.ContactPrefixName))
|
if (!string.IsNullOrEmpty(updated.ContactPrefixName))
|
||||||
{
|
{
|
||||||
candidate.ContactPrefixName = updated.ContactPrefixName;
|
candidate.ContactPrefixName = updated.ContactPrefixName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated.ReligionId != null)
|
//if (updated.ReligionId != null)
|
||||||
{
|
//{
|
||||||
var religion = await _contextOrg.religion.AsQueryable()
|
// var religion = await _contextOrg.religion.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.ReligionId));
|
// .FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.ReligionId));
|
||||||
|
|
||||||
if (religion == null)
|
// if (religion == null)
|
||||||
throw new Exception(GlobalMessages.ReligionNotFound);
|
// throw new Exception(GlobalMessages.ReligionNotFound);
|
||||||
|
|
||||||
candidate.ReligionId = religion.Id;
|
// candidate.ReligionId = religion.Id;
|
||||||
candidate.ReligionName = religion.name;
|
// candidate.ReligionName = religion.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.ReligionName))
|
if (!string.IsNullOrEmpty(updated.ReligionName))
|
||||||
{
|
{
|
||||||
candidate.ReligionName = updated.ReligionName;
|
candidate.ReligionName = updated.ReligionName;
|
||||||
|
|
@ -977,49 +977,49 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
if (candidate == null)
|
if (candidate == null)
|
||||||
throw new Exception(GlobalMessages.ExamNotFound);
|
throw new Exception(GlobalMessages.ExamNotFound);
|
||||||
|
|
||||||
if (updated.PrefixId != null)
|
//if (updated.PrefixId != null)
|
||||||
{
|
//{
|
||||||
var prefix = await _contextOrg.prefixe.AsQueryable()
|
// var prefix = await _contextOrg.prefixe.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
|
// .FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
|
||||||
|
|
||||||
if (prefix == null)
|
// if (prefix == null)
|
||||||
throw new Exception(GlobalMessages.PrefixNotFound);
|
// throw new Exception(GlobalMessages.PrefixNotFound);
|
||||||
|
|
||||||
candidate.PrefixId = prefix.Id;
|
// candidate.PrefixId = prefix.Id;
|
||||||
candidate.PrefixName = prefix.name;
|
// candidate.PrefixName = prefix.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.Prefix))
|
if (!string.IsNullOrEmpty(updated.PrefixName))
|
||||||
{
|
{
|
||||||
candidate.PrefixName = updated.Prefix;
|
candidate.PrefixName = updated.PrefixName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated.ContactPrefixId != null)
|
//if (updated.ContactPrefixId != null)
|
||||||
{
|
//{
|
||||||
var prefix = await _contextOrg.prefixe.AsQueryable()
|
// var prefix = await _contextOrg.prefixe.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == updated.ContactPrefixId);
|
// .FirstOrDefaultAsync(x => x.Id == updated.ContactPrefixId);
|
||||||
|
|
||||||
if (prefix == null)
|
// if (prefix == null)
|
||||||
throw new Exception(GlobalMessages.PrefixNotFound);
|
// throw new Exception(GlobalMessages.PrefixNotFound);
|
||||||
|
|
||||||
candidate.ContactPrefixId = prefix.Id;
|
// candidate.ContactPrefixId = prefix.Id;
|
||||||
candidate.ContactPrefixName = prefix.name;
|
// candidate.ContactPrefixName = prefix.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.ContactPrefixName))
|
if (!string.IsNullOrEmpty(updated.ContactPrefixName))
|
||||||
{
|
{
|
||||||
candidate.ContactPrefixName = updated.ContactPrefixName;
|
candidate.ContactPrefixName = updated.ContactPrefixName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated.ReligionId != null)
|
//if (updated.ReligionId != null)
|
||||||
{
|
//{
|
||||||
var religion = await _contextOrg.religion.AsQueryable()
|
// var religion = await _contextOrg.religion.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.ReligionId));
|
// .FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.ReligionId));
|
||||||
|
|
||||||
if (religion == null)
|
// if (religion == null)
|
||||||
throw new Exception(GlobalMessages.ReligionNotFound);
|
// throw new Exception(GlobalMessages.ReligionNotFound);
|
||||||
|
|
||||||
candidate.ReligionId = religion.Id;
|
// candidate.ReligionId = religion.Id;
|
||||||
candidate.ReligionName = religion.name;
|
// candidate.ReligionName = religion.name;
|
||||||
}
|
//}
|
||||||
if (!string.IsNullOrEmpty(updated.ReligionName))
|
if (!string.IsNullOrEmpty(updated.ReligionName))
|
||||||
{
|
{
|
||||||
candidate.ReligionName = updated.ReligionName;
|
candidate.ReligionName = updated.ReligionName;
|
||||||
|
|
@ -2048,6 +2048,99 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UserConfirmCheckSeatService(string examId, string positionId)
|
||||||
|
{
|
||||||
|
var examGuid = Guid.Parse(examId);
|
||||||
|
var positionGuid = Guid.Parse(positionId);
|
||||||
|
|
||||||
|
// 1) โหลดข้อมูลรอบสอบ
|
||||||
|
var exam = await _context.PeriodExams
|
||||||
|
.Where(p => !p.CheckDisability && p.Id == examGuid)
|
||||||
|
.Include(x => x.PositionExam)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (exam == null)
|
||||||
|
throw new Exception(GlobalMessages.ExamNotFound);
|
||||||
|
|
||||||
|
// 2) โหลด Candidate เดิม (ดึงครั้งเดียวพอ)
|
||||||
|
var candidate = await _context.Candidates
|
||||||
|
.Include(x => x.PositionExam)
|
||||||
|
.Include(x => x.PeriodExam)
|
||||||
|
.FirstOrDefaultAsync(x => x.PeriodExam.Id == exam.Id && x.UserId == UserId);
|
||||||
|
|
||||||
|
if (positionGuid != Guid.Empty)
|
||||||
|
{
|
||||||
|
// 3) ตรวจสอบตำแหน่ง
|
||||||
|
var position = await _context.PositionExams
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == positionGuid && x.PeriodExam.Id == exam.Id);
|
||||||
|
|
||||||
|
if (position == null)
|
||||||
|
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||||
|
|
||||||
|
// 4) ลบข้อมูลตำแหน่งอื่นในรอบนี้
|
||||||
|
var deleteOther = await _context.Candidates
|
||||||
|
.Where(x => x.PeriodExam.Id == exam.Id
|
||||||
|
&& x.UserId == UserId
|
||||||
|
&& x.PositionExam.Id != position.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_context.Candidates.RemoveRange(deleteOther);
|
||||||
|
|
||||||
|
// 5) โหลด candidate ใหม่เฉพาะตำแหน่งที่เลือก
|
||||||
|
candidate = await _context.Candidates
|
||||||
|
.FirstOrDefaultAsync(x => x.PeriodExam.Id == exam.Id
|
||||||
|
&& x.UserId == UserId
|
||||||
|
&& x.PositionExam.Id == position.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidate == null)
|
||||||
|
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||||
|
|
||||||
|
// ต้องอยู่ในสถานะ CHECKREGISTER เท่านั้น
|
||||||
|
if (candidate.Status.Trim().ToUpper() != "CHECKREGISTER")
|
||||||
|
throw new Exception(GlobalMessages.CannotInsertToDatabase);
|
||||||
|
|
||||||
|
// 6) ไม่เสียค่าสมัคร → ต้องออกเลขประจำตัวสอบด้วย
|
||||||
|
if (candidate.PeriodExam.Fee == 0)
|
||||||
|
{
|
||||||
|
candidate.Status = "checkSeat";
|
||||||
|
|
||||||
|
// ❗ออกเลขประจำตัวสอบ (กันซ้ำ 100%)
|
||||||
|
if (string.IsNullOrEmpty(candidate.ExamIdenNumber))
|
||||||
|
{
|
||||||
|
using var transaction = await _context.Database.BeginTransactionAsync();
|
||||||
|
|
||||||
|
// อ่านเลขล่าสุด (Lock ภายใน Transaction)
|
||||||
|
var lastNumber = await _context.Candidates
|
||||||
|
.Where(x => x.PeriodExam.Id == exam.Id)
|
||||||
|
.OrderByDescending(x => x.ExamIdenNumber)
|
||||||
|
.Select(x => x.ExamIdenNumber)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
// Convert → หาเลขลำดับต่อไป
|
||||||
|
int next = 1;
|
||||||
|
if (!string.IsNullOrEmpty(lastNumber))
|
||||||
|
{
|
||||||
|
// ถ้าเลขมี prefix เช่น P01xxxx → ต้องเอาเฉพาะตัวเลข
|
||||||
|
string numeric = new string(lastNumber.Where(char.IsDigit).ToArray());
|
||||||
|
next = int.Parse(numeric) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// สร้างเลขตามตำแหน่งสอบ
|
||||||
|
candidate.ExamIdenNumber =
|
||||||
|
candidate.PositionExam == null
|
||||||
|
? next.ToString("D5")
|
||||||
|
: candidate.PositionExam.Code + next.ToString("D5");
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task AdminCheckCandidateService(string candidateId, string status, RequestApprove item)
|
public async Task AdminCheckCandidateService(string candidateId, string status, RequestApprove item)
|
||||||
{
|
{
|
||||||
var candidate = await _context.Candidates.AsQueryable()
|
var candidate = await _context.Candidates.AsQueryable()
|
||||||
|
|
@ -2180,7 +2273,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
}
|
}
|
||||||
public async Task AdminCheckShowExamInfoService(string[] candidateId)
|
public async Task AdminCheckShowExamInfoService(string[] candidateId)
|
||||||
{
|
{
|
||||||
//var _num = 0;
|
|
||||||
foreach (var _candidateId in candidateId)
|
foreach (var _candidateId in candidateId)
|
||||||
{
|
{
|
||||||
var candidate = await _context.Candidates.AsQueryable()
|
var candidate = await _context.Candidates.AsQueryable()
|
||||||
|
|
@ -2190,7 +2282,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
if (candidate == null)
|
if (candidate == null)
|
||||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||||
|
|
||||||
if (candidate.Status.Trim().ToUpper() != "CHECKREGISTER")
|
if (candidate.Status.Trim().ToUpper() != "CHECKSEAT")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (candidate.PeriodExam == null)
|
if (candidate.PeriodExam == null)
|
||||||
|
|
@ -2208,7 +2300,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
throw new Exception(GlobalMessages.ExamNotFound);
|
throw new Exception(GlobalMessages.ExamNotFound);
|
||||||
|
|
||||||
candidate.IsShowExamInfo = true;
|
candidate.IsShowExamInfo = true;
|
||||||
//++_num;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
Year = periodExam.Year,
|
Year = periodExam.Year,
|
||||||
Status = periodExam.PaymentEndDate == null ? true : DateTime.Now > periodExam.PaymentEndDate,
|
Status = periodExam.PaymentEndDate == null ? true : DateTime.Now > periodExam.PaymentEndDate,
|
||||||
SetSeat = periodExam.SetSeat,
|
SetSeat = periodExam.SetSeat,
|
||||||
|
Fee = periodExam.Fee,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue