parent
91a59936a0
commit
db98f8f6d6
2 changed files with 260 additions and 116 deletions
|
|
@ -665,6 +665,15 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// รายชื่อผู้มีสิทธิ์สอบ แสดงรายชื่อแบ่งตามตำแหน่ง (สอบคัดเลือกผู้พิการ)
|
||||
/// </summary>
|
||||
/// <param name="id">รหัสรอบการสอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("candidate-new/{id:length(36)}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
|
|
@ -681,9 +690,10 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
.OrderBy(x => x.ExamId)
|
||||
.Select(p => new
|
||||
{
|
||||
ExamId = !string.IsNullOrEmpty(p.ExamId) ? p.ExamId.ToThaiNumber() : "",
|
||||
FullName = $"{p.Prefix ?? ""}{p.FirstName ?? ""} {p.LastName ?? ""}",
|
||||
//PositionName = p.PositionName,
|
||||
PositionName = p.PositionName,
|
||||
Remark = !string.IsNullOrEmpty(p.Remark) ? p.Remark.ToThaiNumber() : "",
|
||||
ExamId = !string.IsNullOrEmpty(p.ExamId) ? p.ExamId.ToThaiNumber() : "",
|
||||
ExamName =
|
||||
($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}").ToThaiNumber(),
|
||||
}).ToListAsync();
|
||||
|
|
@ -691,6 +701,24 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
if (data.Count == 0)
|
||||
return Error("ไม่พบข้อมูลในระบบ");
|
||||
|
||||
var examName = data.First().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(),
|
||||
ExamId = x.ExamId,
|
||||
FullName = x.FullName,
|
||||
Remark = x.Remark
|
||||
}).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// เตรียม MemoryStream
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
|
|
@ -699,41 +727,57 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
using (var pdf = new PdfDocument(writer))
|
||||
using (var document = new Document(pdf, iText.Kernel.Geom.PageSize.A4))
|
||||
{
|
||||
// font TH-Sarabun
|
||||
// กำหนดฟ้อนต์ TH-Sarabun
|
||||
var fontPath = System.IO.Path.Combine(Environment.CurrentDirectory, "Fonts", "THSarabun.ttf");
|
||||
var font = PdfFontFactory.CreateFont(fontPath, "Identity-H");
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
|
||||
// margin top, right, bottom, left
|
||||
// ตั้งค่าระยะขอบ top, right, bottom, left
|
||||
document.SetMargins(30, 15, 20, 15);
|
||||
|
||||
// title
|
||||
var title = new Paragraph($"รายชื่อผู้มีสิทธิ์สอบ\n{data.First().ExamName ?? ""}")
|
||||
// Title
|
||||
var title = new Paragraph($"รายชื่อผู้มีสิทธิ์สอบ\n{examName ?? ""}")
|
||||
.SetBold()
|
||||
.SetTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
document.Add(title);
|
||||
|
||||
// create Table
|
||||
var table = new iText.Layout.Element.Table(iText.Layout.Properties.UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();
|
||||
|
||||
// header
|
||||
string[] headers = { "เลขประจำตัวสอบ", "ชื่อ - นามสกุล" };
|
||||
foreach (var h in headers)
|
||||
// Loop Groups
|
||||
foreach (var group in groupData)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h)).SetTextAlignment(TextAlignment.CENTER).SetBold());
|
||||
}
|
||||
// details
|
||||
foreach (var x in data)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.ExamId)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
}
|
||||
// Group Header (ตำแหน่ง)
|
||||
Paragraph positionHeader = new Paragraph($"{group.PositionName} {group.Total}")
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold()
|
||||
.SetFontSize(15)
|
||||
.SetMarginBottom(10);
|
||||
|
||||
document.Add(table);
|
||||
document.Add(positionHeader);
|
||||
|
||||
var table = new iText.Layout.Element.Table(new float[] { 1, 2, 3, 2 }).UseAllAvailableWidth();
|
||||
table.SetWidth(UnitValue.CreatePercentValue(100));
|
||||
|
||||
// Table Header
|
||||
string[] headers = { "ลำดับที่", "เลขประจำตัวสอบ", "ชื่อ-สกุล", "หมายเหตุ" };
|
||||
foreach (var h in headers)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h)).SetTextAlignment(TextAlignment.CENTER).SetBold());
|
||||
}
|
||||
|
||||
// Table Details
|
||||
foreach (var x in group.Persons)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.No)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.ExamId)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.Remark ?? "")).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
document.Add(table);
|
||||
// เว้นระหว่าง groups
|
||||
document.Add(new Paragraph("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}");
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{examName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -742,6 +786,15 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// รายชื่อผู้สอบแข่งขันได้ แสดงรายชื่อแบ่งตามตำแหน่ง (สอบคัดเลือกผู้พิการ)
|
||||
/// </summary>
|
||||
/// <param name="id">รหัสรอบการสอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("pass-new/{id:length(36)}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
|
|
@ -755,8 +808,6 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
var data = await _context.Disables.AsQueryable()
|
||||
.Include(x => x.PeriodExam)
|
||||
.ThenInclude(x => x.ScoreImport)
|
||||
.Include(x => x.Documents)
|
||||
.ThenInclude(x => x.DocumentFile)
|
||||
.Join(_context.DisableScores.AsQueryable()
|
||||
.Include(x => x.ScoreImport)
|
||||
.Where(x => x.ScoreImport.PeriodExamId == id)
|
||||
|
|
@ -765,7 +816,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
sc => new { id = sc.ScoreImport.PeriodExamId, examId = sc.ExamId },
|
||||
(p, sr) => new
|
||||
{
|
||||
Id = p.PeriodExam.Id,
|
||||
PositionName = p.PositionName,
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||
ExamName = $"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round.ToString().ToThaiNumber()}/{p.PeriodExam.Year.Value.ToThaiYear().ToString().ToThaiNumber()}",
|
||||
|
|
@ -775,65 +826,83 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
: (((double)(sr.SumA > 0 ? sr.SumA : 0) + (sr.SumB > 0 ? sr.SumB : 0) + (sr.SumC > 0 ? sr.SumC : 0)).ToString("0.00")).ToThaiNumber(),
|
||||
})
|
||||
.OrderBy(x => x.Number)
|
||||
.Where(x => x.Id == id)
|
||||
.Where(x => x.ExamResult == "ผ่าน")
|
||||
.ToListAsync();
|
||||
|
||||
if (data.Count == 0)
|
||||
return Error("ไม่พบข้อมูลในระบบ");
|
||||
|
||||
var result = data.Select(x => new
|
||||
{
|
||||
Number = x.Number > 0 ? x.Number.ToString().ToThaiNumber() : "",
|
||||
x.FullName,
|
||||
x.SumScore
|
||||
}).ToList();
|
||||
var examName = data.First().ExamName;
|
||||
|
||||
// Group by PositionName
|
||||
var groupData = data
|
||||
.GroupBy(g => g.PositionName)
|
||||
.Select(g => new
|
||||
{
|
||||
PositionName = $"ตำแหน่ง {g.Key}",
|
||||
Total = $"จำนวน {g.Count().ToString().ToThaiNumber()} ราย",
|
||||
Persons = g.Select((x) => new
|
||||
{
|
||||
Number = x.Number > 0 ? x.Number.ToString().ToThaiNumber() : "",
|
||||
FullName = x.FullName,
|
||||
SumScore = x.SumScore
|
||||
}).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// เตรียม MemoryStream
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
// สร้าง PDF document
|
||||
using (var writer = new PdfWriter(stream))
|
||||
using (var pdf = new PdfDocument(writer))
|
||||
using (var document = new Document(pdf, iText.Kernel.Geom.PageSize.A4))
|
||||
{
|
||||
// font TH-Sarabun
|
||||
var fontPath = System.IO.Path.Combine(Environment.CurrentDirectory, "Fonts", "THSarabun.ttf");
|
||||
var font = PdfFontFactory.CreateFont(fontPath, "Identity-H");
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
|
||||
// margin top, right, bottom, left
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
document.SetMargins(30, 15, 20, 15);
|
||||
|
||||
// title
|
||||
var title = new Paragraph($"รายชื่อผู้สอบแข่งขันได้\n{data.First().ExamName ?? ""}")
|
||||
var title = new Paragraph($"รายชื่อผู้สอบแข่งขันได้\n{examName}")
|
||||
.SetBold()
|
||||
.SetTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
document.Add(title);
|
||||
|
||||
// create Table
|
||||
var table = new iText.Layout.Element.Table(iText.Layout.Properties.UnitValue.CreatePercentArray(4)).UseAllAvailableWidth();
|
||||
|
||||
// header
|
||||
string[] headers = { "ลำดับที่", "สนามสอบ", "ชื่อ - นามสกุล", "คะแนนสอบ" };
|
||||
foreach (var h in headers)
|
||||
foreach (var g in groupData)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h)).SetTextAlignment(TextAlignment.CENTER).SetBold());
|
||||
}
|
||||
// details
|
||||
foreach (var x in result)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.Number)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell());
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.SumScore)).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
// Header per group
|
||||
Paragraph positionHeader = new Paragraph($"{g.PositionName} {g.Total}")
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold()
|
||||
.SetFontSize(15)
|
||||
.SetMarginBottom(10);
|
||||
|
||||
document.Add(table);
|
||||
document.Add(positionHeader);
|
||||
|
||||
var table = new iText.Layout.Element.Table(new float[] { 1, 2, 3, 2 }).UseAllAvailableWidth();
|
||||
table.SetWidth(UnitValue.CreatePercentValue(100));
|
||||
|
||||
string[] headers = { "ลำดับที่", "สนามสอบ", "ชื่อ - นามสกุล", "คะแนนสอบ" };
|
||||
foreach (var h in headers)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h))
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold());
|
||||
}
|
||||
|
||||
foreach (var p in g.Persons)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.Number)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell());
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.SumScore)).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
|
||||
document.Add(table);
|
||||
document.Add(new Paragraph("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}");
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{examName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// แสดงรายชื่อแบ่งตามตำแหน่ง (สอบแข่งขัน)
|
||||
/// รายชื่อผู้มีสิทธิ์สอบ แสดงรายชื่อแบ่งตามตำแหน่ง (สอบแข่งขัน)
|
||||
/// </summary>
|
||||
/// <param name="id">รหัสรอบการสอบ</param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -342,32 +342,32 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("candidate-new/{id:length(36)}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetCandidateNewListReportAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _context.Recruits.AsQueryable()
|
||||
.Include(x => x.RecruitImport)
|
||||
.Include(x => x.Payments)
|
||||
.Include(x => x.Documents)
|
||||
.ThenInclude(x => x.DocumentFile)
|
||||
.Where(x => x.RecruitImport.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()
|
||||
: "",
|
||||
Remark = !string.IsNullOrEmpty(p.Remark) ? p.Remark.ToThaiNumber() : "",
|
||||
ExamId = !string.IsNullOrEmpty(p.ExamId) ? p.ExamId.ToThaiNumber() : "",
|
||||
ExamName =
|
||||
$"ครั้งที่ {(p.RecruitImport != null ? p.RecruitImport.Order.ToString().ToThaiNumber() : "")}/{(p.RecruitImport != null ? p.RecruitImport.Year.ToThaiYear().ToString().ToThaiNumber() : "")}",
|
||||
}).ToListAsync();
|
||||
|
||||
if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ");
|
||||
if (data.Count == 0)
|
||||
return Error("ไม่พบข้อมูลในระบบ");
|
||||
|
||||
var examName = data[0].ExamName;
|
||||
var examName = data.First().ExamName;
|
||||
|
||||
var groupData = data
|
||||
.GroupBy(x => x.PositionName)
|
||||
|
|
@ -378,25 +378,75 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
Persons = g.Select((x, index) => new
|
||||
{
|
||||
No = (index + 1).ToString().ToThaiNumber(),
|
||||
RefNo1 = x.RefNo1,
|
||||
ExamId = x.ExamId,
|
||||
FullName = x.FullName,
|
||||
Remark = x.Remark
|
||||
}).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var _data = new
|
||||
// เตรียม MemoryStream
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
template = "rptCandidateList-New",
|
||||
reportName = $"รายชื่อแบ่งตามตำแหน่ง(สอบแข่งขัน)",
|
||||
data = new
|
||||
// สร้าง PDF document
|
||||
using (var writer = new PdfWriter(stream))
|
||||
using (var pdf = new PdfDocument(writer))
|
||||
using (var document = new Document(pdf, iText.Kernel.Geom.PageSize.A4))
|
||||
{
|
||||
examName = examName,
|
||||
data = groupData
|
||||
}
|
||||
};
|
||||
return Success(_data);
|
||||
// กำหนดฟ้อนต์ TH-Sarabun
|
||||
var fontPath = System.IO.Path.Combine(Environment.CurrentDirectory, "Fonts", "THSarabun.ttf");
|
||||
var font = PdfFontFactory.CreateFont(fontPath, "Identity-H");
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
|
||||
// ตั้งค่าระยะขอบ top, right, bottom, left
|
||||
document.SetMargins(30, 15, 20, 15);
|
||||
|
||||
// Title
|
||||
var title = new Paragraph(
|
||||
$"รายชื่อผู้ชำระค่าธรรมเนียมการสมัครสอบการแข่งขันเพื่อบรรจุและแต่งตั้งบุคคลเข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ {examName ?? ""}"
|
||||
)
|
||||
.SetBold()
|
||||
.SetTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
document.Add(title);
|
||||
|
||||
// Loop Groups
|
||||
foreach (var group in groupData)
|
||||
{
|
||||
// Group Header (ตำแหน่ง)
|
||||
Paragraph positionHeader = new Paragraph($"{group.PositionName} {group.Total}")
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold()
|
||||
.SetFontSize(15)
|
||||
.SetMarginBottom(10);
|
||||
|
||||
document.Add(positionHeader);
|
||||
|
||||
var table = new iText.Layout.Element.Table(new float[] { 1, 2, 3, 2 }).UseAllAvailableWidth();
|
||||
table.SetWidth(UnitValue.CreatePercentValue(100));
|
||||
|
||||
// Table Header
|
||||
string[] headers = { "ลำดับที่", "เลขประจำตัวสอบ", "ชื่อ-สกุล", "หมายเหตุ" };
|
||||
foreach (var h in headers)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h)).SetTextAlignment(TextAlignment.CENTER).SetBold());
|
||||
}
|
||||
|
||||
// Table Details
|
||||
foreach (var x in group.Persons)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.No)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.ExamId)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.Remark ?? "")).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
document.Add(table);
|
||||
// เว้นระหว่าง groups
|
||||
document.Add(new Paragraph("\n"));
|
||||
}
|
||||
}
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{examName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -476,21 +526,28 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// รายชื่อผู้สอบแข่งขันได้ แสดงรายชื่อแบ่งตามตำแหน่ง (สอบแข่งขัน)
|
||||
/// </summary>
|
||||
/// <param name="id">รหัสรอบการสอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("pass-new/{id:length(36)}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetPassExamListNewReportAsync(Guid id)
|
||||
public async Task<ActionResult<ResponseObject>> GetPassExamNewListReportAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _context.Recruits.AsQueryable()
|
||||
.Include(x => x.RecruitImport)
|
||||
.ThenInclude(x => x.ScoreImport)
|
||||
.Include(x => x.Documents)
|
||||
.ThenInclude(x => x.DocumentFile)
|
||||
.Join(_context.RecruitScores.AsQueryable()
|
||||
.Include(x => x.ScoreImport)
|
||||
.Where(x => x.ScoreImport.RecruitImportId == id)
|
||||
|
|
@ -499,7 +556,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
sc => new { id = sc.ScoreImport.RecruitImportId, examId = sc.ExamId },
|
||||
(p, sr) => new
|
||||
{
|
||||
Id = p.RecruitImport.Id,
|
||||
PositionName = p.PositionName,
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||
ExamName = p.RecruitImport.Order == null
|
||||
|
|
@ -511,65 +568,83 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
: (((decimal)(sr.SumA > 0 ? sr.SumA : 0) + (sr.SumB > 0 ? sr.SumB : 0) + (sr.SumC > 0 ? sr.SumC : 0)).ToString("0.00")).ToThaiNumber(),
|
||||
})
|
||||
.OrderBy(x => x.Number)
|
||||
.Where(x => x.Id == id)
|
||||
.Where(x => x.ExamResult == "ผ่าน")
|
||||
.ToListAsync();
|
||||
|
||||
if (data.Count == 0)
|
||||
return Error("ไม่พบข้อมูลในระบบ");
|
||||
|
||||
var result = data.Select(x => new
|
||||
{
|
||||
Number = x.Number > 0 ? x.Number.ToString().ToThaiNumber() : "",
|
||||
x.FullName,
|
||||
x.SumScore
|
||||
}).ToList();
|
||||
var examName = data.First().ExamName;
|
||||
|
||||
// Group by PositionName
|
||||
var groupData = data
|
||||
.GroupBy(g => g.PositionName)
|
||||
.Select(g => new
|
||||
{
|
||||
PositionName = $"ตำแหน่ง {g.Key}",
|
||||
Total = $"จำนวน {g.Count().ToString().ToThaiNumber()} ราย",
|
||||
Persons = g.Select((x) => new
|
||||
{
|
||||
Number = x.Number > 0 ? x.Number.ToString().ToThaiNumber() : "",
|
||||
FullName = x.FullName,
|
||||
SumScore = x.SumScore
|
||||
}).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// เตรียม MemoryStream
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
// สร้าง PDF document
|
||||
using (var writer = new PdfWriter(stream))
|
||||
using (var pdf = new PdfDocument(writer))
|
||||
using (var document = new Document(pdf, iText.Kernel.Geom.PageSize.A4))
|
||||
{
|
||||
// font TH-Sarabun
|
||||
var fontPath = System.IO.Path.Combine(Environment.CurrentDirectory, "Fonts", "THSarabun.ttf");
|
||||
var font = PdfFontFactory.CreateFont(fontPath, "Identity-H");
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
|
||||
// margin top, right, bottom, left
|
||||
document.SetFont(font).SetFontSize(16);
|
||||
document.SetMargins(30, 15, 20, 15);
|
||||
|
||||
// title
|
||||
var title = new Paragraph($"รายชื่อผู้สอบแข่งขันได้\n{data.First().ExamName ?? ""}")
|
||||
var title = new Paragraph($"รายชื่อผู้สอบแข่งขันได้\n{examName}")
|
||||
.SetBold()
|
||||
.SetTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
document.Add(title);
|
||||
|
||||
// create Table
|
||||
var table = new iText.Layout.Element.Table(iText.Layout.Properties.UnitValue.CreatePercentArray(4)).UseAllAvailableWidth();
|
||||
|
||||
// header
|
||||
string[] headers = { "ลำดับที่", "สนามสอบ", "ชื่อ - นามสกุล", "คะแนนสอบ" };
|
||||
foreach (var h in headers)
|
||||
foreach (var g in groupData)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h)).SetTextAlignment(TextAlignment.CENTER).SetBold());
|
||||
}
|
||||
// details
|
||||
foreach (var x in result)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.Number)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell());
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(x.SumScore)).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
// Header per group
|
||||
Paragraph positionHeader = new Paragraph($"{g.PositionName} {g.Total}")
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold()
|
||||
.SetFontSize(15)
|
||||
.SetMarginBottom(10);
|
||||
|
||||
document.Add(table);
|
||||
document.Add(positionHeader);
|
||||
|
||||
var table = new iText.Layout.Element.Table(new float[] { 1, 2, 3, 2 }).UseAllAvailableWidth();
|
||||
table.SetWidth(UnitValue.CreatePercentValue(100));
|
||||
|
||||
string[] headers = { "ลำดับที่", "สนามสอบ", "ชื่อ - นามสกุล", "คะแนนสอบ" };
|
||||
foreach (var h in headers)
|
||||
{
|
||||
table.AddHeaderCell(new Cell().Add(new Paragraph(h))
|
||||
.SetTextAlignment(TextAlignment.CENTER)
|
||||
.SetBold());
|
||||
}
|
||||
|
||||
foreach (var p in g.Persons)
|
||||
{
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.Number)).SetTextAlignment(TextAlignment.CENTER));
|
||||
table.AddCell(new Cell());
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.FullName)).SetTextAlignment(TextAlignment.LEFT));
|
||||
table.AddCell(new Cell().Add(new Paragraph(p.SumScore)).SetTextAlignment(TextAlignment.CENTER));
|
||||
}
|
||||
|
||||
document.Add(table);
|
||||
document.Add(new Paragraph("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}");
|
||||
return File(stream.ToArray(), "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{examName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue