ปรับ api ตามที่คุยใหม่
This commit is contained in:
parent
7b038f0131
commit
1a7be19e33
2 changed files with 174 additions and 20 deletions
|
|
@ -37,15 +37,21 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Private "
|
||||
|
||||
private async Task GetReceiverForByCommndTypeAsync(Command command)
|
||||
private async Task<List<CommandReceiver>> GetReceiverForByCommndTypeAsync(Command command)
|
||||
{
|
||||
switch (command.CommandType.Category.Trim().ToUpper())
|
||||
var result = new List<CommandReceiver>();
|
||||
|
||||
switch (command.CommandType.CommandCode.Trim().ToUpper())
|
||||
{
|
||||
case "C-PM-01":
|
||||
await GetReceiver01(command);
|
||||
case "C-PM-02":
|
||||
case "C-PM-03":
|
||||
result = await GetReceiver01(command);
|
||||
break;
|
||||
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -53,10 +59,13 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
private async Task GetReceiver01(Command command)
|
||||
private async Task<List<CommandReceiver>> GetReceiver01(Command command)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new List<CommandReceiver>();
|
||||
|
||||
|
||||
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
||||
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
||||
.Include(x => x.Command)
|
||||
|
|
@ -70,7 +79,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x.Organization)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
||||
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
||||
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
||||
|
|
@ -94,9 +103,10 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
};
|
||||
seq++;
|
||||
|
||||
command.Receivers.Add(receiver);
|
||||
result.Add(receiver);
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -151,10 +161,80 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Command Receiver "
|
||||
|
||||
public async Task SaveSelectedReceiverAsync(Guid id, List<Guid> selected)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>()
|
||||
.Include(x => x.Receivers)
|
||||
.Include(x => x.CommandType)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
||||
.Where(x => selected.Contains(x.Id))
|
||||
.OrderBy(x => x.ExamNumber)
|
||||
.ToListAsync();
|
||||
|
||||
_dbContext.Set<CommandReceiver>().RemoveRange(command.Receivers);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
var seq = 1;
|
||||
foreach (var item in appointPeople)
|
||||
{
|
||||
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = item.CitizenId!,
|
||||
Prefix = item.Prefix!.Name,
|
||||
FirstName = item.Firstname!,
|
||||
LastName = item.Lastname!,
|
||||
RefPlacementProfileId = item.Id
|
||||
};
|
||||
seq++;
|
||||
|
||||
command.Receivers.Add(receiver);
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverForCommandAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>()
|
||||
.Include(x => x.Receivers)
|
||||
.Include(x => x.CommandType)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
else
|
||||
return await GetReceiverForByCommndTypeAsync(command);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
// ปรับใหม่ให้อ่านจาก database ล้วนๆ
|
||||
var command = await _dbContext.Set<Command>()
|
||||
.Include(x => x.Receivers)
|
||||
.Include(x => x.CommandType)
|
||||
|
|
@ -170,10 +250,8 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
await GetReceiverForByCommndTypeAsync(command);
|
||||
|
||||
// query for new list
|
||||
return command.Receivers!;
|
||||
// returrn empty list
|
||||
return new List<CommandReceiver>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -711,14 +789,14 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
try
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
||||
.Include(x => x.OrganizationAgency)
|
||||
.Include(x => x.OrganizationGovernmentAgency)
|
||||
//.Include(x => x.OrganizationAgency)
|
||||
//.Include(x => x.OrganizationGovernmentAgency)
|
||||
.FirstOrDefaultAsync(o => o.Id == ocId);
|
||||
|
||||
if (data == null)
|
||||
throw new Exception(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
return data.OrganizationAgency!.Id;
|
||||
return data.OrganizationAgencyId!.Value;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Command.Service.Requests;
|
||||
|
|
@ -493,7 +494,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// PM7-26 : ข้อมูลเลือกรายชื่อออกคำสั่ง
|
||||
/// PM7-26 : ข้อมูลเลือกรายชื่อออกคำสั่ง ** ยังไม่ได้กรองหน่วยงาน ** ** แสดงรายการจากระบบบรรจุ **
|
||||
/// </summary>
|
||||
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -509,8 +510,57 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
try
|
||||
{
|
||||
// TODO : หาค่า Education มาแสดง
|
||||
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
|
||||
var existed = await _repository.GetReceiverByCommmandIdAsync(orderId);
|
||||
|
||||
var receivers = (await _repository.GetReceiverForCommandAsync(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 = existed.FirstOrDefault(x => x.RefPlacementProfileId!.Value == r.RefPlacementProfileId!.Value) != null,
|
||||
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>
|
||||
/// ข้อมูลเลือกรายชื่อออกคำสั่ง ** ที่ได้เลือกเอาไว้แล้ว **
|
||||
/// </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-selected/{orderId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetCommandSelectReceiverAsync(Guid orderId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
|
||||
.OrderBy(x => x.Sequence)
|
||||
.Select(r => new CommandReceiverResponse
|
||||
{
|
||||
RefRecordId = r.RefPlacementProfileId!.Value,
|
||||
|
|
@ -540,7 +590,33 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง ** ยังไม่ได้กรองหน่วยงาน **
|
||||
/// บันทึกข้อมูลเลือกรายชื่อออกคำสั่ง ** ที่ได้เลือกเอาไว้แล้ว **
|
||||
/// </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("persons/{orderId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> SaveCommandSelectReceiverAsync(Guid orderId,[FromBody] List<Guid> selected)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _repository.SaveSelectedReceiverAsync(orderId, selected);
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PM7-27 : ลบข้อมูลเลือกรายชื่อออกคำสั่ง
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ** ยังไม่ได้กรองหน่วยงาน **
|
||||
|
|
@ -935,8 +1011,8 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
{
|
||||
try
|
||||
{
|
||||
var record = await _repository.GetCommandReceiverAsync(personalId);
|
||||
|
||||
var record = await _repository.GetCommandReceiverAsync(personalId);
|
||||
|
||||
var data = await _repository.GetPlacementSalaryAsync(record!.RefPlacementProfileId!.Value);
|
||||
|
||||
return Success(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue