ออกคำสั่ง 01 02

This commit is contained in:
Bright 2024-10-09 16:18:11 +07:00
parent 037435b3bc
commit 8ef340b75b

View file

@ -1759,6 +1759,158 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success();
}
/// <summary>
/// ออกคำสั่ง C-PM-01 บรรจุและแต่งตั้งผู้สอบแข่งขันได้ (NEW)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("recruit/report/excecute-new")]
public async Task<ActionResult<ResponseObject>> PostReportExecuteRecruitNew([FromBody] ReportExecuteRequest req)
{
try
{
var placementProfile = await _context.PlacementProfiles
.Include(x => x.PlacementCertificates)
.Include(x => x.PlacementEducations)
.ThenInclude(x => x.EducationLevel)
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync();
if (placementProfile == null)
return NotFound();
var resultData = (from p in placementProfile
join r in req.refIds
on p.Id.ToString() equals r.refId
select new
{
bodyProfile = new
{
rank = string.Empty,
prefix = p.Prefix == null ? string.Empty : p.Prefix,
firstName = p.Firstname == null ? string.Empty : p.Firstname,
lastName = p.Lastname == null ? string.Empty : p.Lastname,
citizenId = p.CitizenId == null ? string.Empty : p.CitizenId,
position = p.positionName == null ? string.Empty : p.positionName,
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
email = p.Email == null ? string.Empty : p.Email,
phone = p.MobilePhone == null ? string.Empty : p.MobilePhone,
keycloak = string.Empty,
isProbation = true,
isLeave = false,
dateRetire = (DateTime?)null,
dateAppoint = r.commandAffectDate,
dateStart = r.commandAffectDate,
govAgeAbsent = 0,
govAgePlus = 0,
birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth,
reasonSameDate = (DateTime?)null,
ethnicity = p.Race == null ? string.Empty : p.Race,
telephoneNumber = p.Telephone == null ? string.Empty : p.Telephone,
nationality = p.Nationality == null ? string.Empty : p.Nationality,
gender = p.Gender == null ? string.Empty : p.Gender,
relationship = p.Relationship == null ? string.Empty : p.Relationship,
religion = p.Religion == null ? string.Empty : p.Religion,
bloodGroup = string.Empty,
registrationAddress = p.RegistAddress == null ? string.Empty : p.RegistAddress,
registrationProvinceId = (String?)null,
registrationDistrictId = (String?)null,
registrationSubDistrictId = (String?)null,
registrationZipCode = p.RegistZipCode == null ? string.Empty : p.RegistZipCode,
currentAddress = p.CurrentAddress == null ? string.Empty : p.CurrentAddress,
currentProvinceId = (String?)null,
currentDistrictId = (String?)null,
currentSubDistrictId = (String?)null,
currentZipCode = p.CurrentZipCode == null ? string.Empty : p.CurrentZipCode
},
bodyEducations = p.PlacementEducations.Select(e => new
{
profileId = string.Empty,
country = e.Country ?? string.Empty,
degree = e.Degree ?? string.Empty,
duration = e.Duration ?? string.Empty,
durationYear = e.DurationYear ?? null,
field = e.Field ?? string.Empty,
finishDate = e.FinishDate ?? null,
fundName = e.FundName ?? string.Empty,
gpa = e.Gpa ?? string.Empty,
institute = e.Institute ?? string.Empty,
other = e.Other ?? string.Empty,
startDate = e.StartDate ?? null,
endDate = e.EndDate ?? null,
educationLevel = e.EducationLevel?.Name ?? string.Empty,
educationLevelId = e.EducationLevel?.Id.ToString() ?? string.Empty,
positionPath = e.PositionPath?.Name ?? string.Empty,
positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty,
isDate = e.IsDate ?? false,
isEducation = e.IsEducation ?? false,
note = e.Other ?? string.Empty
}).ToList(),
bodyCertificates = p.PlacementCertificates.Select(e => new
{
profileId = string.Empty,
expireDate = e.ExpireDate ?? null,
issueDate = e.IssueDate ?? null,
certificateNo = e.CertificateNo ?? string.Empty,
certificateType = e.CertificateType ?? string.Empty,
issuer = e.Issuer ?? string.Empty
}).ToList(),
bodySalarys = new
{
profileId = string.Empty,
date = r.commandAffectDate,
amount = p.Amount,
positionSalaryAmount = p.PositionSalaryAmount,
mouthSalaryAmount = p.MouthSalaryAmount,
posNo = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "",
position = p.positionName == null ? string.Empty : p.positionName,
positionLine = string.Empty,
positionPathSide = string.Empty,
positionExecutive = string.Empty,
positionType = p.posTypeName == null ? string.Empty : p.posTypeName,
positionLevel = p.posLevelName == null ? string.Empty : p.posLevelName,
refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}",
templateDoc = r.templateDoc
},
bodyPosition = new
{
posmasterId = p.posmasterId,
positionId = p.positionId
}
}).ToList();
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
data = resultData
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.ForEach(profile => profile.PlacementStatus = "DONE");
await _context.SaveChangesAsync();
return Success();
}
catch
{
throw;
}
}
/// <summary>
/// ส่งรายชื่อออกคำสั่ง C-PM-02
@ -2052,6 +2204,159 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success();
}
/// <summary>
/// ออกคำสั่ง C-PM-02 บรรจุและแต่งตั้งผู้ได้รับคัดเลือก (NEW)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("candidate/report/excecute-new")]
public async Task<ActionResult<ResponseObject>> PostReportExecuteCandidateNew([FromBody] ReportExecuteRequest req)
{
try
{
var placementProfile = await _context.PlacementProfiles
.Include(x => x.PlacementCertificates)
.Include(x => x.PlacementEducations)
.ThenInclude(x => x.EducationLevel)
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync();
if (placementProfile == null)
return NotFound();
var resultData = (from p in placementProfile
join r in req.refIds
on p.Id.ToString() equals r.refId
select new
{
bodyProfile = new
{
rank = string.Empty,
prefix = p.Prefix == null ? string.Empty : p.Prefix,
firstName = p.Firstname == null ? string.Empty : p.Firstname,
lastName = p.Lastname == null ? string.Empty : p.Lastname,
citizenId = p.CitizenId == null ? string.Empty : p.CitizenId,
position = p.positionName == null ? string.Empty : p.positionName,
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
email = p.Email == null ? string.Empty : p.Email,
phone = p.MobilePhone == null ? string.Empty : p.MobilePhone,
keycloak = string.Empty,
isProbation = true,
isLeave = false,
dateRetire = (DateTime?)null,
dateAppoint = r.commandAffectDate,
dateStart = r.commandAffectDate,
govAgeAbsent = 0,
govAgePlus = 0,
birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth,
reasonSameDate = (DateTime?)null,
ethnicity = p.Race == null ? string.Empty : p.Race,
telephoneNumber = p.Telephone == null ? string.Empty : p.Telephone,
nationality = p.Nationality == null ? string.Empty : p.Nationality,
gender = p.Gender == null ? string.Empty : p.Gender,
relationship = p.Relationship == null ? string.Empty : p.Relationship,
religion = p.Religion == null ? string.Empty : p.Religion,
bloodGroup = string.Empty,
registrationAddress = p.RegistAddress == null ? string.Empty : p.RegistAddress,
registrationProvinceId = (String?)null,
registrationDistrictId = (String?)null,
registrationSubDistrictId = (String?)null,
registrationZipCode = p.RegistZipCode == null ? string.Empty : p.RegistZipCode,
currentAddress = p.CurrentAddress == null ? string.Empty : p.CurrentAddress,
currentProvinceId = (String?)null,
currentDistrictId = (String?)null,
currentSubDistrictId = (String?)null,
currentZipCode = p.CurrentZipCode == null ? string.Empty : p.CurrentZipCode
},
bodyEducations = p.PlacementEducations.Select(e => new
{
profileId = string.Empty,
country = e.Country ?? string.Empty,
degree = e.Degree ?? string.Empty,
duration = e.Duration ?? string.Empty,
durationYear = e.DurationYear ?? null,
field = e.Field ?? string.Empty,
finishDate = e.FinishDate ?? null,
fundName = e.FundName ?? string.Empty,
gpa = e.Gpa ?? string.Empty,
institute = e.Institute ?? string.Empty,
other = e.Other ?? string.Empty,
startDate = e.StartDate ?? null,
endDate = e.EndDate ?? null,
educationLevel = e.EducationLevel?.Name ?? string.Empty,
educationLevelId = e.EducationLevel?.Id.ToString() ?? string.Empty,
positionPath = e.PositionPath?.Name ?? string.Empty,
positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty,
isDate = e.IsDate ?? false,
isEducation = e.IsEducation ?? false,
note = e.Other ?? string.Empty
}).ToList(),
bodyCertificates = p.PlacementCertificates.Select(e => new
{
profileId = string.Empty,
expireDate = e.ExpireDate ?? null,
issueDate = e.IssueDate ?? null,
certificateNo = e.CertificateNo ?? string.Empty,
certificateType = e.CertificateType ?? string.Empty,
issuer = e.Issuer ?? string.Empty
}).ToList(),
bodySalarys = new
{
profileId = string.Empty,
date = r.commandAffectDate,
amount = p.Amount,
positionSalaryAmount = p.PositionSalaryAmount,
mouthSalaryAmount = p.MouthSalaryAmount,
posNo = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "",
position = p.positionName == null ? string.Empty : p.positionName,
positionLine = string.Empty,
positionPathSide = string.Empty,
positionExecutive = string.Empty,
positionType = p.posTypeName == null ? string.Empty : p.posTypeName,
positionLevel = p.posLevelName == null ? string.Empty : p.posLevelName,
refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}",
templateDoc = r.templateDoc
},
bodyPosition = new
{
posmasterId = p.posmasterId,
positionId = p.positionId
}
}).ToList();
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
data = resultData
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.ForEach(profile => profile.PlacementStatus = "DONE");
await _context.SaveChangesAsync();
return Success();
}
catch
{
throw;
}
}
/// <summary>
/// ส่งรายชื่อออกคำสั่ง C-PM-03
/// </summary>