filter excel insignia
This commit is contained in:
parent
04b8885e18
commit
a3a111834f
8 changed files with 16654 additions and 4 deletions
|
|
@ -2172,6 +2172,118 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download รายชื่อข้าราชการสามัญฯ ที่มีสิทธิ์ยื่นขอพระราชทานเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="RequestId">Id รอบเครื่องราช</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("download/excel/{RequestId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DownloadExcelInsigniaByFilter([FromForm] 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)
|
||||
.FirstOrDefaultAsync(x => x.Id == RequestId);
|
||||
if (insigniaPeriod == null)
|
||||
return Error(GlobalMessages.InsigniaPeriodNotFound);
|
||||
|
||||
var template_dir = Path.Combine(_hostingEnvironment.ContentRootPath, "Templates");
|
||||
var template_file = Path.Combine(template_dir, "PersonInsignia.xlsx");
|
||||
var tmpDir = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp");
|
||||
if (!Directory.Exists(tmpDir))
|
||||
Directory.CreateDirectory(tmpDir);
|
||||
|
||||
var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
try
|
||||
{
|
||||
// copy template
|
||||
System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
{
|
||||
var workSheet = excel.Workbook.Worksheets[0];
|
||||
var requestProfiles = insigniaPeriod.RequestProfiles.Where(x => x.Status == "PENDING").ToList();
|
||||
if (req.ProfileType != null)
|
||||
requestProfiles = requestProfiles.Where(x => x.Profile.ProfileType == req.ProfileType.Trim().ToUpper()).ToList();
|
||||
if (req.InsigniaId != null)
|
||||
requestProfiles = requestProfiles.Where(x => x.RequestInsignia.Id == req.InsigniaId).ToList();
|
||||
// if (req.OrgId != null)
|
||||
// requestProfiles = requestProfiles.Where(x => x.Request.Organization.Id == req.OrgId).ToList();
|
||||
var row = 2;
|
||||
foreach (var item in requestProfiles)
|
||||
{
|
||||
workSheet.Cells[row, 1].Value = insigniaPeriod.Organization.OrganizationOrganization == null ? "-" : insigniaPeriod.Organization.OrganizationOrganization.Name;
|
||||
workSheet.Cells[row, 2].Value = item.Profile.CitizenId;
|
||||
workSheet.Cells[row, 3].Value = item.Profile.Prefix == null ? "-" : ((item.Profile.Prefix.Name == "นาย" || item.Profile.Prefix.Name == "นาง" || item.Profile.Prefix.Name == "นางสาว") ? item.Profile.Prefix.Name : "-");
|
||||
workSheet.Cells[row, 4].Value = item.Profile.Prefix == null ? "-" : ((item.Profile.Prefix.Name == "นาย" || item.Profile.Prefix.Name == "นาง" || item.Profile.Prefix.Name == "นางสาว") ? "-" : item.Profile.Prefix.Name);
|
||||
workSheet.Cells[row, 5].Value = item.Profile.FirstName;
|
||||
workSheet.Cells[row, 6].Value = item.Profile.LastName;
|
||||
workSheet.Cells[row, 7].Value = item.Profile.Gender == null ? "-" : item.Profile.Gender.Name;
|
||||
workSheet.Cells[row, 8].Value = item.Profile.BirthDate.ToThaiDate();
|
||||
workSheet.Cells[row, 9].Value = item.Profile.DateAppoint == null ? null : item.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, 12].Value = item.Profile.PositionLevel == null ? null : (item.Profile.Salaries.Where(x => x.PositionLevel == item.Profile.PositionLevel).Count() == 0 ? null : (item.Profile.Salaries.Where(x => x.PositionLevel == item.Profile.PositionLevel).OrderBy(x => x.Order).FirstOrDefault().Date == null ? null : item.Profile.Salaries.Where(x => x.PositionLevel == item.Profile.PositionLevel).OrderBy(x => x.Order).FirstOrDefault().Date.Value.ToThaiDate()));
|
||||
workSheet.Cells[row, 13].Value = item.Profile.PositionLevel == null ? null : item.Profile.PositionLevel.Name;
|
||||
workSheet.Cells[row, 14].Value = item.Profile.Position == null ? null : (item.Profile.Salaries.Where(x => x.PositionId == item.Profile.Position.Id).Count() == 0 ? null : (item.Profile.Salaries.Where(x => x.PositionId == item.Profile.Position.Id).OrderBy(x => x.Order).FirstOrDefault().Date == null ? null : item.Profile.Salaries.Where(x => x.PositionId == item.Profile.Position.Id).OrderBy(x => x.Order).FirstOrDefault().Date.Value.ToThaiDate()));
|
||||
workSheet.Cells[row, 15].Value = null;
|
||||
workSheet.Cells[row, 16].Value = item.Profile.Position == null ? "-" : item.Profile.Position.Name;
|
||||
workSheet.Cells[row, 17].Value = item.Profile.Salaries.Count() == 0 ? null : item.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount;
|
||||
workSheet.Cells[row, 18].Value = null;
|
||||
workSheet.Cells[row, 19].Value = item.Profile.Salaries.Count() == 0 ? null : item.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount;
|
||||
workSheet.Cells[row, 20].Value = item.Profile.Insignias.Count() == 0 ? null : (item.Profile.Insignias.OrderByDescending(x => x.CreatedAt).FirstOrDefault().Insignia == null ? null : item.Profile.Insignias.OrderByDescending(x => x.CreatedAt).FirstOrDefault().Insignia.Name);
|
||||
workSheet.Cells[row, 21].Value = item.Profile.Insignias.Count() == 0 ? null : (item.Profile.Insignias.OrderByDescending(x => x.CreatedAt).FirstOrDefault().ReceiveDate == null ? null : item.Profile.Insignias.OrderByDescending(x => x.CreatedAt).FirstOrDefault().ReceiveDate.Value.ToThaiDate());
|
||||
workSheet.Cells[row, 22].Value = null;
|
||||
row++;
|
||||
}
|
||||
excel.Save();
|
||||
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
fs.Close();
|
||||
var fname = Path.GetFileName(exportFile);
|
||||
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = fname
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(exportFile))
|
||||
System.IO.File.Delete(exportFile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload เอกสาร เครื่องราชฯ
|
||||
/// </summary>
|
||||
|
|
@ -2184,12 +2296,16 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
[HttpPut("upload/{requestId:length(36)}"), DisableRequestSizeLimit]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePersonDeferment([FromForm] ImportFileRequest req, Guid requestId)
|
||||
{
|
||||
var insigniaRequest = await _context.InsigniaRequests.Where(x => x.Id == requestId).FirstOrDefaultAsync();
|
||||
var insigniaRequest = await _context.InsigniaRequests.Include(x => x.Document).Where(x => x.Id == requestId).FirstOrDefaultAsync();
|
||||
if (insigniaRequest == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound, 404);
|
||||
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
if (insigniaRequest.Document != null)
|
||||
{
|
||||
await _documentService.DeleteFileAsync(insigniaRequest.Document.Id);
|
||||
}
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue