api รายงานขอโอน
This commit is contained in:
parent
59f782e8cf
commit
83dba4373b
8 changed files with 166 additions and 23 deletions
|
|
@ -29,7 +29,7 @@ namespace BMA.EHR.Application
|
|||
services.AddTransient<InsigniaReportRepository>();
|
||||
services.AddTransient<CommandReportRepository>();
|
||||
services.AddTransient<ProbationReportRepository>();
|
||||
|
||||
services.AddTransient<TransferReportRepository>();
|
||||
services.AddTransient<EmailSenderService>();
|
||||
|
||||
return services;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text.RegularExpressions;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Reports
|
||||
{
|
||||
public class TransferReportRepository
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public TransferReportRepository(IApplicationDBContext dbContext, IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_hostingEnvironment = hostEnvironment;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
#region 2
|
||||
public async Task<dynamic> GetData2Transfer(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.Where(x => x.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var currentdate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 16);
|
||||
return new
|
||||
{
|
||||
CurrentDate = currentdate,
|
||||
Subject = $"ข้าราชการกรุงเทพมหานครสามัญขอโอน",
|
||||
Name = $"{data.Profile.Prefix?.Name}{data.Profile.FirstName} {data.Profile.LastName}",
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 3
|
||||
public async Task<dynamic> GetData3Transfer(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.Where(x => x.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
var currentdate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 16);
|
||||
return new
|
||||
{
|
||||
CurrentDate = currentdate,
|
||||
Subject = $"ข้าราชการขอโอน",
|
||||
Name = $"{data.Profile.Prefix?.Name}{data.Profile.FirstName} {data.Profile.LastName}",
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ using DocumentFormat.OpenXml.Drawing;
|
|||
using Telerik.Reporting;
|
||||
using Telerik.Reporting.Processing;
|
||||
using System.IO;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
|
|
@ -26,18 +27,18 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly GenericReportGenerator _reportGenerator;
|
||||
|
||||
private readonly TransferReportRepository _service;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constuctor and Destructor "
|
||||
|
||||
public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator)
|
||||
public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, TransferReportRepository service)
|
||||
{
|
||||
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_configuration = configuration;
|
||||
_reportGenerator = reportGenerator;
|
||||
_service = service;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -55,11 +56,11 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("1/{exportType}/{id}")]
|
||||
public IActionResult GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
public async Task <ActionResult<ResponseObject>> GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var data = await _service.GetData2Transfer(id);
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
{
|
||||
|
|
@ -68,11 +69,27 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
}
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
|
||||
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp");
|
||||
ReportPackager reportPacker = new ReportPackager();
|
||||
Telerik.Reporting.Report? report = null;
|
||||
|
||||
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
|
||||
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);
|
||||
var content = result.DocumentBytes;
|
||||
return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -92,11 +109,11 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("2/{exportType}/{id}")]
|
||||
public IActionResult GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
public async Task<ActionResult<ResponseObject>> GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var data = await _service.GetData2Transfer(id);
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
{
|
||||
|
|
@ -105,11 +122,36 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
}
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
|
||||
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp");
|
||||
var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp");
|
||||
ReportPackager reportPacker = new ReportPackager();
|
||||
Telerik.Reporting.Report? report = null;
|
||||
Telerik.Reporting.Report? report2 = null;
|
||||
|
||||
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||||
using (var sourceStream2 = System.IO.File.OpenRead(rptFile2))
|
||||
{
|
||||
report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
|
||||
report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2);
|
||||
}
|
||||
|
||||
report.DataSource = data;
|
||||
report2.DataSource = data;
|
||||
|
||||
var reportBook = new ReportBook();
|
||||
reportBook.Reports.Add(report);
|
||||
reportBook.Reports.Add(report2);
|
||||
|
||||
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||||
InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||||
{
|
||||
ReportDocument = reportBook,
|
||||
};
|
||||
|
||||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||||
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
|
||||
var content = result.DocumentBytes;
|
||||
return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -122,18 +164,18 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// <summary>
|
||||
/// หนังสือยินยอมให้โอนและวันที่พร้อมจะให้โอนไปยัง หน่วยงานที่รับโอน
|
||||
/// </summary>
|
||||
/// <param name="id">id </param>
|
||||
/// <param name = "id" > id </param >
|
||||
/// <param name="exportType">pdf, docx หรือ xlsx</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
/// <response code = "200" > เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code = "401" > ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code = "500" > เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("3/{exportType}/{id}")]
|
||||
public IActionResult GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
public async Task<ActionResult<ResponseObject>> GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var data = await _service.GetData3Transfer(id);
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
{
|
||||
|
|
@ -142,11 +184,36 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
}
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
|
||||
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-1.trdp");
|
||||
var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-2.trdp");
|
||||
ReportPackager reportPacker = new ReportPackager();
|
||||
Telerik.Reporting.Report? report = null;
|
||||
Telerik.Reporting.Report? report2 = null;
|
||||
|
||||
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||||
using (var sourceStream2 = System.IO.File.OpenRead(rptFile2))
|
||||
{
|
||||
report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
|
||||
report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2);
|
||||
}
|
||||
|
||||
report.DataSource = data;
|
||||
report2.DataSource = data;
|
||||
|
||||
var reportBook = new ReportBook();
|
||||
reportBook.Reports.Add(report);
|
||||
reportBook.Reports.Add(report2);
|
||||
|
||||
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||||
InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||||
{
|
||||
ReportDocument = reportBook,
|
||||
};
|
||||
|
||||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||||
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
|
||||
var content = result.DocumentBytes;
|
||||
return File(content, mimeType, $"หนังสือยินยอมให้โอน.{exportType.Trim().ToLower()}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
BIN
BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-1.trdp
Normal file
BIN
BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-1.trdp
Normal file
Binary file not shown.
BIN
BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-2.trdp
Normal file
BIN
BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-2.trdp
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue