Get Receiver for Command C-PM-01, C-PM-02

This commit is contained in:
Suphonchai Phoonsawat 2023-08-28 16:18:35 +07:00
parent ec39bf1505
commit 6253d8d2ab
2 changed files with 119 additions and 24 deletions

View file

@ -71,10 +71,11 @@ namespace BMA.EHR.Application.Repositories.Commands
switch (command.CommandType.CommandCode.Trim().ToUpper()) switch (command.CommandType.CommandCode.Trim().ToUpper())
{ {
case "C-PM-01": case "C-PM-01":
case "C-PM-02":
case "C-PM-03":
result = await GetReceiver01Async(command); result = await GetReceiver01Async(command);
break; break;
case "C-PM-02":
result = await GetReceiver02Async(command);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
} }
@ -82,9 +83,9 @@ namespace BMA.EHR.Application.Repositories.Commands
} }
/// <summary> /// <summary>
/// C-PM-01 /// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
/// </summary> /// </summary>
/// <param name="command"></param> /// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns> /// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver01Async(Command command) private async Task<List<CommandReceiver>> GetReceiver01Async(Command command)
{ {
@ -97,13 +98,15 @@ namespace BMA.EHR.Application.Repositories.Commands
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>() var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
.Include(x => x.Command) .Include(x => x.Command)
.ThenInclude(x => x.CommandType) .ThenInclude(x => x.CommandType)
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM")) .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM-01"))
.Where(x => x.Command.Id != command.Id) .Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId) .Select(x => x.CitizenId)
.ToListAsync(); .ToListAsync();
// 2. Query // 2. Query
var appointPeople = await _dbContext.Set<PlacementProfile>() var appointPeople = await _dbContext.Set<PlacementProfile>()
.Include(x => x.Placement)
.ThenInclude(x => x.PlacementType)
.Include(x => x.Prefix) .Include(x => x.Prefix)
.Include(x => x.OrganizationPosition) .Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization) .ThenInclude(x => x!.Organization)
@ -111,6 +114,7 @@ namespace BMA.EHR.Application.Repositories.Commands
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.Draft! == true) .Where(x => x.Draft! == true)
.Where(x => x.Placement!.PlacementType!.Name == "สอบแข่งขัน")
.OrderBy(x => x.ExamNumber) .OrderBy(x => x.ExamNumber)
.ToListAsync(); .ToListAsync();
@ -118,19 +122,20 @@ namespace BMA.EHR.Application.Repositories.Commands
var seq = 1; var seq = 1;
foreach (var item in appointPeople) foreach (var item in appointPeople)
{ {
if (!(await CheckIsActiveOfficer(item.CitizenId!)))
var receiver = new CommandReceiver
{ {
Sequence = seq, var receiver = new CommandReceiver
CitizenId = item.CitizenId!, {
Prefix = item.Prefix!.Name, Sequence = seq,
FirstName = item.Firstname!, CitizenId = item.CitizenId!,
LastName = item.Lastname!, Prefix = item.Prefix!.Name,
RefPlacementProfileId = item.Id FirstName = item.Firstname!,
}; LastName = item.Lastname!,
seq++; RefPlacementProfileId = item.Id
};
result.Add(receiver); seq++;
result.Add(receiver);
}
} }
return result; return result;
@ -141,6 +146,72 @@ namespace BMA.EHR.Application.Repositories.Commands
} }
} }
/// <summary>
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver02Async(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-02")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementProfile>()
.Include(x => x.Placement)
.ThenInclude(x => x.PlacementType)
.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)
.Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน")
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
if (!(await CheckIsActiveOfficer(item.CitizenId!)))
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId!,
Prefix = item.Prefix!.Name,
FirstName = item.Firstname!,
LastName = item.Lastname!,
RefPlacementProfileId = item.Id
};
seq++;
result.Add(receiver);
}
}
return result;
}
catch
{
throw;
}
}
#endregion #endregion
#region " Execute and Deploy " #region " Execute and Deploy "
@ -151,15 +222,20 @@ namespace BMA.EHR.Application.Repositories.Commands
{ {
case "C-PM-01": case "C-PM-01":
case "C-PM-02": case "C-PM-02":
case "C-PM-03": await ExecuteCommand01_02Async(command);
await ExecuteCommand01Async(command);
break; break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
} }
} }
private async Task ExecuteCommand01Async(Command command) /// <summary>
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้,
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand01_02Async(Command command)
{ {
try try
{ {

View file

@ -1,5 +1,7 @@
using BMA.EHR.Application.Common.Interfaces; using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Base; using BMA.EHR.Domain.Models.Base;
using BMA.EHR.Domain.Models.HR;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Security.Claims; using System.Security.Claims;
@ -41,6 +43,23 @@ namespace BMA.EHR.Application.Repositories
#region " Methods " #region " Methods "
public async Task<bool> CheckIsActiveOfficer(string citizenId)
{
try
{
var pf = await _dbContext.Set<Profile>()
.Where(x => x.CitizenId == citizenId)
.Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave)
.FirstOrDefaultAsync();
return pf != null;
}
catch
{
throw;
}
}
public virtual async Task<IReadOnlyList<T>> GetAllAsync() public virtual async Task<IReadOnlyList<T>> GetAllAsync()
{ {
return await _dbSet.ToListAsync(); return await _dbSet.ToListAsync();