diff --git a/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service.csproj
index 7bf765e..d5863cc 100644
--- a/BMA.EHR.Report.Service.csproj
+++ b/BMA.EHR.Report.Service.csproj
@@ -67,6 +67,9 @@
PreserveNewest
+
+ PreserveNewest
+
diff --git a/Controllers/RecruitReportController.cs b/Controllers/RecruitReportController.cs
index 10617f6..c95d7bd 100644
--- a/Controllers/RecruitReportController.cs
+++ b/Controllers/RecruitReportController.cs
@@ -1,5 +1,6 @@
using BMA.EHR.Extensions;
using BMA.EHR.Profile.Service.Controllers;
+using BMA.EHR.Recruit.Service.Services;
using BMA.EHR.Report.Service.Data;
using BMA.EHR.Report.Service.Responses;
using Microsoft.AspNetCore.Authorization;
@@ -26,6 +27,7 @@ namespace BMA.EHR.Report.Service.Controllers
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
private readonly string space = "ㅤ";
+ private readonly RecruitService _recruitService;
#endregion
@@ -33,34 +35,37 @@ namespace BMA.EHR.Report.Service.Controllers
public RecruitReportController(ApplicationDbContext context,
IWebHostEnvironment hostingEnvironment,
- IConfiguration configuration)
+ IConfiguration configuration,
+ RecruitService recruitService)
{
this._context = context;
this._hostingEnvironment = hostingEnvironment;
this._configuration = configuration;
+ this._recruitService = recruitService;
}
- #endregion
+ #endregion
- #region " Methods "
+ #region " Methods "
- ///
- /// แสดงหนังสือรับรอง
- ///
- /// รหัสรอบการสอบ
- /// เลขประจำตัวผู้สมัครสอบ
- ///
- /// เมื่อแสดงรายงานสำเร็จ
- /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง
- /// ไม่ได้ Login เข้าระบบ
- /// เมื่อเกิดข้อผิดพลาดในการทำงาน
+ ///
+ /// แสดงหนังสือรับรอง
+ ///
+ /// รหัสรอบการสอบ
+ /// เลขประจำตัวผู้สมัครสอบ
+ /// ชนิดของรายงาน
+ ///
+ /// เมื่อแสดงรายงานสำเร็จ
+ /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง
+ /// ไม่ได้ Login เข้าระบบ
+ /// เมื่อเกิดข้อผิดพลาดในการทำงาน
- [HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
+ [HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
- public async Task> GetPeriodByIdAsync(Guid id, string examId,int type)
+ public async Task> GetCertificateReportAsync(Guid id, string examId,int type)
{
try
{
@@ -77,10 +82,10 @@ namespace BMA.EHR.Report.Service.Controllers
ExamID = p.ExamId,
p.CitizenId,
Order = p.RecruitImport.Order,
- Year = p.RecruitImport.Year,
+ Year = p.RecruitImport.Year.ToThaiYear(),
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
ExamResult = sr == null ? "" : sr.ExamStatus,
- EndDate = DateTime.Now.ToThaiFullDate3(), // must replace from database
+ EndDate = p.RecruitImport.RegisterEndDate == null ? "-" : p.RecruitImport.RegisterEndDate.Value.ToThaiFullDate3(),
AuthName = "นายณัฐพงศ์ ดิษยบุตร",
AuthPosition = "หัวหน้าสำนักงาน ก.ก."
})
@@ -116,7 +121,99 @@ namespace BMA.EHR.Report.Service.Controllers
}
}
+ ///
+ /// แสดงเอกสารผลสอบ
+ ///
+ /// รหัสรอบการสอบ
+ /// เลขประจำตัวผู้สมัครสอบ
+ ///
+ /// เมื่อแสดงรายงานสำเร็จ
+ /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง
+ /// ไม่ได้ Login เข้าระบบ
+ /// เมื่อเกิดข้อผิดพลาดในการทำงาน
+ [HttpGet("score/{id:length(36)}/{examId}")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(StatusCodes.Status401Unauthorized)]
+ [ProducesResponseType(StatusCodes.Status500InternalServerError)]
+ public async Task> GetScoreReportAsync(Guid id, string examId)
+ {
+ try
+ {
+ var data = await _context.Recruits.AsQueryable()
+ .Include(x => x.RecruitImport)
+ .Include(x => x.Documents)
+ .ThenInclude(x => x.DocumentFile)
+ .Where(x => x.RecruitImport.Id == id)
+ .Where(x => x.ExamId == examId)
+ .Join(_context.RecruitScores.AsQueryable()
+ .Include(x => x.ScoreImport),
+ rc => new { rc.RecruitImport.Year, rc.ExamId },
+ sc => new { sc.ScoreImport.Year, sc.ExamId },
+ (p, sr) => new
+ {
+ ExamId= p.ExamId,
+ CitizenId = p.CitizenId,
+ p.Prefix,
+ FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
+ DateOfBirth = p.DateOfBirth.ToThaiShortDate(),
+ Gender = p.Gendor,
+ Degree = p.Educations.First().Degree,
+ Major = p.Educations.First().Major,
+
+ ExamResult = sr == null ? "" : sr.ExamStatus,
+
+ University = p.Educations.First().University,
+ PositionName = p.PositionName,
+ ExamName = $"{p.RecruitImport.Name} ครั้งที่ {p.RecruitImport.Order}/{p.RecruitImport.Year.ToThaiYear()}",
+
+
+ Number = sr == null ? "" : sr.Number,
+ ExamCount = _recruitService.GetExamCount(p.CitizenId),
+ ScoreExpire = p.RecruitImport.AnnouncementDate == null ? "" : p.RecruitImport.AnnouncementDate.Value.AddYears(2).ToThaiShortDate(),
- #endregion
- }
+
+ FullA = sr == null ? 0 : sr.FullA,
+ SumA = sr == null ? 0 : sr.SumA,
+ FullB = sr == null ? 0 : sr.FullB,
+ SumB = sr == null ? 0 : sr.SumB,
+ FullC = sr == null ? 0 : sr.FullC,
+ SumC = sr == null ? 0 : sr.SumC,
+
+
+
+ })
+ .FirstOrDefaultAsync();
+
+ var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptExamResult.trdp");
+ ReportPackager reportPackager = new ReportPackager();
+ Telerik.Reporting.Report report = null;
+ using (var sourceStream = System.IO.File.OpenRead(rptFile))
+ {
+ report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
+ }
+
+ report.DataSource = data;
+ System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
+
+ InstanceReportSource instanceReportSource = new InstanceReportSource()
+ {
+ ReportDocument = report
+ };
+
+
+ ReportProcessor reportProcessor = new ReportProcessor(_configuration);
+ RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
+
+ var content = result.DocumentBytes;
+ return File(content, "application/pdf", $"ผลคะแนนสอบ_{data.CitizenId}_{data.FullName}.pdf");
+ }
+ catch (Exception ex)
+ {
+ return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน");
+ }
+ }
+
+ #endregion
+ }
}
diff --git a/Models/Recruits/Recruit.cs b/Models/Recruits/Recruit.cs
index c089284..880f96e 100644
--- a/Models/Recruits/Recruit.cs
+++ b/Models/Recruits/Recruit.cs
@@ -76,5 +76,7 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
public DateTime ModifiedDate { get; set; }
public DateTime ApplyDate { get; set; }
+
+ public string? PositionName { get; set; }
}
}
diff --git a/Models/Recruits/RecruitImport.cs b/Models/Recruits/RecruitImport.cs
index 83cd1dc..9ea0f41 100644
--- a/Models/Recruits/RecruitImport.cs
+++ b/Models/Recruits/RecruitImport.cs
@@ -17,7 +17,39 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
[Required, Comment("ครั้งที่"), Column(Order = 3)]
public int Order { get; set; } = 1;
- public Document ImportFile { get; set; } = new Document();
+ [Column(Order = 4, TypeName = "text"), Comment("รายละเอียด")]
+ public string? Detail { get; set; }
+
+ [Column(Order = 5), Comment("ค่าธรรมเนียม")]
+ public int Fee { get; set; } = 0;
+
+ [Column(Order = 6), Comment("วันเริ่มประกาศ")]
+ public DateTime? AnnouncementStartDate { get; set; }
+
+ [Column(Order = 7), Comment("วันสิ้นสุดประกาศ")]
+ public DateTime? AnnouncementEndDate { get; set; }
+
+ [Column(Order = 8), Comment("วันเริ่มชำระเงิน")]
+ public DateTime? PaymentStartDate { get; set; }
+
+ [Column(Order = 9), Comment("วันสิ้นสุดชำระเงิน")]
+ public DateTime? PaymentEndDate { get; set; }
+
+ [Column(Order = 10), Comment("วันเริ่มสมัครสอบ")]
+ public DateTime? RegisterStartDate { get; set; }
+
+ [Column(Order = 11), Comment("วันสิ้นสุดสมัครสอบ")]
+ public DateTime? RegisterEndDate { get; set; }
+
+ [Column(Order = 12), Comment("วันที่สอบ")]
+ public DateTime? ExamDate { get; set; }
+
+ [Column(Order = 13, TypeName = "text"), Comment("หมายเหตุ")]
+ public string? Note { get; set; }
+
+ public DateTime? AnnouncementDate { get; set; }
+
+ public Document ImportFile { get; set; } = new Document();
public List Recruits { get; set; } = new List();
diff --git a/Models/Recruits/RecruitScore.cs b/Models/Recruits/RecruitScore.cs
index 43b1b10..67b0b5a 100644
--- a/Models/Recruits/RecruitScore.cs
+++ b/Models/Recruits/RecruitScore.cs
@@ -37,6 +37,8 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
[MaxLength(200)]
public string Major { get; set; }
+ public string? Number { get; set; } = string.Empty;
+
public ScoreImport ScoreImport { get; set; }
}
}
diff --git a/Program.cs b/Program.cs
index 7fd7df2..42c66c6 100644
--- a/Program.cs
+++ b/Program.cs
@@ -15,6 +15,7 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using BMA.EHR.Report.Service;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using BMA.EHR.Recruit.Service.Services;
var builder = WebApplication.CreateBuilder(args);
var issuer = builder.Configuration["Jwt:Issuer"];
@@ -69,8 +70,7 @@ BsonSerializer.RegisterSerializer(new DateTimeSerializer(BsonType.String));
// Register DbContext
var recruitConnection = builder.Configuration.GetConnectionString("RecruitConnection");
builder.Services.AddDbContext(options =>
- options.UseMySql(recruitConnection, ServerVersion.AutoDetect(recruitConnection), o => o.MigrationsHistoryTable("__ReportMigrationsHistory"))
-);
+ options.UseMySql(recruitConnection, ServerVersion.AutoDetect(recruitConnection), o => o.MigrationsHistoryTable("__ReportMigrationsHistory")), ServiceLifetime.Transient);
// Add config CORS
@@ -84,8 +84,7 @@ builder.Services.AddCors(options => options.AddDefaultPolicy(builder =>
}));
// Register Service
-//builder.Services.AddTransient();
-//builder.Services.AddTransient();
+builder.Services.AddTransient();
// Add services to the container.
builder.Services.AddControllers(options =>
diff --git a/Report/Recruit/rptCertificate1.trdp b/Report/Recruit/rptCertificate1.trdp
index bc4fcfd..17e4dd1 100644
Binary files a/Report/Recruit/rptCertificate1.trdp and b/Report/Recruit/rptCertificate1.trdp differ
diff --git a/Report/Recruit/rptExamResult.trdp b/Report/Recruit/rptExamResult.trdp
new file mode 100644
index 0000000..4b1b30c
Binary files /dev/null and b/Report/Recruit/rptExamResult.trdp differ
diff --git a/Services/RecruitService.cs b/Services/RecruitService.cs
new file mode 100644
index 0000000..af9d858
--- /dev/null
+++ b/Services/RecruitService.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using BMA.EHR.Recruit.Service.Models.Recruits;
+using BMA.EHR.Report.Service.Data;
+
+namespace BMA.EHR.Recruit.Service.Services
+{
+ public class RecruitService
+ {
+ private readonly ApplicationDbContext _context;
+
+ public RecruitService(ApplicationDbContext context)
+ {
+ _context = context;
+ }
+
+ public int GetExamCount(string citizenId)
+ {
+ try
+ {
+ var count = _context.Recruits.AsQueryable()
+ .Where(x => x.CitizenId == citizenId)
+ .Count();
+
+ return count;
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ public async Task GetExamAttributeAsync(Guid period, Guid exam)
+ {
+ try
+ {
+ var payment = await _context.RecruitPayments.AsQueryable()
+ .Include(x => x.Recruit)
+ .ThenInclude(x => x.RecruitImport)
+ .Where(x => x.Recruit.Id == exam)
+ .Where(x => x.Recruit.RecruitImport.Id == period)
+ .FirstOrDefaultAsync();
+
+ return payment != null ? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ";
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ public bool CheckValidCertificate(DateTime certDate, int nextYear = 5)
+ {
+ var valid = true;
+ if (DateTime.Now.Date > certDate.Date.AddYears(nextYear))
+ valid = false;
+
+ return valid;
+ }
+
+ }
+}
\ No newline at end of file