Merge branch 'develop' into adiDev
Some checks failed
release-dev / release-dev (push) Failing after 11s
Some checks failed
release-dev / release-dev (push) Failing after 11s
This commit is contained in:
commit
5f80de81a4
1 changed files with 129 additions and 229 deletions
|
|
@ -69,7 +69,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
|
||||
#endregion
|
||||
|
||||
#region " จัดลำดับเกษียณ "
|
||||
private class ObjectOrderRetire
|
||||
{
|
||||
public int Order { get; set; }
|
||||
|
|
@ -81,173 +80,66 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
public DateTime? LastUpdatedAt { get; set; }
|
||||
public Guid? Id { get; set; }
|
||||
}
|
||||
private async Task GenOrderByYear(Guid id)
|
||||
{
|
||||
var Org = await _context.Organizations.FirstOrDefaultAsync(x => x.OrganizationOrder == null);
|
||||
var ocIdList = await _context.Organizations.Select(x => x.Id).ToListAsync();
|
||||
if (Org != null)
|
||||
ocIdList = _documentService.GetAllIdByRoot(Org.Id);
|
||||
var retire = await _context.RetirementPeriods
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (retire == null)
|
||||
return;
|
||||
var _retireProfile = await _context.RetirementProfiles
|
||||
.Where(x => x.RetirementPeriod == retire)
|
||||
.ToListAsync();
|
||||
var profiles = new List<ObjectOrderRetire>();
|
||||
if (retire.Type.Trim().ToUpper().Contains("OFFICER"))
|
||||
{
|
||||
profiles = await (from x in _context.RetirementProfiles
|
||||
where x.RetirementPeriod == retire
|
||||
select new ObjectOrderRetire
|
||||
{
|
||||
Id = x.Id,
|
||||
Order = x.Order,
|
||||
Order1 = x.Order,
|
||||
// Order1 = x.Order == null ? 999999999 : x.Order,
|
||||
Order2 = x.posTypeRank,
|
||||
Order3 = x.posLevelRank,
|
||||
LastUpdateFullName = x.LastUpdateFullName,
|
||||
LastUpdateUserId = x.LastUpdateUserId,
|
||||
LastUpdatedAt = x.LastUpdatedAt,
|
||||
}).ToListAsync();
|
||||
}
|
||||
if (retire.Type.Trim().ToUpper().Contains("EMPLOYEE"))
|
||||
{
|
||||
profiles = await (from x in _context.RetirementProfiles
|
||||
where x.RetirementPeriod == retire
|
||||
// x.Profile.PositionEmployeeLevelId == null ? null : x.Profile.PositionEmployeeLevelId.Order
|
||||
select new ObjectOrderRetire
|
||||
{
|
||||
Id = x.Id,
|
||||
Order = x.Order,
|
||||
Order1 = x.Order,
|
||||
// Order1 = x.Order == null ? 999999999 : x.Order,
|
||||
LastUpdateFullName = x.LastUpdateFullName,
|
||||
LastUpdateUserId = x.LastUpdateUserId,
|
||||
LastUpdatedAt = x.LastUpdatedAt,
|
||||
}).ToListAsync();
|
||||
}
|
||||
var _profiles = profiles.AsQueryable().OrderBy(x => x.Order1).ThenBy(x => x.Order2).ThenBy(x => x.Order3).ToList();
|
||||
var order = 1;
|
||||
foreach (var profile in _profiles)
|
||||
{
|
||||
var retireProfile = _retireProfile.Find(x => x.Id == profile.Id);
|
||||
retireProfile.Order = order;
|
||||
retireProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
retireProfile.LastUpdateUserId = UserId ?? "";
|
||||
retireProfile.LastUpdatedAt = DateTime.Now;
|
||||
order++;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private int SortOrg(Guid? ocId)
|
||||
{
|
||||
if (ocId == null)
|
||||
return 999999999;
|
||||
var Org = _context.Organizations.Include(x => x.OrganizationOrganization).FirstOrDefault(x => x.OrganizationOrder == null);
|
||||
if (Org != null && Org.OrganizationOrganization != null && Org.OrganizationOrganization.Name.Contains("ปลัด"))
|
||||
return -1;
|
||||
var ocIdList = _context.Organizations.Select(x => x.Id).ToList();
|
||||
if (Org != null)
|
||||
ocIdList = _documentService.GetAllIdByRoot(Org.Id);
|
||||
int index = ocIdList.IndexOf((Guid)ocId);
|
||||
if (index == -1)
|
||||
return 999999999;
|
||||
return index;
|
||||
}
|
||||
|
||||
private async Task<string> GetAgency(Guid profileId)
|
||||
{
|
||||
var organizationAgency = "-";
|
||||
var _profile = await _context.Profiles
|
||||
.Where(x => x.Id == profileId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (_profile != null)
|
||||
{
|
||||
if (_profile.ProfileType == "officer")
|
||||
{
|
||||
var organization = await _context.Organizations
|
||||
.Where(x => x.Id == _profile.OcId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (organization != null)
|
||||
{
|
||||
var _organizationAgency = await _context.Organizations
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Where(x => x.Id == organization.OrganizationAgencyId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (_organizationAgency != null && _organizationAgency.OrganizationOrganization != null)
|
||||
{
|
||||
organizationAgency = _organizationAgency.OrganizationOrganization.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var profilePosition = await _context.OrganizationEmployees
|
||||
.Include(x => x.OrganizationAgency)
|
||||
.ThenInclude(x => x.OrganizationOrganization)
|
||||
.Where(x => x.Organization != null)
|
||||
.Where(x => x.OrganizationAgency != null)
|
||||
.Where(x => x.OrganizationAgency.OrganizationOrganization != null)
|
||||
.Where(x => x.OrganizationAgency.OrganizationOrganization.Name != null)
|
||||
.Where(x => x.Organization.Id == _profile.OcId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (profilePosition != null)
|
||||
{
|
||||
organizationAgency = profilePosition.OrganizationAgency.OrganizationOrganization.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return organizationAgency;
|
||||
}
|
||||
|
||||
private async Task<string> GetGovermentAgency(Guid profileId)
|
||||
{
|
||||
var organizationGovernmentAgency = "-";
|
||||
var _profile = await _context.Profiles
|
||||
.Where(x => x.Id == profileId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (_profile != null)
|
||||
{
|
||||
if (_profile.ProfileType == "officer")
|
||||
{
|
||||
var organization = await _context.Organizations
|
||||
.Where(x => x.Id == _profile.OcId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (organization != null)
|
||||
{
|
||||
var _organizationGovernmentAgency = await _context.Organizations
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Where(x => x.Id == organization.OrganizationGovernmentAgencyId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (_organizationGovernmentAgency != null && _organizationGovernmentAgency.OrganizationOrganization != null)
|
||||
{
|
||||
organizationGovernmentAgency = _organizationGovernmentAgency.OrganizationOrganization.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var profilePosition = await _context.OrganizationEmployees
|
||||
.Include(x => x.OrganizationGovernmentAgency)
|
||||
.ThenInclude(x => x.OrganizationOrganization)
|
||||
.Where(x => x.Organization != null)
|
||||
.Where(x => x.OrganizationGovernmentAgency != null)
|
||||
.Where(x => x.OrganizationGovernmentAgency.OrganizationOrganization != null)
|
||||
.Where(x => x.OrganizationGovernmentAgency.OrganizationOrganization.Name != null)
|
||||
.Where(x => x.Organization.Id == _profile.OcId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (profilePosition != null)
|
||||
{
|
||||
organizationGovernmentAgency = profilePosition.OrganizationGovernmentAgency.OrganizationOrganization.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return organizationGovernmentAgency;
|
||||
}
|
||||
#endregion
|
||||
// private async Task GenOrderByYear(Guid id)
|
||||
// {
|
||||
// // var Org = await _context.Organizations.FirstOrDefaultAsync(x => x.OrganizationOrder == null);
|
||||
// // var ocIdList = await _context.Organizations.Select(x => x.Id).ToListAsync();
|
||||
// // if (Org != null)
|
||||
// // ocIdList = _documentService.GetAllIdByRoot(Org.Id);
|
||||
// // var retire = await _context.RetirementPeriods
|
||||
// // .FirstOrDefaultAsync(x => x.Id == id);
|
||||
// // if (retire == null)
|
||||
// // return;
|
||||
// // var _retireProfile = await _context.RetirementProfiles
|
||||
// // .Where(x => x.RetirementPeriod == retire)
|
||||
// // .ToListAsync();
|
||||
// // var profiles = new List<ObjectOrderRetire>();
|
||||
// // if (retire.Type.Trim().ToUpper().Contains("OFFICER"))
|
||||
// // {
|
||||
// // profiles = await (from x in _context.RetirementProfiles
|
||||
// // where x.RetirementPeriod == retire
|
||||
// // select new ObjectOrderRetire
|
||||
// // {
|
||||
// // Id = x.Id,
|
||||
// // Order = x.Order,
|
||||
// // Order1 = x.Order,
|
||||
// // // Order1 = x.Order == null ? 999999999 : x.Order,
|
||||
// // Order2 = x.posTypeRank,
|
||||
// // Order3 = x.posLevelRank,
|
||||
// // LastUpdateFullName = x.LastUpdateFullName,
|
||||
// // LastUpdateUserId = x.LastUpdateUserId,
|
||||
// // LastUpdatedAt = x.LastUpdatedAt,
|
||||
// // }).ToListAsync();
|
||||
// // }
|
||||
// // if (retire.Type.Trim().ToUpper().Contains("EMPLOYEE"))
|
||||
// // {
|
||||
// // profiles = await (from x in _context.RetirementProfiles
|
||||
// // where x.RetirementPeriod == retire
|
||||
// // // x.Profile.PositionEmployeeLevelId == null ? null : x.Profile.PositionEmployeeLevelId.Order
|
||||
// // select new ObjectOrderRetire
|
||||
// // {
|
||||
// // Id = x.Id,
|
||||
// // Order = x.Order,
|
||||
// // Order1 = x.Order,
|
||||
// // // Order1 = x.Order == null ? 999999999 : x.Order,
|
||||
// // LastUpdateFullName = x.LastUpdateFullName,
|
||||
// // LastUpdateUserId = x.LastUpdateUserId,
|
||||
// // LastUpdatedAt = x.LastUpdatedAt,
|
||||
// // }).ToListAsync();
|
||||
// // }
|
||||
// // var _profiles = profiles.AsQueryable().OrderBy(x => x.Order1).ThenBy(x => x.Order2).ThenBy(x => x.Order3).ToList();
|
||||
// // var order = 1;
|
||||
// // foreach (var profile in _profiles)
|
||||
// // {
|
||||
// // var retireProfile = _retireProfile.Find(x => x.Id == profile.Id);
|
||||
// // retireProfile.Order = order;
|
||||
// // retireProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
// // retireProfile.LastUpdateUserId = UserId ?? "";
|
||||
// // retireProfile.LastUpdatedAt = DateTime.Now;
|
||||
// // order++;
|
||||
// // }
|
||||
// // await _context.SaveChangesAsync();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// list ประกาศเกษียณอายุราชการ
|
||||
|
|
@ -538,7 +430,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
order++;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
await GenOrderByYear(retire.Id);
|
||||
// await GenOrderByYear(retire.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1004,7 +896,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
retire_profile.LastUpdateUserId = UserId ?? "";
|
||||
retire_profile.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
var num = 1;
|
||||
var num = 0;
|
||||
|
||||
var profileRawCount = await _context.RetirementRawProfiles
|
||||
.CountAsync(x => x.RetirementPeriod.Id == retireId);
|
||||
|
|
@ -1119,10 +1011,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
_context.RetirementProfiles.Add(data);
|
||||
_context.RetirementRawProfiles.Add(dataRaw);
|
||||
await _context.SaveChangesAsync();
|
||||
if (retire.RetirementPeriodHistorys.Count() == 0)
|
||||
{
|
||||
await GenOrderByYear(retire.Id);
|
||||
}
|
||||
// if (retire.RetirementPeriodHistorys.Count() == 0)
|
||||
// {
|
||||
// await GenOrderByYear(retire.Id);
|
||||
// }
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
|
|
@ -1230,10 +1122,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
_context.RetirementProfiles.Add(data);
|
||||
_context.RetirementRawProfiles.Add(dataRaw);
|
||||
await _context.SaveChangesAsync();
|
||||
if (retire.RetirementPeriodHistorys.Count() == 0)
|
||||
{
|
||||
await GenOrderByYear(retire.Id);
|
||||
}
|
||||
// if (retire.RetirementPeriodHistorys.Count() == 0)
|
||||
// {
|
||||
// await GenOrderByYear(retire.Id);
|
||||
// }
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
|
|
@ -1313,7 +1205,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
{
|
||||
_context.RetirementProfiles.Remove(profile);
|
||||
_context.SaveChanges();
|
||||
await GenOrderByYear(profile.RetirementPeriod.Id);
|
||||
// await GenOrderByYear(profile.RetirementPeriod.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1375,7 +1267,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
if (retire == null)
|
||||
return Error(GlobalMessages.RetirementNotFound, 404);
|
||||
|
||||
await GenOrderByYear(retire.Id);
|
||||
// await GenOrderByYear(retire.Id);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
|
@ -1418,58 +1310,66 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
retire.LastUpdateUserId = UserId ?? "";
|
||||
retire.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
var apiUrl = $"{_configuration["API"]}/org/root/search/sort";
|
||||
dynamic rootOrder = new List<string>();
|
||||
dynamic child1Order = new List<string>();
|
||||
dynamic child2Order = new List<string>();
|
||||
dynamic child3Order = new List<string>();
|
||||
dynamic child4Order = new List<string>();
|
||||
dynamic posTypeNameOrder = new List<string>();
|
||||
dynamic posLevelNameOrder = new List<string>();
|
||||
using (var client = new HttpClient())
|
||||
if(retire.TypeReport == null)
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var _res = await client.SendAsync(_req);
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<dynamic>(_result);
|
||||
|
||||
if (org != null && org.result != null)
|
||||
var apiUrl = $"{_configuration["API"]}/org/root/search/sort";
|
||||
dynamic rootOrder = new List<string>();
|
||||
dynamic child1Order = new List<string>();
|
||||
dynamic child2Order = new List<string>();
|
||||
dynamic child3Order = new List<string>();
|
||||
dynamic child4Order = new List<string>();
|
||||
dynamic posTypeNameOrder = new List<string>();
|
||||
dynamic posLevelNameOrder = new List<string>();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
rootOrder = org.result.root;
|
||||
child1Order = org.result.child1;
|
||||
child2Order = org.result.child2;
|
||||
child3Order = org.result.child3;
|
||||
child4Order = org.result.child4;
|
||||
posTypeNameOrder = org.result.posTypeNameOrder;
|
||||
posLevelNameOrder = org.result.posLevelNameOrder;
|
||||
client.DefaultRequestHeaders.Authorization =
|
||||
new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var _res = await client.SendAsync(_req);
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<dynamic>(_result);
|
||||
|
||||
if (org != null && org.result != null)
|
||||
{
|
||||
rootOrder = org.result.root;
|
||||
child1Order = org.result.child1;
|
||||
child2Order = org.result.child2;
|
||||
child3Order = org.result.child3;
|
||||
child4Order = org.result.child4;
|
||||
posTypeNameOrder = org.result.posTypeNameOrder;
|
||||
posLevelNameOrder = org.result.posLevelNameOrder;
|
||||
}
|
||||
}
|
||||
|
||||
var order = 1;
|
||||
foreach (var profile in retire.RetirementProfiles
|
||||
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => child1Order.ToObject<List<string>>().IndexOf(x.child1 ?? ""))
|
||||
.ThenBy(x => child2Order.ToObject<List<string>>().IndexOf(x.child2 ?? ""))
|
||||
.ThenBy(x => child3Order.ToObject<List<string>>().IndexOf(x.child3 ?? ""))
|
||||
.ThenBy(x => child4Order.ToObject<List<string>>().IndexOf(x.child4 ?? ""))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")))
|
||||
{
|
||||
profile.Order = order;
|
||||
order++;
|
||||
}
|
||||
|
||||
order = 1;
|
||||
foreach (var profile in retire.RetirementRawProfiles
|
||||
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => child1Order.ToObject<List<string>>().IndexOf(x.child1 ?? ""))
|
||||
.ThenBy(x => child2Order.ToObject<List<string>>().IndexOf(x.child2 ?? ""))
|
||||
.ThenBy(x => child3Order.ToObject<List<string>>().IndexOf(x.child3 ?? ""))
|
||||
.ThenBy(x => child4Order.ToObject<List<string>>().IndexOf(x.child4 ?? ""))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")))
|
||||
{
|
||||
profile.Order = order;
|
||||
order++;
|
||||
}
|
||||
}
|
||||
var order = 1;
|
||||
foreach (var profile in retire.RetirementProfiles.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => child1Order.ToObject<List<string>>().IndexOf(x.child1 ?? ""))
|
||||
.ThenBy(x => child2Order.ToObject<List<string>>().IndexOf(x.child2 ?? ""))
|
||||
.ThenBy(x => child3Order.ToObject<List<string>>().IndexOf(x.child3 ?? ""))
|
||||
.ThenBy(x => child4Order.ToObject<List<string>>().IndexOf(x.child4 ?? ""))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")))
|
||||
{
|
||||
profile.Order = order;
|
||||
order++;
|
||||
}
|
||||
order = 1;
|
||||
foreach (var profile in retire.RetirementRawProfiles.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => child1Order.ToObject<List<string>>().IndexOf(x.child1 ?? ""))
|
||||
.ThenBy(x => child2Order.ToObject<List<string>>().IndexOf(x.child2 ?? ""))
|
||||
.ThenBy(x => child3Order.ToObject<List<string>>().IndexOf(x.child3 ?? ""))
|
||||
.ThenBy(x => child4Order.ToObject<List<string>>().IndexOf(x.child4 ?? ""))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")))
|
||||
{
|
||||
profile.Order = order;
|
||||
order++;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue