Merge branch 'develop' into work

This commit is contained in:
Kittapath 2023-08-07 16:34:11 +07:00
commit 7b038f0131
9 changed files with 327 additions and 65 deletions

View file

@ -18,6 +18,7 @@ namespace BMA.EHR.Application
services.AddTransient<CommandStatusRepository>(); services.AddTransient<CommandStatusRepository>();
services.AddTransient<InsigniaPeriodsRepository>(); services.AddTransient<InsigniaPeriodsRepository>();
services.AddTransient<RetirementRepository>(); services.AddTransient<RetirementRepository>();
services.AddTransient<UserProfileRepository>();
return services; return services;
} }

View file

@ -1,14 +1,14 @@
using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Requests.Commands; 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.Commands.Core;
using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Transactions;
using Command = BMA.EHR.Domain.Models.Commands.Core.Command; using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
namespace BMA.EHR.Application.Repositories.Commands namespace BMA.EHR.Application.Repositories.Commands
@ -35,6 +35,77 @@ namespace BMA.EHR.Application.Repositories.Commands
#region " Methods " #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 " #region " Override "
public override async Task<Command?> GetByIdAsync(Guid id) public override async Task<Command?> GetByIdAsync(Guid id)
@ -93,54 +164,16 @@ namespace BMA.EHR.Application.Repositories.Commands
throw new Exception(GlobalMessages.CommandNotFound); throw new Exception(GlobalMessages.CommandNotFound);
else else
{ {
if (command.Receivers != null || command!.Receivers!.Count > 0) if (command.Receivers != null && command!.Receivers!.Count > 0)
{ {
return command.Receivers; return command.Receivers;
} }
else else
{ {
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน await GetReceiverForByCommndTypeAsync(command);
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.OrganizationPosition)
.ThenInclude(x => x.Organization)
//.Where(x => x.OrganizationPosition.Organization.Id )
.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();
// query for new list // query for new list
return command.Receivers; return command.Receivers!;
} }
} }
} }
@ -560,6 +593,30 @@ namespace BMA.EHR.Application.Repositories.Commands
#region " Placement " #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) public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req)
{ {
try try
@ -605,7 +662,30 @@ namespace BMA.EHR.Application.Repositories.Commands
#endregion #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 try
{ {
@ -626,5 +706,27 @@ namespace BMA.EHR.Application.Repositories.Commands
#endregion #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);
if (data == null)
throw new Exception(GlobalMessages.OrganizationNotFound);
return data.OrganizationAgency!.Id;
}
catch
{
throw;
}
}
#endregion
} }
} }

View file

@ -0,0 +1,55 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories
{
public class UserProfileRepository : GenericRepository<Guid, Profile>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Costructor and Destructor "
public UserProfileRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Methods "
public Guid GetUserOCId(Guid keycloakId)
{
try
{
var data = _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Where(x => x.Profile!.KeycloakId == keycloakId)
.FirstOrDefault();
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
return data.OrganizationPosition!.Organization!.Id;
}
catch
{
throw;
}
}
#endregion
}
}

View 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;
}
}

View 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;
}
}

View file

@ -1,16 +1,14 @@
using Amazon.S3.Model.Internal.MarshallTransformations; using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Requests.Commands;
using BMA.EHR.Command.Service.Requests; using BMA.EHR.Command.Service.Requests;
using BMA.EHR.Command.Service.Responses;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims; using System.Security.Claims;
@ -35,6 +33,7 @@ namespace BMA.EHR.Command.Service.Controllers
private readonly PrefixRepository _prefixRepository; private readonly PrefixRepository _prefixRepository;
private readonly CommandTypeRepository _commandTypeRepository; private readonly CommandTypeRepository _commandTypeRepository;
private readonly CommandStatusRepository _commandStatusRepository; private readonly CommandStatusRepository _commandStatusRepository;
private readonly UserProfileRepository _userProfileRepository;
#endregion #endregion
@ -47,7 +46,8 @@ namespace BMA.EHR.Command.Service.Controllers
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
PrefixRepository prefixRepository, PrefixRepository prefixRepository,
CommandTypeRepository commandTypeRepository, CommandTypeRepository commandTypeRepository,
CommandStatusRepository commandStatusRepository) CommandStatusRepository commandStatusRepository,
UserProfileRepository userProfileRepository)
{ {
_repository = repository; _repository = repository;
_context = context; _context = context;
@ -57,6 +57,7 @@ namespace BMA.EHR.Command.Service.Controllers
_prefixRepository = prefixRepository; _prefixRepository = prefixRepository;
_commandTypeRepository = commandTypeRepository; _commandTypeRepository = commandTypeRepository;
_commandStatusRepository = commandStatusRepository; _commandStatusRepository = commandStatusRepository;
_userProfileRepository = userProfileRepository;
} }
#endregion #endregion
@ -69,6 +70,17 @@ namespace BMA.EHR.Command.Service.Controllers
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
private Guid OcId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion #endregion
#region " Methods " #region " Methods "
@ -382,7 +394,9 @@ namespace BMA.EHR.Command.Service.Controllers
ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionRegisterDate = req.conclusionRegisterDate,
ConclusionResultNo = req.conclusionResultNo, ConclusionResultNo = req.conclusionResultNo,
ConclusionResultDate = req.conclusionResultDate, ConclusionResultDate = req.conclusionResultDate,
CommandAffectDate = req.orderDate CommandAffectDate = req.orderDate,
OwnerGovId = OcId
}; };
var result = await _repository.AddAsync(inserted); var result = await _repository.AddAsync(inserted);
@ -496,16 +510,27 @@ namespace BMA.EHR.Command.Service.Controllers
{ {
// TODO : หาค่า Education มาแสดง // TODO : หาค่า Education มาแสดง
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId)) var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
.Select(r => new .OrderBy(x => x.Sequence)
.Select(r => new CommandReceiverResponse
{ {
personId = r.Id, RefRecordId = r.RefPlacementProfileId!.Value,
sequence = r.Sequence, PersonalId = r.Id,
idCard = r.CitizenId, Sequence = r.Sequence,
name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}", IdCard = r.CitizenId,
selectStatus = true, Name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน SelectStatus = true,
Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน
}).ToList(); }).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); return Success(receivers);
} }
catch catch
@ -515,8 +540,11 @@ namespace BMA.EHR.Command.Service.Controllers
} }
/// <summary> /// <summary>
/// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง /// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง ** ยังไม่ได้กรองหน่วยงาน **
/// </summary> /// </summary>
/// <remarks>
/// ** ยังไม่ได้กรองหน่วยงาน **
/// </remarks>
/// <param name="personalId">Record Id ของผู้รับคำสั่งในรายการบัญชีแนบท้าย</param> /// <param name="personalId">Record Id ของผู้รับคำสั่งในรายการบัญชีแนบท้าย</param>
/// <returns></returns> /// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response> /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
@ -547,7 +575,7 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response> /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("persons/{personalId}")] [HttpGet("copy-order/{orderId}")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesResponseType(StatusCodes.Status500InternalServerError)]
@ -882,7 +910,7 @@ namespace BMA.EHR.Command.Service.Controllers
{ {
try try
{ {
await _repository.UpdateCommandInfo(orderId, req.OrderNo, req.OrderYear, req.SignDate); await _repository.UpdateCommandInfoAsync(orderId, req.OrderNo, req.OrderYear, req.SignDate);
return Success(); return Success();
} }
catch catch
@ -891,6 +919,34 @@ 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 record = await _repository.GetCommandReceiverAsync(personalId);
var data = await _repository.GetPlacementSalaryAsync(record!.RefPlacementProfileId!.Value);
return Success(data);
}
catch
{
throw;
}
}
/// <summary> /// <summary>
/// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ /// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ
/// </summary> /// </summary>
@ -899,7 +955,7 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response> /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("salary/{id}")] [HttpPut("salary/{personalId}")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesResponseType(StatusCodes.Status500InternalServerError)]

View 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;
}
}

View file

@ -1,8 +1,7 @@
using Microsoft.EntityFrameworkCore; using BMA.EHR.Domain.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using BMA.EHR.Domain.Models.Base;
using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace BMA.EHR.Domain.Models.Organizations namespace BMA.EHR.Domain.Models.Organizations
{ {

View file

@ -88,6 +88,8 @@
public static readonly string CommandNotFound = "ไม่พบรายการคำสั่งนี้ในระบบ โปรดตรวจความถูกต้อง"; public static readonly string CommandNotFound = "ไม่พบรายการคำสั่งนี้ในระบบ โปรดตรวจความถูกต้อง";
public static readonly string MethodForCommandTypeNotImplement = "Method for this command type not implement!";
#endregion #endregion
} }