diff --git a/Controllers/DisableController.cs b/Controllers/DisableController.cs
index 183ccaa..53e9d38 100644
--- a/Controllers/DisableController.cs
+++ b/Controllers/DisableController.cs
@@ -974,19 +974,19 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
.Where(x => x.CheckDisability == true)
.Include(x => x.ImportHostories)
.Include(x => x.ImportFile)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Addresses)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Occupations)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Certificates)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Educations)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Payments)
- .Include(x => x.Disables)
- .ThenInclude(x => x.Documents)
- .ThenInclude(x => x.DocumentFile)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Addresses)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Occupations)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Certificates)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Educations)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Payments)
+ //.Include(x => x.Disables)
+ //.ThenInclude(x => x.Documents)
+ //.ThenInclude(x => x.DocumentFile)
.Include(x => x.ScoreImport)
.ThenInclude(x => x.ImportFile)
.Include(x => x.ScoreImport)
@@ -1895,6 +1895,11 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
cmd.Parameters.Add(new MySqlParameter("@r", req.ExamResult));
}
+ 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();
@@ -1936,8 +1941,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
}
}
- if (data != null && data.Count > 0)
- data = data.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
+ //if (data != null && data.Count > 0)
+ // data = data.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
dynamic header = null;
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
diff --git a/Controllers/DisableReportController.cs b/Controllers/DisableReportController.cs
index 0b699ff..81bf835 100644
--- a/Controllers/DisableReportController.cs
+++ b/Controllers/DisableReportController.cs
@@ -12,6 +12,10 @@ using Telerik.Reporting;
using Telerik.Reporting.Processing;
using BMA.EHR.Recurit.Exam.Service.Response;
using BMA.EHR.Recurit.Exam.Service.Models;
+using OfficeOpenXml.Style;
+using OfficeOpenXml;
+using System.Drawing;
+using Nest;
namespace BMA.EHR.Recurit.Exam.Service.Controllers
{
@@ -251,6 +255,135 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
}
}
+ ///
+ /// รายงานรายชื่อผู้มีสิทธิ์สอบ
+ ///
+ /// รหัสรอบการสอบแข่งขัน
+ ///
+ [HttpGet("candidate-new/{id:length(36)}")]
+ public async Task GetCandidateNewListReportAsync(Guid id)
+ {
+ var data = await _context.Disables.AsQueryable()
+ .Include(x => x.PeriodExam)
+ .Where(x => x.PeriodExam.Id == id)
+ .OrderBy(x => x.ExamId)
+ .Select(p => new
+ {
+ FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
+ PositionName = p.PositionName,
+ Remark = p.Remark != null ? p.Remark.ToThaiNumber() : "",
+ RefNo1 = p.Payments.Select(x => x.RefNo1).FirstOrDefault() != null
+ ? p.Payments.Select(x => x.RefNo1).FirstOrDefault().ToThaiNumber()
+ : "",
+ ExamName =
+ $"{p.PeriodExam.Name} ครั้งที่ {(p.PeriodExam != null ? p.PeriodExam.Round.ToString().ToThaiNumber() : "")}/{(p.PeriodExam.Year > 2500 ? p.PeriodExam.Year.ToString().ToThaiNumber() : (p.PeriodExam.Year+543).ToString().ToThaiNumber())}",
+ }).ToListAsync();
+
+ if (data.Count == 0)
+ {
+ return NotFound(new { Message = "ไม่พบข้อมูลในระบบ" });
+ }
+
+ var examName = data[0].ExamName;
+
+ var groupData = data
+ .GroupBy(x => x.PositionName)
+ .Select(g => new
+ {
+ PositionName = $"ตำแหน่ง {g.Key}",
+ Total = $"จำนวน {g.Count().ToString().ToThaiNumber()} ราย",
+ Persons = g.Select((x, index) => new
+ {
+ No = (index + 1).ToString().ToThaiNumber(),
+ RefNo1 = x.RefNo1,
+ FullName = x.FullName,
+ Remark = x.Remark
+ }).ToList()
+ })
+ .ToList();
+
+ using var package = new ExcelPackage();
+ var ws = package.Workbook.Worksheets.Add(examName);
+ // ตั้งค่า Font ทั้ง sheet
+ ws.Cells.Style.Font.Name = "TH Sarabun PSK";
+ ws.Cells.Style.Font.Size = 14;
+ int row = 1;
+
+ // ======= Header =======
+ ws.Cells[row, 1, row + 2, 4].Merge = true;
+ ws.Cells[row, 1].Value = $"รายชื่อผู้มีสิทธิ์สอบ" +
+ $"{examName}";
+
+ ws.Cells[row, 1].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
+ ws.Cells[row, 1].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
+ ws.Cells[row, 1].Style.Font.Bold = true;
+ ws.Cells[row, 1].Style.WrapText = true;
+
+ row += 4;
+
+ foreach (var group in groupData)
+ {
+ // ======= Position Header =======
+ ws.Cells[row, 1, row + 1, 4].Merge = true; // merge 2 แถว และ column A-D
+ ws.Cells[row, 1].Value = $"{group.PositionName}\n{group.Total}";
+ ws.Cells[row, 1].Style.Font.Bold = true;
+ ws.Cells[row, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
+ ws.Cells[row, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
+ ws.Cells[row, 1].Style.WrapText = true;
+
+ row += 2; // ขยับ row ไปหลัง header ที่ merge 2 แถว
+
+ // ======= Table Header =======
+ ws.Cells[row, 1].Value = "ลำดับ";
+ ws.Cells[row, 2].Value = "เลขประจำตัวสอบ";
+ ws.Cells[row, 3].Value = "ชื่อ-สกุล";
+ ws.Cells[row, 4].Value = "หมายเหตุ";
+
+ ws.Cells[row, 1, row, 4].Style.Font.Bold = true;
+ ws.Cells[row, 1, row, 4].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
+ ws.Cells[row, 1, row, 4].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
+ ws.Cells[row, 1, row, 4].Style.Fill.PatternType = ExcelFillStyle.Solid;
+ ws.Cells[row, 1, row, 4].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
+
+ row++;
+
+ // ======= Table Detail =======
+ foreach (var person in group.Persons)
+ {
+ ws.Cells[row, 1].Value = person.No;
+ ws.Cells[row, 2].Value = person.RefNo1;
+ ws.Cells[row, 3].Value = person.FullName;
+ ws.Cells[row, 4].Value = person.Remark;
+
+ // จัดกลางเฉพาะ No และ RefNo1
+ ws.Cells[row, 1, row, 2].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
+ ws.Cells[row, 1, row, 2].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
+
+ // เพิ่มกรอบให้แต่ละ cell
+ for (int col = 1; col <= 4; col++)
+ {
+ ws.Cells[row, col].Style.Border.Top.Style = ExcelBorderStyle.Thin;
+ ws.Cells[row, col].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
+ ws.Cells[row, col].Style.Border.Left.Style = ExcelBorderStyle.Thin;
+ ws.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
+ }
+
+ row++;
+ }
+
+ row++;
+ }
+
+ ws.Cells.AutoFitColumns();
+
+ var fileBytes = package.GetAsByteArray();
+ var fileName = $"รายชื่อผู้สอบ_{examName}.xlsx";
+
+ return File(fileBytes,
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ fileName);
+ }
+
#endregion
}
}
diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs
index abbd615..c26cce0 100644
--- a/Core/RequestLoggingMiddleware.cs
+++ b/Core/RequestLoggingMiddleware.cs
@@ -165,19 +165,66 @@ namespace BMA.EHR.Recurit.Exam.Service.Core
// อ่านข้อมูลจาก Response หลังจากที่ได้ถูกส่งออกไป
memoryStream.Seek(0, SeekOrigin.Begin);
var responseBody = new StreamReader(memoryStream).ReadToEnd();
- if (responseBody != "")
- responseBodyJson = JsonSerializer.Serialize(JsonSerializer.Deserialize