2023-08-11 01:57:09 +07:00
|
|
|
|
using BMA.EHR.Application.Repositories;
|
2023-09-07 19:03:53 +07:00
|
|
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
2023-08-11 01:57:09 +07:00
|
|
|
|
using BMA.EHR.Domain.Common;
|
|
|
|
|
|
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 Swashbuckle.AspNetCore.Annotations;
|
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BMA.EHR.Retirement.Service.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
[Route("api/v{version:apiVersion}/retirement/expulsion")]
|
|
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
[SwaggerTag("ระบบไล่ออก")]
|
|
|
|
|
|
public class RetirementExpulsionController : BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly RetirementRepository _repository;
|
2023-09-07 19:03:53 +07:00
|
|
|
|
private readonly NotificationRepository _repositoryNoti;
|
2023-08-11 01:57:09 +07:00
|
|
|
|
private readonly ApplicationDBContext _context;
|
|
|
|
|
|
private readonly MinIOService _documentService;
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public RetirementExpulsionController(RetirementRepository repository,
|
2023-09-07 19:03:53 +07:00
|
|
|
|
NotificationRepository repositoryNoti,
|
2023-08-11 01:57:09 +07:00
|
|
|
|
ApplicationDBContext context,
|
|
|
|
|
|
MinIOService documentService,
|
|
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
|
|
{
|
|
|
|
|
|
_repository = repository;
|
2023-09-07 19:03:53 +07:00
|
|
|
|
_repositoryNoti = repositoryNoti;
|
2023-08-11 01:57:09 +07:00
|
|
|
|
_context = context;
|
|
|
|
|
|
_documentService = documentService;
|
|
|
|
|
|
_httpContextAccessor = httpContextAccessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region " Properties "
|
|
|
|
|
|
|
|
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
#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()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var retirementExpulsions = await _context.RetirementExpulsions.AsQueryable()
|
|
|
|
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
|
|
|
|
.Select(p => new
|
|
|
|
|
|
{
|
|
|
|
|
|
p.Id,
|
|
|
|
|
|
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
|
|
|
|
|
p.Profile.FirstName,
|
|
|
|
|
|
p.Profile.LastName,
|
2023-08-31 11:52:04 +07:00
|
|
|
|
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
|
2023-08-11 01:57:09 +07:00
|
|
|
|
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
2023-08-31 11:52:04 +07:00
|
|
|
|
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
|
2023-08-11 01:57:09 +07:00
|
|
|
|
p.CreatedAt,
|
|
|
|
|
|
p.Organization,
|
|
|
|
|
|
p.Reason,
|
|
|
|
|
|
p.Status,
|
|
|
|
|
|
p.Date,
|
|
|
|
|
|
salary = p.AmountOld,
|
|
|
|
|
|
p.PositionTypeOld,
|
|
|
|
|
|
p.PositionLevelOld,
|
|
|
|
|
|
p.PositionNumberOld,
|
|
|
|
|
|
p.OrganizationPositionOld,
|
|
|
|
|
|
p.IsActive,
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
return Success(retirementExpulsions);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 data = await _context.RetirementExpulsions.AsQueryable()
|
|
|
|
|
|
.Where(x => x.Id == id)
|
|
|
|
|
|
.Where(x => x.Profile != null)
|
|
|
|
|
|
.Select(p => new
|
|
|
|
|
|
{
|
|
|
|
|
|
p.Id,
|
|
|
|
|
|
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
|
|
|
|
|
|
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
|
|
|
|
|
p.Profile.FirstName,
|
|
|
|
|
|
p.Profile.LastName,
|
|
|
|
|
|
ProfileId = p.Profile.Id,
|
2023-08-31 11:52:04 +07:00
|
|
|
|
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
|
2023-08-11 01:57:09 +07:00
|
|
|
|
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
2023-08-31 11:52:04 +07:00
|
|
|
|
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
|
2023-08-11 01:57:09 +07:00
|
|
|
|
organizationOrganization = p.Profile.OrganizationOrganization,
|
|
|
|
|
|
p.Reason,
|
|
|
|
|
|
p.Status,
|
|
|
|
|
|
p.Organization,
|
|
|
|
|
|
p.Date,
|
|
|
|
|
|
salary = p.AmountOld,
|
|
|
|
|
|
p.CreatedAt,
|
|
|
|
|
|
p.PositionTypeOld,
|
|
|
|
|
|
p.PositionLevelOld,
|
|
|
|
|
|
p.PositionNumberOld,
|
|
|
|
|
|
p.OrganizationPositionOld,
|
2023-09-06 13:52:32 +07:00
|
|
|
|
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
|
2023-08-11 01:57:09 +07:00
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
if (data == null)
|
|
|
|
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
2023-09-06 13:52:32 +07:00
|
|
|
|
var _data = new
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Id,
|
|
|
|
|
|
data.PrefixId,
|
|
|
|
|
|
data.Prefix,
|
|
|
|
|
|
data.FirstName,
|
|
|
|
|
|
data.LastName,
|
|
|
|
|
|
data.ProfileId,
|
|
|
|
|
|
data.position,
|
|
|
|
|
|
data.posNo,
|
|
|
|
|
|
data.positionLevel,
|
|
|
|
|
|
data.organizationOrganization,
|
|
|
|
|
|
data.Reason,
|
|
|
|
|
|
data.Status,
|
|
|
|
|
|
data.Organization,
|
|
|
|
|
|
data.Date,
|
|
|
|
|
|
data.salary,
|
|
|
|
|
|
data.CreatedAt,
|
|
|
|
|
|
data.PositionTypeOld,
|
|
|
|
|
|
data.PositionLevelOld,
|
|
|
|
|
|
data.PositionNumberOld,
|
|
|
|
|
|
data.OrganizationPositionOld,
|
|
|
|
|
|
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
|
|
|
|
|
|
};
|
2023-08-11 01:57:09 +07:00
|
|
|
|
|
2023-09-06 13:52:32 +07:00
|
|
|
|
return Success(_data);
|
2023-08-11 01:57:09 +07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 profile = await _context.Profiles
|
|
|
|
|
|
.Include(x => x.PositionLevel)
|
|
|
|
|
|
.Include(x => x.PositionType)
|
|
|
|
|
|
.Include(x => x.PosNo)
|
|
|
|
|
|
.Include(x => x.Salaries)
|
|
|
|
|
|
.Include(x => x.Position)
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == req.Id);
|
|
|
|
|
|
if (profile == null)
|
|
|
|
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
|
|
|
|
|
|
|
|
var retirementExpulsion = new RetirementExpulsion
|
|
|
|
|
|
{
|
|
|
|
|
|
Profile = profile,
|
|
|
|
|
|
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
|
|
|
|
|
|
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
|
|
|
|
|
|
// Date = req.Date,
|
2023-10-02 19:51:38 +07:00
|
|
|
|
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
2023-08-11 01:57:09 +07:00
|
|
|
|
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
|
|
|
|
|
|
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
|
|
|
|
|
|
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
|
|
|
|
|
|
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
|
|
|
|
|
|
Status = "WAITTING",
|
2023-11-18 01:43:03 +07:00
|
|
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
|
|
|
|
CreatedUserId = UserId ?? "",
|
2023-08-11 01:57:09 +07:00
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
|
|
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
|
|
LastUpdatedAt = DateTime.Now,
|
|
|
|
|
|
};
|
|
|
|
|
|
await _context.RetirementExpulsions.AddAsync(retirementExpulsion);
|
|
|
|
|
|
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] RetirementExpulsionEditRequest req, Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var uppdated = await _context.RetirementExpulsions
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
|
|
if (uppdated == null)
|
|
|
|
|
|
return Error(GlobalMessages.RetirementExpulsionNotFound, 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.RetirementExpulsions
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
|
|
if (uppdated == null)
|
|
|
|
|
|
return Error(GlobalMessages.RetirementExpulsionNotFound, 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 deleted = await _context.RetirementExpulsions.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
|
|
if (deleted == null)
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
_context.RetirementExpulsions.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)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in req.Id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var uppdated = await _context.RetirementExpulsions
|
|
|
|
|
|
.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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|