ออกคำสั่ง

This commit is contained in:
kittapath 2024-10-02 16:02:20 +07:00
parent 139969b324
commit 1374757bf2
8 changed files with 560 additions and 3 deletions

View file

@ -1,6 +1,7 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
@ -473,5 +474,60 @@ namespace BMA.EHR.Placement.Service.Controllers
// return Success();
// }
/// <summary>
/// ออกคำสั่ง C-PM-16
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
{
// create new profile
foreach (var recv in req.refIds)
{
var data = await _context.PlacementRepatriations
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(recv.refId));
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = recv.commandAffectDate,
amount = recv.amount,
positionSalaryAmount = recv.positionSalaryAmount,
mouthSalaryAmount = recv.mouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{recv.commandNo}/{recv.commandYear.ToThaiYear()}",
templateDoc = recv.templateDoc,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
data.Status = "DONE";
await _context.SaveChangesAsync();
}
return Success();
}
}
}