migrate + ปรับสอบคัดเลือกผู้พิการ (#3)

Co-authored-by: harid <harid_pr61@live.rmutl.com>
This commit is contained in:
Harid Promsri 2025-10-16 15:57:31 +07:00 committed by GitHub
parent b296304697
commit ecd794a070
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 6533 additions and 114 deletions

View file

@ -1299,19 +1299,19 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
r.LastName = workSheet?.Cells[row, 8]?.GetValue<string>() ?? "";
r.Gendor = workSheet?.Cells[row, 98]?.GetValue<string>() ?? "";
r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? "";
r.Race = "";//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.Race = "";
r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? "";
r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue;
r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null;
r.CitizenId = workSheet?.Cells[row, 12]?.GetValue<string>() ?? "";
r.typeTest = workSheet?.Cells[row, 13]?.GetValue<string>() ?? "";
r.Marry = "";//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.Marry = "";
r.Isspecial = "N";
r.CitizenCardIssuer = "";//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.CitizenCardExpireDate = DateTime.MinValue;//Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"));
r.ApplyDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 87]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 87]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue;
r.PositionType = "";//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.PositionLevel = "";//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.CitizenCardIssuer = "";
r.CitizenCardExpireDate = null;
r.ModifiedDate = null;
r.ApplyDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 87]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 87]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null;
r.PositionType = "";
r.PositionLevel = "";
r.CreatedAt = DateTime.Now;
r.CreatedUserId = UserId ?? "";
r.CreatedFullName = FullName ?? "System Administrator";
@ -1324,13 +1324,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
{
Degree = workSheet?.Cells[row, 18]?.GetValue<string>() ?? "",
Major = workSheet?.Cells[row, 19]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 20]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 19]?.GetValue<string>() ?? "",
MajorGroupId = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
MajorGroupName = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
MajorGroupId = "",
MajorGroupName = "",
University = workSheet?.Cells[row, 21]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 22]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 21]?.GetValue<string>() ?? "",
GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(),
Specialist = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
Specialist = "",
HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "",
BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue,
BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _disableService.CheckDateTime(workSheet?.Cells[row, 25]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null,
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator",
@ -1345,8 +1345,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
Occupation = workSheet?.Cells[row, 33]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 34]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 33]?.GetValue<string>() ?? "",
Position = workSheet?.Cells[row, 37]?.GetValue<string>() ?? "",
Workplace = $"{(workSheet?.Cells[row, 36]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 35]?.GetValue<string>() ?? "")}",
Telephone = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
WorkAge = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
Telephone = "",
WorkAge = "",
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator",
@ -1367,7 +1367,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
Province = workSheet?.Cells[row, 56]?.GetValue<string>() ?? "",
ZipCode = workSheet?.Cells[row, 57]?.GetValue<string>() ?? "",
Telephone = workSheet?.Cells[row, 58]?.GetValue<string>() ?? "",
Mobile = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
Mobile = "",
Address1 = $"{(workSheet?.Cells[row, 61]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 62]?.GetValue<string>() ?? "")}",
Moo1 = workSheet?.Cells[row, 63]?.GetValue<string>() ?? "",
Soi1 = workSheet?.Cells[row, 64]?.GetValue<string>() ?? "",
@ -1410,21 +1410,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator"
});
// certificate
r.Certificates.Add(new DisableCertificate()
{
CertificateNo = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
Description = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
IssueDate = DateTime.MinValue,//Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
ExpiredDate = DateTime.MinValue,//Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator",
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator"
});
/* Comment ข้อมูลใบประกอบวิชาชีพ เพราะใน template ยังไม่มีคอลัมน์ที่ระบุข้อมูลส่วนนี้ */
//// certificate
//r.Certificates.Add(new DisableCertificate()
//{
// CertificateNo = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
// Description = "",//workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
// IssueDate = DateTime.MinValue,//Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
// ExpiredDate = DateTime.MinValue,//Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
// CreatedAt = DateTime.Now,
// CreatedUserId = UserId ?? "",
// CreatedFullName = FullName ?? "System Administrator",
// LastUpdatedAt = DateTime.Now,
// LastUpdateUserId = UserId ?? "",
// LastUpdateFullName = FullName ?? "System Administrator"
//});
r.PeriodExam = imported;
_context.Disables.Add(r);
@ -2035,13 +2035,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
);
}
int total = await query.CountAsync();
query = query
.Skip((req.Page - 1) * req.PageSize)
.Take(req.PageSize);
var data = await query
// join กับ DisableScores ก่อน เพื่อ filter ตาม ExamStatus
var queryWithScores = query
.GroupJoin(
_context.DisableScores.Include(x => x.ScoreImport),
rc => new { rc.PeriodExam!.Id, rc.ExamId },
@ -2050,49 +2045,78 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
)
.SelectMany(
x => x.scores.DefaultIfEmpty(),
(x, sr) => new
{
examID = x.disable.ExamId,
profileID = x.disable.CitizenId,
prefix = x.disable.Prefix,
fullName = $"{x.disable.FirstName} {x.disable.LastName}",
dateOfBirth = x.disable.DateOfBirth != null && x.disable.DateOfBirth != DateTime.MinValue
? x.disable.DateOfBirth.ToThaiShortDate()
: "",
gender = x.disable.Gendor,
degree = x.disable.Educations.Any() ? x.disable.Educations.First().Degree : "",
major = x.disable.Educations.Any() ? x.disable.Educations.First().Major : "",
certificateNo = x.disable.Certificates.Any()
? x.disable.Certificates.First().CertificateNo ?? ""
: "",
certificateIssueDate = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null && x.disable.Certificates.First().IssueDate != DateTime.MinValue
? x.disable.Certificates.First().IssueDate.ToThaiShortDate()
: "",
examScore = sr == null ? 0.0 : sr.TotalScore,
examResult = sr == null ? "" : sr.ExamStatus,
examAttribute = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null
? _disableService.CheckValidCertificate(x.disable.Certificates.First().IssueDate, 5)
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
: "ไม่มีคุณสมบัติ",
remark = x.disable.Remark,
isSpecial = x.disable.Isspecial == "Y" ? x.disable.Isspecial : "",
applyDate = x.disable.ApplyDate != null && x.disable.ApplyDate != DateTime.MinValue
? x.disable.ApplyDate.ToThaiShortDate()
: "",
university = x.disable.Educations.Any() ? x.disable.Educations.First().University : "",
position_name = x.disable.PositionName,
hddPosition = x.disable.HddPosition ?? "",
typeTest = x.disable.typeTest ?? "",
position_level = x.disable.PositionLevel ?? "",
position_type = x.disable.PositionType ?? "",
exam_name = x.disable.PeriodExam!.Name,
exam_order = x.disable.PeriodExam != null && x.disable.PeriodExam.Round != null
? x.disable.PeriodExam.Round.ToString()
: "",
score_year = x.disable.PeriodExam != null && x.disable.PeriodExam.Year != null
? (x.disable.PeriodExam.Year > 2500 ? x.disable.PeriodExam.Year : x.disable.PeriodExam.Year + 543).ToString()
: "",
})
(x, sr) => new { x.disable, score = sr }
);
// filter ตาม req.ExamResult
if (!string.IsNullOrWhiteSpace(req.ExamResult))
{
switch (req.ExamResult.ToLower())
{
case "missed_exam":
queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ขส.");
break;
case "pass":
queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ผ่าน");
break;
case "notpass":
queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ไม่ผ่าน");
break;
}
}
// total count หลังกรอง
int total = await queryWithScores.CountAsync();
// pagination
queryWithScores = queryWithScores
.Skip((req.Page - 1) * req.PageSize)
.Take(req.PageSize);
// mapping
var data = await queryWithScores
.Select(x => new
{
examID = x.disable.ExamId,
profileID = x.disable.CitizenId,
prefix = x.disable.Prefix,
fullName = $"{x.disable.FirstName} {x.disable.LastName}",
dateOfBirth = x.disable.DateOfBirth.HasValue && x.disable.DateOfBirth.Value != DateTime.MinValue
? x.disable.DateOfBirth.Value.ToThaiShortDate()
: "",
gender = x.disable.Gendor,
degree = x.disable.Educations.Any() ? x.disable.Educations.First().Degree : "",
major = x.disable.Educations.Any() ? x.disable.Educations.First().Major : "",
certificateNo = x.disable.Certificates.Any() ? x.disable.Certificates.First().CertificateNo ?? "" : "",
certificateIssueDate = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null && x.disable.Certificates.First().IssueDate != DateTime.MinValue
? x.disable.Certificates.First().IssueDate.ToThaiShortDate()
: "",
examScore = x.score == null ? 0.0 : x.score.TotalScore,
examResult = x.score == null ? "" : x.score.ExamStatus,
examAttribute = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null
? _disableService.CheckValidCertificate(x.disable.Certificates.First().IssueDate, 5)
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
: "ไม่มีคุณสมบัติ",
remark = x.disable.Remark,
isSpecial = x.disable.Isspecial == "Y" ? x.disable.Isspecial : "",
applyDate = x.disable.ApplyDate.HasValue && x.disable.ApplyDate.Value != DateTime.MinValue
? x.disable.ApplyDate.Value.ToThaiShortDate()
: "",
university = x.disable.Educations.Any() ? x.disable.Educations.First().University : "",
position_name = x.disable.PositionName,
hddPosition = x.disable.HddPosition ?? "",
typeTest = x.disable.typeTest ?? "",
position_level = x.disable.PositionLevel ?? "",
position_type = x.disable.PositionType ?? "",
exam_name = x.disable.PeriodExam!.Name,
exam_order = x.disable.PeriodExam != null && x.disable.PeriodExam.Round != null
? x.disable.PeriodExam.Round.ToString()
: "",
score_year = x.disable.PeriodExam != null && x.disable.PeriodExam.Year != null
? (x.disable.PeriodExam.Year > 2500 ? x.disable.PeriodExam.Year : x.disable.PeriodExam.Year + 543).ToString()
: "",
number = x.score == null ? "" : x.score.Number,
})
.ToListAsync();
// ---------------------------
@ -2177,10 +2201,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
ProfileID = p.CitizenId,
p.Prefix,
FullName = $"{p.FirstName} {p.LastName}",
DateOfBirth = p.DateOfBirth != null
? p.DateOfBirth != DateTime.MinValue
? p.DateOfBirth.ToThaiShortDate()
: ""
DateOfBirth = p.DateOfBirth.HasValue && p.DateOfBirth.Value != DateTime.MinValue
? p.DateOfBirth.Value.ToThaiShortDate()
: "",
Gender = p.Gendor,
Degree = p.Educations.First().Degree,
@ -2484,10 +2506,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
ExamID = p.ExamId != null ? p.ExamId.ToThaiNumber() : "",
CitizenId = p.CitizenId != null ? p.CitizenId.ToThaiNumber() : "",
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
DateOfBirth = p.DateOfBirth != null
? p.DateOfBirth != DateTime.MinValue
? p.DateOfBirth.ToThaiShortDate().ToString().ToThaiNumber()
: ""
DateOfBirth = p.DateOfBirth.HasValue && p.DateOfBirth.Value != DateTime.MinValue
? p.DateOfBirth.Value.ToThaiShortDate().ToThaiNumber()
: "",
Gender = p.Gendor,
Degree = p.Educations.First().Degree,