1. ตรวจสอบสถานะความพร้อมในการออกคำสั่ง 2. เปลี่ยนสถานะไป state ถัดไป 3. เปลี่ยนสถานะไป state ก่อนหน้า
739 lines
34 KiB
C#
739 lines
34 KiB
C#
using Amazon.S3.Model.Internal.MarshallTransformations;
|
|
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.Commands;
|
|
using BMA.EHR.Command.Service.Requests;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Commands.Core;
|
|
using BMA.EHR.Domain.Models.MetaData;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
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;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region " Constuctor and Destructor "
|
|
|
|
public OrderController(CommandRepository repository,
|
|
PlacementRepository placementRepository,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
PrefixRepository prefixRepository,
|
|
CommandTypeRepository commandTypeRepository)
|
|
{
|
|
_repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_placementRepository = placementRepository;
|
|
_prefixRepository = prefixRepository;
|
|
_commandTypeRepository = commandTypeRepository;
|
|
}
|
|
|
|
#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");
|
|
|
|
#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_ATTATCHMENT);
|
|
|
|
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
|
|
{
|
|
OrderName = d.CommandSubject,
|
|
OrderNo = d.CommandNo,
|
|
FiscalYear = d.CommandYear,
|
|
OrderDate = d.CommandAffectDate,
|
|
OrderByOrganization = d.IssuerOrganizationName,
|
|
OrderBy = d.AuthorizedUserFullName,
|
|
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("{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.Round,
|
|
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]
|
|
[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
|
|
};
|
|
|
|
var result = await _repository.AddAsync(inserted);
|
|
|
|
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))
|
|
.Select(r => new
|
|
{
|
|
personId = r.Id,
|
|
sequence = r.Sequence,
|
|
idCard = r.CitizenId,
|
|
name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
|
|
selectStatus = true,
|
|
education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน
|
|
}).ToList();
|
|
|
|
return Success(receivers);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง
|
|
/// </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("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("persons/{personalId}")]
|
|
[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_ATTATCHMENT).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;
|
|
}
|
|
}
|
|
|
|
#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.UpdateCommandInfo(orderId, req.OrderNo, req.OrderYear, req.SignDate);
|
|
return Success();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|