361 lines
17 KiB
C#
361 lines
17 KiB
C#
using BMA.EHR.Profile.Service.Controllers;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Swashbuckle.AspNetCore.Annotations;
|
||
using Telerik.Reporting.Processing;
|
||
using Telerik.Reporting;
|
||
using BMA.EHR.Report.Service.Responses;
|
||
using BMA.EHR.Report.Service.Data;
|
||
using BMA.EHR.Report.Service.Services;
|
||
|
||
namespace BMA.EHR.Report.Service.Controllers
|
||
{
|
||
[Route("api/v{version:apiVersion}/report/organization")]
|
||
[ApiVersion("1.0")]
|
||
[ApiController]
|
||
[Produces("application/json")]
|
||
//[Authorize]
|
||
[SwaggerTag("รายงานระบบโครงสร้าง")]
|
||
public class OrganizationReportController : BaseController
|
||
{
|
||
#region " Fields "
|
||
|
||
private readonly EHRDbContext _context;
|
||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||
private readonly IConfiguration _configuration;
|
||
private readonly string space = "ㅤ";
|
||
private readonly OrganizationReportService _organizationReportService;
|
||
|
||
#endregion
|
||
|
||
#region " Constructor and Destructor "
|
||
|
||
public OrganizationReportController(EHRDbContext context,
|
||
IWebHostEnvironment hostingEnvironment,
|
||
IConfiguration configuration,
|
||
OrganizationReportService organizationReportService)
|
||
{
|
||
this._context = context;
|
||
this._hostingEnvironment = hostingEnvironment;
|
||
this._configuration = configuration;
|
||
this._organizationReportService = organizationReportService;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region " Methods "
|
||
|
||
[HttpGet("oc-type")]
|
||
public async Task<ActionResult<ResponseObject>> GetOCType()
|
||
{
|
||
try
|
||
{
|
||
return Success(await _organizationReportService.GetOrganizationTypes("หน่วยงาน"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// รายงานบัญชี 1
|
||
/// </summary>
|
||
/// <param name="id">รหัสสำนัก</param>
|
||
/// <returns></returns>
|
||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||
|
||
[HttpGet("account1/{id:length(36)}")]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
[AllowAnonymous]
|
||
public async Task<ActionResult<ResponseObject>> GetAccount1Report(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var data = await _organizationReportService.GetReport1Query(id);
|
||
var result_data = new List<Account1ResultItem>();
|
||
|
||
foreach (var d in data)
|
||
{
|
||
result_data.Add(new Account1ResultItem
|
||
{
|
||
Id = d.Id,
|
||
RootOcId = d.RootOcId,
|
||
RootOcName = d.RootOcName,
|
||
OcFullName = d.OcFullName.Replace($"\r\n{d.OcName}", string.Empty),
|
||
OcId = d.OcId,
|
||
OcName = d.OcName,
|
||
ShortName = d.ShortName,
|
||
PositionNumber = d.PositionNumber,
|
||
PositionNumberInt = Convert.ToInt32(d.PositionNumber.Replace(d.ShortName, string.Empty)),
|
||
PositionName = d.PositionName,
|
||
PositionSide = d.PositionSide,
|
||
PositionExecutive = d.PositionExecutive,
|
||
PositionExecutiveSide = d.PositionExecutiveSide,
|
||
OcOrder = d.OcOrder,
|
||
PositionLevel = d.PositionLevel,
|
||
Remark = d.Remark,
|
||
PositionType = d.PositionType,
|
||
IsDirector = d.IsDirector,
|
||
GovernmentCode = d.GovernmentCode,
|
||
});
|
||
}
|
||
|
||
//var items = result_data.OrderBy(x => x.GovernmentCode).ThenBy(x => x.PositionNumberInt).ToList();
|
||
|
||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Organization", $"rptAccount1.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 = result_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 first_record = result_data.FirstOrDefault();
|
||
|
||
var content = result.DocumentBytes;
|
||
return File(content, "application/pdf", $"รายงานบัญชี1_{first_record.RootOcName}_.pdf");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// รายงานบัญชี 2
|
||
/// </summary>
|
||
/// <param name="id">รหัสสำนัก</param>
|
||
/// <returns></returns>
|
||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||
|
||
[HttpGet("account2/{id:length(36)}")]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
[AllowAnonymous]
|
||
public async Task<ActionResult<ResponseObject>> GetAccount2Report(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var data = (await _organizationReportService.GetReport2Query(id)).OrderBy(x => x.OcOrder).ThenBy(x => x.PositionNumberIntNew).ToList();
|
||
|
||
var result_data = new List<Account2ResultItem>();
|
||
foreach (var d in data)
|
||
{
|
||
result_data.Add(new Account2ResultItem
|
||
{
|
||
Id = d.Id,
|
||
RootOcId = d.RootOcId,
|
||
RootOcName = d.RootOcName,
|
||
OcFullName = d.OcFullName.Replace($"\r\n{d.OcName}", string.Empty),
|
||
OcId = d.OcId,
|
||
OcName = d.OcName,
|
||
ShortName = d.ShortName,
|
||
PositionNumber = d.PositionNumber,
|
||
PositionNumberInt = d.PositionNumber == "" ? 0 : Convert.ToInt32(d.PositionNumber.Split(".").Last()),
|
||
PositionName = d.PositionName,
|
||
PositionSide = d.PositionSide,
|
||
PositionExecutive = d.PositionExecutive,
|
||
PositionExecutiveSide = d.PositionExecutiveSide,
|
||
OcOrder = d.OcOrder,
|
||
PositionLevel = d.PositionLevel,
|
||
Remark = d.Remark,
|
||
PositionType = d.PositionType,
|
||
|
||
OcIdNew = d.OcIdNew,
|
||
OcFullNameNew = d.OcFullNameNew.Replace($"\r\n{d.OcNameNew}", string.Empty),
|
||
OcNameNew = d.OcNameNew,
|
||
ShortNameNew = d.ShortNameNew,
|
||
PositionNumberNew = d.PositionNumberNew == "" ? d.PositionNumber : d.PositionNumberNew,
|
||
PositionNumberIntNew = d.PositionNumberNew == "" ? Convert.ToInt32(d.PositionNumber.Split(".").Last()) :
|
||
Convert.ToInt32(d.PositionNumberNew.Split(".").Last()),
|
||
PositionLevelNew = d.PositionLevelNew == "" ? d.PositionLevel : d.PositionLevelNew,
|
||
PositionNameNew = d.PositionNameNew == "" ? d.PositionName : d.PositionNameNew,
|
||
PositionSideNew = d.PositionSideNew == "" ? d.PositionSide : d.PositionSideNew,
|
||
PositionExecutiveNew = d.PositionExecutiveNew == "" ? d.PositionExecutive : d.PositionExecutiveNew,
|
||
PositionExecutiveSideNew = d.PositionExecutiveSideNew == "" ? d.PositionExecutiveSide : d.PositionExecutiveSideNew,
|
||
PositionTypeNew = d.PositionTypeNew == "" ? d.PositionType : d.PositionTypeNew,
|
||
|
||
Prefix = d.Prefix,
|
||
FirstName = d.FirstName,
|
||
LastName = d.LastName,
|
||
Degree = d.Degree,
|
||
|
||
Salary = d.Salary,
|
||
SalaryPosition = d.SalaryPosition,
|
||
FullName = $"{d.Prefix}{d.FirstName} {d.LastName}".Trim()
|
||
});
|
||
}
|
||
|
||
|
||
var items = result_data.OrderBy(x => x.OcOrder).ThenBy(x => x.PositionNumberIntNew).ToList();
|
||
|
||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Organization", $"rptAccount2.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 = items;
|
||
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 first_record = items.FirstOrDefault();
|
||
|
||
var content = result.DocumentBytes;
|
||
return File(content, "application/pdf", $"รายงานบัญชี2_{first_record.RootOcName}_.pdf");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// รายงานบัญชี 3
|
||
/// </summary>
|
||
/// <param name="id">รหัสสำนัก</param>
|
||
/// <returns></returns>
|
||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||
|
||
[HttpGet("account3/{id:length(36)}")]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
[AllowAnonymous]
|
||
public async Task<ActionResult<ResponseObject>> GetAccount3Report(Guid id)
|
||
{
|
||
try
|
||
{
|
||
try
|
||
{
|
||
var data = (await _organizationReportService.GetReport2Query(id)).OrderBy(x => x.OcOrder).ThenBy(x => x.PositionNumberIntNew).ToList();
|
||
var result_data = new List<Account2ResultItem>();
|
||
foreach (var d in data)
|
||
{
|
||
result_data.Add(new Account2ResultItem
|
||
{
|
||
Id = d.Id,
|
||
RootOcId = d.RootOcId,
|
||
RootOcName = d.RootOcName,
|
||
OcFullName = d.OcFullName.Replace($"\r\n{d.OcName}", string.Empty),
|
||
OcId = d.OcId,
|
||
OcName = d.OcName,
|
||
ShortName = d.ShortName,
|
||
PositionNumber = d.PositionNumber,
|
||
PositionNumberInt = d.PositionNumberInt,
|
||
PositionName = d.PositionName,
|
||
PositionSide = d.PositionSide,
|
||
PositionExecutive = d.PositionExecutive,
|
||
PositionExecutiveSide = d.PositionExecutiveSide,
|
||
OcOrder = d.OcOrder,
|
||
PositionLevel = d.PositionLevel,
|
||
Remark = d.Remark,
|
||
PositionType = d.PositionType,
|
||
|
||
OcIdNew = d.OcIdNew,
|
||
OcFullNameNew = d.OcFullNameNew.Replace($"\r\n{d.OcNameNew}", string.Empty),
|
||
OcNameNew = d.OcNameNew,
|
||
ShortNameNew = d.ShortNameNew,
|
||
PositionNumberNew = d.PositionNumberNew == "" ? d.PositionNumber : d.PositionNumberNew,
|
||
PositionNumberIntNew = d.PositionNumberNew == "" ? Convert.ToInt32(d.PositionNumber.Split(".").Last()) :
|
||
Convert.ToInt32(d.PositionNumberNew.Split(".").Last()),
|
||
PositionLevelNew = d.PositionLevelNew == "" ? d.PositionLevel : d.PositionLevelNew,
|
||
PositionNameNew = d.PositionNameNew == "" ? d.PositionName : d.PositionNameNew,
|
||
PositionSideNew = d.PositionSideNew == "" ? d.PositionSide : d.PositionSideNew,
|
||
PositionExecutiveNew = d.PositionExecutiveNew == "" ? d.PositionExecutive : d.PositionExecutiveNew,
|
||
PositionExecutiveSideNew = d.PositionExecutiveSideNew == "" ? d.PositionExecutiveSide : d.PositionExecutiveSideNew,
|
||
PositionTypeNew = d.PositionTypeNew == "" ? d.PositionType : d.PositionTypeNew,
|
||
|
||
Prefix = d.Prefix,
|
||
FirstName = d.FirstName,
|
||
LastName = d.LastName,
|
||
Degree = d.Degree,
|
||
|
||
Salary = d.Salary,
|
||
SalaryPosition = d.SalaryPosition,
|
||
FullName = $"{d.Prefix}{d.FirstName} {d.LastName}".Trim()
|
||
});
|
||
}
|
||
|
||
|
||
var items = result_data.OrderBy(x => x.OcOrder).ThenBy(x => x.PositionNumberIntNew).ToList();
|
||
|
||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Organization", $"rptAccount3.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 = items;
|
||
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 first_record = items.FirstOrDefault();
|
||
|
||
var content = result.DocumentBytes;
|
||
return File(content, "application/pdf", $"รายงานบัญชี3_{first_record.RootOcName}_.pdf");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|