Add Certificate Report
This commit is contained in:
parent
5cfdd1561d
commit
dfc9cb2e85
31 changed files with 3737 additions and 79 deletions
90
Controllers/BaseController.cs
Normal file
90
Controllers/BaseController.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using BMA.EHR.Core;
|
||||
using BMA.EHR.Report.Service.Responses;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BMA.EHR.Profile.Service.Controllers
|
||||
{
|
||||
public class BaseController : ControllerBase
|
||||
{
|
||||
#region " Methods "
|
||||
|
||||
#region " Protected "
|
||||
|
||||
#region " IActionResult "
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Success(string message, object? result = null)
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
return Ok(new ResponseObject
|
||||
{
|
||||
Status = StatusCodes.Status200OK,
|
||||
Message = message,
|
||||
Result = result
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new ResponseObject
|
||||
{
|
||||
Status = StatusCodes.Status200OK,
|
||||
Message = message
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Success(object? result = null)
|
||||
{
|
||||
return Success(GlobalMessages.Success, result);
|
||||
}
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Error(string message, string result, int statusCode = StatusCodes.Status500InternalServerError)
|
||||
{
|
||||
return StatusCode((int)statusCode, new ResponseObject
|
||||
{
|
||||
Status = statusCode,
|
||||
Message = message,
|
||||
Result = result
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Error(string message, int statusCode = StatusCodes.Status500InternalServerError)
|
||||
{
|
||||
return Error(message, message, statusCode);
|
||||
}
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Error(Exception exception, string message, int statusCode = StatusCodes.Status500InternalServerError)
|
||||
{
|
||||
var msg = exception.Message;
|
||||
var inner = exception.InnerException;
|
||||
while (inner != null)
|
||||
{
|
||||
msg += $" {inner.Message}\r\n";
|
||||
inner = inner.InnerException;
|
||||
}
|
||||
|
||||
return Error(message, msg, statusCode);
|
||||
}
|
||||
|
||||
protected virtual ActionResult<ResponseObject> Error(Exception exception, int statusCode = StatusCodes.Status500InternalServerError)
|
||||
{
|
||||
var msg = exception.Message;
|
||||
var inner = exception.InnerException;
|
||||
while (inner != null)
|
||||
{
|
||||
msg += $" {inner.Message}\r\n";
|
||||
inner = inner.InnerException;
|
||||
}
|
||||
|
||||
return Error(msg, msg, statusCode);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
121
Controllers/RecruitReportController.cs
Normal file
121
Controllers/RecruitReportController.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using BMA.EHR.Extensions;
|
||||
using BMA.EHR.Profile.Service.Controllers;
|
||||
using BMA.EHR.Report.Service.Data;
|
||||
using BMA.EHR.Report.Service.Responses;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using Telerik.Reporting;
|
||||
using Telerik.Reporting.Processing;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/report/recruit")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("รายงานข้อมูลการสอบแข่งขัน")]
|
||||
public class RecruitReportController : BaseController
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly string space = "ㅤ";
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public RecruitReportController(ApplicationDbContext context,
|
||||
IWebHostEnvironment hostingEnvironment,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
this._context = context;
|
||||
this._hostingEnvironment = hostingEnvironment;
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
/// <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("certificate/{id:length(36)}/{examId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetPeriodByIdAsync(Guid id, string examId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _context.Recruits.AsQueryable()
|
||||
.Include(x => x.RecruitImport)
|
||||
.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,
|
||||
p.CitizenId,
|
||||
Order = p.RecruitImport.Order,
|
||||
Year = p.RecruitImport.Year,
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||
EndDate = DateTime.Now.ToThaiShortDate2()
|
||||
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", "rptCertificate.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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue