ย้ายมาออกรายงานผ่านระบบ
This commit is contained in:
parent
4987f7c5ad
commit
b817b781d2
144 changed files with 5573 additions and 63 deletions
254
Controllers/ExamReportController.cs
Normal file
254
Controllers/ExamReportController.cs
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
using BMA.EHR.Profile.Service.Controllers;
|
||||
using BMA.EHR.Report.Service.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using Telerik.Reporting.Processing;
|
||||
using Telerik.Reporting;
|
||||
using BMA.EHR.Report.Service.Responses;
|
||||
using BMA.EHR.Extensions;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/report/exam")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("รายงานข้อมูลการสอบคัดเลือก")]
|
||||
public class ExamReportController : BaseController
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly ExamDbContext _context;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly string space = "ㅤ";
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public ExamReportController(ExamDbContext context,
|
||||
IWebHostEnvironment hostingEnvironment,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
this._context = context;
|
||||
this._hostingEnvironment = hostingEnvironment;
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
#region " Privates "
|
||||
|
||||
private int GetExamCountTes(string citizenId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var count = _context.Candidates.AsQueryable()
|
||||
.Where(x => x.CitizenId == citizenId)
|
||||
.Count();
|
||||
|
||||
return count;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// แสดงหนังสือรับรอง
|
||||
/// </summary>
|
||||
/// <param name="id">รหัสรอบการสอบ</param>
|
||||
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
||||
/// <param name="type">ชนิดของรายงาน</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
|
||||
[HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetCertificateReportAsync(Guid id, string examId, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _context.Disables.AsQueryable()
|
||||
.Include(x => x.PeriodExam)
|
||||
.Where(x => x.PeriodExam.Id == id)
|
||||
.Where(x => x.ExamId == examId)
|
||||
.Join(_context.DisableScores.AsQueryable()
|
||||
.Include(x => x.ScoreImport),
|
||||
rc => new { rc.PeriodExam.Year, rc.ExamId },
|
||||
sc => new { sc.ScoreImport.Year, sc.ExamId },
|
||||
(p, sr) => new
|
||||
{
|
||||
ExamID = p.ExamId,
|
||||
p.CitizenId,
|
||||
Order = p.PeriodExam.Round,
|
||||
Year = p.PeriodExam.Year.Value.ToThaiYear(),
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||
EndDate = p.PeriodExam.RegisterEndDate.ToThaiFullDate3(),
|
||||
AuthName = "นายณัฐพงศ์ ดิษยบุตร",
|
||||
AuthPosition = "หัวหน้าสำนักงาน ก.ก."
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCertificate{type}.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, "เกิดข้อผิดพลาดในการแสดงรายงาน");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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("score/{id:length(36)}/{examId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetScoreReportAsync(Guid id, string examId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _context.Disables.AsQueryable()
|
||||
.Include(x => x.PeriodExam)
|
||||
.Include(x => x.Documents)
|
||||
.ThenInclude(x => x.DocumentFile)
|
||||
.Where(x => x.PeriodExam.Id == id)
|
||||
.Where(x => x.ExamId == examId)
|
||||
.Join(_context.DisableScores.AsQueryable()
|
||||
.Include(x => x.ScoreImport),
|
||||
rc => new { rc.PeriodExam.Year, rc.ExamId },
|
||||
sc => new { sc.ScoreImport.Year, sc.ExamId },
|
||||
(p, sr) => new
|
||||
{
|
||||
ExamId = p.ExamId,
|
||||
CitizenId = p.CitizenId,
|
||||
p.Prefix,
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
DateOfBirth = p.DateOfBirth.ToThaiShortDate(),
|
||||
Gender = p.Gendor,
|
||||
Degree = p.Educations.First().Degree,
|
||||
Major = p.Educations.First().Major,
|
||||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||||
University = p.Educations.First().University,
|
||||
PositionName = p.PositionName,
|
||||
ExamName = $"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}",
|
||||
Number = sr == null ? "" : sr.Number,
|
||||
// ExamCount = 10,
|
||||
// ExamCount = GetExamCountTes(p.CitizenId),
|
||||
ScoreExpire = p.PeriodExam.AnnouncementDate == null ? "" : p.PeriodExam.AnnouncementDate.AddYears(2).ToThaiShortDate(),
|
||||
FullA = sr == null ? 0 : sr.FullA,
|
||||
SumA = sr == null ? 0 : sr.SumA,
|
||||
FullB = sr == null ? 0 : sr.FullB,
|
||||
SumB = sr == null ? 0 : sr.SumB,
|
||||
FullC = sr == null ? 0 : sr.FullC,
|
||||
SumC = sr == null ? 0 : sr.SumC,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptExamResult.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;
|
||||
if (data != null)
|
||||
{
|
||||
var _data = new
|
||||
{
|
||||
ExamId = data.ExamId,
|
||||
CitizenId = data.CitizenId,
|
||||
Prefix = data.Prefix,
|
||||
FullName = data.FullName,
|
||||
DateOfBirth = data.DateOfBirth,
|
||||
Gender = data.Gender,
|
||||
Degree = data.Degree,
|
||||
Major = data.Major,
|
||||
ExamResult = data.ExamResult,
|
||||
University = data.University,
|
||||
PositionName = data.PositionName,
|
||||
ExamName = data.ExamName,
|
||||
Number = data.Number,
|
||||
ExamCount = GetExamCountTes(data.CitizenId),
|
||||
ScoreExpire = data.ScoreExpire,
|
||||
FullA = data.FullA,
|
||||
SumA = data.SumA,
|
||||
FullB = data.FullB,
|
||||
SumB = data.SumB,
|
||||
FullC = data.FullC,
|
||||
SumC = data.SumC,
|
||||
};
|
||||
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
|
||||
}
|
||||
}
|
||||
11
Controllers/OrganizationReportController.cs
Normal file
11
Controllers/OrganizationReportController.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class OrganizationReportController : ControllerBase
|
||||
{
|
||||
}
|
||||
}
|
||||
552
Controllers/ProfileReportController.cs
Normal file
552
Controllers/ProfileReportController.cs
Normal file
|
|
@ -0,0 +1,552 @@
|
|||
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 System.Runtime.Versioning;
|
||||
using System.Linq;
|
||||
using BMA.EHR.Profile.Service.Services;
|
||||
using Telerik.Reporting.Processing;
|
||||
using Telerik.Reporting;
|
||||
using System.Security.Cryptography.Pkcs;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using BMA.EHR.Recruit.Service.Services;
|
||||
using System.Drawing;
|
||||
using iText.Kernel.Pdf;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Telerik.Reporting.Drawing;
|
||||
using GreatFriends.ThaiBahtText;
|
||||
using BMA.EHR.Core;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/report/profile")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
//[Authorize]
|
||||
[SwaggerTag("รายงานระบบทะเบียนประวัติ")]
|
||||
public class ProfileReportController : BaseController
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly EHRDbContext _context;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly string space = "ㅤ";
|
||||
private readonly ProfileService _profileService;
|
||||
private readonly MinIOService _minioService;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public ProfileReportController(EHRDbContext context,
|
||||
IWebHostEnvironment hostingEnvironment,
|
||||
IConfiguration configuration,
|
||||
ProfileService profileService,
|
||||
MinIOService minioService)
|
||||
{
|
||||
this._context = context;
|
||||
this._hostingEnvironment = hostingEnvironment;
|
||||
this._configuration = configuration;
|
||||
this._profileService = profileService;
|
||||
this._minioService = minioService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
/// <summary>
|
||||
/// แสดงหนังสือรับรอง
|
||||
/// </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("kp7-short/{id:length(36)}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetKp7ShortReport(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile_salaries = (from ps in _context.ProfileSalaries.ToList()
|
||||
join pos in _context.PositionPaths.ToList()
|
||||
on ps.PositionId equals pos.Id
|
||||
where ps.Profile.Id == id
|
||||
select new
|
||||
{
|
||||
ProfileId = ps.Profile.Id,
|
||||
PositionName = pos.Name,
|
||||
ps.OcId,
|
||||
SalaryDateAnnounce = ps.Date,
|
||||
ps.Amount,
|
||||
ps.PositionSalaryAmount
|
||||
}).ToList();
|
||||
|
||||
var profile = (from p in _context.Profiles.ToList()
|
||||
join pf in _context.Prefixes.ToList() on p.PrefixId equals pf.Id
|
||||
|
||||
where p.Id == id
|
||||
select new
|
||||
{
|
||||
CitizenId = p.CitizenId,
|
||||
Prefix = pf.Name,
|
||||
p.FirstName,
|
||||
p.LastName,
|
||||
DateOfBirth = p.BirthDate.ToThaiShortDate(),
|
||||
RegistrationAddress = "-",
|
||||
OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false),
|
||||
DateAppoint = p.DateAppoint == null ? "" : p.DateAppoint.Value.ToThaiShortDate(),
|
||||
Salaries = profile_salaries,
|
||||
SalaryAmount = p.Salaries.Count == 0 ? "-"
|
||||
: $"{p.Salaries.OrderByDescending(s => s.Date.Value).FirstOrDefault().Amount.Value.ToString("#,##0")}",
|
||||
Education = p.Educations.Count == 0 ? "-"
|
||||
: $"{p.Educations.OrderByDescending(e => e.EndDate.Value.Year).FirstOrDefault().Degree} {p.Educations.OrderByDescending(e => e.EndDate.Value.Year).FirstOrDefault().Field}"
|
||||
}).FirstOrDefault();
|
||||
|
||||
var data = new List<dynamic>();
|
||||
var c = 1;
|
||||
if (profile.Salaries.Count == 0)
|
||||
{
|
||||
var ret2 = new
|
||||
{
|
||||
CitizenId = profile.CitizenId,
|
||||
Prefix = profile.Prefix,
|
||||
FirstName = profile.FirstName,
|
||||
LastName = profile.LastName,
|
||||
DateOfBirth = profile.DateOfBirth,
|
||||
RegistrationAddress = profile.RegistrationAddress,
|
||||
SalaryAmount = profile.SalaryAmount,
|
||||
Education = profile.Education,
|
||||
AppointText = "",
|
||||
SalaryDate = profile.DateAppoint,
|
||||
PositionName = "",
|
||||
OCFullPath = profile.OcFullPath
|
||||
};
|
||||
data.Add(ret2);
|
||||
}
|
||||
var old_date = DateTime.Now;
|
||||
var old_position = "";
|
||||
var old_ocid = Guid.NewGuid();
|
||||
dynamic ret;
|
||||
|
||||
foreach (var s in profile.Salaries)
|
||||
{
|
||||
//if((old_date.Date != s.SalaryDateAnnounce.Value.Date))
|
||||
//{
|
||||
// old_date = s.SalaryDateAnnounce.Value;
|
||||
// old_position= s.PositionName;
|
||||
// old_ocid = s.OcId;
|
||||
|
||||
// ret = new
|
||||
// {
|
||||
// CitizenId = profile.CitizenId,
|
||||
// Prefix = profile.Prefix,
|
||||
// FirstName = profile.FirstName,
|
||||
// LastName = profile.LastName,
|
||||
// DateOfBirth = profile.DateOfBirth,
|
||||
// RegistrationAddress = profile.RegistrationAddress,
|
||||
// SalaryAmount = profile.SalaryAmount,
|
||||
// Education = profile.Education,
|
||||
// AppointText = c == 1 ? "(เริ่มรับราชการ)" : "",
|
||||
// SalaryDate = s.SalaryDateAnnounce.Value.ToThaiShortDate(),
|
||||
// PositionName = s.PositionName,
|
||||
// OCFullPath = CoreCommandReport.GetOrganizationNameFullPath(s.OcId, false, false)
|
||||
// };
|
||||
// data.Add(ret);
|
||||
//}
|
||||
if (old_position != s.PositionName)
|
||||
{
|
||||
old_date = s.SalaryDateAnnounce.Value;
|
||||
old_position = s.PositionName;
|
||||
old_ocid = s.OcId.Value;
|
||||
ret = new
|
||||
{
|
||||
CitizenId = profile.CitizenId,
|
||||
Prefix = profile.Prefix,
|
||||
FirstName = profile.FirstName,
|
||||
LastName = profile.LastName,
|
||||
DateOfBirth = profile.DateOfBirth,
|
||||
RegistrationAddress = profile.RegistrationAddress,
|
||||
SalaryAmount = profile.SalaryAmount,
|
||||
Education = profile.Education,
|
||||
AppointText = c == 1 ? "(เริ่มรับราชการ)" : "",
|
||||
SalaryDate = s.SalaryDateAnnounce.Value.ToThaiShortDate(),
|
||||
PositionName = s.PositionName,
|
||||
OCFullPath = _profileService.GetOrganizationNameFullPath(s.OcId.Value, false, false)
|
||||
};
|
||||
data.Add(ret);
|
||||
}
|
||||
else if (old_ocid != s.OcId)
|
||||
{
|
||||
old_date = s.SalaryDateAnnounce.Value;
|
||||
old_position = s.PositionName;
|
||||
old_ocid = s.OcId.Value;
|
||||
ret = new
|
||||
{
|
||||
CitizenId = profile.CitizenId,
|
||||
Prefix = profile.Prefix,
|
||||
FirstName = profile.FirstName,
|
||||
LastName = profile.LastName,
|
||||
DateOfBirth = profile.DateOfBirth,
|
||||
RegistrationAddress = profile.RegistrationAddress,
|
||||
SalaryAmount = profile.SalaryAmount,
|
||||
Education = profile.Education,
|
||||
AppointText = c == 1 ? "(เริ่มรับราชการ)" : "",
|
||||
SalaryDate = s.SalaryDateAnnounce.Value.ToThaiShortDate(),
|
||||
PositionName = s.PositionName,
|
||||
OCFullPath = _profileService.GetOrganizationNameFullPath(s.OcId.Value, false, false)
|
||||
};
|
||||
data.Add(ret);
|
||||
}
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptShortKp7.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.First().CitizenId}.pdf");
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถแสดงผลรายงานได้!!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("kk1/{id:length(36)}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetKK1Report(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = (from p in _context.Profiles
|
||||
join pf in _context.Prefixes on p.PrefixId equals pf.Id into p_pf_join
|
||||
from p_pf in p_pf_join.DefaultIfEmpty()
|
||||
join cpf in _context.Prefixes on p.CouplePrefixId equals cpf.Id into c_pf_join
|
||||
from c_pf in c_pf_join.DefaultIfEmpty()
|
||||
join fpf in _context.Prefixes on p.FatherPrefixId equals fpf.Id into f_pf_join
|
||||
from f_pf in f_pf_join.DefaultIfEmpty()
|
||||
join mpf in _context.Prefixes on p.MotherPrefixId equals mpf.Id into m_pf_join
|
||||
from m_pf in m_pf_join.DefaultIfEmpty()
|
||||
where p.Id == id
|
||||
select new
|
||||
{
|
||||
p.CitizenId,
|
||||
Prefix = p_pf == null ? "" : p_pf.Name,
|
||||
p.FirstName,
|
||||
p.LastName,
|
||||
FullName = $"{p.FirstName} {p.LastName}",
|
||||
BirthDay = p.BirthDate.Day,
|
||||
BirthDayText = Convert.ToDecimal(p.BirthDate.Day).ThaiBahtText(UsesEt.Always, GreatFriends.ThaiBahtText.Unit.Baht, 2, false).Replace("บาท", ""),
|
||||
BirthMonth = p.BirthDate.Month.ToThaiMonth(),
|
||||
BirthYear = p.BirthDate.Year.ToThaiYear(),
|
||||
BirthYearText = Convert.ToDecimal(p.BirthDate.Year.ToThaiYear()).ThaiBahtText(UsesEt.Always, GreatFriends.ThaiBahtText.Unit.Baht, 2, false).Replace("บาท", ""),
|
||||
Address = "",
|
||||
District = "",
|
||||
Area = "",
|
||||
Province = "",
|
||||
Telephone = p.TelephoneNumber,
|
||||
CouplePrefix = c_pf == null ? "" : c_pf.Name,
|
||||
CoupleFullName = $"{p.CoupleFirstName} {p.CoupleLastName}".Trim(),
|
||||
FatherPrefix = f_pf == null ? "" : f_pf.Name,
|
||||
FatherFullName = $"{p.FatherFirstName} {p.FatherLastName}".Trim(),
|
||||
MotherPrefix = m_pf == null ? "" : m_pf.Name,
|
||||
MotherFullName = $"{p.MotherFirstName} {p.MotherLastName}".Trim(),
|
||||
OcId = p.OcId,
|
||||
OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false),
|
||||
Division = "",
|
||||
Institute = "",
|
||||
StartDate = p.DateStart == null ? "" : p.DateStart.Value.ToThaiShortDate(),
|
||||
AppointDate = p.DateAppoint == null ? "" : p.DateAppoint.Value.ToThaiShortDate(),
|
||||
BirthDate = p.BirthDate.ToThaiShortDate(),
|
||||
RetireDate = p.BirthDate.CalculateRetireDate().ToThaiShortDate(),
|
||||
}).ToList();
|
||||
|
||||
if (!profile.Any())
|
||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
|
||||
// certificate
|
||||
var cert = (from c in _context.ProfileCertificates.AsQueryable()
|
||||
where c.Profile.Id == id
|
||||
orderby c.IssueDate.Value.Year
|
||||
select new
|
||||
{
|
||||
c.CertificateType,
|
||||
c.Issuer,
|
||||
c.CertificateNo,
|
||||
IssueDate = c.IssueDate == null ? "" : c.IssueDate.Value.ToThaiShortDate()
|
||||
}).ToList();
|
||||
|
||||
// add temp rows
|
||||
while (cert.Count < 3)
|
||||
{
|
||||
cert.Add(new
|
||||
{
|
||||
CertificateType = "",
|
||||
Issuer = "",
|
||||
CertificateNo = "",
|
||||
IssueDate = ""
|
||||
});
|
||||
}
|
||||
|
||||
// training
|
||||
var training = (from t in _context.ProfileTrainings.AsQueryable()
|
||||
where t.Profile.Id == id
|
||||
orderby t.StartDate.Value.Year
|
||||
select new
|
||||
{
|
||||
Institute = t.Host,
|
||||
Start = t.StartDate == null ? "" : t.StartDate.Value.Year.ToThaiYear().ToString(),
|
||||
End = t.EndDate == null ? "" : t.EndDate.Value.Year.ToThaiYear().ToString(),
|
||||
Level = "",
|
||||
Degree = t.Subject,
|
||||
Field = ""
|
||||
}).ToList();
|
||||
|
||||
while (training.Count < 3)
|
||||
{
|
||||
training.Add(new
|
||||
{
|
||||
Institute = "",
|
||||
Start = "",
|
||||
End = "",
|
||||
Level = "",
|
||||
Degree = "",
|
||||
Field = ""
|
||||
});
|
||||
}
|
||||
|
||||
// disciplines
|
||||
var discipline = (from d in _context.ProfileDisciplines.AsQueryable()
|
||||
where d.Profile.Id == id
|
||||
orderby d.Date.Value.Year
|
||||
select new
|
||||
{
|
||||
DisciplineYear = d.Date == null ? "" : d.Date.Value.Year.ToThaiYear().ToString(),
|
||||
DisciplineDetail = d.Detail,
|
||||
RefNo = d.RefCommandNo
|
||||
}).ToList();
|
||||
|
||||
while (discipline.Count < 3)
|
||||
{
|
||||
discipline.Add(new
|
||||
{
|
||||
DisciplineYear = "",
|
||||
DisciplineDetail = "",
|
||||
RefNo = ""
|
||||
});
|
||||
}
|
||||
|
||||
// education
|
||||
var education = (from e in _context.ProfileEducations.AsQueryable()
|
||||
where e.Profile.Id == id
|
||||
orderby e.StartDate.Value.Year
|
||||
select new
|
||||
{
|
||||
Institute = e.Institute,
|
||||
Start = e.StartDate == null ? "" : e.StartDate.Value.Year.ToThaiYear().ToString(),
|
||||
End = e.EndDate == null ? "" : e.EndDate.Value.Year.ToThaiYear().ToString(),
|
||||
Level = e.EducationLevel,
|
||||
Degree = e.Degree,
|
||||
Field = e.Field.Trim() == "-" ? "" : e.Field
|
||||
}).ToList();
|
||||
|
||||
while (education.Count < 4)
|
||||
{
|
||||
education.Add(new
|
||||
{
|
||||
Institute = "",
|
||||
Start = "",
|
||||
End = "",
|
||||
Level = "",
|
||||
Degree = "",
|
||||
Field = ""
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page1.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 = profile;
|
||||
|
||||
// binding to table
|
||||
var tblCertificate = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblCertificate"];
|
||||
tblCertificate.DataSource = cert;
|
||||
|
||||
var tblTraining = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblTraining"];
|
||||
tblTraining.DataSource = training;
|
||||
|
||||
var tblDiscipline = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblDiscipline"];
|
||||
tblDiscipline.DataSource = discipline;
|
||||
|
||||
var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"];
|
||||
tblEducation.DataSource = education;
|
||||
|
||||
try
|
||||
{
|
||||
// Get avatar Image
|
||||
var picContent = (await _minioService.DownloadFileAsync(Guid.Parse("08db510a-a7cb-44ef-85c8-f5c214f87972"))).FileContent;
|
||||
var pictureBox = (Telerik.Reporting.PictureBox)report.Items["pageFooterSection1"].Items["picAvatar"];
|
||||
pictureBox.Value = Image.FromStream(new MemoryStream(picContent));
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
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);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content = result.DocumentBytes;
|
||||
|
||||
// page2
|
||||
var salary = (from s in _context.ProfileSalaries
|
||||
join pos in _context.PositionPaths on s.PositionId equals pos.Id
|
||||
join pos_no in _context.PositionNumbers on s.PosNoId equals pos_no.Id
|
||||
join pos_lv in _context.PositionLevels on s.PositionLevelId equals pos_lv.Id
|
||||
join pos_type in _context.PositionTypes on s.PositionTypeId equals pos_type.Id
|
||||
where s.Profile.Id == id
|
||||
orderby s.Date.Value
|
||||
select new
|
||||
{
|
||||
SalaryDate = s.Date == null ? "" : s.Date == new DateTime(1, 1, 1) ? "" : s.Date.Value.ToThaiShortDate(),
|
||||
Position = s.SalaryClass,
|
||||
PosNo = pos_no.Name,
|
||||
Rank = pos_lv.Name,
|
||||
Salary = s.Amount == null ? "" : s.Amount.ToString().ToInteger().ToNumericText(),
|
||||
RefAll = s.SalaryRef,
|
||||
PositionType = pos_type.Name,
|
||||
PositionLevel = pos_lv.Name,
|
||||
PositionAmount = s.PositionSalaryAmount,
|
||||
FullName = $"{s.Profile.FirstName} {s.Profile.LastName}",
|
||||
OcFullPath = _profileService.GetOrganizationNameFullPath(s.Profile.OcId.Value, false, false),
|
||||
}).ToList();
|
||||
|
||||
var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page2.trdp");
|
||||
|
||||
ReportPackager reportPackager2 = new ReportPackager();
|
||||
Telerik.Reporting.Report? report2 = null;
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile2))
|
||||
{
|
||||
report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||||
}
|
||||
report2.DataSource = salary;
|
||||
// binding to table
|
||||
var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"];
|
||||
tblSalary.DataSource = salary;
|
||||
|
||||
System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable();
|
||||
|
||||
InstanceReportSource instanceReportSource2 = new InstanceReportSource()
|
||||
{
|
||||
ReportDocument = report2
|
||||
};
|
||||
|
||||
|
||||
ReportProcessor reportProcessor2 = new ReportProcessor(_configuration);
|
||||
RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content2 = result2.DocumentBytes;
|
||||
|
||||
// merge pdf
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true)))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (MemoryStream memoryStream = new MemoryStream(content))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (PdfReader reader = new PdfReader(memoryStream))
|
||||
{
|
||||
PdfDocument srcDoc = new PdfDocument(reader);
|
||||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
|
||||
}
|
||||
}
|
||||
|
||||
// Create reader from bytes
|
||||
using (MemoryStream memoryStream = new MemoryStream(content2))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (PdfReader reader = new PdfReader(memoryStream))
|
||||
{
|
||||
PdfDocument srcDoc = new PdfDocument(reader);
|
||||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
|
||||
}
|
||||
}
|
||||
|
||||
pdf.Close();
|
||||
}
|
||||
|
||||
var fileContent = ms.ToArray();
|
||||
return File(fileContent, "application/pdf", $"กก_1_{id}.pdf");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue