รายงานคำสั่ง c-pm-21

This commit is contained in:
Suphonchai Phoonsawat 2023-09-05 12:02:25 +07:00
parent 0c1a8f29cc
commit 33da6f2d70
4 changed files with 161 additions and 4 deletions

View file

@ -1,9 +1,13 @@
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.OrganizationEmployee;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using DocumentFormat.OpenXml.Drawing.Charts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using Telerik.Reporting;
using Telerik.Reporting.Processing;
@ -1978,6 +1982,80 @@ namespace BMA.EHR.Report.Service.Controllers
#endregion
#region " C-PM-21 "
private async Task<byte[]> GenerateCommandReportType21_Cover(Guid commandId, string exportType)
{
try
{
var raw_data = await _repository.GetByIdAsync(commandId);
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
//var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
//var positionList = string.Empty;
var command = new
{
CommandNo = raw_data.CommandNo,
CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
IssuerOrganizationName = raw_data.IssuerOrganizationName,
ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
ConclusionResultNo = raw_data.ConclusionResultNo,
ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
PositionList = "",
Count = raw_data.Receivers.Count,
CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
AuthorizedPosition = raw_data.AuthorizedPosition,
};
var receiver = await _commandReportRepository.GetCommandType21AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"20-คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ-2.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 = command;
var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
tblData.DataSource = receiver;
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
if (exportType == "docx")
deviceInfo["OutputFormat"] = "DOCX";
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return content;
}
catch
{
throw;
}
}
#endregion
#endregion
#region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ "
@ -3369,7 +3447,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType21CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType21CoverReportAsync(Guid id, string exportType = "pdf")
{
try
{
@ -3381,10 +3459,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"20-คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ-2.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var cmd = await _repository.GetByIdAsync(id);
if (cmd == null)
throw new Exception(GlobalMessages.CommandNotFound);
return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType21_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{