1027 lines
48 KiB
C#
1027 lines
48 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.Commands;
|
|
using BMA.EHR.Application.Requests.Commands;
|
|
using BMA.EHR.Command.Service.Requests;
|
|
using BMA.EHR.Command.Service.Responses;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Commands.Core;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Command.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/order")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("API ระบบออกคำสั่ง")]
|
|
public class OrderController : BaseController
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly CommandRepository _repository;
|
|
private readonly PlacementRepository _placementRepository;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly PrefixRepository _prefixRepository;
|
|
private readonly CommandTypeRepository _commandTypeRepository;
|
|
private readonly CommandStatusRepository _commandStatusRepository;
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
|
|
#endregion
|
|
|
|
#region " Constuctor and Destructor "
|
|
|
|
public OrderController(CommandRepository repository,
|
|
PlacementRepository placementRepository,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
PrefixRepository prefixRepository,
|
|
CommandTypeRepository commandTypeRepository,
|
|
CommandStatusRepository commandStatusRepository,
|
|
UserProfileRepository userProfileRepository)
|
|
{
|
|
_repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_placementRepository = placementRepository;
|
|
_prefixRepository = prefixRepository;
|
|
_commandTypeRepository = commandTypeRepository;
|
|
_commandStatusRepository = commandStatusRepository;
|
|
_userProfileRepository = userProfileRepository;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Properties "
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
|
|
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
|
|
|
private Guid OcId
|
|
{
|
|
get
|
|
{
|
|
if (UserId != null || UserId != "")
|
|
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
|
else
|
|
return Guid.Empty;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
/// <summary>
|
|
/// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ถ้าไม่มีข้อมูลเลยจะ default ปีปัจจุบันให้ 1 รายการ
|
|
/// </remarks>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("fiscal-year")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetFiscalAsync()
|
|
{
|
|
var data = await _repository.GetAllAsync();
|
|
if (data != null)
|
|
{
|
|
var _data = data.GroupBy(x => x.CommandYear).Select(x => new
|
|
{
|
|
Id = x.FirstOrDefault().CommandYear.ToInteger().ToCeYear(),
|
|
Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(),
|
|
}).ToList();
|
|
|
|
if (_data == null || _data.Count == 0)
|
|
{
|
|
_data!.Add(new
|
|
{
|
|
Id = DateTime.Now.Year,
|
|
Name = DateTime.Now.Year.ToThaiYear()
|
|
});
|
|
}
|
|
|
|
return Success(_data);
|
|
}
|
|
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// แสดงประเภทคำสั่ง โดยดึงจากข้อมูลที่มีในระบบ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("order-type")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetCommandTypeAsync()
|
|
{
|
|
try
|
|
{
|
|
var data = (await _commandTypeRepository.GetAllAsync()).OrderBy(x => x.CommandCode);
|
|
|
|
return Success(data);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ตรวจสอบความพร้อมในการออกคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns>
|
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
|
/// </returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("ready/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> CheckReadyToExcecuteAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
var command = await _repository.GetByIdAsync(orderId);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
var cover = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_COVER);
|
|
var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTACHMENT);
|
|
|
|
if (command.CommandNo != "" &&
|
|
command.CommandYear != null &&
|
|
command.CommandExcecuteDate != null &&
|
|
cover != null &&
|
|
attatchment != null)
|
|
{
|
|
return Success(new { result = "Y" });
|
|
}
|
|
else
|
|
return Success(new { result = "N" });
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns>
|
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
|
/// </returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("next/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GoToNextState(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
await _repository.GotoNextStateAsync(orderId);
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status ของคำสั่งไปขั้นตอนก่อนหน้า
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns>
|
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
|
/// </returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("prev/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GoToPrevState(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
await _repository.GotoPrevStateAsync(orderId);
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-19 : หน้าจอรายการออกคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetAllAsync()
|
|
{
|
|
try
|
|
{
|
|
var data = (await _repository.GetAllAsync())
|
|
.Select(d => new
|
|
{
|
|
OrderId = d.Id,
|
|
OrderName = d.CommandSubject,
|
|
OrderNo = d.CommandNo,
|
|
FiscalYear = d.CommandYear,
|
|
OrderDate = d.CommandAffectDate,
|
|
OrderByOrganization = d.IssuerOrganizationName,
|
|
OrderBy = d.IssuerOrganizationId,
|
|
signatoryBy = d.AuthorizedUserFullName,
|
|
signatoryPosition = d.AuthorizedPosition,
|
|
OrderStatusValue = d.CommandStatusId,
|
|
OrderStatusName = d.CommandStatus.Name,
|
|
OrderTypeValue = d.CommandTypeId,
|
|
OrderTypeName = d.CommandType.Name
|
|
}).ToList();
|
|
return Success(data);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-20 : ลบรายการคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> DeleteAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
var data = await _repository.GetByIdAsync(orderId);
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
await _repository.DeleteAsync(data!);
|
|
|
|
return Success(data);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-21 : รายละเอียดการออกคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("detail/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetByIdAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
var data = await _repository.GetByIdAsync(orderId);
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
var result = new
|
|
{
|
|
orderId = orderId,
|
|
orderTypeValue = data.CommandTypeId,
|
|
orderTitle = data.CommandSubject,
|
|
orderNo = data.CommandNo,
|
|
orderYear = data.CommandYear,
|
|
orderDate = data.CommandAffectDate,
|
|
orderBy = data.IssuerOrganizationId,
|
|
signatoryBy = data.AuthorizedUserFullName,
|
|
signatoryPosition = data.AuthorizedPosition,
|
|
examRound = data.Placement.Id,
|
|
registerPosition = "",
|
|
conclusionRegisterNo = data.ConclusionRegisterNo,
|
|
conclusionRegisterDate = data.ConclusionRegisterDate,
|
|
conclusionResultNo = data.ConclusionResultNo,
|
|
conclusionResultDate = data.ConclusionResultDate,
|
|
};
|
|
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("detail")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PostAsync([FromBody] CreateCommandRequest req)
|
|
{
|
|
try
|
|
{
|
|
var inserted = new Domain.Models.Commands.Core.Command
|
|
{
|
|
CommandNo = req.orderNo.ToString(),
|
|
CommandYear = req.orderYear.ToString(),
|
|
CommandSubject = req.orderTitle,
|
|
PositionName = req.registerPosition,
|
|
CommandTypeId = req.orderTypeValue,
|
|
IssuerOrganizationId = req.orderBy,
|
|
AuthorizedUserFullName = req.signatoryBy,
|
|
AuthorizedPosition = req.signatoryPosition,
|
|
PlacementId = req.examRound,
|
|
ConclusionRegisterNo = req.conclusionRegisterNo,
|
|
ConclusionRegisterDate = req.conclusionRegisterDate,
|
|
ConclusionResultNo = req.conclusionResultNo,
|
|
ConclusionResultDate = req.conclusionResultDate,
|
|
CommandAffectDate = req.orderDate,
|
|
OwnerGovId = OcId
|
|
|
|
};
|
|
|
|
var result = await _repository.AddAsync(inserted);
|
|
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("detail/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PutAsync(Guid orderId, [FromBody] CreateCommandRequest req)
|
|
{
|
|
try
|
|
{
|
|
var order = await _repository.GetByIdAsync(orderId);
|
|
if (order == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
var placement = await _placementRepository.GetByIdAsync(req.examRound);
|
|
var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue);
|
|
var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId);
|
|
|
|
order.CommandNo = req.orderNo.ToString();
|
|
order.CommandYear = req.orderYear.ToString();
|
|
order.CommandSubject = req.orderTitle;
|
|
order.PositionName = req.registerPosition;
|
|
order.CommandType = commandType!;
|
|
order.IssuerOrganizationId = req.orderBy;
|
|
order.AuthorizedUserFullName = req.signatoryBy;
|
|
order.AuthorizedPosition = req.signatoryPosition;
|
|
order.Placement = placement!;
|
|
order.ConclusionRegisterNo = req.conclusionRegisterNo;
|
|
order.ConclusionRegisterDate = req.conclusionRegisterDate;
|
|
order.ConclusionResultNo = req.conclusionResultNo;
|
|
order.ConclusionResultDate = req.conclusionResultDate;
|
|
order.CommandStatus = status!;
|
|
order.CommandAffectDate = req.orderDate;
|
|
|
|
var result = await _repository.UpdateAsync(order);
|
|
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// PM7-24 : dropdown รอบการสอบ หน้ารายละเอียดการออกคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("detail/exam-round")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetExamRoundAsync()
|
|
{
|
|
try
|
|
{
|
|
var data = (await _placementRepository.GetAllAsync())
|
|
.Select(x => new
|
|
{
|
|
examRoundValue = x.Id,
|
|
examRoundName = $"{x.Name} ครั้งที่ {x.Round}/{x.Year.ToThaiYear()}"
|
|
|
|
})
|
|
.ToList();
|
|
|
|
return Success(data);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-26 : ข้อมูลเลือกรายชื่อออกคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("persons/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetCommandReceiverAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
// TODO : หาค่า Education มาแสดง
|
|
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
|
|
.OrderBy(x => x.Sequence)
|
|
.Select(r => new CommandReceiverResponse
|
|
{
|
|
RefRecordId = r.RefPlacementProfileId!.Value,
|
|
PersonalId = r.Id,
|
|
Sequence = r.Sequence,
|
|
IdCard = r.CitizenId,
|
|
Name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
|
|
SelectStatus = true,
|
|
Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน
|
|
}).ToList();
|
|
|
|
foreach (var r in receivers)
|
|
{
|
|
var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId);
|
|
|
|
r.SalaryAmount = salary.SalaryAmount;
|
|
r.PositionSalaryAmount = salary.PositionSalaryAmount;
|
|
r.MonthSalaryAmount = salary.MonthSalaryAmount;
|
|
}
|
|
|
|
return Success(receivers);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง ** ยังไม่ได้กรองหน่วยงาน **
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ** ยังไม่ได้กรองหน่วยงาน **
|
|
/// </remarks>
|
|
/// <param name="personalId">Record Id ของผู้รับคำสั่งในรายการบัญชีแนบท้าย</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("persons/{personalId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> DeleteCommandReceiverAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
var receiver = await _repository.DeleteCommandReceiverAsync(personalId);
|
|
return Success(receiver);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-28 : ข้อมูลเลือกรายชื่อส่งสำเนาคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("copy-order/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetCommandDeploymentAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
var deployments = (await _repository.GetDeploymentByCommandIdAsync(orderId))
|
|
.Select(x => new
|
|
{
|
|
personalId = x.Id,
|
|
sequence = x.Sequence,
|
|
selectStatus = true,
|
|
idCard = x.CitizenId,
|
|
name = $"{x.Prefix}{x.FirstName} {x.LastName}",
|
|
position = x.PositionName,
|
|
unit = x.OrganizationName,
|
|
emailChannel = x.IsSendMail,
|
|
inboxChannel = x.IsSendInbox
|
|
})
|
|
.ToList();
|
|
|
|
return Success(deployments);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-30 : popup - เลือกรายชื่อส่งสำเนาคำสั่ง
|
|
/// </summary>
|
|
/// <param name="organizationId">Record Id ของหน่วยงาน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("copy-order/persons/{organizationId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetPeopleByOrganizationIdAsync(Guid organizationId)
|
|
{
|
|
try
|
|
{
|
|
var people = (await _repository.GetProfileByOrganizationIdAsync(organizationId))
|
|
.Select(x => new
|
|
{
|
|
profileId = x.Profile!.Id,
|
|
idCard = x.Profile!.CitizenId,
|
|
name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
|
|
position = x.OrganizationPosition!.PositionMaster!.PositionPath!.Name,
|
|
unit = x.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
|
|
prefixId = x.Profile!.Prefix!.Id,
|
|
firstName = x.Profile!.FirstName,
|
|
lastName = x.Profile!.LastName
|
|
})
|
|
.ToList();
|
|
|
|
return Success(people);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-31 : เพิ่มรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("copy-order/persons/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> CreateCommandDeploymentAsync(Guid orderId, [FromBody] List<CreateCommandDeploymentRequest> req)
|
|
{
|
|
try
|
|
{
|
|
// transform req
|
|
var deploys = new List<CommandDeployment>();
|
|
foreach (var p in req)
|
|
{
|
|
var prefix = await _prefixRepository.GetByIdAsync(p.PrefixId);
|
|
deploys.Add(new CommandDeployment
|
|
{
|
|
CitizenId = p.IdCard,
|
|
Prefix = prefix.Name,
|
|
FirstName = p.FirstName,
|
|
LastName = p.LastName,
|
|
OrganizationName = p.Unit,
|
|
PositionName = p.Position
|
|
});
|
|
}
|
|
|
|
await _repository.CreateCommandDeploymentAsync(orderId, deploys);
|
|
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-32 : บันทึกช่องทางการส่งสำเนาคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("copy-order")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateCommandDeploymentAsync([FromBody] List<UpdateCommandDeploymentRequest> req)
|
|
{
|
|
try
|
|
{
|
|
// transform
|
|
var deploys = new List<CommandDeployment>();
|
|
foreach (var p in req)
|
|
{
|
|
var updated = await _repository.GetCommandDeploymentById(p.PersonalId);
|
|
updated!.IsSendInbox = p.InboxChannel;
|
|
updated!.IsSendMail = p.EmailChannel;
|
|
deploys.Add(updated);
|
|
}
|
|
|
|
await _repository.UpdatCommandDeploymentAsync(deploys);
|
|
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-33 : ลบรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง
|
|
/// </summary>
|
|
/// <param name="personalId">Record Id ของผู้รับสำเนาคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("copy-order/{personalId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> DeleteCommandDeloymentAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
await _repository.DeleteCommandDeploymentAsync(personalId);
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#region " Documents "
|
|
|
|
/// <summary>
|
|
/// PM7-34 : ข้อมูลรายละเอียดคำสั่งและแนบท้าย
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("attachment/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetCommandAttatchmentAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
var command = await _repository.GetByIdAsync(orderId);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
var documents = await _repository.GetCommandDocumentAsync(orderId);
|
|
var cover = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_COVER).FirstOrDefault();
|
|
var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTACHMENT).FirstOrDefault();
|
|
|
|
var result = new
|
|
{
|
|
orderNo = command.CommandNo,
|
|
orderYear = command.CommandYear,
|
|
signDate = command.CommandExcecuteDate,
|
|
orderFileUrl = cover == null ? null : _documentService.ImagesPath(cover.Document.ObjectRefId),
|
|
attachmentFileUrl = attach == null ? null : _documentService.ImagesPath(attach.Document.ObjectRefId),
|
|
};
|
|
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// PM7-35 : อัปโหลดไฟล์คำสั่ง
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("attachment/order-file/{orderId}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> UploadCommandCoverAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
// check upload file
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
|
|
// get exit file
|
|
var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_COVER);
|
|
|
|
// delete exist document from s3
|
|
foreach (var doc in docs)
|
|
{
|
|
await _documentService.DeleteFileAsync(doc.Document.ObjectRefId);
|
|
}
|
|
|
|
// upload new document to s3
|
|
var cover = await _documentService.UploadFileAsync(file);
|
|
|
|
// create new CommandDocumentEntity
|
|
var commandDoc = new CommandDocument
|
|
{
|
|
Category = GlobalConstants.TYPE_COVER,
|
|
Document = cover,
|
|
};
|
|
|
|
// send to repo to save in database
|
|
await _repository.UploadDocument(orderId, GlobalConstants.TYPE_COVER, commandDoc);
|
|
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-36 : อัปโหลดไฟล์เอกสารแนบท้าย
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("attachment/file/{orderId}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> UploadCommandAttachmentAsync(Guid orderId)
|
|
{
|
|
try
|
|
{
|
|
// check upload file
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
|
|
// get exit file
|
|
var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_ATTACHMENT);
|
|
|
|
// delete exist document from s3
|
|
foreach (var doc in docs)
|
|
{
|
|
await _documentService.DeleteFileAsync(doc.Document.ObjectRefId);
|
|
}
|
|
|
|
// upload new document to s3
|
|
var cover = await _documentService.UploadFileAsync(file);
|
|
|
|
// create new CommandDocumentEntity
|
|
var commandDoc = new CommandDocument
|
|
{
|
|
Category = GlobalConstants.TYPE_ATTACHMENT,
|
|
Document = cover,
|
|
};
|
|
|
|
// send to repo to save in database
|
|
await _repository.UploadDocument(orderId, GlobalConstants.TYPE_ATTACHMENT, commandDoc);
|
|
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// PM7-37 : บันทึกข้อมูลคำสั่งและแนบท้าย
|
|
/// </summary>
|
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("attachment/{orderId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateCommandExecuteAsync(Guid orderId, [FromBody] UpdateCommandExecuteRequest req)
|
|
{
|
|
try
|
|
{
|
|
await _repository.UpdateCommandInfoAsync(orderId, req.OrderNo, req.OrderYear, req.SignDate);
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อ่านข้อมูลเงินเดือนสำหรับผู้บรรจุ จากข้อมูลระบบสรรหา
|
|
/// </summary>
|
|
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("salary/{personalId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetPlacementSalaryAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
var record = await _repository.GetCommandReceiverAsync(personalId);
|
|
|
|
var data = await _repository.GetPlacementSalaryAsync(record!.RefPlacementProfileId!.Value);
|
|
|
|
return Success(data);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ
|
|
/// </summary>
|
|
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("salary/{personalId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdatePlacementSalaryAsync(Guid personalId, [FromBody] UpdatePlacementSalaryRequest req)
|
|
{
|
|
try
|
|
{
|
|
var receiver = await _repository.GetCommandReceiverAsync(personalId);
|
|
|
|
if (receiver == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
await _repository.UpdatePlacementSalaryAsync(personalId, req);
|
|
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// สลับลำดับข้อมูลในบัญชีแนบท้ายขึ้น
|
|
/// </summary>
|
|
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("swap/up/{personalId}")]
|
|
public async Task<ActionResult<ResponseObject>> SwapUpReceiverOrderAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
await _repository.SwapReceiverOrderAsync(personalId, "up");
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// สลับลำดับข้อมูลในบัญชีแนบท้ายลง
|
|
/// </summary>
|
|
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("swap/down/{personalId}")]
|
|
public async Task<ActionResult<ResponseObject>> SwapDownReceiverOrderAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
await _repository.SwapReceiverOrderAsync(personalId, "down");
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|