fix Export Excel Insignia

This commit is contained in:
Suphonchai Phoonsawat 2024-06-30 19:47:09 +07:00
parent 451806fd00
commit 02c5d5b6ca

View file

@ -2208,7 +2208,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
try
{
// copy template
@ -2233,7 +2233,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
workSheet.Cells[row, 8].Value = profile.BirthDate.ToThaiDate();
workSheet.Cells[row, 9].Value = profile.DateAppoint == null ? null : profile.DateAppoint.Value.ToThaiDate();
// workSheet.Cells[row, 10].Value = null;
// workSheet.Cells[row, 11].Value = item.Profile.Position == null ? null : item.Profile.Position.Name;
//workSheet.Cells[row, 11].Value = item.Profile.Position == null ? null : item.Profile.Position.Name;
workSheet.Cells[row, 12].Value = "";
workSheet.Cells[row, 13].Value = profile.PosLevel == null ? null : profile.PosLevel.PosLevelName;
workSheet.Cells[row, 14].Value = "";
@ -2265,7 +2265,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
}
catch (Exception ex)
{
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!");
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!");
}
finally
{
@ -2277,7 +2277,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <summary>
/// Download รายชื่อข้าราชการสามัญฯ ที่มีสิทธิ์ยื่นขอพระราชทานเครื่องราชอิสริยาภรณ์
/// </summary>
/// <param name="RequestId">Id รอบเครื่องราช</param>
/// <param name="RequestId">Id การขอเครื่องราช (Request)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
@ -2287,27 +2287,8 @@ namespace BMA.EHR.Insignia.Service.Controllers
public async Task<ActionResult<ResponseObject>> DownloadExcelInsigniaByFilter([FromBody] ExportFileInsigniaRequest req, Guid RequestId)
{
var insigniaPeriod = await _context.InsigniaRequests
//.Include(x => x.Organization)
//.ThenInclude(x => x.OrganizationOrganization)
.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.Profile)
//.ThenInclude(x => x.Prefix)
//.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.Profile)
//.ThenInclude(x => x.Position)
//.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.Profile)
//.ThenInclude(x => x.PositionLevel)
//.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.Profile)
//.ThenInclude(x => x.Salaries)
//.ThenInclude(x => x.PositionLevel)
//.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.Profile)
//.ThenInclude(x => x.Insignias)
//.ThenInclude(x => x.Insignia)
//.Include(x => x.RequestProfiles)
//.ThenInclude(x => x.RequestInsignia)
.ThenInclude(x => x.RequestInsignia)
.FirstOrDefaultAsync(x => x.Id == RequestId);
if (insigniaPeriod == null)
return Error(GlobalMessages.InsigniaPeriodNotFound);
@ -2318,7 +2299,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
try
{
// copy template
@ -2340,7 +2321,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
foreach (var item in requestProfiles)
{
var profile = _userProfileRepository.GetOfficerProfileById(item.ProfileId, AccessToken);
workSheet.Cells[row, 1].Value = "-";
workSheet.Cells[row, 1].Value = _userProfileRepository.GetOc(insigniaPeriod.OrganizationId, 0, AccessToken).Root;
workSheet.Cells[row, 2].Value = profile.CitizenId;
workSheet.Cells[row, 3].Value = profile.Prefix == null ? "-" : ((profile.Prefix == "นาย" || profile.Prefix == "นาง" || profile.Prefix == "นางสาว") ? profile.Prefix : "-");
workSheet.Cells[row, 4].Value = profile.Prefix == null ? "-" : ((profile.Prefix == "นาย" || profile.Prefix == "นาง" || profile.Prefix == "นางสาว") ? "-" : profile.Prefix);
@ -2382,7 +2363,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
}
catch (Exception ex)
{
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!");
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!");
}
finally
{