Co-authored-by: harid <harid_pr61@live.rmutl.com>
This commit is contained in:
parent
f3cdb61581
commit
80d678a582
1 changed files with 77 additions and 93 deletions
|
|
@ -2013,103 +2013,87 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
if (periodExam == null)
|
if (periodExam == null)
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
|
||||||
var data = new List<dynamic>();
|
var query = _context.Disables
|
||||||
var p_Id = new MySqlParameter("@id", id);
|
.Include(x => x.PeriodExam)
|
||||||
int total = 0;
|
.Include(x => x.Educations)
|
||||||
|
.Include(x => x.Certificates)
|
||||||
|
.OrderBy(x => x.ExamId)
|
||||||
|
.Where(x => x.PeriodExam != null && x.PeriodExam.Id == id);
|
||||||
|
|
||||||
// ---------------------------
|
var keywordParam = req.keyword?.Trim();
|
||||||
// 1️. ดึงรายละเอียดสอบ (exam_info)
|
if (!string.IsNullOrWhiteSpace(keywordParam))
|
||||||
// ---------------------------
|
|
||||||
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
||||||
{
|
{
|
||||||
cmd.CommandTimeout = 0;
|
query = query.Where(x =>
|
||||||
|
x.ExamId.Contains(keywordParam) ||
|
||||||
var sb = new StringBuilder();
|
x.CitizenId.Contains(keywordParam) ||
|
||||||
sb.Append(@"
|
x.Prefix.Contains(keywordParam) ||
|
||||||
SELECT
|
x.FirstName.Contains(keywordParam) ||
|
||||||
examID, profileID, prefix, fullName, dateofbirth, gender, degree, major, majorgroup,
|
x.LastName.Contains(keywordParam) ||
|
||||||
certificateno, certificateIssueDate, score, result, examAttribute, remark, isspecial,
|
x.HddPosition.Contains(keywordParam) ||
|
||||||
applydate, university, position_name, hddPosition, typeTest, position_level, position_type,
|
x.PositionName.Contains(keywordParam)
|
||||||
exam_name, exam_order, score_year,
|
);
|
||||||
COUNT(*) OVER() AS total_count
|
|
||||||
FROM exam_info
|
|
||||||
WHERE disable_import_id = @id
|
|
||||||
");
|
|
||||||
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
cmd.Parameters.Add(p_Id);
|
|
||||||
|
|
||||||
var keywordParam = req.keyword?.Trim();
|
|
||||||
if (!string.IsNullOrWhiteSpace(keywordParam))
|
|
||||||
{
|
|
||||||
sb.Append(@"
|
|
||||||
AND (
|
|
||||||
examID LIKE @kw
|
|
||||||
OR profileID LIKE @kw
|
|
||||||
OR prefix LIKE @kw
|
|
||||||
OR fullName LIKE @kw
|
|
||||||
OR hddPosition LIKE @kw
|
|
||||||
OR position_name LIKE @kw
|
|
||||||
)
|
|
||||||
");
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@kw", $"%{keywordParam}%"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
// Paging + Sorting
|
|
||||||
// ---------------------------
|
|
||||||
sb.Append(" ORDER BY examID ");
|
|
||||||
sb.Append(" LIMIT @PageSize OFFSET @Offset ");
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@PageSize", req.PageSize));
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@Offset", (req.Page - 1) * req.PageSize));
|
|
||||||
|
|
||||||
cmd.CommandText = sb.ToString();
|
|
||||||
|
|
||||||
_context.Database.OpenConnection();
|
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
// ดึงข้อมูล + total
|
|
||||||
// ---------------------------
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
if (total == 0)
|
|
||||||
total = Convert.ToInt32(reader["total_count"]);
|
|
||||||
|
|
||||||
data.Add(new
|
|
||||||
{
|
|
||||||
examID = reader["examID"].ToString(),
|
|
||||||
profileID = reader["profileID"].ToString(),
|
|
||||||
prefix = reader["prefix"].ToString(),
|
|
||||||
fullName = reader["fullName"].ToString(),
|
|
||||||
dateOfBirth = reader["dateofbirth"] == DBNull.Value ? "" : Convert.ToDateTime(reader["dateofbirth"]).ToThaiShortDate(),
|
|
||||||
gender = reader["gender"].ToString(),
|
|
||||||
degree = reader["degree"].ToString(),
|
|
||||||
major = reader["major"].ToString(),
|
|
||||||
majorgroup = reader["majorgroup"].ToString(),
|
|
||||||
certificateNo = reader["certificateno"].ToString(),
|
|
||||||
certificateIssueDate = reader["certificateIssueDate"] == DBNull.Value ? "" : Convert.ToDateTime(reader["certificateIssueDate"]).ToThaiShortDate(),
|
|
||||||
ExamScore = reader["score"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["score"]),
|
|
||||||
ExamResult = reader["result"].ToString(),
|
|
||||||
ExamAttribute = reader["examAttribute"].ToString(),
|
|
||||||
Remark = reader["remark"].ToString(),
|
|
||||||
IsSpecial = reader["isspecial"].ToString(),
|
|
||||||
applyDate = reader["applydate"] == DBNull.Value ? "" : Convert.ToDateTime(reader["applydate"]).ToThaiShortDate(),
|
|
||||||
university = reader["university"].ToString(),
|
|
||||||
position_name = reader["position_name"].ToString(),
|
|
||||||
hddPosition = reader["hddPosition"].ToString(),
|
|
||||||
typeTest = reader["typeTest"].ToString(),
|
|
||||||
position_level = reader["position_level"].ToString(),
|
|
||||||
position_type = reader["position_type"].ToString(),
|
|
||||||
exam_name = reader["exam_name"].ToString(),
|
|
||||||
exam_order = reader["exam_order"].ToString(),
|
|
||||||
score_year = Convert.ToInt32(reader["score_year"]).ToThaiYear().ToString()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int total = await query.CountAsync();
|
||||||
|
|
||||||
|
query = query
|
||||||
|
.Skip((req.Page - 1) * req.PageSize)
|
||||||
|
.Take(req.PageSize);
|
||||||
|
|
||||||
|
var data = await query
|
||||||
|
.GroupJoin(
|
||||||
|
_context.DisableScores.Include(x => x.ScoreImport),
|
||||||
|
rc => new { rc.PeriodExam!.Id, rc.ExamId },
|
||||||
|
sc => new { Id = sc.ScoreImport!.PeriodExamId, sc.ExamId },
|
||||||
|
(disable, scores) => new { disable, scores }
|
||||||
|
)
|
||||||
|
.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()
|
||||||
|
: "",
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// 3️. ดึงสรุปคะแนน
|
// 3️. ดึงสรุปคะแนน
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue