Merge branch 'develop' into working

# Conflicts:
#	.github/workflows/release_leave.yaml
This commit is contained in:
Suphonchai Phoonsawat 2024-07-10 10:48:34 +07:00
commit 92a162f93e
13 changed files with 633 additions and 65 deletions

View file

@ -101,6 +101,9 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-04":
result = await GetReceiver04Async(command);
break;
case "C-PM-39":
result = await GetReceiver39Async(command);
break;
case "C-PM-05":
result = await GetReceiver05Async(command);
break;
@ -446,6 +449,65 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
/// <summary>
/// C-PM-39 - คำสั่งเลื่อน : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver39Async(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-39")
.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)
.Where(x => x.Placement.Id == command.Placement.Id)
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.typeCommand.Trim().ToUpper() == "SLIP")
.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 == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-05 - คำสั่งแต่งตั้ง
/// </summary>
@ -2626,6 +2688,9 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-04":
await ExecuteCommand04Async(command, token);
break;
case "C-PM-39":
await ExecuteCommand39Async(command, token);
break;
case "C-PM-05":
await ExecuteCommand05Async(command, token);
break;
@ -3347,6 +3412,161 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
// <summary>
/// C-PM-39 - คำสั่งเลื่อน : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand39Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.positionName,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งเลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.PlacementStatus = "CONTAIN";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-05 - คำสั่งแต่งตั้ง
/// </summary>
@ -8301,6 +8521,13 @@ namespace BMA.EHR.Application.Repositories.Commands
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
break;
case "C-PM-39":
command = await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
break;
default:
command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
@ -8337,6 +8564,9 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-04":
salary = await GetPlacementSalaryAsync(item.RefPlacementProfileId.Value);
break;
case "C-PM-39":
salary = await GetPlacementSalaryAsync(item.RefPlacementProfileId.Value);
break;
default:
salary = await GetCommandReceiverSalary(item.RefPlacementProfileId.Value, item.Amount, item.MouthSalaryAmount, item.PositionSalaryAmount);
break;