เพิ่ม api แสดงข้อมูลเงินเดือนที่บันทึกในระบบสรรหา
This commit is contained in:
parent
f80c1ca295
commit
72c53c2e42
6 changed files with 236 additions and 67 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
|
|
@ -33,6 +35,77 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Methods "
|
||||
|
||||
#region " Private "
|
||||
|
||||
private async Task GetReceiverForByCommndTypeAsync(Command command)
|
||||
{
|
||||
switch (command.CommandType.Category.Trim().ToUpper())
|
||||
{
|
||||
case "C-PM-01":
|
||||
await GetReceiver01(command);
|
||||
break;
|
||||
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-01
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
private async Task GetReceiver01(Command command)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 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-01")
|
||||
.Where(x => x.Id != command.Id)
|
||||
.Select(x => x.CitizenId)
|
||||
.ToListAsync();
|
||||
|
||||
// 2. Query
|
||||
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 => !otherCommandReceivers.Contains(x.CitizenId!))
|
||||
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
||||
.Where(x => x.Draft! == true)
|
||||
.OrderBy(x => x.ExamNumber)
|
||||
.ToListAsync();
|
||||
|
||||
// 3. Create new Record
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Override "
|
||||
|
||||
public override async Task<Command?> GetByIdAsync(Guid id)
|
||||
|
|
@ -97,49 +170,10 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
// 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-01")
|
||||
.Where(x => x.Id != Id)
|
||||
.Select(x => x.CitizenId)
|
||||
.ToListAsync();
|
||||
|
||||
// 2. Query
|
||||
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 => !otherCommandReceivers.Contains(x.CitizenId!))
|
||||
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
||||
.Where(x => x.Draft! == true)
|
||||
.OrderBy(x => x.ExamNumber)
|
||||
.ToListAsync();
|
||||
|
||||
// 3. Create new Record
|
||||
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();
|
||||
await GetReceiverForByCommndTypeAsync(command);
|
||||
|
||||
// query for new list
|
||||
return command.Receivers;
|
||||
return command.Receivers!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -559,6 +593,30 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Placement "
|
||||
|
||||
public async Task<PlacementSalaryResponse> GetPlacementSalaryAsync(Guid placementProfileId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
||||
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
|
||||
|
||||
if (placementProfile == null)
|
||||
throw new Exception($"Invalid placement profile: {placementProfileId}");
|
||||
|
||||
return new PlacementSalaryResponse
|
||||
{
|
||||
SalaryAmount = placementProfile.Amount ?? 0,
|
||||
PositionSalaryAmount = placementProfile.PositionSalaryAmount ?? 0,
|
||||
MonthSalaryAmount = placementProfile.MouthSalaryAmount ?? 0
|
||||
};
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req)
|
||||
{
|
||||
try
|
||||
|
|
@ -604,7 +662,30 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#endregion
|
||||
|
||||
public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate)
|
||||
#region " Command Info "
|
||||
|
||||
public async Task<CommandInfoResponse> GetCommandInfoAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
return new CommandInfoResponse
|
||||
{
|
||||
SignDate = command.CommandExcecuteDate.Value,
|
||||
OrderNo = command.CommandNo,
|
||||
OrderYear = command.CommandYear,
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateCommandInfoAsync(Guid id, string orderNo, string orderYear, DateTime signDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -623,25 +704,27 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
//public async Task<Guid> GetRootOcIdAsync(Guid ocId)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
||||
#endregion
|
||||
|
||||
public async Task<Guid> GetRootOcIdAsync(Guid ocId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
||||
.Include(x => x.OrganizationAgency)
|
||||
.Include(x => x.OrganizationGovernmentAgency)
|
||||
.FirstOrDefaultAsync(o => o.Id == ocId);
|
||||
|
||||
// .FirstOrDefaultAsync(o => o.Id == ocId);
|
||||
if (data == null)
|
||||
throw new Exception(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
// if (data == null)
|
||||
// throw new Exception(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
// return data
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// throw;
|
||||
// }
|
||||
//}
|
||||
return data.OrganizationAgency!.Id;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
11
BMA.EHR.Application/Responses/CommandInfoResponse.cs
Normal file
11
BMA.EHR.Application/Responses/CommandInfoResponse.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses
|
||||
{
|
||||
public class CommandInfoResponse
|
||||
{
|
||||
public string OrderNo { get; set; } = string.Empty;
|
||||
|
||||
public string OrderYear { get; set; } = string.Empty;
|
||||
|
||||
public DateTime SignDate { get; set; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
11
BMA.EHR.Application/Responses/PlacementSalaryResponse.cs
Normal file
11
BMA.EHR.Application/Responses/PlacementSalaryResponse.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses
|
||||
{
|
||||
public class PlacementSalaryResponse
|
||||
{
|
||||
public double SalaryAmount { get; set; } = 0;
|
||||
|
||||
public double PositionSalaryAmount { get; set; } = 0;
|
||||
|
||||
public double MonthSalaryAmount { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Command.Service.Requests;
|
||||
using BMA.EHR.Command.Service.Responses;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
|
|
@ -510,16 +511,26 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
// TODO : หาค่า Education มาแสดง
|
||||
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
|
||||
.OrderBy(x => x.Sequence)
|
||||
.Select(r => new
|
||||
.Select(r => new CommandReceiverResponse
|
||||
{
|
||||
personId = r.Id,
|
||||
sequence = r.Sequence,
|
||||
idCard = r.CitizenId,
|
||||
name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
|
||||
selectStatus = true,
|
||||
education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน
|
||||
RefRecordId = r.RefPlacementProfileId!.Value,
|
||||
PersonalId = r.Id,
|
||||
Sequence = r.Sequence,
|
||||
IdCard = r.CitizenId,
|
||||
Name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
|
||||
SelectStatus = true,
|
||||
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
|
||||
|
|
@ -899,7 +910,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
{
|
||||
try
|
||||
{
|
||||
await _repository.UpdateCommandInfo(orderId, req.OrderNo, req.OrderYear, req.SignDate);
|
||||
await _repository.UpdateCommandInfoAsync(orderId, req.OrderNo, req.OrderYear, req.SignDate);
|
||||
return Success();
|
||||
}
|
||||
catch
|
||||
|
|
@ -908,6 +919,32 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// อ่านข้อมูลเงินเดือนสำหรับผู้บรรจุ จากข้อมูลระบบสรรหา
|
||||
/// </summary>
|
||||
/// <param name="personalId">Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("salary/{personalId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetPlacementSalaryAsync(Guid personalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _repository.GetPlacementSalaryAsync(personalId);
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ
|
||||
/// </summary>
|
||||
|
|
@ -916,7 +953,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("salary/{id}")]
|
||||
[HttpPut("salary/{personalId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
|
|
|
|||
25
BMA.EHR.Command.Service/Responses/CommandReceiverResponse.cs
Normal file
25
BMA.EHR.Command.Service/Responses/CommandReceiverResponse.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
namespace BMA.EHR.Command.Service.Responses
|
||||
{
|
||||
public class CommandReceiverResponse
|
||||
{
|
||||
public Guid RefRecordId { get; set; } = Guid.Empty;
|
||||
|
||||
public Guid PersonalId { get; set; } = Guid.Empty;
|
||||
|
||||
public int Sequence { get; set; } = 0;
|
||||
|
||||
public string IdCard { get; set; } = string.Empty;
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public bool SelectStatus { get; set; } = true;
|
||||
|
||||
public string Education { get; set; } = string.Empty;
|
||||
|
||||
public double SalaryAmount { get; set; } = 0;
|
||||
|
||||
public double PositionSalaryAmount { get; set; } = 0;
|
||||
|
||||
public double MonthSalaryAmount { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -88,6 +88,8 @@
|
|||
|
||||
public static readonly string CommandNotFound = "ไม่พบรายการคำสั่งนี้ในระบบ โปรดตรวจความถูกต้อง";
|
||||
|
||||
public static readonly string MethodForCommandTypeNotImplement = "Method for this command type not implement!";
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue