Get command Receiver For C-PM-03 , C-PM-04
This commit is contained in:
parent
6253d8d2ab
commit
9b3efd8981
2 changed files with 155 additions and 1 deletions
|
|
@ -76,6 +76,12 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
case "C-PM-02":
|
case "C-PM-02":
|
||||||
result = await GetReceiver02Async(command);
|
result = await GetReceiver02Async(command);
|
||||||
break;
|
break;
|
||||||
|
case "C-PM-03":
|
||||||
|
result = await GetReceiver03Async(command);
|
||||||
|
break;
|
||||||
|
case "C-PM-04":
|
||||||
|
result = await GetReceiver04Async(command);
|
||||||
|
break;
|
||||||
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,6 +217,137 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<List<CommandReceiver>> GetReceiver03Async(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-03")
|
||||||
|
.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)
|
||||||
|
{
|
||||||
|
var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!);
|
||||||
|
if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id == profile_oc)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<List<CommandReceiver>> GetReceiver04Async(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-03")
|
||||||
|
.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)
|
||||||
|
{
|
||||||
|
var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!);
|
||||||
|
if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id != profile_oc)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,24 @@ namespace BMA.EHR.Application.Repositories
|
||||||
|
|
||||||
#region " Methods "
|
#region " Methods "
|
||||||
|
|
||||||
public async Task<bool> CheckIsActiveOfficer(string citizenId)
|
public async Task<Guid> GetProfileOrganizationAsync(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 || pf.Oc == null ? Guid.Empty : pf.OcId!.Value;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> CheckIsActiveOfficerAsync(string citizenId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue