คิวรี่ชื่อสังกัด เกษียณ

This commit is contained in:
Kittapath 2023-09-19 10:14:40 +07:00
parent 978e1bada1
commit 3328bdf726
2 changed files with 130 additions and 19 deletions

View file

@ -20,6 +20,7 @@ namespace BMA.EHR.Application.Repositories.Reports
private readonly IApplicationDBContext _dbContext; private readonly IApplicationDBContext _dbContext;
private readonly IWebHostEnvironment _hostingEnvironment; private readonly IWebHostEnvironment _hostingEnvironment;
private readonly MinIOService _documentService; private readonly MinIOService _documentService;
private readonly OrganizationCommonRepository _organizationCommonRepository;
#endregion #endregion
@ -27,10 +28,12 @@ namespace BMA.EHR.Application.Repositories.Reports
public RetireReportRepository(IApplicationDBContext dbContext, public RetireReportRepository(IApplicationDBContext dbContext,
MinIOService documentService, MinIOService documentService,
OrganizationCommonRepository organizationCommonRepository,
IWebHostEnvironment hostEnvironment) IWebHostEnvironment hostEnvironment)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_hostingEnvironment = hostEnvironment; _hostingEnvironment = hostEnvironment;
_organizationCommonRepository = organizationCommonRepository;
_documentService = documentService; _documentService = documentService;
} }
@ -66,6 +69,7 @@ namespace BMA.EHR.Application.Repositories.Reports
var retire = await _dbContext.Set<RetirementPeriod>() var retire = await _dbContext.Set<RetirementPeriod>()
.Include(x => x.RetirementProfiles) .Include(x => x.RetirementProfiles)
.FirstOrDefaultAsync(x => x.Id == retireId); .FirstOrDefaultAsync(x => x.Id == retireId);
var retires = new List<dynamic>();
if (retire == null) if (retire == null)
{ {
var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable() var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable()
@ -116,7 +120,7 @@ namespace BMA.EHR.Application.Repositories.Reports
{ {
profiles = profiles.OrderBy(x => x.order).ToList(); 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 else
@ -135,19 +139,44 @@ namespace BMA.EHR.Application.Repositories.Reports
prefix = x.Profile.Prefix == null ? string.Empty : x.Profile.Prefix.Name, prefix = x.Profile.Prefix == null ? string.Empty : x.Profile.Prefix.Name,
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
organizationOrganization = x.Profile.OrganizationOrganization, organizationOrganization = x.Profile.OrganizationOrganization,
oc = x.Profile.Oc, ocId = x.Profile.OcId,
position = x.Profile.Position == null ? string.Empty : x.Profile.Position.Name, position = x.Profile.Position == null ? string.Empty : x.Profile.Position.Name,
positionType = x.Profile.PositionType == null ? string.Empty : x.Profile.PositionType.Name, positionType = x.Profile.PositionType == null ? string.Empty : x.Profile.PositionType.Name,
positionExecutive = x.Profile.PositionExecutive, positionExecutive = x.Profile.PositionExecutive,
posNo = x.Profile.PosNo == null ? string.Empty : x.Profile.PosNo.Name, posNo = x.Profile.PosNo == null ? string.Empty : x.Profile.PosNo.Name,
positionEmployeePosition = x.Profile.PositionEmployeePosition, positionEmployeePosition = x.Profile.PositionEmployeePosition == null ? null : x.Profile.PositionEmployeePosition.Name,
positionEmployeeLevel = x.Profile.PositionEmployeeLevel, positionEmployeeLevel = x.Profile.PositionEmployeeLevel == null ? null : x.Profile.PositionEmployeeLevel.Name,
positionEmployeeGroup = x.Profile.PositionEmployeeGroup, positionEmployeeGroup = x.Profile.PositionEmployeeGroup == null ? null : x.Profile.PositionEmployeeGroup.Name,
posNoEmployee = x.Profile.PosNoEmployee, posNoEmployee = x.Profile.PosNoEmployee,
}) })
.ToListAsync(); .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 #endregion

View file

@ -26,6 +26,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly NotificationRepository _repositoryNoti; private readonly NotificationRepository _repositoryNoti;
private readonly ApplicationDBContext _context; private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService; private readonly MinIOService _documentService;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
@ -34,12 +35,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
ApplicationDBContext context, ApplicationDBContext context,
MinIOService documentService, MinIOService documentService,
IConfiguration configuration, IConfiguration configuration,
OrganizationCommonRepository organizationCommonRepository,
IHttpContextAccessor httpContextAccessor) IHttpContextAccessor httpContextAccessor)
{ {
_repository = repository; _repository = repository;
_repositoryNoti = repositoryNoti; _repositoryNoti = repositoryNoti;
_context = context; _context = context;
_documentService = documentService; _documentService = documentService;
_organizationCommonRepository = organizationCommonRepository;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_configuration = configuration; _configuration = configuration;
} }
@ -277,10 +280,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Error(GlobalMessages.RetirementNotCreated); return Error(GlobalMessages.RetirementNotCreated);
if (req.Option == null) if (req.Option == null)
req.Option = "EDIT"; req.Option = "EDIT";
var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}";
var profile_old = await _context.RetirementProfiles var profile_old = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire) .Where(x => x.RetirementPeriod == retire)
.Select(x => new ProfileJsonRequest .Select(x => new
{ {
order = x.Order, order = x.Order,
id = x.Id, id = x.Id,
@ -291,7 +293,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name,
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
organizationOrganization = x.Profile.OrganizationOrganization, organizationOrganization = x.Profile.OrganizationOrganization,
oc = x.Profile.Oc, ocId = x.Profile.OcId,
position = x.Profile.Position == null ? null : x.Profile.Position.Name, position = x.Profile.Position == null ? null : x.Profile.Position.Name,
positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name,
positionExecutive = x.Profile.PositionExecutive, positionExecutive = x.Profile.PositionExecutive,
@ -302,7 +304,34 @@ namespace BMA.EHR.Retirement.Service.Controllers
posNoEmployee = x.Profile.PosNoEmployee, posNoEmployee = x.Profile.PosNoEmployee,
}) })
.ToListAsync(); .ToListAsync();
var profile = Newtonsoft.Json.JsonConvert.SerializeObject(profile_old); var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}";
var profile_olds = new List<ProfileJsonRequest>();
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); await _documentService.GenerateJsonFile(profile, "/retire", file_name);
var history = new RetirementPeriodHistory var history = new RetirementPeriodHistory
{ {
@ -411,7 +440,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
// await _context.SaveChangesAsync(); // await _context.SaveChangesAsync();
var profile_new = await _context.RetirementProfiles var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire) .Where(x => x.RetirementPeriod == retire)
.Select(x => new ProfileJsonRequest .Select(x => new
{ {
order = x.Order, order = x.Order,
id = x.Id, id = x.Id,
@ -422,7 +451,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name,
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
organizationOrganization = x.Profile.OrganizationOrganization, organizationOrganization = x.Profile.OrganizationOrganization,
oc = x.Profile.Oc, ocId = x.Profile.OcId,
position = x.Profile.Position == null ? null : x.Profile.Position.Name, position = x.Profile.Position == null ? null : x.Profile.Position.Name,
positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name,
positionExecutive = x.Profile.PositionExecutive, positionExecutive = x.Profile.PositionExecutive,
@ -433,7 +462,33 @@ namespace BMA.EHR.Retirement.Service.Controllers
posNoEmployee = x.Profile.PosNoEmployee, posNoEmployee = x.Profile.PosNoEmployee,
}) })
.ToListAsync(); .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<ProfileJsonRequest>();
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 });
} }
/// <summary> /// <summary>
@ -473,7 +528,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
} }
var profile_new = await _context.RetirementProfiles var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire) .Where(x => x.RetirementPeriod == retire)
.Select(x => new ProfileJsonRequest .Select(x => new
{ {
order = x.Order, order = x.Order,
id = x.Id, id = x.Id,
@ -484,7 +539,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name,
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
organizationOrganization = x.Profile.OrganizationOrganization, organizationOrganization = x.Profile.OrganizationOrganization,
oc = x.Profile.Oc, ocId = x.Profile.OcId,
position = x.Profile.Position == null ? null : x.Profile.Position.Name, position = x.Profile.Position == null ? null : x.Profile.Position.Name,
positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name,
positionExecutive = x.Profile.PositionExecutive, positionExecutive = x.Profile.PositionExecutive,
@ -495,8 +550,35 @@ namespace BMA.EHR.Retirement.Service.Controllers
posNoEmployee = x.Profile.PosNoEmployee, posNoEmployee = x.Profile.PosNoEmployee,
}) })
.ToListAsync(); .ToListAsync();
var profile_news = new List<ProfileJsonRequest>();
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); 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 });
} }
/// <summary> /// <summary>