placement ผูกโครงสร้างใหม่

This commit is contained in:
Kittapath 2024-04-30 00:10:07 +07:00
parent 0afe06fac0
commit dc91f81262
11 changed files with 35152 additions and 86 deletions

View file

@ -13,6 +13,9 @@ using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
using System.Security.Cryptography;
using Microsoft.Extensions.Configuration;
using System.Net.Http.Headers;
using Newtonsoft.Json;
namespace BMA.EHR.Placement.Service.Controllers
{
@ -29,18 +32,21 @@ namespace BMA.EHR.Placement.Service.Controllers
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public PlacementController(PlacementRepository 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 "
@ -48,6 +54,7 @@ namespace BMA.EHR.Placement.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? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
@ -672,72 +679,66 @@ namespace BMA.EHR.Placement.Service.Controllers
if (person.Draft == true)
return Error("ไม่สามารถแก้ไขข้อมูลนี้ได้เนื่องจากเผยแพร่ไปแล้ว");
// if (req.PosNoId != null)
// {
// var save_posNo = await _context.PositionNumbers.FindAsync(req.PosNoId);
// if (save_posNo == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// person.PositionNumber = save_posNo;
// person.organizationName = req.organizationName;
// person.orgTreeShortName = req.orgTreeShortName;
// person.PosPath = req.posPath;
// person.PosNumber = req.posNumber;
// person.node = req.node;
// person.nodeId = req.nodeId;
// person.posmasterId = req.posmasterId;
// person.positionId = req.positionId;
// person.Amount = req.SalaryAmount;
// person.MouthSalaryAmount = req.MouthSalaryAmount;
// person.PositionSalaryAmount = req.PositionSalaryAmount;
// person.RecruitDate = req.ReportingDate;
// person.ReportingDate = req.ReportingDate;
// var save_orgPosition = await _context.OrganizationPositions.FirstOrDefaultAsync(x => x.PositionNumber == save_posNo);
// if (save_orgPosition == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// person.OrganizationPosition = save_orgPosition;
// }
var apiUrl = $"{_configuration["API"]}org/find/all";
// if (req.PositionId != null)
// {
// var save = await _context.PositionPaths.FindAsync(req.PositionId);
// if (save == null)
// return Error(GlobalMessages.PositionPathNotFound, 404);
// person.PositionPath = save;
// }
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
node = req.node,
nodeId = req.nodeId,
});
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
// if (req.PositionLevelId != null)
// {
// var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
// if (save == null)
// return Error(GlobalMessages.PositionLevelNotFound, 404);
// person.PositionLevel = save;
// }
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
// if (req.PositionLineId != null)
// {
// var save = await _context.PositionLines.FindAsync(req.PositionLineId);
// if (save == null)
// return Error(GlobalMessages.PositionLineNotFound, 404);
// person.PositionLine = save;
// }
person.root = org.result.root;
person.rootId = org.result.rootId;
person.rootShortName = org.result.rootShortName;
person.child1 = req.node <= 0 ? null : org.result.child1;
person.child1Id = req.node <= 0 ? null : org.result.child1Id;
person.child1ShortName = req.node <= 0 ? null : org.result.child1ShortName;
person.child2 = req.node <= 1 ? null : org.result.child2;
person.child2Id = req.node <= 1 ? null : org.result.child2Id;
person.child2ShortName = req.node <= 1 ? null : org.result.child2ShortName;
person.child3 = req.node <= 2 ? null : org.result.child3;
person.child3Id = req.node <= 2 ? null : org.result.child3Id;
person.child3ShortName = req.node <= 2 ? null : org.result.child3ShortName;
person.child4 = req.node <= 3 ? null : org.result.child4;
person.child4Id = req.node <= 3 ? null : org.result.child4Id;
person.child4ShortName = req.node <= 3 ? null : org.result.child4ShortName;
}
// if (req.PositionPathSideId != null)
// {
// var save = await _context.PositionPathSides.FindAsync(req.PositionPathSideId);
// if (save == null)
// return Error(GlobalMessages.PositionPathSideNotFound, 404);
// person.PositionPathSide = save;
// }
// if (req.PositionTypeId != null)
// {
// var save = await _context.PositionTypes.FindAsync(req.PositionTypeId);
// if (save == null)
// return Error(GlobalMessages.PositionTypeNotFound, 404);
// person.PositionType = save;
// }
person.Draft = false;
person.organizationName = req.organizationName;
person.orgTreeShortName = req.orgTreeShortName;
person.PosPath = req.posPath;
person.PosNumber = req.posNumber;
person.node = req.node;
person.nodeId = req.nodeId;
person.posmasterId = req.posmasterId;
person.orgRevisionId = req.orgRevisionId;
person.positionId = req.positionId;
person.Amount = req.SalaryAmount;
person.MouthSalaryAmount = req.MouthSalaryAmount;
person.PositionSalaryAmount = req.PositionSalaryAmount;
person.RecruitDate = req.ReportingDate;
person.ReportingDate = req.ReportingDate;
person.posMasterNo = req.posMasterNo;
person.positionName = req.positionName;
person.positionField = req.positionField;
person.posTypeId = req.posTypeId;
person.posTypeName = req.posTypeName;
person.posLevelId = req.posLevelId;
person.posLevelName = req.posLevelName;
person.PlacementStatus = "PREPARE-CONTAIN";
person.LastUpdateFullName = FullName ?? "System Administrator";
person.LastUpdateUserId = UserId ?? "";