เรียกรายชื่อจากระบบทดลองงาน
This commit is contained in:
parent
bb9a0bc73e
commit
3b24682301
5 changed files with 283 additions and 10 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using Amazon;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
|
|
@ -13,6 +12,9 @@ using BMA.EHR.Domain.Models.Retirement;
|
|||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
|
||||
using Profile = BMA.EHR.Domain.Models.HR.Profile;
|
||||
|
||||
|
|
@ -26,6 +28,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -34,12 +37,14 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
public CommandRepository(IApplicationDBContext dbContext,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
UserProfileRepository userProfileRepository) : base(dbContext, httpContextAccessor)
|
||||
UserProfileRepository userProfileRepository,
|
||||
IConfiguration configuration) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_organizationCommonRepository = organizationCommonRepository;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -65,7 +70,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " List Receiver "
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverForByCommndTypeAsync(Command command)
|
||||
public async Task<List<CommandReceiver>> GetReceiverForByCommndTypeAsync(Command command, string token = "")
|
||||
{
|
||||
var result = new List<CommandReceiver>();
|
||||
|
||||
|
|
@ -98,6 +103,15 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
case "C-PM-09":
|
||||
result = await GetReceiver09Async(command);
|
||||
break;
|
||||
case "C-PM-10":
|
||||
result = await GetReceiver10Async(command);
|
||||
break;
|
||||
case "C-PM-11":
|
||||
result = await GetReceiver11Async(command, token);
|
||||
break;
|
||||
case "C-PM-12":
|
||||
result = await GetReceiver12Async(command, token);
|
||||
break;
|
||||
case "C-PM-13":
|
||||
result = await GetReceiver13Async(command);
|
||||
break;
|
||||
|
|
@ -686,6 +700,226 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
|
||||
/// </summary>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CommandReceiver>> GetReceiver10Async(Command command)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new List<CommandReceiver>();
|
||||
var seq = 1;
|
||||
// เอาชื่อของกรรมการ ไปหาจากทะเบียนประวัติ
|
||||
|
||||
var p1 = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Select(x => new
|
||||
{
|
||||
profileId = x.Id,
|
||||
citizenId = x.CitizenId,
|
||||
prefix = x.Prefix.Name,
|
||||
firstName = x.FirstName,
|
||||
lastName = x.LastName,
|
||||
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
||||
})
|
||||
.FirstOrDefaultAsync(x => x.fullName == command.ChairManFullName);
|
||||
|
||||
if (p1 != null)
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = p1.citizenId!,
|
||||
Prefix = p1.prefix!,
|
||||
FirstName = p1.firstName!,
|
||||
LastName = p1.lastName!,
|
||||
RefPlacementProfileId = p1.profileId
|
||||
};
|
||||
seq++;
|
||||
result.Add(receiver);
|
||||
}
|
||||
|
||||
var p2 = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Select(x => new
|
||||
{
|
||||
profileId = x.Id,
|
||||
citizenId = x.CitizenId,
|
||||
prefix = x.Prefix.Name,
|
||||
firstName = x.FirstName,
|
||||
lastName = x.LastName,
|
||||
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
||||
})
|
||||
.FirstOrDefaultAsync(x => x.fullName == command.Member1FullName);
|
||||
|
||||
if (p2 != null)
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = p2.citizenId!,
|
||||
Prefix = p2.prefix!,
|
||||
FirstName = p2.firstName!,
|
||||
LastName = p2.lastName!,
|
||||
RefPlacementProfileId = p2.profileId
|
||||
};
|
||||
seq++;
|
||||
result.Add(receiver);
|
||||
}
|
||||
|
||||
var p3 = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Select(x => new
|
||||
{
|
||||
profileId = x.Id,
|
||||
citizenId = x.CitizenId,
|
||||
prefix = x.Prefix.Name,
|
||||
firstName = x.FirstName,
|
||||
lastName = x.LastName,
|
||||
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
||||
})
|
||||
.FirstOrDefaultAsync(x => x.fullName == command.Member2FullName);
|
||||
|
||||
if (p3 != null)
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = p3.citizenId!,
|
||||
Prefix = p3.prefix!,
|
||||
FirstName = p3.firstName!,
|
||||
LastName = p3.lastName!,
|
||||
RefPlacementProfileId = p3.profileId
|
||||
};
|
||||
seq++;
|
||||
result.Add(receiver);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
|
||||
/// </summary>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CommandReceiver>> GetReceiver11Async(Command command, string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resultData = new List<CommandReceiver>();
|
||||
|
||||
var baseAPI = _configuration["Node:API"];
|
||||
var apiUrl = $"{baseAPI}/report/pass";
|
||||
|
||||
var response = new PassProbationResponse();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var res = await client.SendAsync(req);
|
||||
var result = await res.Content.ReadAsStringAsync();
|
||||
|
||||
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
|
||||
|
||||
var seq = 1;
|
||||
foreach (var d in response!.data)
|
||||
{
|
||||
var pf = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.FirstOrDefaultAsync(x => x.Id == d.person.id);
|
||||
|
||||
if (pf != null)
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = pf.CitizenId!,
|
||||
Prefix = pf.Prefix!.Name,
|
||||
FirstName = pf.FirstName!,
|
||||
LastName = pf.LastName!,
|
||||
RefPlacementProfileId = pf.Id
|
||||
};
|
||||
seq++;
|
||||
|
||||
resultData.Add(receiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultData;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
|
||||
/// </summary>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CommandReceiver>> GetReceiver12Async(Command command, string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resultData = new List<CommandReceiver>();
|
||||
|
||||
var baseAPI = _configuration["Node:API"];
|
||||
var apiUrl = $"{baseAPI}/report/not-pass";
|
||||
|
||||
var response = new PassProbationResponse();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var res = await client.SendAsync(req);
|
||||
var result = await res.Content.ReadAsStringAsync();
|
||||
|
||||
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
|
||||
|
||||
var seq = 1;
|
||||
foreach (var d in response!.data)
|
||||
{
|
||||
var pf = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.FirstOrDefaultAsync(x => x.Id == d.person.id);
|
||||
|
||||
if (pf != null)
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = pf.CitizenId!,
|
||||
Prefix = pf.Prefix!.Name,
|
||||
FirstName = pf.FirstName!,
|
||||
LastName = pf.LastName!,
|
||||
RefPlacementProfileId = pf.Id
|
||||
};
|
||||
seq++;
|
||||
|
||||
resultData.Add(receiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultData;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
|
||||
/// </summary>
|
||||
|
|
@ -1645,7 +1879,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverForCommandAsync(Guid id)
|
||||
public async Task<List<CommandReceiver>> GetReceiverForCommandAsync(Guid id, string token = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -1657,7 +1891,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
else
|
||||
return await GetReceiverForByCommndTypeAsync(command);
|
||||
return await GetReceiverForByCommndTypeAsync(command, token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
21
BMA.EHR.Application/Responses/PassProbationResponse.cs
Normal file
21
BMA.EHR.Application/Responses/PassProbationResponse.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
namespace BMA.EHR.Application.Responses
|
||||
{
|
||||
public class PassProbationResponse
|
||||
{
|
||||
public bool successful { get; set; }
|
||||
|
||||
public List<DataResponse> data { get; set; } = new();
|
||||
}
|
||||
|
||||
public class DataResponse
|
||||
{
|
||||
public ProfileResponse person { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ProfileResponse
|
||||
{
|
||||
public Guid id { get; set; } = Guid.Empty;
|
||||
|
||||
public string name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,8 +12,8 @@ using BMA.EHR.Infrastructure.Persistence;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace BMA.EHR.Command.Service.Controllers
|
||||
{
|
||||
|
|
@ -2485,10 +2485,23 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetCommandReceiverAsync(Guid orderId)
|
||||
public async Task<ActionResult<ResponseObject>> GetCommandReceiverAsync([FromHeader] string authorization, Guid orderId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = string.Empty;
|
||||
if (AuthenticationHeaderValue.TryParse(authorization, out var headerValue))
|
||||
{
|
||||
// we have a valid AuthenticationHeaderValue that has the following details:
|
||||
|
||||
var scheme = headerValue.Scheme;
|
||||
token = headerValue.Parameter;
|
||||
|
||||
// scheme will be "Bearer"
|
||||
// parmameter will be the token itself.
|
||||
}
|
||||
|
||||
|
||||
var command = await _repository.GetByIdAsync(orderId);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
|
@ -2496,7 +2509,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
// TODO : หาค่า Education มาแสดง
|
||||
var existed = await _repository.GetReceiverByCommmandIdAsync(orderId);
|
||||
|
||||
var receivers = (await _repository.GetReceiverForCommandAsync(orderId))
|
||||
var receivers = (await _repository.GetReceiverForCommandAsync(orderId, token!))
|
||||
.OrderBy(x => x.Sequence)
|
||||
.Select(r => new CommandReceiverResponse
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
|
|
@ -47,6 +48,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
// Authorization
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt =>
|
||||
{
|
||||
opt.SaveToken = true;
|
||||
opt.RequireHttpsMetadata = false; //false for dev
|
||||
opt.Authority = issuer;
|
||||
opt.TokenValidationParameters = new()
|
||||
|
|
|
|||
|
|
@ -31,5 +31,8 @@
|
|||
"SecretKey": "FPTadmin2357",
|
||||
"BucketName": "bma-ehr-fpt"
|
||||
},
|
||||
"Protocol": "HTTPS"
|
||||
"Protocol": "HTTPS",
|
||||
"Node": {
|
||||
"API": "https://bma-ehr.frappet.synology.me/api/v1/probation"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue