678 lines
36 KiB
C#
678 lines
36 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Application.Responses.Profiles;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Placement;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using BMA.EHR.Retirement.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.Net.Http.Headers;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Retirement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/retirement/out")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบให้ออก")]
|
|
public class RetirementOutController : BaseController
|
|
{
|
|
private readonly RetirementRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
private readonly PermissionRepository _permission;
|
|
|
|
public RetirementOutController(RetirementRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration,
|
|
UserProfileRepository userProfileRepository,
|
|
PermissionRepository permission)
|
|
{
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
_userProfileRepository = userProfileRepository;
|
|
_permission = permission;
|
|
}
|
|
|
|
#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"];
|
|
private string? AccessToken => _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("{type}")]
|
|
public async Task<ActionResult<ResponseObject>> GetListByAdmin(string type, string? status = "")
|
|
{
|
|
string role = "";
|
|
if (type.Trim().ToUpper() == "OFFICER")
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISMISS");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
role = jsonData["result"]?.ToString();
|
|
}
|
|
else
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISMISS_EMP");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
role = jsonData["result"]?.ToString();
|
|
}
|
|
var nodeId = string.Empty;
|
|
var profileAdmin = new GetUserOCAllDto();
|
|
profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken);
|
|
if (role == "NORMAL" || role == "CHILD")
|
|
{
|
|
nodeId = profileAdmin?.Node == 4
|
|
? profileAdmin?.Child4DnaId
|
|
: profileAdmin?.Node == 3
|
|
? profileAdmin?.Child3DnaId
|
|
: profileAdmin?.Node == 2
|
|
? profileAdmin?.Child2DnaId
|
|
: profileAdmin?.Node == 1
|
|
? profileAdmin?.Child1DnaId
|
|
: profileAdmin?.Node == 0
|
|
? profileAdmin?.RootDnaId
|
|
: "";
|
|
}
|
|
else if (role == "ROOT" || role == "PARENT")
|
|
{
|
|
nodeId = profileAdmin?.RootDnaId;
|
|
}
|
|
|
|
var node = profileAdmin?.Node;
|
|
var retirementOuts = await _context.RetirementOuts.AsQueryable()
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Where(x => x.profileType.Trim().ToUpper().Contains(type.Trim().ToUpper()))
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.profileType,
|
|
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.rootDnaOldId,
|
|
p.child1DnaOldId,
|
|
p.child2DnaOldId,
|
|
p.child3DnaOldId,
|
|
p.child4DnaOldId,
|
|
})
|
|
.ToListAsync();
|
|
|
|
if (!string.IsNullOrEmpty(status))
|
|
retirementOuts = retirementOuts.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
|
|
|
|
if (role == "OWNER")
|
|
{
|
|
node = null;
|
|
}
|
|
if (role == "OWNER" || role == "CHILD")
|
|
{
|
|
retirementOuts = retirementOuts
|
|
.Where(x => node == 4 ? x.child4DnaOldId == nodeId : (node == 3 ? x.child3DnaOldId == nodeId : (node == 2 ? x.child2DnaOldId == nodeId : (node == 1 ? x.child1DnaOldId == nodeId : (node == 0 ? x.rootDnaOldId == nodeId : (node == null ? true : true)))))).ToList();
|
|
}
|
|
else if (role == "ROOT")
|
|
{
|
|
retirementOuts = retirementOuts
|
|
.Where(x => x.rootDnaOldId == nodeId).ToList();
|
|
}
|
|
else if (role == "PARENT")
|
|
{
|
|
retirementOuts = retirementOuts
|
|
.Where(x => x.rootDnaOldId == nodeId && x.child1DnaOldId != null).ToList();
|
|
}
|
|
else if (role == "NORMAL")
|
|
{
|
|
retirementOuts = retirementOuts
|
|
.Where(x => node == 0 ? x.child1DnaOldId == null : (node == 1 ? x.child2DnaOldId == null : (node == 2 ? x.child3DnaOldId == null : (node == 3 ? x.child4DnaOldId == null : true)))).ToList();
|
|
}
|
|
return Success(retirementOuts);
|
|
}
|
|
|
|
/// <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_DISMISS");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISMISS");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var data = await _context.RetirementOuts.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.profileType,
|
|
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.OrganizationOld,
|
|
})
|
|
.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] RetirementAddProfileRequest req)
|
|
{
|
|
var retirementOut = new RetirementOut
|
|
{
|
|
profileType = req.profileType.Trim().ToUpper(),
|
|
Status = "WAITTING",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
if (req.profileType.Trim().ToUpper() == "OFFICER")
|
|
{
|
|
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);
|
|
|
|
retirementOut.profileId = org.result.profileId;
|
|
retirementOut.prefix = org.result.prefix;
|
|
retirementOut.firstName = org.result.firstName;
|
|
retirementOut.lastName = org.result.lastName;
|
|
retirementOut.citizenId = org.result.citizenId;
|
|
retirementOut.rootOld = org.result.root;
|
|
retirementOut.rootOldId = org.result.rootId;
|
|
retirementOut.rootDnaOldId = org.result.rootDnaId;
|
|
retirementOut.rootShortNameOld = org.result.rootShortName;
|
|
retirementOut.child1Old = org.result.child1;
|
|
retirementOut.child1OldId = org.result.child1Id;
|
|
retirementOut.child1DnaOldId = org.result.child1DnaId;
|
|
retirementOut.child1ShortNameOld = org.result.child1ShortName;
|
|
retirementOut.child2Old = org.result.child2;
|
|
retirementOut.child2OldId = org.result.child2Id;
|
|
retirementOut.child2DnaOldId = org.result.child2DnaId;
|
|
retirementOut.child2ShortNameOld = org.result.child2ShortName;
|
|
retirementOut.child3Old = org.result.child3;
|
|
retirementOut.child3OldId = org.result.child3Id;
|
|
retirementOut.child3DnaOldId = org.result.child3DnaId;
|
|
retirementOut.child3ShortNameOld = org.result.child3ShortName;
|
|
retirementOut.child4Old = org.result.child4;
|
|
retirementOut.child4OldId = org.result.child4Id;
|
|
retirementOut.child4DnaOldId = org.result.child4DnaId;
|
|
retirementOut.child4ShortNameOld = org.result.child4ShortName;
|
|
retirementOut.posMasterNoOld = org.result.posMasterNo;
|
|
retirementOut.posTypeOldId = org.result.posTypeId;
|
|
retirementOut.posTypeNameOld = org.result.posTypeName;
|
|
retirementOut.posLevelOldId = org.result.posLevelId;
|
|
retirementOut.posLevelNameOld = org.result.posLevelName;
|
|
|
|
retirementOut.PositionOld = org.result.position;
|
|
retirementOut.PositionExecutiveOld = org.result.posExecutiveName;
|
|
retirementOut.positionExecutiveFieldOld = org.result.positionExecutiveField;
|
|
retirementOut.positionAreaOld = org.result.positionArea;
|
|
retirementOut.PositionLevelOld = org.result.posLevelName;
|
|
retirementOut.PositionTypeOld = org.result.posTypeName;
|
|
retirementOut.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
|
retirementOut.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);
|
|
retirementOut.OrganizationPositionOld = org.result.position + "\n" +
|
|
(retirementOut.PositionExecutiveOld == null ? "" : (retirementOut.positionExecutiveField == null ? retirementOut.PositionExecutiveOld + "\n" : retirementOut.PositionExecutiveOld + "(" + retirementOut.positionExecutiveField + ")" + "\n"))
|
|
+ retirementOut.OrganizationOld;
|
|
retirementOut.AmountOld = org.result.salary;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/profile-employee/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);
|
|
|
|
retirementOut.profileId = org.result.profileId;
|
|
retirementOut.prefix = org.result.prefix;
|
|
retirementOut.firstName = org.result.firstName;
|
|
retirementOut.lastName = org.result.lastName;
|
|
retirementOut.citizenId = org.result.citizenId;
|
|
retirementOut.rootOld = org.result.root;
|
|
retirementOut.rootOldId = org.result.rootId;
|
|
retirementOut.rootDnaOldId = org.result.rootDnaId;
|
|
retirementOut.rootShortNameOld = org.result.rootShortName;
|
|
retirementOut.child1Old = org.result.child1;
|
|
retirementOut.child1OldId = org.result.child1Id;
|
|
retirementOut.child1DnaOldId = org.result.child1DnaId;
|
|
retirementOut.child1ShortNameOld = org.result.child1ShortName;
|
|
retirementOut.child2Old = org.result.child2;
|
|
retirementOut.child2OldId = org.result.child2Id;
|
|
retirementOut.child2DnaOldId = org.result.child2DnaId;
|
|
retirementOut.child2ShortNameOld = org.result.child2ShortName;
|
|
retirementOut.child3Old = org.result.child3;
|
|
retirementOut.child3OldId = org.result.child3Id;
|
|
retirementOut.child3DnaOldId = org.result.child3DnaId;
|
|
retirementOut.child3ShortNameOld = org.result.child3ShortName;
|
|
retirementOut.child4Old = org.result.child4;
|
|
retirementOut.child4OldId = org.result.child4Id;
|
|
retirementOut.child4DnaOldId = org.result.child4DnaId;
|
|
retirementOut.child4ShortNameOld = org.result.child4ShortName;
|
|
retirementOut.posMasterNoOld = org.result.posMasterNo;
|
|
retirementOut.posTypeOldId = org.result.posTypeId;
|
|
retirementOut.posTypeNameOld = org.result.posTypeName;
|
|
retirementOut.posLevelOldId = org.result.posLevelId;
|
|
retirementOut.posLevelNameOld = org.result.posLevelName;
|
|
|
|
retirementOut.PositionOld = org.result.position;
|
|
retirementOut.PositionLevelOld = org.result.posLevelName;
|
|
retirementOut.PositionTypeOld = org.result.posTypeName;
|
|
retirementOut.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
|
retirementOut.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);
|
|
retirementOut.OrganizationPositionOld = org.result.position + "\n" + (retirementOut.PositionExecutiveOld == null ? "" : retirementOut.PositionExecutiveOld + "\n") + retirementOut.OrganizationOld;
|
|
retirementOut.AmountOld = org.result.salary;
|
|
}
|
|
}
|
|
await _context.RetirementOuts.AddAsync(retirementOut);
|
|
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] RetirementOutEditRequest req, Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISMISS");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var uppdated = await _context.RetirementOuts
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.RetirementOutNotFound, 404);
|
|
|
|
uppdated.PositionNumberOld = req.PositionNumberOld;
|
|
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.RetirementOuts
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.RetirementOutNotFound, 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_DISMISS");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var deleted = await _context.RetirementOuts.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
return NotFound();
|
|
_context.RetirementOuts.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] RetirementProfileRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_DISMISS");
|
|
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.RetirementOuts
|
|
.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>
|
|
/// ส่งรายชื่อออกคำสั่ง C-PM-18
|
|
/// </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.RetirementOuts
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = req.status.Trim().ToUpper());
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบรายชื่อออกคำสั่ง C-PM-18
|
|
/// </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>> PostDeleteReport([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.RetirementOuts
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
// .Where(x => x.Status.ToUpper() == "REPORT")
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "APPROVE");
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ออกคำสั่ง C-PM-18 คำสั่งให้ออกจากราชการ
|
|
/// </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>> PostReportExecuteLeave([FromBody] ReportExecuteRequest req)
|
|
{
|
|
var data = await _context.RetirementOuts
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
var resultData = (from p in data
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
select new
|
|
{
|
|
profileId = p.profileId,
|
|
amount = r.amount,
|
|
amountSpecial = r.amountSpecial,
|
|
positionSalaryAmount = r.positionSalaryAmount,
|
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
positionExecutive = p.PositionExecutiveOld,
|
|
positionExecutiveField = p.positionExecutiveFieldOld,
|
|
positionArea = p.positionAreaOld,
|
|
positionType = p.PositionTypeOld,
|
|
positionLevel = p.PositionLevelOld,
|
|
isLeave = true,
|
|
leaveReason = "ให้ออกจากราชการ",
|
|
dateLeave = r.commandDateAffect,
|
|
commandId = r.commandId,
|
|
isGovernment = false,
|
|
orgRoot = p.rootOld,
|
|
orgChild1 = p.child1Old,
|
|
orgChild2 = p.child2Old,
|
|
orgChild3 = p.child3Old,
|
|
orgChild4 = p.child4Old,
|
|
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-leave";
|
|
if (data.Count > 0)
|
|
{
|
|
if (data[0].profileType == "EMPLOYEE")
|
|
{
|
|
apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
}
|