api พ้นราชการ

This commit is contained in:
Kittapath 2023-07-25 14:32:02 +07:00
parent b800b9e60d
commit 1c09aa8e23
8 changed files with 12002 additions and 30 deletions

View file

@ -56,7 +56,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (type.Trim().ToUpper().Contains("OFFICER"))
{
var profiles = await _context.RetirementProfiles
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.RetirementPeriod.Year == year)
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderBy(x => x.Profile.OrganizationOrganization)
.ThenBy(x => x.Profile.PositionType == null ? null : x.Profile.PositionType.Name)
@ -75,7 +75,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (type.Trim().ToUpper().Contains("EMPLOYEE"))
{
var profiles = await _context.RetirementProfiles
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.RetirementPeriod.Year == year)
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderBy(x => x.Profile.OrganizationOrganization)
.ThenBy(x => x.Profile.EmployeeType)
@ -112,7 +112,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var retire_old = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderByDescending(x => x.Round)
.FirstOrDefaultAsync();
@ -121,13 +121,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var data = await _context.RetirementPeriods
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.Where(x => year > 0 ? (x.CreatedAt.Year == year) : (x.CreatedAt.Year > 0))
.Where(x => year > 0 ? (x.Year == year) : (x.Year > 0))
.Select(x => new
{
Id = x.Id,
CreatedAt = x.CreatedAt,
Year = x.Year,
Round = x.Round,
Total = retire_old.Id == x.Id ? retire_old.RetirementProfiles.Count() : retire_old.RetirementProfiles.Count() - x.RetirementProfiles.Where(x => x.Remove == true).Count(),
Total = retire_old.Id == x.Id ? retire_old.RetirementProfiles.Count() : retire_old.RetirementProfiles.Count() - x.RetirementProfiles.Where(x => x.Remove != "pending").Count(),
}).OrderByDescending(x => x.CreatedAt)
.ToListAsync();
return Success(data);
@ -152,7 +153,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var round = 1;
var retire_old = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderByDescending(x => x.Round)
.FirstOrDefaultAsync();
@ -163,6 +164,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
Round = round,
Type = type.Trim().ToUpper(),
Year = year,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
@ -175,7 +177,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var profiles = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire_old)
.Where(x => x.Remove == false)
.Where(x => x.Remove == "pending")
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.ToListAsync();
foreach (var profile in profiles)
@ -198,14 +200,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
// where p.BirthDate.CalculateRetireDate().Year == year
// select p)
// .ToListAsync();
profiles = profiles.Where(x=>x.BirthDate.CalculateRetireDate().Year == year).ToList();
profiles = profiles.Where(x => x.BirthDate.CalculateRetireDate().Year == year).ToList();
var order = 1;
foreach (var profile in profiles)
{
var data = new RetirementProfile
{
Order = order,
Remove = false,
Remove = "pending",
RetirementPeriod = retire,
Profile = profile,
CreatedUserId = FullName ?? "",
@ -220,15 +222,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
}
_context.SaveChanges();
var retire_all_year = await _context.RetirementPeriods
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.CountAsync();
if (retire_all_year <= 1)
{
await GenOrderByYear(type.Trim().ToUpper(), year);
}
_context.SaveChanges();
var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
@ -255,7 +248,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
PosNoEmployee = x.Profile.PosNoEmployee,
})
.ToListAsync();
return Success(new { retire.Id, retire.CreatedAt, retire.Round, retire.Type, profile = profile_new });
return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, profile = profile_new });
}
/// <summary>
@ -277,6 +270,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var retire_old = await _context.RetirementPeriods
.Where(x => x.CreatedAt < retire.CreatedAt)
.Where(x => x.Year == retire.Year)
.Where(x => x.Type.Trim().ToUpper().Contains(retire.Type.Trim().ToUpper()))
.ToListAsync();
@ -326,7 +320,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
_context.RetirementProfiles.Remove(profile);
profile.Remove = "delete";
profile.LastUpdateFullName = FullName ?? "System Administrator";
profile.LastUpdateUserId = UserId ?? "";
profile.LastUpdatedAt = DateTime.Now;
_context.SaveChanges();
return Success();
@ -356,9 +353,13 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Error(GlobalMessages.InvalidRetirementRequest, 404);
var order = 1;
var retire_old = await _context.RetirementPeriods
.Where(x => x.CreatedAt.Year == retire.CreatedAt.Year)
.Include(x => x.RetirementProfiles)
.ThenInclude(x => x.Profile)
.Where(x => x.Year == retire.Year)
.Where(x => x.Type.Trim().ToUpper().Contains(retire.Type.Trim().ToUpper()))
.ToListAsync();
if (retire_old.Where(x => x.RetirementProfiles.Where(y => y.Profile == profile).Count() > 0).Count() > 0)
return Error("บุคคลนี้ได้ทำการเลือกไว้อยู่แล้ว");
var last_order = await _context.RetirementProfiles
.Where(x => retire_old.Contains(x.RetirementPeriod))
@ -370,7 +371,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var data = new RetirementProfile
{
Order = order,
Remove = false,
Remove = "pending",
RetirementPeriod = retire,
Profile = profile,
CreatedUserId = FullName ?? "",
@ -380,10 +381,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
if (retire_old.Count() <= 1)
{
await GenOrderByYear(retire.Type.Trim().ToUpper(), retire.CreatedAt.Year);
}
_context.RetirementProfiles.Add(data);
_context.SaveChanges();
@ -409,7 +406,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
profile.Remove = true;
profile.Remove = "change";
profile.Reason = req.Reason;
profile.LastUpdateFullName = FullName ?? "System Administrator";
profile.LastUpdateUserId = UserId ?? "";
@ -443,5 +440,27 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success(profile);
}
/// <summary>
/// View รายชื่อผู้เกษียณอายุราชการในประกาศ
/// </summary>
/// <param name="retireId">Id ประกาศ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{retireId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateProfileRetirement(Guid retireId)
{
var retire = await _context.RetirementPeriods
.FirstOrDefaultAsync(x => x.Id == retireId);
if (retire == null)
return Error(GlobalMessages.InvalidRetirementRequest, 404);
await GenOrderByYear(retire.Type.Trim().ToUpper(), retire.Year);
return Success();
}
}
}