fix bug GetList คำสั่ง

เพิ่ม api แก้ไขคำสั่ง
This commit is contained in:
Suphonchai Phoonsawat 2023-08-04 11:59:02 +07:00
parent ab7135fcbf
commit 680bfba81e
4 changed files with 255 additions and 9 deletions

View file

@ -1,8 +1,10 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
@ -44,6 +46,15 @@ namespace BMA.EHR.Application.Repositories.Commands
.FirstOrDefaultAsync(x => x.Id == id);
}
public override async Task<IReadOnlyList<Command>> GetAllAsync()
{
return await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.CommandType)
.Include(x => x.CommandStatus)
.ToListAsync();
}
public override async Task<Command> AddAsync(Command command)
{
var status = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == 1);
@ -335,6 +346,54 @@ namespace BMA.EHR.Application.Repositories.Commands
#region " Documents "
public async Task<List<CommandDocument>> GetExistDocument(Guid id, string category)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Documents)
.ThenInclude(x => x.Document)
.FirstOrDefaultAsync(c => c.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
// insert new record to comand Document
var exist = command.Documents.Where(x => x.Category == category).ToList();
return exist;
}
catch
{
throw;
}
}
public async Task UploadDocument(Guid id, string category, CommandDocument document)
{
try
{
var command = await _dbContext.Set<Command>().Include(x => x.Documents).FirstOrDefaultAsync(c => c.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
// insert new record to comand Document
var exist = command.Documents.Where(x => x.Category == category).ToList();
if (exist.Any())
{
_dbContext.Set<CommandDocument>().RemoveRange(exist);
await _dbContext.SaveChangesAsync();
}
// insert new Record
command.Documents.Add(document);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<List<CommandDocument>> GetCommandDocumentAsync(Guid id)
{
try
@ -407,6 +466,36 @@ namespace BMA.EHR.Application.Repositories.Commands
#endregion
#region " Change Detail Sequence "
#endregion
#region " Placement "
public async Task<List<PositionPath>> GetPlacementPositionPath(Guid id)
{
try
{
var data = await _dbContext.Set<PlacementProfile>()
.Include(x => x.PositionPath)
.Include(x => x.Placement)
.Where(x => x.Placement!.Id == id)
.Where(x => x.PositionPath != null)
.Select(x => x.PositionPath)
.Distinct()
.ToListAsync();
return data!;
}
catch
{
throw;
}
}
#endregion
public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate)
{
try

View file

@ -33,8 +33,7 @@ namespace BMA.EHR.Command.Service.Controllers
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly PrefixRepository _prefixRepository;
private readonly CommandTypeRepository _commandTypeRepository;
private readonly CommandStatusRepository _commandStatusRepository;
#endregion
@ -46,7 +45,8 @@ namespace BMA.EHR.Command.Service.Controllers
MinIOService documentService,
IHttpContextAccessor httpContextAccessor,
PrefixRepository prefixRepository,
CommandTypeRepository commandTypeRepository)
CommandTypeRepository commandTypeRepository,
CommandStatusRepository commandStatusRepository)
{
_repository = repository;
_context = context;
@ -55,6 +55,7 @@ namespace BMA.EHR.Command.Service.Controllers
_placementRepository = placementRepository;
_prefixRepository = prefixRepository;
_commandTypeRepository = commandTypeRepository;
_commandStatusRepository = commandStatusRepository;
}
#endregion
@ -159,7 +160,7 @@ namespace BMA.EHR.Command.Service.Controllers
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);
var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTACHMENT);
if (command.CommandNo != "" &&
command.CommandYear != null &&
@ -250,6 +251,7 @@ namespace BMA.EHR.Command.Service.Controllers
var data = (await _repository.GetAllAsync())
.Select(d => new
{
OrderId = d.Id,
OrderName = d.CommandSubject,
OrderNo = d.CommandNo,
FiscalYear = d.CommandYear,
@ -310,7 +312,7 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{orderId}")]
[HttpGet("detail/{orderId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@ -333,7 +335,7 @@ namespace BMA.EHR.Command.Service.Controllers
orderBy = data.IssuerOrganizationId,
signatoryBy = data.AuthorizedUserFullName,
signatoryPosition = data.AuthorizedPosition,
examRound = data.Placement.Round,
examRound = data.Placement.Id,
registerPosition = "",
conclusionRegisterNo = data.ConclusionRegisterNo,
conclusionRegisterDate = data.ConclusionRegisterDate,
@ -357,7 +359,7 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost]
[HttpPost("detail")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@ -392,6 +394,56 @@ namespace BMA.EHR.Command.Service.Controllers
}
}
/// <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!;
var result = await _repository.UpdateAsync(order);
return Success(result);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-24 : dropdown รอบการสอบ หน้ารายละเอียดการออกคำสั่ง
/// </summary>
@ -688,7 +740,7 @@ namespace BMA.EHR.Command.Service.Controllers
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 attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTACHMENT).FirstOrDefault();
var result = new
{
@ -707,6 +759,109 @@ namespace BMA.EHR.Command.Service.Controllers
}
}
/// <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>

View file

@ -2,7 +2,7 @@
{
public class GlobalConstants
{
public static readonly string TYPE_ATTATCHMENT = "attachment";
public static readonly string TYPE_ATTACHMENT = "attachment";
public static readonly string TYPE_COVER = "cover";
}
}

View file

@ -16,6 +16,8 @@
public static readonly string FileNotFoundOnServer = "ไม่พบไฟล์ในระบบ!!";
public static readonly string NoFileToUpload = "ไม่พบไฟล์ที่ทำการอัพโหลด!";
#region " Meta Data "
public static readonly string DataExist5 = "เนื่องจากมีการกำหนดวันหยุดในการทำงาน 5 วันอยู่";