From 3328bdf726179cf1f73a213bc4dc9b1b7df49741 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 19 Sep 2023 10:14:40 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B8=B4=E0=B8=A7=E0=B8=A3=E0=B8=B5?= =?UTF-8?q?=E0=B9=88=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B8=87=E0=B8=81=E0=B8=B1=E0=B8=94=20=E0=B9=80=E0=B8=81?= =?UTF-8?q?=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reports/RetireReportRepository.cs | 47 ++++++-- .../Controllers/RetirementController.cs | 102 ++++++++++++++++-- 2 files changed, 130 insertions(+), 19 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs index 257299e0..3ec81cfb 100644 --- a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs @@ -20,6 +20,7 @@ namespace BMA.EHR.Application.Repositories.Reports private readonly IApplicationDBContext _dbContext; private readonly IWebHostEnvironment _hostingEnvironment; private readonly MinIOService _documentService; + private readonly OrganizationCommonRepository _organizationCommonRepository; #endregion @@ -27,10 +28,12 @@ namespace BMA.EHR.Application.Repositories.Reports public RetireReportRepository(IApplicationDBContext dbContext, MinIOService documentService, + OrganizationCommonRepository organizationCommonRepository, IWebHostEnvironment hostEnvironment) { _dbContext = dbContext; _hostingEnvironment = hostEnvironment; + _organizationCommonRepository = organizationCommonRepository; _documentService = documentService; } @@ -66,6 +69,7 @@ namespace BMA.EHR.Application.Repositories.Reports var retire = await _dbContext.Set() .Include(x => x.RetirementProfiles) .FirstOrDefaultAsync(x => x.Id == retireId); + var retires = new List(); if (retire == null) { var retireHistorys = await _dbContext.Set().AsQueryable() @@ -116,7 +120,7 @@ namespace BMA.EHR.Application.Repositories.Reports { profiles = profiles.OrderBy(x => x.order).ToList(); } - return new { retireHistorys.Detail, retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profile = profiles}; + return new { retireHistorys.Detail, retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profile = profiles }; } } else @@ -135,19 +139,44 @@ namespace BMA.EHR.Application.Repositories.Reports prefix = x.Profile.Prefix == null ? string.Empty : x.Profile.Prefix.Name, fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", organizationOrganization = x.Profile.OrganizationOrganization, - oc = x.Profile.Oc, + ocId = x.Profile.OcId, position = x.Profile.Position == null ? string.Empty : x.Profile.Position.Name, positionType = x.Profile.PositionType == null ? string.Empty : x.Profile.PositionType.Name, positionExecutive = x.Profile.PositionExecutive, posNo = x.Profile.PosNo == null ? string.Empty : x.Profile.PosNo.Name, - positionEmployeePosition = x.Profile.PositionEmployeePosition, - positionEmployeeLevel = x.Profile.PositionEmployeeLevel, - positionEmployeeGroup = x.Profile.PositionEmployeeGroup, - posNoEmployee = x.Profile.PosNoEmployee, - }) - .ToListAsync(); + positionEmployeePosition = x.Profile.PositionEmployeePosition == null ? null : x.Profile.PositionEmployeePosition.Name, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel == null ? null : x.Profile.PositionEmployeeLevel.Name, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup == null ? null : x.Profile.PositionEmployeeGroup.Name, + posNoEmployee = x.Profile.PosNoEmployee, + }) + .ToListAsync(); + foreach (var r in profile_retire) + { + var data = new ProfileJsonRequest + { + order = r.order, + id = r.id, + reason = r.reason, + remove = r.remove, + profileId = r.profileId, + citizenId = r.citizenId, + prefix = r.prefix, + fullName = r.fullName, + organizationOrganization = r.organizationOrganization, + oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value), + position = r.position, + positionType = r.positionType, + positionExecutive = r.positionExecutive, + posNo = r.posNo, + positionEmployeePosition = r.positionEmployeePosition, + positionEmployeeLevel = r.positionEmployeeLevel, + positionEmployeeGroup = r.positionEmployeeGroup, + posNoEmployee = r.posNoEmployee, + }; + retires.Add(data); + } - return new { retire.Detail, retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire }; + return new { retire.Detail, retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = retires }; } } #endregion diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs index 1809c4b7..538445fe 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs @@ -26,6 +26,7 @@ namespace BMA.EHR.Retirement.Service.Controllers private readonly NotificationRepository _repositoryNoti; private readonly ApplicationDBContext _context; private readonly MinIOService _documentService; + private readonly OrganizationCommonRepository _organizationCommonRepository; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IConfiguration _configuration; @@ -34,12 +35,14 @@ namespace BMA.EHR.Retirement.Service.Controllers ApplicationDBContext context, MinIOService documentService, IConfiguration configuration, + OrganizationCommonRepository organizationCommonRepository, IHttpContextAccessor httpContextAccessor) { _repository = repository; _repositoryNoti = repositoryNoti; _context = context; _documentService = documentService; + _organizationCommonRepository = organizationCommonRepository; _httpContextAccessor = httpContextAccessor; _configuration = configuration; } @@ -277,10 +280,9 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(GlobalMessages.RetirementNotCreated); if (req.Option == null) req.Option = "EDIT"; - var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}"; var profile_old = await _context.RetirementProfiles .Where(x => x.RetirementPeriod == retire) - .Select(x => new ProfileJsonRequest + .Select(x => new { order = x.Order, id = x.Id, @@ -291,7 +293,7 @@ namespace BMA.EHR.Retirement.Service.Controllers prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", organizationOrganization = x.Profile.OrganizationOrganization, - oc = x.Profile.Oc, + ocId = x.Profile.OcId, position = x.Profile.Position == null ? null : x.Profile.Position.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionExecutive = x.Profile.PositionExecutive, @@ -302,7 +304,34 @@ namespace BMA.EHR.Retirement.Service.Controllers posNoEmployee = x.Profile.PosNoEmployee, }) .ToListAsync(); - var profile = Newtonsoft.Json.JsonConvert.SerializeObject(profile_old); + var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}"; + var profile_olds = new List(); + foreach (var r in profile_old) + { + var data = new ProfileJsonRequest + { + order = r.order, + id = r.id, + reason = r.reason, + remove = r.remove, + profileId = r.profileId, + citizenId = r.citizenId, + prefix = r.prefix, + fullName = r.fullName, + organizationOrganization = r.organizationOrganization, + oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value), + position = r.position, + positionType = r.positionType, + positionExecutive = r.positionExecutive, + posNo = r.posNo, + positionEmployeePosition = r.positionEmployeePosition, + positionEmployeeLevel = r.positionEmployeeLevel, + positionEmployeeGroup = r.positionEmployeeGroup, + posNoEmployee = r.posNoEmployee, + }; + profile_olds.Add(data); + } + var profile = Newtonsoft.Json.JsonConvert.SerializeObject(profile_olds); await _documentService.GenerateJsonFile(profile, "/retire", file_name); var history = new RetirementPeriodHistory { @@ -411,7 +440,7 @@ namespace BMA.EHR.Retirement.Service.Controllers // await _context.SaveChangesAsync(); var profile_new = await _context.RetirementProfiles .Where(x => x.RetirementPeriod == retire) - .Select(x => new ProfileJsonRequest + .Select(x => new { order = x.Order, id = x.Id, @@ -422,7 +451,7 @@ namespace BMA.EHR.Retirement.Service.Controllers prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", organizationOrganization = x.Profile.OrganizationOrganization, - oc = x.Profile.Oc, + ocId = x.Profile.OcId, position = x.Profile.Position == null ? null : x.Profile.Position.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionExecutive = x.Profile.PositionExecutive, @@ -433,7 +462,33 @@ namespace BMA.EHR.Retirement.Service.Controllers posNoEmployee = x.Profile.PosNoEmployee, }) .ToListAsync(); - return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.Detail, profile = profile_new }); + var profile_news = new List(); + foreach (var r in profile_new) + { + var data = new ProfileJsonRequest + { + order = r.order, + id = r.id, + reason = r.reason, + remove = r.remove, + profileId = r.profileId, + citizenId = r.citizenId, + prefix = r.prefix, + fullName = r.fullName, + organizationOrganization = r.organizationOrganization, + oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value), + position = r.position, + positionType = r.positionType, + positionExecutive = r.positionExecutive, + posNo = r.posNo, + positionEmployeePosition = r.positionEmployeePosition, + positionEmployeeLevel = r.positionEmployeeLevel, + positionEmployeeGroup = r.positionEmployeeGroup, + posNoEmployee = r.posNoEmployee, + }; + profile_news.Add(data); + } + return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.Detail, profile = profile_news }); } /// @@ -473,7 +528,7 @@ namespace BMA.EHR.Retirement.Service.Controllers } var profile_new = await _context.RetirementProfiles .Where(x => x.RetirementPeriod == retire) - .Select(x => new ProfileJsonRequest + .Select(x => new { order = x.Order, id = x.Id, @@ -484,7 +539,7 @@ namespace BMA.EHR.Retirement.Service.Controllers prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", organizationOrganization = x.Profile.OrganizationOrganization, - oc = x.Profile.Oc, + ocId = x.Profile.OcId, position = x.Profile.Position == null ? null : x.Profile.Position.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionExecutive = x.Profile.PositionExecutive, @@ -495,8 +550,35 @@ namespace BMA.EHR.Retirement.Service.Controllers posNoEmployee = x.Profile.PosNoEmployee, }) .ToListAsync(); + var profile_news = new List(); + foreach (var r in profile_new) + { + var data = new ProfileJsonRequest + { + order = r.order, + id = r.id, + reason = r.reason, + remove = r.remove, + profileId = r.profileId, + citizenId = r.citizenId, + prefix = r.prefix, + fullName = r.fullName, + organizationOrganization = r.organizationOrganization, + oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value), + position = r.position, + positionType = r.positionType, + positionExecutive = r.positionExecutive, + posNo = r.posNo, + positionEmployeePosition = r.positionEmployeePosition, + positionEmployeeLevel = r.positionEmployeeLevel, + positionEmployeeGroup = r.positionEmployeeGroup, + posNoEmployee = r.posNoEmployee, + }; + profile_news.Add(data); + } + var file = retire.Document == null ? null : await _documentService.ImagesPath(retire.Document.Id); - return Success(new { Json = false, retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.Detail, profile = profile_new, File = file }); + return Success(new { Json = false, retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.Detail, profile = profile_news, File = file }); } ///