Add API For Coimmand Type 24

This commit is contained in:
Suphonchai Phoonsawat 2023-10-27 14:00:04 +07:00
parent ab538869d2
commit 385a20c265
2 changed files with 153 additions and 0 deletions

View file

@ -155,6 +155,9 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-23":
result = await GetReceiver23Async(command);
break;
case "C-PM-24":
result = await GetReceiver24Async(command);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
}
@ -1597,6 +1600,65 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
// <summary>
/// C-PM-24
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver24Async(Command command)
{
try
{
var result = new List<CommandReceiver>();
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
.Include(x => x.Command)
.ThenInclude(x => x.CommandType)
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-24")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
.Where(x => x.Profile.ProfileType == "employee")
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.Profile!.CitizenId!,
Prefix = item.Profile!.Prefix!.Name,
FirstName = item.Profile!.FirstName!,
LastName = item.Profile!.LastName!,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
#endregion
#region " Execute and Deploy "

View file

@ -2836,6 +2836,97 @@ namespace BMA.EHR.Command.Service.Controllers
#endregion
#region " C-PM-24 "
/// <summary>
/// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-24
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("c-pm-24/detail")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> PostType24Async([FromBody] CreateCommandGroup0Request req)
{
try
{
var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue);
var inserted = new Domain.Models.Commands.Core.Command
{
CommandNo = req.orderNo,
CommandYear = req.orderYear.ToString(),
CommandSubject = req.orderTitle,
CommandTypeId = req.orderTypeValue,
IssuerOrganizationId = req.orderBy,
IssuerOrganizationName = req.orderByOrganizationName,
AuthorizedUserFullName = req.signatoryBy,
AuthorizedPosition = req.signatoryPosition,
CommandAffectDate = req.orderDate,
OwnerGovId = OcId,
};
var result = await _repository.AddAsync(inserted);
return Success(result);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-24
/// </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("c-pm-24/detail/{orderId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> PutType24Async(Guid orderId, [FromBody] CreateCommandGroup0Request req)
{
try
{
var order = await _repository.GetByIdAsync(orderId);
if (order == null)
throw new Exception(GlobalMessages.CommandNotFound);
var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue);
var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId);
order.CommandNo = req.orderNo;
order.CommandYear = req.orderYear.ToString();
order.CommandSubject = req.orderTitle;
order.CommandType = commandType!;
order.IssuerOrganizationId = req.orderBy;
order.IssuerOrganizationName = req.orderByOrganizationName;
order.AuthorizedUserFullName = req.signatoryBy;
order.AuthorizedPosition = req.signatoryPosition;
order.CommandStatus = status!;
order.CommandAffectDate = req.orderDate;
var result = await _repository.UpdateAsync(order);
return Success(result);
}
catch
{
throw;
}
}
#endregion
#endregion
/// <summary>