Change REport
This commit is contained in:
parent
55a83a43ec
commit
4987f7c5ad
9 changed files with 224 additions and 24 deletions
|
|
@ -67,6 +67,9 @@
|
||||||
<None Update="Report\Recruit\rptCertificate2.trdp">
|
<None Update="Report\Recruit\rptCertificate2.trdp">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Report\Recruit\rptExamResult.trdp">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using BMA.EHR.Extensions;
|
using BMA.EHR.Extensions;
|
||||||
using BMA.EHR.Profile.Service.Controllers;
|
using BMA.EHR.Profile.Service.Controllers;
|
||||||
|
using BMA.EHR.Recruit.Service.Services;
|
||||||
using BMA.EHR.Report.Service.Data;
|
using BMA.EHR.Report.Service.Data;
|
||||||
using BMA.EHR.Report.Service.Responses;
|
using BMA.EHR.Report.Service.Responses;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
@ -26,6 +27,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
||||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly string space = "ㅤ";
|
private readonly string space = "ㅤ";
|
||||||
|
private readonly RecruitService _recruitService;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -33,34 +35,37 @@ namespace BMA.EHR.Report.Service.Controllers
|
||||||
|
|
||||||
public RecruitReportController(ApplicationDbContext context,
|
public RecruitReportController(ApplicationDbContext context,
|
||||||
IWebHostEnvironment hostingEnvironment,
|
IWebHostEnvironment hostingEnvironment,
|
||||||
IConfiguration configuration)
|
IConfiguration configuration,
|
||||||
|
RecruitService recruitService)
|
||||||
{
|
{
|
||||||
this._context = context;
|
this._context = context;
|
||||||
this._hostingEnvironment = hostingEnvironment;
|
this._hostingEnvironment = hostingEnvironment;
|
||||||
this._configuration = configuration;
|
this._configuration = configuration;
|
||||||
|
this._recruitService = recruitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Methods "
|
#region " Methods "
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// แสดงหนังสือรับรอง
|
/// แสดงหนังสือรับรอง
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">รหัสรอบการสอบ</param>
|
/// <param name="id">รหัสรอบการสอบ</param>
|
||||||
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
||||||
/// <returns></returns>
|
/// <param name="type">ชนิดของรายงาน</param>
|
||||||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
/// <returns></returns>
|
||||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
|
||||||
[HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
|
[HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<ResponseObject>> GetPeriodByIdAsync(Guid id, string examId,int type)
|
public async Task<ActionResult<ResponseObject>> GetCertificateReportAsync(Guid id, string examId,int type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -77,10 +82,10 @@ namespace BMA.EHR.Report.Service.Controllers
|
||||||
ExamID = p.ExamId,
|
ExamID = p.ExamId,
|
||||||
p.CitizenId,
|
p.CitizenId,
|
||||||
Order = p.RecruitImport.Order,
|
Order = p.RecruitImport.Order,
|
||||||
Year = p.RecruitImport.Year,
|
Year = p.RecruitImport.Year.ToThaiYear(),
|
||||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||||
EndDate = DateTime.Now.ToThaiFullDate3(), // must replace from database
|
EndDate = p.RecruitImport.RegisterEndDate == null ? "-" : p.RecruitImport.RegisterEndDate.Value.ToThaiFullDate3(),
|
||||||
AuthName = "นายณัฐพงศ์ ดิษยบุตร",
|
AuthName = "นายณัฐพงศ์ ดิษยบุตร",
|
||||||
AuthPosition = "หัวหน้าสำนักงาน ก.ก."
|
AuthPosition = "หัวหน้าสำนักงาน ก.ก."
|
||||||
})
|
})
|
||||||
|
|
@ -116,7 +121,99 @@ namespace BMA.EHR.Report.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// แสดงเอกสารผลสอบ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">รหัสรอบการสอบ</param>
|
||||||
|
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("score/{id:length(36)}/{examId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> 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,
|
||||||
|
|
||||||
#endregion
|
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(),
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,5 +76,7 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
|
||||||
public DateTime ModifiedDate { get; set; }
|
public DateTime ModifiedDate { get; set; }
|
||||||
|
|
||||||
public DateTime ApplyDate { get; set; }
|
public DateTime ApplyDate { get; set; }
|
||||||
|
|
||||||
|
public string? PositionName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,39 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
|
||||||
[Required, Comment("ครั้งที่"), Column(Order = 3)]
|
[Required, Comment("ครั้งที่"), Column(Order = 3)]
|
||||||
public int Order { get; set; } = 1;
|
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<Recruit> Recruits { get; set; } = new List<Recruit>();
|
public List<Recruit> Recruits { get; set; } = new List<Recruit>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
|
||||||
[MaxLength(200)]
|
[MaxLength(200)]
|
||||||
public string Major { get; set; }
|
public string Major { get; set; }
|
||||||
|
|
||||||
|
public string? Number { get; set; } = string.Empty;
|
||||||
|
|
||||||
public ScoreImport ScoreImport { get; set; }
|
public ScoreImport ScoreImport { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ using MongoDB.Bson;
|
||||||
using MongoDB.Bson.Serialization;
|
using MongoDB.Bson.Serialization;
|
||||||
using BMA.EHR.Report.Service;
|
using BMA.EHR.Report.Service;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
using BMA.EHR.Recruit.Service.Services;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
var issuer = builder.Configuration["Jwt:Issuer"];
|
var issuer = builder.Configuration["Jwt:Issuer"];
|
||||||
|
|
@ -69,8 +70,7 @@ BsonSerializer.RegisterSerializer(new DateTimeSerializer(BsonType.String));
|
||||||
// Register DbContext
|
// Register DbContext
|
||||||
var recruitConnection = builder.Configuration.GetConnectionString("RecruitConnection");
|
var recruitConnection = builder.Configuration.GetConnectionString("RecruitConnection");
|
||||||
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
builder.Services.AddDbContext<ApplicationDbContext>(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
|
// Add config CORS
|
||||||
|
|
@ -84,8 +84,7 @@ builder.Services.AddCors(options => options.AddDefaultPolicy(builder =>
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Register Service
|
// Register Service
|
||||||
//builder.Services.AddTransient<ProfileService>();
|
builder.Services.AddTransient<RecruitService>();
|
||||||
//builder.Services.AddTransient<MinIOService>();
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllers(options =>
|
builder.Services.AddControllers(options =>
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
Report/Recruit/rptExamResult.trdp
Normal file
BIN
Report/Recruit/rptExamResult.trdp
Normal file
Binary file not shown.
65
Services/RecruitService.cs
Normal file
65
Services/RecruitService.cs
Normal file
|
|
@ -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<string> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue