601 lines
32 KiB
C#
601 lines
32 KiB
C#
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;
|
|
using BMA.EHR.Placement.Service.Requests;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System;
|
|
using System.Net.Http.Headers;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Placement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/placement/repatriation")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบส่งตัวกลับ")]
|
|
public class PlacementRepatriationController : BaseController
|
|
{
|
|
private readonly PlacementRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly PermissionRepository _permission;
|
|
|
|
public PlacementRepatriationController(PlacementRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration,
|
|
PermissionRepository permiss)
|
|
{
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
_permission = permiss;
|
|
}
|
|
|
|
#region " Properties "
|
|
|
|
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"];
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// list รายการส่งตัวกลับของ Admin
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet()]
|
|
public async Task<ActionResult<ResponseObject>> GetListByAdmin(string? status = "ALL")
|
|
{
|
|
var getPermission = await _permission.GetPermissionOrgAPIAsync("LIST", "SYS_TEMPDUTY2", UserId);
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
// string?[] rootId = jsonData?.result?.rootId ?? null;
|
|
// string?[] child1Id = jsonData?.result?.child1Id ?? null;
|
|
// string?[] child2Id = jsonData?.result?.child2Id ?? null;
|
|
// string?[] child3Id = jsonData?.result?.child3Id ?? null;
|
|
// string?[] child4Id = jsonData?.result?.child4Id ?? null;
|
|
var placementRepatriations = await _context.PlacementRepatriations.AsQueryable()
|
|
// .Where(x => rootId == null ? true : rootId.Contains(x.rootOldId))
|
|
// .Where(x => child1Id == null ? true : child1Id.Contains(x.child1OldId))
|
|
// .Where(x => child2Id == null ? true : child2Id.Contains(x.child2OldId))
|
|
// .Where(x => child3Id == null ? true : child3Id.Contains(x.child3OldId))
|
|
// .Where(x => child4Id == null ? true : child4Id.Contains(x.child4OldId))
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.citizenId,
|
|
p.profileId,
|
|
p.prefix,
|
|
p.firstName,
|
|
p.lastName,
|
|
p.rootOld,
|
|
p.rootOldId,
|
|
p.rootShortNameOld,
|
|
p.child1Old,
|
|
p.child1OldId,
|
|
p.child1ShortNameOld,
|
|
p.child2Old,
|
|
p.child2OldId,
|
|
p.child2ShortNameOld,
|
|
p.child3Old,
|
|
p.child3OldId,
|
|
p.child3ShortNameOld,
|
|
p.child4Old,
|
|
p.child4OldId,
|
|
p.child4ShortNameOld,
|
|
p.PositionOld,
|
|
p.PositionExecutiveOld,
|
|
p.posMasterNoOld,
|
|
p.posTypeOldId,
|
|
p.posTypeNameOld,
|
|
p.posLevelOldId,
|
|
p.posLevelNameOld,
|
|
p.CreatedAt,
|
|
p.Organization,
|
|
p.Reason,
|
|
p.Status,
|
|
p.Date,
|
|
salary = p.AmountOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.IsActive,
|
|
p.DateRepatriation,
|
|
})
|
|
.ToListAsync();
|
|
if (status != null && status.Trim().ToUpper() != "ALL")
|
|
placementRepatriations = placementRepatriations.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
|
|
return Success(placementRepatriations);
|
|
}
|
|
|
|
/// <summary>
|
|
/// get รายละเอียดส่งตัวกลับเจ้าหน้าที่
|
|
/// </summary>
|
|
/// <param name="id">Id ส่งตัวกลับ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
|
|
{
|
|
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_TEMPDUTY2");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_TEMPDUTY2");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var data = await _context.PlacementRepatriations.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.profileId,
|
|
p.prefix,
|
|
p.firstName,
|
|
p.lastName,
|
|
p.rootOld,
|
|
p.rootOldId,
|
|
p.rootShortNameOld,
|
|
p.child1Old,
|
|
p.child1OldId,
|
|
p.child1ShortNameOld,
|
|
p.child2Old,
|
|
p.child2OldId,
|
|
p.child2ShortNameOld,
|
|
p.child3Old,
|
|
p.child3OldId,
|
|
p.child3ShortNameOld,
|
|
p.child4Old,
|
|
p.child4OldId,
|
|
p.child4ShortNameOld,
|
|
p.posMasterNoOld,
|
|
p.posTypeOldId,
|
|
p.posTypeNameOld,
|
|
p.posLevelOldId,
|
|
p.posLevelNameOld,
|
|
p.Reason,
|
|
p.Status,
|
|
p.Organization,
|
|
p.Date,
|
|
salary = p.AmountOld,
|
|
p.CreatedAt,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.PositionOld,
|
|
p.PositionExecutiveOld,
|
|
p.DateRepatriation,
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// สร้างส่งตัวกลับ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost()]
|
|
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementAddProfileRequest req)
|
|
{
|
|
|
|
var placementOfficer = await _context.PlacementOfficers
|
|
.Where(x => x.Id == (req.OfficerId ?? Guid.Parse("00000000-0000-0000-0000-000000000000")))
|
|
.FirstOrDefaultAsync();
|
|
if (placementOfficer == null)
|
|
return Error("ไม่พบรายการช่วยราชการ", 404);
|
|
var placementRepatriation = new PlacementRepatriation
|
|
{
|
|
Organization = placementOfficer.Organization,
|
|
refId = req.OfficerId ?? Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
|
// Reason = placementOfficer.Reason,
|
|
Date = placementOfficer.DateStart,
|
|
DateRepatriation = placementOfficer.DateEnd,
|
|
Status = "WAITTING",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
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 ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
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);
|
|
|
|
placementRepatriation.profileId = org.result.profileId;
|
|
placementRepatriation.prefix = org.result.prefix;
|
|
placementRepatriation.firstName = org.result.firstName;
|
|
placementRepatriation.lastName = org.result.lastName;
|
|
placementRepatriation.citizenId = org.result.citizenId;
|
|
placementRepatriation.rootOld = org.result.root;
|
|
placementRepatriation.rootOldId = org.result.rootId;
|
|
placementRepatriation.rootDnaOldId = org.result.rootDnaId;
|
|
placementRepatriation.rootShortNameOld = org.result.rootShortName;
|
|
placementRepatriation.child1Old = org.result.child1;
|
|
placementRepatriation.child1OldId = org.result.child1Id;
|
|
placementRepatriation.child1DnaOldId = org.result.child1DnaId;
|
|
placementRepatriation.child1ShortNameOld = org.result.child1ShortName;
|
|
placementRepatriation.child2Old = org.result.child2;
|
|
placementRepatriation.child2OldId = org.result.child2Id;
|
|
placementRepatriation.child2DnaOldId = org.result.child2DnaId;
|
|
placementRepatriation.child2ShortNameOld = org.result.child2ShortName;
|
|
placementRepatriation.child3Old = org.result.child3;
|
|
placementRepatriation.child3OldId = org.result.child3Id;
|
|
placementRepatriation.child3DnaOldId = org.result.child3DnaId;
|
|
placementRepatriation.child3ShortNameOld = org.result.child3ShortName;
|
|
placementRepatriation.child4Old = org.result.child4;
|
|
placementRepatriation.child4OldId = org.result.child4Id;
|
|
placementRepatriation.child4DnaOldId = org.result.child4DnaId;
|
|
placementRepatriation.child4ShortNameOld = org.result.child4ShortName;
|
|
placementRepatriation.posMasterNoOld = org.result.posMasterNo;
|
|
placementRepatriation.posTypeOldId = org.result.posTypeId;
|
|
placementRepatriation.posTypeNameOld = org.result.posTypeName;
|
|
placementRepatriation.posLevelOldId = org.result.posLevelId;
|
|
placementRepatriation.posLevelNameOld = org.result.posLevelName;
|
|
|
|
placementRepatriation.PositionOld = org.result.position;
|
|
placementRepatriation.PositionExecutiveOld = org.result.posExecutiveName;
|
|
placementRepatriation.PositionLevelOld = org.result.posLevelName;
|
|
placementRepatriation.PositionTypeOld = org.result.posTypeName;
|
|
placementRepatriation.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
|
|
placementRepatriation.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
|
(org.result.child1 == null ? "" : org.result.child1 + "\n") +
|
|
(org.result.root == null ? "" : org.result.root);
|
|
placementRepatriation.OrganizationPositionOld = org.result.position + "\n" + (placementRepatriation.PositionExecutiveOld == null ? "" : placementRepatriation.PositionExecutiveOld + "\n") + placementRepatriation.OrganizationOld;
|
|
}
|
|
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/profile/assistance/status";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
refId = req.OfficerId ?? Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
|
status = "DONE"
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
}
|
|
await _context.PlacementRepatriations.AddAsync(placementRepatriation);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขส่งตัวกลับ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> Put([FromBody] PlacementRepatriationEditRequest req, Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_TEMPDUTY2");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var uppdated = await _context.PlacementRepatriations
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.PlacementRepatriationNotFound, 404);
|
|
|
|
uppdated.PositionNumberOld = req.PositionNumberOld;//
|
|
uppdated.DateRepatriation = req.DateRepatriation;//
|
|
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;//
|
|
uppdated.PositionLevelOld = req.PositionLevelOld;//
|
|
uppdated.PositionTypeOld = req.PositionTypeOld;//
|
|
uppdated.AmountOld = req.AmountOld;//
|
|
uppdated.Organization = req.Organization;//
|
|
uppdated.Reason = req.Reason;//
|
|
uppdated.Date = req.Date;//
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// อนุมัติส่งตัวกลับ
|
|
/// </summary>
|
|
/// <param name="id">Id ส่งตัวกลับ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("confirm/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
|
|
{
|
|
var uppdated = await _context.PlacementRepatriations
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.PlacementRepatriationNotFound, 404);
|
|
|
|
uppdated.Status = "APPROVE";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบส่งตัวกลับ
|
|
/// </summary>
|
|
/// <param name="id">Id ส่งตัวกลับ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_TEMPDUTY2");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var deleted = await _context.PlacementRepatriations.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
return NotFound();
|
|
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/profile/assistance/status";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
refId = deleted.refId ?? Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
|
status = "PENDING"
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
}
|
|
_context.PlacementRepatriations.Remove(deleted);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// สั่งรายชื่อไปออกคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("report")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] PlacementProfileRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_TEMPDUTY2");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.PlacementRepatriations
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
uppdated.Status = "REPORT";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
// /// <summary>
|
|
// /// วันที่ส่งตัวกลับ
|
|
// /// </summary>
|
|
// /// <param name="id">Id ส่งตัวกลับ</param>
|
|
// /// <returns></returns>
|
|
// /// <response code="200"></response>
|
|
// /// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
// /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
// /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
// [HttpPut("date/{id:length(36)}")]
|
|
// public async Task<ActionResult<ResponseObject>> UpdateDateRepatriation([FromBody] PlacementRepatriationDateRequest req, Guid id)
|
|
// {
|
|
// var uppdated = await _context.PlacementRepatriations
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
// if (uppdated == null)
|
|
// return Error(GlobalMessages.PlacementRepatriationNotFound, 404);
|
|
// uppdated.DateRepatriation = req.Date;
|
|
// uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
// uppdated.LastUpdateUserId = UserId ?? "";
|
|
// uppdated.LastUpdatedAt = DateTime.Now;
|
|
|
|
// await _context.SaveChangesAsync();
|
|
|
|
// 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("command/report")]
|
|
public async Task<ActionResult<ResponseObject>> PostReport([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.PlacementRepatriations
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "REPORT");
|
|
await _context.SaveChangesAsync();
|
|
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("command/report/delete")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportDelete([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.PlacementRepatriations
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "APPROVE");
|
|
await _context.SaveChangesAsync();
|
|
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("command/report/excecute")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
|
|
{
|
|
var data = await _context.PlacementRepatriations
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
string? _null = null;
|
|
var resultData = (from p in data
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
select new
|
|
{
|
|
refId = p.Id,
|
|
profileId = p.profileId,
|
|
amount = r.amount,
|
|
amountSpecial = r.amountSpecial,
|
|
positionSalaryAmount = r.positionSalaryAmount,
|
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
positionExecutive = "",
|
|
positionType = p.PositionTypeOld,
|
|
positionLevel = p.PositionLevelOld,
|
|
commandId = r.commandId,
|
|
orgRoot = p.rootOld,
|
|
orgChild1 = p.child1Old,
|
|
orgChild2 = p.child2Old,
|
|
orgChild3 = p.child3Old,
|
|
orgChild4 = p.child4Old,
|
|
officerOrg = p.Organization,
|
|
dateStart = p.Date,
|
|
dateEnd = p.DateRepatriation,
|
|
commandNo = r.commandNo,
|
|
commandYear = r.commandYear,
|
|
posNo = p.posMasterNoOld?.ToString(),
|
|
posNoAbb = p.child4ShortNameOld != null ? $"{p.child4ShortNameOld}" :
|
|
p.child3ShortNameOld != null ? $"{p.child3ShortNameOld}" :
|
|
p.child2ShortNameOld != null ? $"{p.child2ShortNameOld}" :
|
|
p.child1ShortNameOld != null ? $"{p.child1ShortNameOld}" :
|
|
p.rootShortNameOld != null ? $"{p.rootShortNameOld}" : "",
|
|
commandDateAffect = r.commandDateAffect,
|
|
commandDateSign = r.commandDateSign,
|
|
positionName = p.PositionOld,
|
|
commandCode = r.commandCode,
|
|
commandName = r.commandName,
|
|
remark = r.remark,
|
|
}).ToList();
|
|
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
data = resultData,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
data.ForEach(profile => profile.Status = "DONE");
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
return Success();
|
|
}
|
|
}
|
|
}
|