แก้ระบบบรรจุผูกโครงสร้างใหม่

This commit is contained in:
Kittapath 2024-05-02 09:31:38 +07:00
parent 57164f5d45
commit 18d75f4b04
37 changed files with 79295 additions and 3904 deletions

View file

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Reflection.Metadata;
using System.Security.Claims;
using System.Security.Cryptography;
@ -60,7 +61,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
/// <summary>
@ -74,64 +77,87 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetList()
{
var retirementDeceaseds = await _context.RetirementDeceaseds.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
ProfileId = p.Profile.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
Position = p.Profile.Position == null ? null : p.Profile.Position.Name,
PositionType = p.Profile.PositionType == null ? null : p.Profile.PositionType.Name,
p.Profile.PositionLine,
// PositionLine = p.Profile.PositionLine == null ? null : p.Profile.PositionLine.Name,
PositionLevel = p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name,
p.Profile.PositionExecutive,
// PositionExecutive = p.Profile.PositionExecutive == null ? null : p.Profile.PositionExecutive.Name,
Organization = p.Profile.Oc,
// Organization = p.Profile.Oc == null ? null : p.Profile.Oc.Name,
p.Number,
p.Date,
p.Location,
p.Reason,
FileName = p.Document == null ? null : p.Document.FileName,
PathName = p.Document == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Document.Id,
p.IsActive,
p.CreatedAt,
})
.ToListAsync();
var _retirementDeceaseds = new List<dynamic>();
foreach (var data in retirementDeceaseds)
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
var _data = new
{
data.Id,
data.ProfileId,
data.Prefix,
data.FirstName,
data.LastName,
data.Position,
data.PositionExecutive,
data.PositionType,
data.PositionLine,
data.PositionLevel,
data.Organization,
data.Number,
data.Date,
data.Location,
data.Reason,
data.FileName,
PathName = data.PathName == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.PathName),
data.IsActive,
data.CreatedAt,
};
_retirementDeceaseds.Add(_data);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var retirementDeceaseds = await _context.RetirementDeceaseds.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => RetirementAdmin == true ? true : (rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))))
.Select(p => new
{
p.Id,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.CreatedAt,
p.IsActive,
})
.ToListAsync();
// var _retirementDeceaseds = new List<dynamic>();
// foreach (var data in retirementDeceaseds)
// {
// var _data = new
// {
// data.Id,
// data.ProfileId,
// data.Prefix,
// data.FirstName,
// data.LastName,
// data.Position,
// data.PositionExecutive,
// data.PositionType,
// data.PositionLine,
// data.PositionLevel,
// data.Organization,
// data.Number,
// data.Date,
// data.Location,
// data.Reason,
// data.FileName,
// PathName = data.PathName == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.PathName),
// data.IsActive,
// data.CreatedAt,
// };
// _retirementDeceaseds.Add(_data);
// }
return Success(retirementDeceaseds);
}
return Success(_retirementDeceaseds);
}
/// <summary>
@ -151,26 +177,24 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
p.Id,
ProfileId = p.Profile.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
p.Profile.FirstName,
p.Profile.LastName,
Position = p.Profile.Position == null ? null : p.Profile.Position.Name,
PositionId = p.Profile.Position == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Position.Id,
PositionType = p.Profile.PositionType == null ? null : p.Profile.PositionType.Name,
PositionTypeId = p.Profile.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionType.Id,
p.Profile.PositionLine,
p.Profile.PositionLineId,
// PositionLine = p.Profile.PositionLine == null ? null : p.Profile.PositionLine.Name,
PositionLevel = p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name,
PositionLevelId = p.Profile.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionLevel.Id,
p.Profile.PositionExecutive,
p.Profile.PositionExecutiveId,
// PositionExecutive = p.Profile.PositionExecutive == null ? null : p.Profile.PositionExecutive.Name,
Organization = p.Profile.Oc,
OrganizationId = p.Profile.OcId,
// Organization = p.Profile.Oc == null ? null : p.Profile.Oc.Name,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Number,
p.Date,
p.Location,
@ -179,7 +203,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
PathName = p.Document == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Document.Id,
p.IsActive,
p.CreatedAt,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
// Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
})
.FirstOrDefaultAsync();
if (data == null)
@ -187,32 +211,32 @@ namespace BMA.EHR.Retirement.Service.Controllers
var _data = new
{
data.Id,
data.ProfileId,
data.Prefix,
data.PrefixId,
data.FirstName,
data.LastName,
data.Position,
data.PositionExecutive,
data.PositionType,
data.PositionLine,
data.PositionLevel,
data.Organization,
data.PositionId,
data.PositionExecutiveId,
data.PositionTypeId,
data.PositionLineId,
data.PositionLevelId,
data.OrganizationId,
data.profileId,
data.prefix,
data.firstName,
data.lastName,
data.root,
data.rootShortName,
data.child1,
data.child1ShortName,
data.child2,
data.child2ShortName,
data.child3,
data.child3ShortName,
data.child4,
data.child4ShortName,
data.posMasterNo,
data.position,
data.posLevelName,
data.posTypeName,
data.Number,
data.Date,
data.Location,
data.Reason,
data.FileName,
PathName = data.PathName == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.PathName),
data.IsActive,
data.CreatedAt,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
// Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
};
return Success(_data);
@ -229,18 +253,19 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementDeceasedRequest req)
{
var profile = await _context.Profiles
.Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == req.ProfileId);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
profile.LeaveDate = DateTime.Now;
profile.IsLeave = true;
profile.LeaveReason = "DEATH";
// var profile = await _context.Profiles
// .Include(x => x.Prefix)
// .FirstOrDefaultAsync(x => x.Id == req.ProfileId);
// if (profile == null)
// return Error(GlobalMessages.DataNotFound, 404);
// profile.LeaveDate = DateTime.Now;
// profile.IsLeave = true;
// profile.LeaveReason = "DEATH";
var retirementDeceased = new RetirementDeceased
{
Profile = profile,
// Profile = profile,
Number = req.Number,
Date = req.Date,
Location = req.Location,
@ -253,6 +278,46 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}org/profile/profileid/position/{req.ProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementDeceased.profileId = org.result.profileId;
retirementDeceased.prefix = org.result.prefix;
retirementDeceased.firstName = org.result.firstName;
retirementDeceased.lastName = org.result.lastName;
retirementDeceased.citizenId = org.result.citizenId;
retirementDeceased.root = org.result.root;
retirementDeceased.rootId = org.result.rootId;
retirementDeceased.rootShortName = org.result.rootShortName;
retirementDeceased.child1 = org.result.child1;
retirementDeceased.child1Id = org.result.child1Id;
retirementDeceased.child1ShortName = org.result.child1ShortName;
retirementDeceased.child2 = org.result.child2;
retirementDeceased.child2Id = org.result.child2Id;
retirementDeceased.child2ShortName = org.result.child2ShortName;
retirementDeceased.child3 = org.result.child3;
retirementDeceased.child3Id = org.result.child3Id;
retirementDeceased.child3ShortName = org.result.child3ShortName;
retirementDeceased.child4 = org.result.child4;
retirementDeceased.child4Id = org.result.child4Id;
retirementDeceased.child4ShortName = org.result.child4ShortName;
retirementDeceased.posMasterNo = org.result.posMasterNo;
retirementDeceased.position = org.result.position;
retirementDeceased.posTypeId = org.result.posTypeId;
retirementDeceased.posTypeName = org.result.posTypeName;
retirementDeceased.posLevelId = org.result.posLevelId;
retirementDeceased.posLevelName = org.result.posLevelName;
}
await _context.RetirementDeceaseds.AddAsync(retirementDeceased);
await _context.SaveChangesAsync();
var _doc = new Domain.Models.Documents.Document();
@ -267,16 +332,68 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (_doc != null)
retirementDeceased.Document = _doc;
}
await _context.ProfileSalaries.AddAsync(new ProfileSalary
// await _context.ProfileSalaries.AddAsync(new ProfileSalary
// {
// Date = req.Date,
// SalaryRef = req.Number,
// CommandNo = "-",
// SalaryClass = "-",
// PosNoEmployee = "-",
// CommandTypeName = "-",
// SalaryStatus = "DEATH",
// Profile = profile,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
// if (_doc != null)
// {
// await _context.ProfilePapers.AddAsync(new ProfilePaper
// {
// Detail = "ถึงแก่กรรม",
// CategoryName = "DEATH",
// Document = _doc,
// Profile = profile,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
// }
// var orgPos = await _context.ProfilePositions
// .Include(x => x.Profile)
// .ThenInclude(x => x!.Prefix)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x!.Organization)
// .ThenInclude(x => x!.OrganizationOrganization)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x!.PositionMaster)
// .ThenInclude(x => x!.PositionPath)
// .Where(x => x.OrganizationPosition!.IsDirector! == true)
// .Where(x => x.OrganizationPosition!.Organization!.Id == profile.OcId)
// .FirstOrDefaultAsync();
// if (orgPos != null)
// {
// if (orgPos.Profile != null)
// {
retirementDeceased.RetirementDeceasedNotis.Add(new RetirementDeceasedNoti
{
Date = req.Date,
SalaryRef = req.Number,
CommandNo = "-",
SalaryClass = "-",
PosNoEmployee = "-",
CommandTypeName = "-",
SalaryStatus = "DEATH",
Profile = profile,
CitizenId = retirementDeceased.citizenId,
Prefix = retirementDeceased.prefix,
FirstName = retirementDeceased.firstName,
LastName = retirementDeceased.lastName,
IsSendMail = true,
IsSendInbox = true,
IsSendNotification = true,
// OrganizationName = retirementDeceased.OrganizationName,
// PositionName = retirementDeceased.PositionName,
// ReceiveUser = profile,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
@ -284,60 +401,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
if (_doc != null)
{
await _context.ProfilePapers.AddAsync(new ProfilePaper
{
Detail = "ถึงแก่กรรม",
CategoryName = "DEATH",
Document = _doc,
Profile = profile,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
var orgPos = await _context.ProfilePositions
.Include(x => x.Profile)
.ThenInclude(x => x!.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.ThenInclude(x => x!.OrganizationOrganization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Where(x => x.OrganizationPosition!.IsDirector! == true)
.Where(x => x.OrganizationPosition!.Organization!.Id == profile.OcId)
.FirstOrDefaultAsync();
if (orgPos != null)
{
if (orgPos.Profile != null)
{
retirementDeceased.RetirementDeceasedNotis.Add(new RetirementDeceasedNoti
{
CitizenId = orgPos!.Profile!.CitizenId!,
Prefix = orgPos!.Profile!.Prefix!.Name,
FirstName = orgPos!.Profile!.FirstName!,
LastName = orgPos!.Profile!.LastName!,
IsSendMail = true,
IsSendInbox = true,
IsSendNotification = true,
OrganizationName = orgPos!.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
PositionName = orgPos!.OrganizationPosition!.PositionMaster!.PositionPath!.Name,
ReceiveUser = profile,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
}
// }
// }
await _context.SaveChangesAsync();
return Success();
@ -532,8 +597,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
var items = await _context.RetirementDeceasedNotis.AsQueryable()
.Include(x => x.ReceiveUser)
.Include(x => x.RetirementDeceased)
.ThenInclude(x => x.Profile)
.ThenInclude(x => x.Prefix)
// .ThenInclude(x => x.Profile)
// .ThenInclude(x => x.Prefix)
.Where(x => x.RetirementDeceased.Id == id)
.ToListAsync();
@ -562,14 +627,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var item in items)
{
var prefix = item.RetirementDeceased.Profile.Prefix == null ? "" : item.RetirementDeceased.Profile.Prefix.Name;
var prefix = item.RetirementDeceased.prefix;
var profile = req.Persons.FirstOrDefault(x => x.ProfileId == item.ReceiveUser.Id);
if (profile != null)
{
await _repositoryNoti.PushNotificationAsync(
item.ReceiveUser.Id,
$"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
$"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
$"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
$"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
payload_str,
profile.IsSendInbox,
profile.IsSendMail
@ -582,8 +647,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
await _repositoryNoti.PushNotificationAsync(
item.ReceiveUser.Id,
$"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
$"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
$"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
$"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
payload_str,
item.IsSendInbox,
item.IsSendMail

View file

@ -8,7 +8,9 @@ using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
@ -26,18 +28,21 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public RetirementOtherController(RetirementRepository repository,
NotificationRepository repositoryNoti,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{
_repository = repository;
_repositoryNoti = repositoryNoti;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#region " Properties "
@ -45,6 +50,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
@ -61,54 +67,70 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var retirementOthers = await _context.RetirementOthers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.CitizenId,
Prefix = p.Prefix == null ? null : p.Prefix.Name,
p.Firstname,
p.Lastname,
p.DateOfBirth,
Gender = p.Gender == null ? null : p.Gender.Name,
p.Status,
p.Amount,
p.RecruitDate,
PositionNumber = p.PositionNumber == null ? null : p.PositionNumber.Name,
PositionPath = p.PositionPath == null ? null : p.PositionPath.Name,
PositionPathSide = p.PositionPathSide == null ? null : p.PositionPathSide.Name,
PositionType = p.PositionType == null ? null : p.PositionType.Name,
PositionLine = p.PositionLine == null ? null : p.PositionLine.Name,
PositionLevel = p.PositionLevel == null ? null : p.PositionLevel.Name,
PosNoId = p.PositionNumber == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionNumber.Id,
PositionId = p.PositionPath == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPath.Id,
PositionPathSideId = p.PositionPathSide == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPathSide.Id,
PositionTypeId = p.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionType.Id,
PositionLineId = p.PositionLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLine.Id,
PositionLevelId = p.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLevel.Id,
OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
OrganizationName = p.OrganizationPosition == null ? null : (p.OrganizationPosition.Organization == null ? null : (p.OrganizationPosition.Organization.OrganizationOrganization == null ? null : p.OrganizationPosition.Organization.OrganizationOrganization.Name)),////
OrganizationShortName = p.OrganizationPosition == null ? null : (p.OrganizationPosition.Organization == null ? null : (p.OrganizationPosition.Organization.OrganizationShortName == null ? null : p.OrganizationPosition.Organization.OrganizationShortName.Name)),////
p.IsActive,
p.PositionDate,
p.Reason,
p.MilitaryDate,
p.EducationOld,
p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.CreatedAt,
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementOthers.Where(x => x.Status.Trim().ToUpper().Contains("PENDING"));
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
return Success(retirementOthers);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var retirementOthers = await _context.RetirementOthers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => RetirementAdmin == true ? true : (rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))))
.Select(p => new
{
p.Id,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Status,
p.CreatedAt,
p.Reason,
p.MilitaryDate,
p.EducationOld,
p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.PositionDate,
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.ToListAsync();
return Success(retirementOthers);
}
}
/// <summary>
@ -128,30 +150,25 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
p.Id,
ProfileId = p.Profile.Id,
p.CitizenId,
Prefix = p.Prefix == null ? null : p.Prefix.Name,
PrefixId = p.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Prefix.Id,
p.Firstname,
p.Lastname,
p.DateOfBirth,
Gender = p.Gender == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Gender.Id,
p.Nationality,
p.Race,
Religion = p.Religion == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Religion.Id,
BloodGroup = p.BloodGroup == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.BloodGroup.Id,
Relationship = p.Relationship == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Relationship.Id,
p.TelephoneNumber,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Status,
p.Amount,
p.RecruitDate,
PosNo = p.PositionNumber == null ? "-" : p.PositionNumber.Name,
Position = p.PositionPath == null ? "-" : p.PositionPath.Name,
PositionPathSide = p.PositionPathSide == null ? "-" : p.PositionPathSide.Name,
PositionType = p.PositionType == null ? "-" : p.PositionType.Name,
PositionLine = p.PositionLine == null ? "-" : p.PositionLine.Name,
PositionLevel = p.PositionLevel == null ? "-" : p.PositionLevel.Name,
OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
p.CreatedAt,
p.Reason,
p.MilitaryDate,
@ -162,67 +179,67 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.PositionNumberOld,
p.OrganizationPositionOld,
p.PositionDate,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
RetirementOtherDocs = p.RetirementOtherDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
// Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
// RetirementOtherDocs = p.RetirementOtherDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementOtherDocs = new List<dynamic>();
foreach (var doc in data.RetirementOtherDocs)
{
var _doc = new
{
doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
};
retirementOtherDocs.Add(_doc);
}
var _data = new
{
data.Id,
data.ProfileId,
data.CitizenId,
data.Prefix,
data.PrefixId,
data.Firstname,
data.Lastname,
data.DateOfBirth,
data.Gender,
data.Nationality,
data.Race,
data.Religion,
data.BloodGroup,
data.Relationship,
data.TelephoneNumber,
data.Status,
data.Amount,
data.RecruitDate,
data.PosNo,
data.Position,
data.PositionPathSide,
data.PositionType,
data.PositionLine,
data.PositionLevel,
data.OrganizationPositionId,
data.CreatedAt,
data.Reason,
data.MilitaryDate,
data.EducationOld,
data.AmountOld,
data.PositionTypeOld,
data.PositionLevelOld,
data.PositionNumberOld,
data.OrganizationPositionOld,
data.PositionDate,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
Docs = retirementOtherDocs,
data.CommandType,
};
// var retirementOtherDocs = new List<dynamic>();
// foreach (var doc in data.RetirementOtherDocs)
// {
// var _doc = new
// {
// doc.FileName,
// PathName = await _documentService.ImagesPath(doc.Id)
// };
// retirementOtherDocs.Add(_doc);
// }
// var _data = new
// {
// data.Id,
// data.ProfileId,
// data.CitizenId,
// data.Prefix,
// data.PrefixId,
// data.Firstname,
// data.Lastname,
// data.DateOfBirth,
// data.Gender,
// data.Nationality,
// data.Race,
// data.Religion,
// data.BloodGroup,
// data.Relationship,
// data.TelephoneNumber,
// data.Status,
// data.Amount,
// data.RecruitDate,
// data.PosNo,
// data.Position,
// data.PositionPathSide,
// data.PositionType,
// data.PositionLine,
// data.PositionLevel,
// data.OrganizationPositionId,
// data.CreatedAt,
// data.Reason,
// data.MilitaryDate,
// data.EducationOld,
// data.AmountOld,
// data.PositionTypeOld,
// data.PositionLevelOld,
// data.PositionNumberOld,
// data.OrganizationPositionOld,
// data.PositionDate,
// // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
// // Docs = retirementOtherDocs,
// data.CommandType,
// };
return Success(_data);
return Success(data);
}
/// <summary>
@ -236,46 +253,33 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Educations)
.Include(x => x.Position)
.Include(x => x.Gender)
.Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementOther = new RetirementOther
{
Profile = profile,
CitizenId = profile.CitizenId,
Prefix = profile.Prefix,
Firstname = profile.FirstName,
Lastname = profile.LastName,
DateOfBirth = profile.BirthDate,
Gender = profile.Gender,
Nationality = profile.Nationality,
Race = profile.Race,
Religion = await _context.Religions.FindAsync(profile.ReligionId),
BloodGroup = await _context.BloodGroups.FindAsync(profile.BloodGroupId),
Relationship = await _context.Relationships.FindAsync(profile.RelationshipId),
TelephoneNumber = profile.TelephoneNumber,
EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}",
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
PositionNumber = profile.PosNo,
PositionPath = profile.Position,
PositionPathSide = await _context.PositionPathSides.FindAsync(profile.PositionPathSideId),
PositionType = profile.PositionType,
PositionLine = await _context.PositionLines.FindAsync(profile.PositionLineId),
PositionLevel = profile.PositionLevel,
// Profile = profile,
// CitizenId = profile.CitizenId,
// Prefix = profile.Prefix,
// Firstname = profile.FirstName,
// Lastname = profile.LastName,
// DateOfBirth = profile.BirthDate,
// Gender = profile.Gender,
// Nationality = profile.Nationality,
// Race = profile.Race,
// Religion = await _context.Religions.FindAsync(profile.ReligionId),
// BloodGroup = await _context.BloodGroups.FindAsync(profile.BloodGroupId),
// Relationship = await _context.Relationships.FindAsync(profile.RelationshipId),
// TelephoneNumber = profile.TelephoneNumber,
// EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}",
// AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
// PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
// PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
// PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
// OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
// PositionNumber = profile.PosNo,
// PositionPath = profile.Position,
// PositionPathSide = await _context.PositionPathSides.FindAsync(profile.PositionPathSideId),
// PositionType = profile.PositionType,
// PositionLine = await _context.PositionLines.FindAsync(profile.PositionLineId),
// PositionLevel = profile.PositionLevel,
// OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
Status = "WAITTING",
CreatedFullName = FullName ?? "System Administrator",
@ -285,118 +289,158 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}org/profile/profileid/position/{req.Id}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementOther.profileId = org.result.profileId;
retirementOther.prefix = org.result.prefix;
retirementOther.firstName = org.result.firstName;
retirementOther.lastName = org.result.lastName;
retirementOther.citizenId = org.result.citizenId;
retirementOther.root = org.result.root;
retirementOther.rootId = org.result.rootId;
retirementOther.rootShortName = org.result.rootShortName;
retirementOther.child1 = org.result.child1;
retirementOther.child1Id = org.result.child1Id;
retirementOther.child1ShortName = org.result.child1ShortName;
retirementOther.child2 = org.result.child2;
retirementOther.child2Id = org.result.child2Id;
retirementOther.child2ShortName = org.result.child2ShortName;
retirementOther.child3 = org.result.child3;
retirementOther.child3Id = org.result.child3Id;
retirementOther.child3ShortName = org.result.child3ShortName;
retirementOther.child4 = org.result.child4;
retirementOther.child4Id = org.result.child4Id;
retirementOther.child4ShortName = org.result.child4ShortName;
retirementOther.posMasterNo = org.result.posMasterNo;
retirementOther.position = org.result.position;
retirementOther.posTypeId = org.result.posTypeId;
retirementOther.posTypeName = org.result.posTypeName;
retirementOther.posLevelId = org.result.posLevelId;
retirementOther.posLevelName = org.result.posLevelName;
}
await _context.RetirementOthers.AddAsync(retirementOther);
await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
foreach (var file in Request.Form.Files)
{
var fileExtension = Path.GetExtension(file.FileName);
// if (Request.Form.Files != null && Request.Form.Files.Count != 0)
// {
// foreach (var file in Request.Form.Files)
// {
// var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var retirementOtherDoc = new RetirementOtherDoc
{
RetirementOther = retirementOther,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementOtherDocs.AddAsync(retirementOtherDoc);
// var doc = await _documentService.UploadFileAsync(file, file.FileName);
// var _doc = await _context.Documents.AsQueryable()
// .FirstOrDefaultAsync(x => x.Id == doc.Id);
// if (_doc != null)
// {
// var retirementOtherDoc = new RetirementOtherDoc
// {
// RetirementOther = retirementOther,
// Document = _doc,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// };
// await _context.RetirementOtherDocs.AddAsync(retirementOtherDoc);
}
}
}
await _context.SaveChangesAsync();
// }
// }
// }
// await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// เลือกหน่วยงาน
/// </summary>
/// <param name="id">Id อื่นๆ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("position/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdatePositionRetirementOther([FromBody] PersonSelectPositionOtherRequest req, Guid id)
{
var uppdated = await _context.RetirementOthers
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementOtherNotFound, 404);
if (req.PosNoId != null)
{
var save_posNo = await _context.PositionNumbers.FindAsync(req.PosNoId);
if (save_posNo == null)
return Error(GlobalMessages.PositionPosNoNotFound, 404);
uppdated.PositionNumber = save_posNo;
// /// <summary>
// /// เลือกหน่วยงาน
// /// </summary>
// /// <param name="id">Id อื่นๆ</param>
// /// <returns></returns>
// /// <response code="200"></response>
// /// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
// /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
// /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
// [HttpPut("position/{id:length(36)}")]
// public async Task<ActionResult<ResponseObject>> UpdatePositionRetirementOther([FromBody] PersonSelectPositionOtherRequest req, Guid id)
// {
// var uppdated = await _context.RetirementOthers
// .FirstOrDefaultAsync(x => x.Id == id);
// if (uppdated == null)
// return Error(GlobalMessages.RetirementOtherNotFound, 404);
// if (req.PosNoId != null)
// {
// var save_posNo = await _context.PositionNumbers.FindAsync(req.PosNoId);
// if (save_posNo == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// uppdated.PositionNumber = save_posNo;
var save_orgPosition = await _context.OrganizationPositions.FirstOrDefaultAsync(x => x.PositionNumber == save_posNo);
if (save_orgPosition == null)
return Error(GlobalMessages.PositionPosNoNotFound, 404);
uppdated.OrganizationPosition = save_orgPosition;
}
// var save_orgPosition = await _context.OrganizationPositions.FirstOrDefaultAsync(x => x.PositionNumber == save_posNo);
// if (save_orgPosition == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// uppdated.OrganizationPosition = save_orgPosition;
// }
if (req.PositionId != null)
{
var save = await _context.PositionPaths.FindAsync(req.PositionId);
if (save == null)
return Error(GlobalMessages.PositionPathNotFound, 404);
uppdated.PositionPath = save;
}
// if (req.PositionId != null)
// {
// var save = await _context.PositionPaths.FindAsync(req.PositionId);
// if (save == null)
// return Error(GlobalMessages.PositionPathNotFound, 404);
// uppdated.PositionPath = save;
// }
if (req.PositionLevelId != null)
{
var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
if (save == null)
return Error(GlobalMessages.PositionLevelNotFound, 404);
uppdated.PositionLevel = save;
}
// if (req.PositionLevelId != null)
// {
// var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
// if (save == null)
// return Error(GlobalMessages.PositionLevelNotFound, 404);
// uppdated.PositionLevel = save;
// }
if (req.PositionLineId != null)
{
var save = await _context.PositionLines.FindAsync(req.PositionLineId);
if (save == null)
return Error(GlobalMessages.PositionLineNotFound, 404);
uppdated.PositionLine = save;
}
// if (req.PositionLineId != null)
// {
// var save = await _context.PositionLines.FindAsync(req.PositionLineId);
// if (save == null)
// return Error(GlobalMessages.PositionLineNotFound, 404);
// uppdated.PositionLine = save;
// }
if (req.PositionPathSideId != null)
{
var save = await _context.PositionPathSides.FindAsync(req.PositionPathSideId);
if (save == null)
return Error(GlobalMessages.PositionPathSideNotFound, 404);
uppdated.PositionPathSide = save;
}
// if (req.PositionPathSideId != null)
// {
// var save = await _context.PositionPathSides.FindAsync(req.PositionPathSideId);
// if (save == null)
// return Error(GlobalMessages.PositionPathSideNotFound, 404);
// uppdated.PositionPathSide = save;
// }
if (req.PositionTypeId != null)
{
var save = await _context.PositionTypes.FindAsync(req.PositionTypeId);
if (save == null)
return Error(GlobalMessages.PositionTypeNotFound, 404);
uppdated.PositionType = save;
}
// if (req.PositionTypeId != null)
// {
// var save = await _context.PositionTypes.FindAsync(req.PositionTypeId);
// if (save == null)
// return Error(GlobalMessages.PositionTypeNotFound, 404);
// uppdated.PositionType = save;
// }
uppdated.RecruitDate = req.RecruitDate;
uppdated.Status = "PENDING";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
// uppdated.RecruitDate = req.RecruitDate;
// uppdated.Status = "PENDING";
// uppdated.LastUpdateFullName = FullName ?? "System Administrator";
// uppdated.LastUpdateUserId = UserId ?? "";
// uppdated.LastUpdatedAt = DateTime.Now;
// await _context.SaveChangesAsync();
return Success();
}
// return Success();
// }
/// <summary>
/// แก้ไขอื่นๆ
@ -414,53 +458,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (uppdated == null)
return Error(GlobalMessages.RetirementOtherNotFound, 404);
if (req.PrefixId != null)
{
var save = await _context.Prefixes.FindAsync(req.PrefixId);
if (save == null)
return Error(GlobalMessages.PrefixNotFound, 404);
uppdated.Prefix = save;
}
if (req.RelationshipId != null)
{
var save = await _context.Relationships.FindAsync(req.RelationshipId);
if (save == null)
return Error(GlobalMessages.RelationshipNotFound, 404);
uppdated.Relationship = save;
}
if (req.ReligionId != null)
{
var save = await _context.Religions.FindAsync(req.ReligionId);
if (save == null)
return Error(GlobalMessages.ReligionNotFound, 404);
uppdated.Religion = save;
}
if (req.BloodGroupId != null)
{
var save = await _context.BloodGroups.FindAsync(req.BloodGroupId);
if (save == null)
return Error(GlobalMessages.BloodGroupNotFound, 404);
uppdated.BloodGroup = save;
}
if (req.GenderId != null)
{
var save = await _context.Genders.FindAsync(req.GenderId);
if (save == null)
return Error(GlobalMessages.GenderNotFound, 404);
uppdated.Gender = save;
}
uppdated.CitizenId = req.CitizenId;
uppdated.Firstname = req.Firstname;
uppdated.Lastname = req.Lastname;
uppdated.DateOfBirth = req.DateOfBirth;
uppdated.Nationality = req.Nationality;
uppdated.Race = req.Race;
uppdated.TelephoneNumber = req.TelephoneNumber;
uppdated.EducationOld = req.EducationOld;
uppdated.Reason = req.Reason;
uppdated.MilitaryDate = req.MilitaryDate;
@ -468,7 +465,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
uppdated.PositionTypeOld = req.PositionTypeOld;
uppdated.PositionLevelOld = req.PositionLevelOld;
uppdated.PositionNumberOld = req.PositionNumberOld;
uppdated.Amount = req.Amount;
uppdated.AmountOld = req.AmountOld;
uppdated.PositionDate = req.PositionDate;
uppdated.LastUpdateFullName = FullName ?? "System Administrator";

View file

@ -8,7 +8,9 @@ using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
@ -26,18 +28,21 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public RetirementOutController(RetirementRepository repository,
NotificationRepository repositoryNoti,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{
_repository = repository;
_repositoryNoti = repositoryNoti;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#region " Properties "
@ -45,6 +50,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
@ -61,35 +67,69 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var retirementOuts = await _context.RetirementOuts.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementOuts.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
return Success(retirementOuts);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var retirementOuts = await _context.RetirementOuts.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => RetirementAdmin == true ? true : (rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))))
.Select(p => new
{
p.Id,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
return Success(retirementOuts);
}
}
/// <summary>
@ -106,19 +146,27 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var data = await _context.RetirementOuts.AsQueryable()
.Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new
{
p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
organizationOrganization = p.Profile.OrganizationOrganization,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Reason,
p.Status,
p.Organization,
@ -129,37 +177,37 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
// Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
var _data = new
{
data.Id,
data.PrefixId,
data.Prefix,
data.FirstName,
data.LastName,
data.ProfileId,
data.position,
data.posNo,
data.positionLevel,
data.organizationOrganization,
data.Reason,
data.Status,
data.Organization,
data.Date,
data.salary,
data.CreatedAt,
data.PositionTypeOld,
data.PositionLevelOld,
data.PositionNumberOld,
data.OrganizationPositionOld,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
};
// var _data = new
// {
// data.Id,
// data.PrefixId,
// data.Prefix,
// data.FirstName,
// data.LastName,
// data.ProfileId,
// data.position,
// data.posNo,
// data.positionLevel,
// data.organizationOrganization,
// data.Reason,
// data.Status,
// data.Organization,
// data.Date,
// data.salary,
// data.CreatedAt,
// data.PositionTypeOld,
// data.PositionLevelOld,
// data.PositionNumberOld,
// data.OrganizationPositionOld,
// Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
// };
return Success(_data);
return Success(data);
}
/// <summary>
@ -173,27 +221,27 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
// var profile = await _context.Profiles
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionType)
// .Include(x => x.PosNo)
// .Include(x => x.Salaries)
// .Include(x => x.Position)
// .FirstOrDefaultAsync(x => x.Id == req.Id);
// if (profile == null)
// return Error(GlobalMessages.DataNotFound, 404);
var retirementOut = new RetirementOut
{
Profile = profile,
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
// Profile = profile,
// Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
// Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// // Date = req.Date,
// AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
// PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
// PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
// PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
// OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
@ -202,6 +250,46 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}org/profile/profileid/position/{req.Id}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementOut.profileId = org.result.profileId;
retirementOut.prefix = org.result.prefix;
retirementOut.firstName = org.result.firstName;
retirementOut.lastName = org.result.lastName;
retirementOut.citizenId = org.result.citizenId;
retirementOut.root = org.result.root;
retirementOut.rootId = org.result.rootId;
retirementOut.rootShortName = org.result.rootShortName;
retirementOut.child1 = org.result.child1;
retirementOut.child1Id = org.result.child1Id;
retirementOut.child1ShortName = org.result.child1ShortName;
retirementOut.child2 = org.result.child2;
retirementOut.child2Id = org.result.child2Id;
retirementOut.child2ShortName = org.result.child2ShortName;
retirementOut.child3 = org.result.child3;
retirementOut.child3Id = org.result.child3Id;
retirementOut.child3ShortName = org.result.child3ShortName;
retirementOut.child4 = org.result.child4;
retirementOut.child4Id = org.result.child4Id;
retirementOut.child4ShortName = org.result.child4ShortName;
retirementOut.posMasterNo = org.result.posMasterNo;
retirementOut.position = org.result.position;
retirementOut.posTypeId = org.result.posTypeId;
retirementOut.posTypeName = org.result.posTypeName;
retirementOut.posLevelId = org.result.posLevelId;
retirementOut.posLevelName = org.result.posLevelName;
}
await _context.RetirementOuts.AddAsync(retirementOut);
await _context.SaveChangesAsync();