ปรับ report ระบบสรรหา

This commit is contained in:
Bright 2025-01-08 17:46:00 +07:00
parent 07903d3b67
commit e94eb0f3e9
2 changed files with 463 additions and 12 deletions

View file

@ -731,11 +731,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
{
try
{
var stream = await _periodExamService.DownloadCandidateAsync(examId);
//var stream = await _periodExamService.DownloadCandidateAsync(examId);
string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
// return Success();
//string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
//return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
var data = await _periodExamService.NewDownloadCandidateAsync(examId);
return Success(data);
}
catch (Exception ex)
{
@ -759,11 +761,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
{
try
{
var stream = await _periodExamService.DownloadCandidateAllAsync(examId);
//var stream = await _periodExamService.DownloadCandidateAllAsync(examId);
string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
// return Success();
//string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
//return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
var data = await _periodExamService.NewDownloadCandidateAllAsync(examId);
return Success(data);
}
catch (Exception ex)
{
@ -787,11 +791,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
{
try
{
var stream = await _periodExamService.GetsDashboardExamAsync(item, examId);
//var stream = await _periodExamService.GetsDashboardExamAsync(item, examId);
string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
// return Success();
//string excelName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
//return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
var data = await _periodExamService.NewGetsDashboardExamAsync(item, examId);
return Success(data);
}
catch (Exception ex)
{

View file

@ -1338,6 +1338,128 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return stream;
}
public async Task<dynamic> NewDownloadCandidateAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
var candidates = new List<Candidate>();
if (periodExam.SetSeat == true)
{
candidates = await _context.Candidates
.AsQueryable()
.Include(x => x.PositionExam)
.OrderBy(x => x.ExamIdenNumber)
.Where(x => x.PeriodExam == periodExam)
.Where(x => x.Status != "waiver")
.Where(x => x.Status != "register")
.ToListAsync();
}
else
{
candidates = await _context.Candidates
.AsQueryable()
.Include(x => x.PositionExam)
.OrderBy(x => x.ExamIdenNumber)
.Where(x => x.PeriodExam == periodExam)
.Where(x => x.Status != "register")
.ToListAsync();
}
var _data = new List<object>();
if (candidates.Count > 0)
{
foreach (var item in candidates)
{
_data.Add(new
{
Number = item.Number != null ? item.Number.ToThaiNumber() : "-",
ExamIdenNumber = item.ExamIdenNumber != null ? item.ExamIdenNumber.ToString() : "-",
CitizenId = item.CitizenId != null ? item.CitizenId.ToThaiNumber() : "-",
SeatNumber = item.SeatNumber != null ? item.SeatNumber.ToThaiNumber() : "-",
PrefixName = item.PrefixName != null ? item.PrefixName.ToThaiNumber() : "-",
FullName = item.FirstName != null && item.LastName != null ? $"{item.FirstName} {item.LastName}" : "-",
PositionName = item.PositionExam != null && item.PositionExam?.PositionName != null ? item.PositionExam?.PositionName.ToThaiNumber() : "-",
PositionLevelName = item.PositionExam != null && item.PositionExam?.PositionLevelName != null ? item.PositionExam?.PositionLevelName.ToThaiNumber() : "-",
PointPath1A = item.PointPath1A != null ? item.PointPath1A.ToThaiNumber() : "-",
PointPath2A = item.PointPath2A != null ? item.PointPath2A.ToThaiNumber() : "-",
PointPath3A = item.PointPath3A != null ? item.PointPath3A.ToThaiNumber() : "-",
PointA = item.PointA != null ? item.PointA.ToThaiNumber() : "-",
PointPerA = item.PointPerA != null ? item.PointPerA.ToThaiNumber() : "-",
ResultA = item.ResultA != null ? item.ResultA.ToThaiNumber() : "-",
PointB = item.PointB != null ? item.PointB.ToThaiNumber() : "-",
PointPerB = item.PointPerB != null ? item.PointPerB.ToThaiNumber() : "-",
ResultB = item.ResultB != null ? item.ResultB.ToThaiNumber() : "-",
PointPath1C = item.PointPath1C != null ? item.PointPath1C.ToThaiNumber() : "-",
PointPath2C = item.PointPath2C != null ? item.PointPath2C.ToThaiNumber() : "-",
PointC = item.PointC != null ? item.PointC.ToThaiNumber() : "-",
PointPerC = item.PointPerC != null ? item.PointPerC.ToThaiNumber() : "-",
ResultC = item.ResultC != null ? item.ResultC.ToThaiNumber() : "-",
Pass = item.Pass != null ? item.Pass.ToThaiNumber() : "-",
PaymentStatus = item.PeriodExam == null || item.PeriodExam.Fee <= 0 ? "ไม่มีชำระเงิน" : (item.PaymentDate == null ? "ยังไม่ชำระเงิน" : "ชำระแล้ว"),
PaymentDate = item.PaymentDate == null ? "-" : $"{item.PaymentDate.Value.ToThaiShortDate()} {item.PaymentDate.Value:HH:mm:ss.ffff}".ToString().ToThaiNumber(),
RegisterDate = item.RegisterDate == null ? "-" : $"{item.RegisterDate.Value.ToThaiShortDate()} {item.RegisterDate.Value:HH:mm:ss.ffff}".ToString().ToThaiNumber(),
ExamReason = item.ExamReason != null ? item.ExamReason.ToThaiNumber() : "-"
});
}
}
else
{
_data.Add(new
{
Number = "-",
ExamIdenNumber = "-",
CitizenId = "-",
SeatNumber = "-",
PrefixName = "-",
FullName = "-",
PositionName = "-",
PositionLevelName = "-",
PointPath1A = "-",
PointPath2A = "-",
PointPath3A = "-",
PointA = "-",
PointPerA = "-",
ResultA = "-",
PointB = "-",
PointPerB = "-",
ResultB = "-",
PointPath1C = "-",
PointPath2C = "-",
PointC = "-",
PointPerC = "-",
ResultC = "-",
Pass = "-",
PaymentStatus = "-",
PaymentDate = "-",
RegisterDate = "-",
ExamReason = "-"
});
}
return new
{
template = "candidate",
reportName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}",
data = new
{
data = _data
}
};
}
public async Task<PeriodExam> GetsPaymentExamAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
@ -1769,6 +1891,186 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return stream;
}
public async Task<dynamic> NewDownloadCandidateAllAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
var candidates = await _context.Candidates
.AsQueryable()
.OrderBy(x => x.ExamIdenNumber)
.Where(x => x.PeriodExam == periodExam)
.Where(x => x.Status != "register")
.Select(c => new
{
Id = c.Id,
Status = c.Status,
CitizenId = c.CitizenId,
FullName = $"{c.PrefixName}{c.FirstName} {c.LastName}",
Nationality = c.Nationality,
DateOfBirth = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.ToThaiShortDate(),
Age = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.CalculateAgeStrV2(0, 0),
ReligionName = c.ReligionName,
Telephone = c.Telephone,
MobilePhone = c.MobilePhone,
Email = c.Email,
Knowledge = c.Knowledge,
RegistAddress = c.RegistAddress,
RegistProvinceName = c.RegistProvinceName,
RegistDistrictName = c.RegistDistrictName,
RegistSubDistrictName = c.RegistSubDistrictName,
RegistZipCode = c.RegistZipCode,
CurrentAddress = c.CurrentAddress,
CurrentProvinceName = c.CurrentProvinceName,
CurrentDistrictName = c.CurrentDistrictName,
CurrentSubDistrictName = c.CurrentSubDistrictName,
CurrentZipCode = c.CurrentZipCode,
OccupationOrg = c.OccupationOrg,
OccupationPile = c.OccupationPile,
OccupationGroup = c.OccupationGroup,
OccupationSalary = c.OccupationSalary,
OccupationPosition = c.OccupationPosition,
OccupationPositionType = c.OccupationPositionType,
OccupationTelephone = c.OccupationTelephone,
RegisterDate = c.RegisterDate,
PositionName = c.PositionExam.PositionName,
PositionLevelName = c.PositionExam.PositionLevelName,
ContactFullName = $"{c.ContactPrefixName}{c.ContactFirstname} {c.ContactLastname}",
ContactRelations = c.ContactRelations,
ContactTel = c.ContactTel,
Number = c.Number,
ExamIdenNumber = c.ExamIdenNumber,
SeatNumber = c.SeatNumber,
PointTotalA = c.PointTotalA,
PointPath1A = c.PointPath1A,
PointPath2A = c.PointPath2A,
PointPath3A = c.PointPath3A,
PointA = c.PointA,
PointPerA = c.PointPerA,
ResultA = c.ResultA,
PointTotalB = c.PointTotalB,
PointB = c.PointB,
PointPerB = c.PointPerB,
ResultB = c.ResultB,
PointTotalC = c.PointTotalC,
PointPath1C = c.PointPath1C,
PointPath2C = c.PointPath2C,
PointC = c.PointC,
PointPerC = c.PointPerC,
ResultC = c.ResultC,
Pass = c.Pass,
ExamReason = c.ExamReason,
CreatedAt = c.CreatedAt,
})
.ToListAsync();
var _data = new List<object>();
if (candidates.Count > 0)
{
int num = 1;
foreach (var item in candidates)
{
var education = await _context.Educations
.AsQueryable()
.OrderBy(x => x.EducationEndDate)
.Where(x => x.Candidate.Id == item.Id)
.FirstOrDefaultAsync();
var careers = await _context.Careers
.AsQueryable()
.OrderBy(x => x.DurationStart)
.Where(x => x.Candidate.Id == item.Id)
.ToListAsync();
_data.Add(new
{
Num = num.ToString().ToThaiNumber(),
PositionName = item.PositionName != null && item.PositionLevelName != null ? $"{item.PositionName} {item.PositionLevelName}".ToThaiNumber() : "-",
FullName = item.FullName != null ? item.FullName.ToThaiNumber() : "-",
Nationality = item.Nationality != null ? item.Nationality.ToThaiNumber() : "-",
ReligionName = item.ReligionName != null ? item.ReligionName.ToThaiNumber() : "-",
DateOfBirth = item.DateOfBirth != null ? item.DateOfBirth.ToThaiNumber() : "-",
Age = item.Age != null ? item.Age.ToThaiNumber() : "-",
Telephone = item.Telephone != null ? item.Telephone.ToThaiNumber() : "-",
Email = item.Email != null ? item.Email : "-",
CitizenId = item.CitizenId != null ? item.CitizenId.ToThaiNumber() : "-",
EducationLevelExamName = education == null ? "-" : education.EducationLevelExamName.ToThaiNumber(),
EducationName = education == null ? "-" : education.EducationName.ToThaiNumber(),
EducationMajor = education == null ? "-" : education.EducationMajor.ToThaiNumber(),
EducationLocation = education == null ? "-" : education.EducationLocation.ToThaiNumber(),
EducationEndDate = education == null ? "-" : (education.EducationEndDate == null ? "-" : education.EducationEndDate.Value.Date.ToThaiShortDate().ToThaiNumber()),
EducationScores = education == null ? "-" : education.EducationScores.ToThaiNumber(),
EducationType = education == null ? "-" : education.EducationType.ToThaiNumber(),
EducationLevelHighName = education == null ? "-" : education.EducationLevelHighName.ToThaiNumber().ToThaiNumber(),
OccupationPositionType = item.OccupationPositionType == null ? "-" : GenerateStatusOccupation(item.OccupationPositionType),
OccupationPosition = item.OccupationPosition == null ? "-" : item.OccupationPosition.ToThaiNumber(),
OccupationSalary = item.OccupationSalary == null ? "-" : item.OccupationSalary.ToString().ToThaiNumber(),
OccupationGroup = item.OccupationGroup == null ? "-" : item.OccupationGroup.ToThaiNumber(),
OccupationPile = item.OccupationPile == null ? "-" : item.OccupationPile.ToThaiNumber(),
OccupationOrg = item.OccupationOrg == null ? "-" : item.OccupationOrg.ToThaiNumber(),
OccupationTelephone = item.OccupationTelephone == null ? "-" : item.OccupationTelephone.ToThaiNumber(),
Position = /*career.Position == null ? "-" : career.Position.ToThaiNumber()*/"-",
Type = /*career.Type == null ? "-" : career.Type*/"-",
DurationStart = /*career.DurationStart == null ? "-" : career.DurationStart.Date.ToThaiShortDate().ToThaiNumber()*/"-",
DurationEnd = /*career.DurationEnd == null ? "-" : career.DurationEnd.Date.ToThaiShortDate().ToThaiNumber()*/"-",
RangeDate = /*career.RangeDate == null ? "-" : career.RangeDate.ToThaiNumber()*/"-",
CurrentAddress = item.CurrentAddress == null ? "-" : item.CurrentAddress.ToThaiNumber(),
CurrentProvinceName = item.CurrentProvinceName == null ? "-" : item.CurrentProvinceName.ToThaiNumber(),
CurrentDistrictName = item.CurrentDistrictName == null ? "-" : item.CurrentDistrictName.ToThaiNumber(),
CurrentSubDistrictName = item.CurrentSubDistrictName == null ? "-" : item.CurrentSubDistrictName.ToThaiNumber(),
CurrentZipCode = item.CurrentZipCode == null ? "-" : item.CurrentZipCode.ToThaiNumber(),
RegistAddress = item.RegistAddress == null ? "-" : item.RegistAddress.ToThaiNumber(),
RegistProvinceName = item.RegistProvinceName == null ? "-" : item.RegistProvinceName.ToThaiNumber(),
RegistDistrictName = item.RegistDistrictName == null ? "-" : item.RegistDistrictName.ToThaiNumber(),
RegistSubDistrictName = item.RegistSubDistrictName == null ? "-" : item.RegistSubDistrictName.ToThaiNumber(),
RegistZipCode = item.RegistZipCode == null ? "-" : item.RegistZipCode.ToThaiNumber(),
ContactFullName = item.ContactFullName == null ? "-" : item.ContactFullName.ToThaiNumber(),
ContactRelations = item.ContactRelations == null ? "-" : item.ContactRelations.ToThaiNumber(),
ContactTel = item.ContactTel == null ? "-" : item.ContactTel.ToThaiNumber(),
CandidateStatus = GenerateStatusCandidate(item.Status),
Number = item.Number == null ? "-" : item.Number.ToThaiNumber(),
ExamIdenNumber = item.ExamIdenNumber == null ? "-" : item.ExamIdenNumber.ToThaiNumber(),
SeatNumber = item.SeatNumber == null ? "-" : item.SeatNumber.ToThaiNumber(),
PointTotalA = item.PointTotalA == null ? "-" : item.PointTotalA.ToThaiNumber(),
PointA = item.PointA == null ? "-" : item.PointA.ToThaiNumber(),
ResultA = item.ResultA == null ? "-" : item.ResultA.ToThaiNumber(),
PointTotalB = item.PointTotalB == null ? "-" : item.PointTotalB.ToThaiNumber(),
PointB = item.PointB == null ? "-" : item.PointB.ToThaiNumber(),
ResultB = item.ResultB == null ? "-" : item.ResultB.ToThaiNumber(),
PointTotalC = item.PointTotalC == null ? "-" : item.PointTotalC.ToThaiNumber(),
PointC = item.PointC == null ? "-" : item.PointC.ToThaiNumber(),
ResultC = item.ResultC == null ? "-" : item.ResultC.ToThaiNumber(),
Pass = item.Pass == null ? "-" : item.Pass.ToThaiNumber(),
CreatedAt = item.CreatedAt.Date == null ? "-" : item.CreatedAt.Date.ToThaiShortDate().ToThaiNumber(),
RegisterDate = item.RegisterDate.Value.Date == null ? "-" : $"{item.RegisterDate.Value.Date.ToThaiShortDate()} {item.RegisterDate.Value.ToString("HH:mm:ss.ffff")}".ToThaiNumber()
});
num = num + 1;
}
}
return new
{
template = "candidateDetail",
reportName = $"CandidateDetail_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}",
data = new
{
data = _data
}
};
}
public async Task<MemoryStream> GetsDashboardExamAsync(RequestCandidateDashboard item, string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
@ -1966,6 +2268,149 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return stream;
}
public async Task<dynamic> NewGetsDashboardExamAsync(RequestCandidateDashboard item, string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
var candidates = await _context.Candidates
.AsQueryable()
.OrderBy(x => x.ExamIdenNumber)
.Where(x => x.PeriodExam == periodExam)
.Where(x => x.Status != "register")
.Select(c => new
{
Id = c.Id,
Status = c.Status,
CitizenId = c.CitizenId,
FullName = $"{c.PrefixName}{c.FirstName} {c.LastName}",
Nationality = c.Nationality,
DateOfBirth = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.ToThaiShortDate(),
Age = c.DateOfBirth == null ? 0 : DateTime.Now.Date.Year - c.DateOfBirth.Value.Date.Year,
ReligionName = c.ReligionName,
Telephone = c.Telephone,
MobilePhone = c.MobilePhone,
Email = c.Email,
Knowledge = c.Knowledge,
RegistAddress = c.RegistAddress,
RegistProvinceName = c.RegistProvinceName,
RegistDistrictName = c.RegistDistrictName,
RegistSubDistrictName = c.RegistSubDistrictName,
RegistZipCode = c.RegistZipCode,
CurrentAddress = c.CurrentAddress,
CurrentProvinceName = c.CurrentProvinceName,
CurrentDistrictName = c.CurrentDistrictName,
CurrentSubDistrictName = c.CurrentSubDistrictName,
CurrentZipCode = c.CurrentZipCode,
OccupationOrg = c.OccupationOrg,
OccupationPile = c.OccupationPile,
OccupationGroup = c.OccupationGroup,
OccupationSalary = c.OccupationSalary,
OccupationPosition = c.OccupationPosition,
OccupationPositionType = c.OccupationPositionType,
OccupationTelephone = c.OccupationTelephone,
Number = c.Number,
ExamIdenNumber = c.ExamIdenNumber,
SeatNumber = c.SeatNumber,
PointTotalA = c.PointTotalA,
PointPath1A = c.PointPath1A,
PointPath2A = c.PointPath2A,
PointPath3A = c.PointPath3A,
PointA = c.PointA,
PointPerA = c.PointPerA,
ResultA = c.ResultA,
PointTotalB = c.PointTotalB,
PointB = c.PointB,
PointPerB = c.PointPerB,
ResultB = c.ResultB,
PointTotalC = c.PointTotalC,
PointPath1C = c.PointPath1C,
PointPath2C = c.PointPath2C,
PointC = c.PointC,
PointPerC = c.PointPerC,
ResultC = c.ResultC,
Pass = c.Pass,
ExamReason = c.ExamReason,
CreatedAt = c.CreatedAt,
})
.ToListAsync();
var educations = new List<object>();
var careers = new List<object>();
var ages = new {
one = "",
two = "",
three = "",
four = "",
five = "",
six = "",
};
var educationsCount = 0;
var careersCount = 0;
if (candidates.Count > 0)
{
educations = await _context.Educations
.AsQueryable()
.Where(x => x.Candidate.PeriodExam == periodExam)
.Where(x => x.Candidate.Status != "register")
.GroupBy(x => x.EducationLevelExamName)
.Select(x => (object)new
{
Name = x.Key,
ToTal = x.Count(),
Count = x.Count().ToString().ToThaiNumber(),
})
.ToListAsync();
educationsCount = educations.Sum(x => ((dynamic)x).ToTal);
careers = await _context.Careers
.AsQueryable()
.Where(x => x.Candidate.PeriodExam == periodExam)
.Where(x => x.Candidate.Status != "register")
.GroupBy(x => x.Position)
.Select(x => (object)new
{
Name = x.Key,
Total = x.Count(),
Count = x.Count().ToString().ToThaiNumber(),
})
.ToListAsync();
careersCount = careers.Sum(x => ((dynamic)x).Total);
ages = new
{
one = candidates.Where(x => x.Age >= 1 && x.Age <= 20).Count().ToString().ToThaiNumber(),
two = candidates.Where(x => x.Age >= 21 && x.Age <= 45).Count().ToString().ToThaiNumber(),
three = candidates.Where(x => x.Age >= 46 && x.Age <= 60).Count().ToString().ToThaiNumber(),
four = candidates.Where(x => x.Age >= 61 && x.Age <= 70).Count().ToString().ToThaiNumber(),
five = candidates.Where(x => x.Age >= 71 && x.Age <= 80).Count().ToString().ToThaiNumber(),
six = candidates.Where(x => x.Age >= 81).Count().ToString().ToThaiNumber(),
};
}
return new
{
template = "candidateDashboard",
reportName = $"สรุปข้อลการสมัครสอบ {periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}",
data = new
{
periodExamName = periodExam.Name.ToThaiNumber(),
periodExamRound = $"{periodExam.Round}/{periodExam.Year + 543}".ToThaiNumber(),
candidatesCount = candidates.Count().ToString().ToThaiNumber(),
educations = educations,
educationsCount = educationsCount.ToString().ToThaiNumber(),
careers = careers,
careersCount = careersCount.ToString().ToThaiNumber(),
ages = ages
}
};
}
public async Task<MemoryStream> DownloadCandidatePaymentAllAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()