Add Command Controller Code (Not Complete)
This commit is contained in:
parent
9ee5b86a26
commit
7f5ed43f3f
27 changed files with 58797 additions and 84 deletions
|
|
@ -40,7 +40,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<None Update="SeedCommand.xlsx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
240
BMA.EHR.Command.Service/Controllers/OrderController.cs
Normal file
240
BMA.EHR.Command.Service/Controllers/OrderController.cs
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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 PlacementCommandRepository _repository;
|
||||
private readonly PlacementRepository _placementRepository;
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constuctor and Destructor "
|
||||
|
||||
public OrderController(PlacementCommandRepository repository,
|
||||
PlacementRepository placementRepository,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_repository = repository;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_placementRepository = placementRepository;
|
||||
}
|
||||
|
||||
#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>
|
||||
/// <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>> GetFiscal()
|
||||
{
|
||||
var data = await _repository.GetAllAsync();
|
||||
if (data != null)
|
||||
{
|
||||
var _data = data.GroupBy(x => x.CommandYear).Select(x => new
|
||||
{
|
||||
Id = x.FirstOrDefault().CommandYear,
|
||||
Name = x.FirstOrDefault().CommandYear + 543,
|
||||
}).ToList();
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <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.ExamRoundId,
|
||||
registerPosition = "",
|
||||
conclusionRegisterNo = data.ConclusionRegisterNo,
|
||||
conclusionRegisterDate = data.ConclusionRegisterDate,
|
||||
conclusionResultNo = data.ConclusionResultNo,
|
||||
conclusionResultDate = data.ConclusionResultDate,
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -126,6 +126,9 @@ var app = builder.Build();
|
|||
await using var db = scope.ServiceProvider.GetRequiredService<ApplicationDBContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
|
||||
// seed default data
|
||||
await CommandDataSeeder.SeedData(app);
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
BMA.EHR.Command.Service/SeedCommand.xlsx
Normal file
BIN
BMA.EHR.Command.Service/SeedCommand.xlsx
Normal file
Binary file not shown.
|
|
@ -14,7 +14,7 @@
|
|||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
|
||||
"DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue