แก้คำสั่ง

This commit is contained in:
kittapath 2024-10-02 22:54:34 +07:00
parent a09a732ff1
commit 4cf3f15fb8
8 changed files with 296 additions and 27 deletions

View file

@ -2,7 +2,6 @@
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
@ -15,8 +14,6 @@ using Newtonsoft.Json.Linq;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Security.Cryptography;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace BMA.EHR.Retirement.Service.Controllers
{
@ -1637,7 +1634,7 @@ $"คำขอลาออกของ {updated.prefix}{updated.firstName} {upda
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report/report")]
[HttpPost("command/report")]
public async Task<ActionResult<ResponseObject>> PostReport([FromBody] ReportPersonRequest req)
{
var placementProfiles = await _context.RetirementResigns
@ -1661,7 +1658,7 @@ $"คำขอลาออกของ {updated.prefix}{updated.firstName} {upda
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report/report/attachment")]
[HttpPost("command/report/attachment")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
@ -1704,7 +1701,7 @@ $"คำขอลาออกของ {updated.prefix}{updated.firstName} {upda
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report/excecute")]
[HttpPost("command/report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
{
// create new profile
@ -1811,5 +1808,77 @@ $"คำขอลาออกของ {updated.prefix}{updated.firstName} {upda
}
return Success();
}
/// <summary>
/// ออกคำสั่ง C-PM-23
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("leave-cancel/report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecuteLeaveCancel([FromBody] ReportExecuteRequest req)
{
// create new profile
foreach (var recv in req.refIds)
{
var data = await _context.RetirementResigns
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(recv.refId));
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
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, apiUrl);
string? _null = null;
var _res = await client.PostAsJsonAsync(apiUrl, new
{
isLeave = false,
leaveReason = _null,
dateLeave = _null,
});
var _result = await _res.Content.ReadAsStringAsync();
}
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 = "DONEREJECT";
await _context.SaveChangesAsync();
}
return Success();
}
}
}