Merge branch 'develop' into working
This commit is contained in:
commit
fb5ffde9d3
30 changed files with 49951 additions and 51 deletions
|
|
@ -10,6 +10,8 @@ using DocumentFormat.OpenXml.Drawing;
|
|||
using Telerik.Reporting;
|
||||
using Telerik.Reporting.Processing;
|
||||
using System.IO;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Report.Service.Requests;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
|
|
@ -26,18 +28,25 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly GenericReportGenerator _reportGenerator;
|
||||
|
||||
private readonly RetireReportRepository _repository;
|
||||
private readonly MinIOService _documentService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constuctor and Destructor "
|
||||
|
||||
public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator)
|
||||
public DeceasedReportController(IWebHostEnvironment hostingEnvironment,
|
||||
IConfiguration configuration,
|
||||
MinIOService documentService,
|
||||
GenericReportGenerator reportGenerator,
|
||||
RetireReportRepository repository)
|
||||
{
|
||||
|
||||
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_configuration = configuration;
|
||||
_reportGenerator = reportGenerator;
|
||||
_repository = repository;
|
||||
_documentService = documentService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -55,23 +64,74 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("36/{exportType}/{id}")]
|
||||
public IActionResult GetDeceasedConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
public async Task<ActionResult<ResponseObject>> GetDeceasedReportAsync(Guid id, string exportType = "pdf")
|
||||
{
|
||||
try
|
||||
{
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
var data = await _repository.GetRetirementDeceasedAsync(id);
|
||||
if (data != null)
|
||||
{
|
||||
case "pdf": mimeType = "application/pdf"; break;
|
||||
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
|
||||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
{
|
||||
case "pdf": mimeType = "application/pdf"; break;
|
||||
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
|
||||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
}
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp");
|
||||
ReportPackager reportPacker = new ReportPackager();
|
||||
Telerik.Reporting.Report? report = null;
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||||
{
|
||||
report = (Telerik.Reporting.Report)reportPacker.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($"{exportType}", instanceReportSource, deviceInfo);
|
||||
return File(result.DocumentBytes, mimeType, $"deceased.{exportType.Trim().ToLower()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp");
|
||||
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
|
||||
|
||||
return File(contentData, mimeType, $"deceased.{exportType.Trim().ToLower()}");
|
||||
|
||||
/// <summary>
|
||||
/// อัปไฟล์บันทึกเวียนแจ้งการถึงแก่กรรม
|
||||
/// </summary>
|
||||
/// <param name="id">id </param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("attachment/36/{id}")]
|
||||
public async Task<ActionResult<ResponseObject>> UploadDeceasedReportAsync([FromForm] FileRequest req, Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _repository.GetRetirementDeceasedAsync(id);
|
||||
if (data == null)
|
||||
return NotFound();
|
||||
// check upload file
|
||||
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
||||
{
|
||||
return Error(GlobalMessages.NoFileToUpload);
|
||||
}
|
||||
var file = Request.Form.Files[0];
|
||||
var cover = await _documentService.UploadFileAsync(file);
|
||||
await _repository.UploadFileRetirementDeceasedAsync(id, cover);
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
10
BMA.EHR.Report.Service/Requests/FileRequest.cs
Normal file
10
BMA.EHR.Report.Service/Requests/FileRequest.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Requests
|
||||
{
|
||||
public class FileRequest
|
||||
{
|
||||
public List<FormFile>? File { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue