แก้ระบบบรรจุผูกโครงสร้างใหม่
This commit is contained in:
parent
57164f5d45
commit
18d75f4b04
37 changed files with 79295 additions and 3904 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue