Merge branch 'develop' into dev
Some checks failed
Build & Deploy on Dev / build (push) Failing after 27m52s
Some checks failed
Build & Deploy on Dev / build (push) Failing after 27m52s
* develop: test บรรจุ พิการ raw query to EF query #1833 (#2) add noti
This commit is contained in:
commit
43323269d1
7 changed files with 408 additions and 296 deletions
22
.github/workflows/discord-notify.yml
vendored
Normal file
22
.github/workflows/discord-notify.yml
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
name: Discord PR Notify
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
discord:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Send Discord
|
||||||
|
run: |
|
||||||
|
curl -X POST "${{ secrets.DISCORD_WEBHOOK_PULLREQUEST }}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"embeds": [{
|
||||||
|
"title": "🔔 **Service:** ${{ github.repository }}",
|
||||||
|
"description": "👤 **Author:** ${{ github.event.pull_request.user.login }}\n🌿 **Branch:** ${{ github.event.pull_request.head.ref }} → ${{ github.event.pull_request.base.ref }}\n📦 **Pull Request:** [#${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})",
|
||||||
|
"color": 5814783,
|
||||||
|
"timestamp": "${{ github.event.pull_request.created_at }}"
|
||||||
|
}]
|
||||||
|
}'
|
||||||
|
|
@ -27,6 +27,7 @@ using System.Text;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using BMA.EHR.Recurit.Exam.Service.Request;
|
||||||
|
|
||||||
namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -2013,108 +2014,92 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
if (periodExam == null)
|
if (periodExam == null)
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
|
||||||
var data = new List<dynamic>();
|
var query = _context.Disables
|
||||||
var p_Id = new MySqlParameter("@id", id);
|
.Include(x => x.PeriodExam)
|
||||||
int total = 0;
|
.Include(x => x.Educations)
|
||||||
|
.Include(x => x.Certificates)
|
||||||
|
.OrderBy(x => x.ExamId)
|
||||||
|
.Where(x => x.PeriodExam != null && x.PeriodExam.Id == id);
|
||||||
|
|
||||||
// ---------------------------
|
var keywordParam = req.keyword?.Trim();
|
||||||
// 1️. ดึงรายละเอียดสอบ (exam_info)
|
if (!string.IsNullOrWhiteSpace(keywordParam))
|
||||||
// ---------------------------
|
|
||||||
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
||||||
{
|
{
|
||||||
cmd.CommandTimeout = 0;
|
query = query.Where(x =>
|
||||||
|
x.ExamId.Contains(keywordParam) ||
|
||||||
var sb = new StringBuilder();
|
x.CitizenId.Contains(keywordParam) ||
|
||||||
sb.Append(@"
|
x.Prefix.Contains(keywordParam) ||
|
||||||
SELECT
|
x.FirstName.Contains(keywordParam) ||
|
||||||
examID, profileID, prefix, fullName, dateofbirth, gender, degree, major, majorgroup,
|
x.LastName.Contains(keywordParam) ||
|
||||||
certificateno, certificateIssueDate, score, result, examAttribute, remark, isspecial,
|
x.HddPosition.Contains(keywordParam) ||
|
||||||
applydate, university, position_name, hddPosition, typeTest, position_level, position_type,
|
x.PositionName.Contains(keywordParam)
|
||||||
exam_name, exam_order, score_year,
|
);
|
||||||
COUNT(*) OVER() AS total_count
|
|
||||||
FROM exam_info
|
|
||||||
WHERE disable_import_id = @id
|
|
||||||
");
|
|
||||||
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
cmd.Parameters.Add(p_Id);
|
|
||||||
|
|
||||||
var keywordParam = req.keyword?.Trim();
|
|
||||||
if (!string.IsNullOrWhiteSpace(keywordParam))
|
|
||||||
{
|
|
||||||
sb.Append(@"
|
|
||||||
AND (
|
|
||||||
examID LIKE @kw
|
|
||||||
OR profileID LIKE @kw
|
|
||||||
OR prefix LIKE @kw
|
|
||||||
OR fullName LIKE @kw
|
|
||||||
OR hddPosition LIKE @kw
|
|
||||||
OR position_name LIKE @kw
|
|
||||||
)
|
|
||||||
");
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@kw", $"%{keywordParam}%"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
// Paging + Sorting
|
|
||||||
// ---------------------------
|
|
||||||
sb.Append(" ORDER BY examID ");
|
|
||||||
sb.Append(" LIMIT @PageSize OFFSET @Offset ");
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@PageSize", req.PageSize));
|
|
||||||
cmd.Parameters.Add(new MySqlParameter("@Offset", (req.Page - 1) * req.PageSize));
|
|
||||||
|
|
||||||
cmd.CommandText = sb.ToString();
|
|
||||||
|
|
||||||
_context.Database.OpenConnection();
|
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
// ดึงข้อมูล + total
|
|
||||||
// ---------------------------
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
if (total == 0)
|
|
||||||
total = Convert.ToInt32(reader["total_count"]);
|
|
||||||
|
|
||||||
data.Add(new
|
|
||||||
{
|
|
||||||
examID = reader["examID"].ToString(),
|
|
||||||
profileID = reader["profileID"].ToString(),
|
|
||||||
prefix = reader["prefix"].ToString(),
|
|
||||||
fullName = reader["fullName"].ToString(),
|
|
||||||
dateOfBirth = reader["dateofbirth"] == DBNull.Value ? "" : Convert.ToDateTime(reader["dateofbirth"]).ToThaiShortDate(),
|
|
||||||
gender = reader["gender"].ToString(),
|
|
||||||
degree = reader["degree"].ToString(),
|
|
||||||
major = reader["major"].ToString(),
|
|
||||||
majorgroup = reader["majorgroup"].ToString(),
|
|
||||||
certificateNo = reader["certificateno"].ToString(),
|
|
||||||
certificateIssueDate = reader["certificateIssueDate"] == DBNull.Value ? "" : Convert.ToDateTime(reader["certificateIssueDate"]).ToThaiShortDate(),
|
|
||||||
ExamScore = reader["score"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["score"]),
|
|
||||||
ExamResult = reader["result"].ToString(),
|
|
||||||
ExamAttribute = reader["examAttribute"].ToString(),
|
|
||||||
Remark = reader["remark"].ToString(),
|
|
||||||
IsSpecial = reader["isspecial"].ToString(),
|
|
||||||
applyDate = reader["applydate"] == DBNull.Value ? "" : Convert.ToDateTime(reader["applydate"]).ToThaiShortDate(),
|
|
||||||
university = reader["university"].ToString(),
|
|
||||||
position_name = reader["position_name"].ToString(),
|
|
||||||
hddPosition = reader["hddPosition"].ToString(),
|
|
||||||
typeTest = reader["typeTest"].ToString(),
|
|
||||||
position_level = reader["position_level"].ToString(),
|
|
||||||
position_type = reader["position_type"].ToString(),
|
|
||||||
exam_name = reader["exam_name"].ToString(),
|
|
||||||
exam_order = reader["exam_order"].ToString(),
|
|
||||||
score_year = Convert.ToInt32(reader["score_year"]).ToThaiYear().ToString()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int total = await query.CountAsync();
|
||||||
|
|
||||||
|
query = query
|
||||||
|
.Skip((req.Page - 1) * req.PageSize)
|
||||||
|
.Take(req.PageSize);
|
||||||
|
|
||||||
|
var data = await query
|
||||||
|
.GroupJoin(
|
||||||
|
_context.DisableScores.Include(x => x.ScoreImport),
|
||||||
|
rc => new { rc.PeriodExam!.Id, rc.ExamId },
|
||||||
|
sc => new { Id = sc.ScoreImport!.PeriodExamId, sc.ExamId },
|
||||||
|
(disable, scores) => new { disable, scores }
|
||||||
|
)
|
||||||
|
.SelectMany(
|
||||||
|
x => x.scores.DefaultIfEmpty(),
|
||||||
|
(x, sr) => new
|
||||||
|
{
|
||||||
|
examID = x.disable.ExamId,
|
||||||
|
profileID = x.disable.CitizenId,
|
||||||
|
prefix = x.disable.Prefix,
|
||||||
|
fullName = $"{x.disable.FirstName} {x.disable.LastName}",
|
||||||
|
dateOfBirth = x.disable.DateOfBirth != null && x.disable.DateOfBirth != DateTime.MinValue
|
||||||
|
? x.disable.DateOfBirth.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
gender = x.disable.Gendor,
|
||||||
|
degree = x.disable.Educations.Any() ? x.disable.Educations.First().Degree : "",
|
||||||
|
major = x.disable.Educations.Any() ? x.disable.Educations.First().Major : "",
|
||||||
|
certificateNo = x.disable.Certificates.Any()
|
||||||
|
? x.disable.Certificates.First().CertificateNo ?? ""
|
||||||
|
: "",
|
||||||
|
certificateIssueDate = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null && x.disable.Certificates.First().IssueDate != DateTime.MinValue
|
||||||
|
? x.disable.Certificates.First().IssueDate.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
examScore = sr == null ? 0.0 : sr.TotalScore,
|
||||||
|
examResult = sr == null ? "" : sr.ExamStatus,
|
||||||
|
examAttribute = x.disable.Certificates.Any() && x.disable.Certificates.First().IssueDate != null
|
||||||
|
? _disableService.CheckValidCertificate(x.disable.Certificates.First().IssueDate, 5)
|
||||||
|
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
|
||||||
|
: "ไม่มีคุณสมบัติ",
|
||||||
|
remark = x.disable.Remark,
|
||||||
|
isSpecial = x.disable.Isspecial == "Y" ? x.disable.Isspecial : "",
|
||||||
|
applyDate = x.disable.ApplyDate != null && x.disable.ApplyDate != DateTime.MinValue
|
||||||
|
? x.disable.ApplyDate.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
university = x.disable.Educations.Any() ? x.disable.Educations.First().University : "",
|
||||||
|
position_name = x.disable.PositionName,
|
||||||
|
hddPosition = x.disable.HddPosition ?? "",
|
||||||
|
typeTest = x.disable.typeTest ?? "",
|
||||||
|
position_level = x.disable.PositionLevel ?? "",
|
||||||
|
position_type = x.disable.PositionType ?? "",
|
||||||
|
exam_name = x.disable.PeriodExam!.Name,
|
||||||
|
exam_order = x.disable.PeriodExam != null && x.disable.PeriodExam.Round != null
|
||||||
|
? x.disable.PeriodExam.Round.ToString()
|
||||||
|
: "",
|
||||||
|
score_year = x.disable.PeriodExam != null && x.disable.PeriodExam.Year != null
|
||||||
|
? (x.disable.PeriodExam.Year > 2500 ? x.disable.PeriodExam.Year : x.disable.PeriodExam.Year + 543).ToString()
|
||||||
|
: "",
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// 3️. ดึงสรุปคะแนน
|
// 3️. ดึงสรุปคะแนน
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
dynamic header = null;
|
dynamic header = null;
|
||||||
int _count = await _context.Disables.Where(x=> x.PeriodExam.Id == id).CountAsync();
|
int _count = await _context.Disables.Where(x => x.PeriodExam.Id == id).CountAsync();
|
||||||
if (data.Count > 0)
|
if (data.Count > 0)
|
||||||
{
|
{
|
||||||
header = await _context.DisableScores
|
header = await _context.DisableScores
|
||||||
|
|
@ -2448,15 +2433,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
/// <response code="200">เมื่อโอนคนสรรหาไปบรรจุสำเร็จ</response>
|
/// <response code="200">เมื่อโอนคนสรรหาไปบรรจุสำเร็จ</response>
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
[HttpGet("placement/{examId:length(36)}")]
|
[HttpPost("placement/{examId:length(36)}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<ResponseObject>> UpdateAsyncDisableToPlacement(Guid examId)
|
public async Task<ActionResult<ResponseObject>> UpdateAsyncDisableToPlacement(Guid examId, [FromBody] RecruitDateRequest req)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _periodExamService.UpdateAsyncDisableToPlacement(examId);
|
await _periodExamService.UpdateAsyncDisableToPlacement(examId, req.AccountStartDate);
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Models
|
||||||
{
|
{
|
||||||
public class EducationLevel : EntityBase
|
public class EducationLevel : EntityBase
|
||||||
{
|
{
|
||||||
[Required, MaxLength(100), Column(Order = 1), Comment("ระดับการศึกษา")]
|
[MaxLength(255), Column(Order = 1), Comment("ระดับการศึกษา")]
|
||||||
public string name { get; set; } = string.Empty;
|
public string? name { get; set; } = null;
|
||||||
|
|
||||||
// [Column(Order = 2), Comment("สถานะการใช้งาน")]
|
// [Column(Order = 2), Comment("สถานะการใช้งาน")]
|
||||||
// public bool IsActive { get; set; } = true;
|
// public bool IsActive { get; set; } = true;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ namespace BMA.EHR.Recurit.Exam.Service.Models
|
||||||
{
|
{
|
||||||
public class SubDistrict : EntityBase
|
public class SubDistrict : EntityBase
|
||||||
{
|
{
|
||||||
[Required, MaxLength(150), Column(Order = 1), Comment("เขต/อำเภอ")]
|
[MaxLength(255), Column(Order = 1), Comment("แขวง")]
|
||||||
public string name { get; set; } = string.Empty;
|
public string? name { get; set; } = null;
|
||||||
|
|
||||||
[Required, MaxLength(10), Column(Order = 2), Comment("รหัสไปรษณีย์")]
|
[MaxLength(10), Column(Order = 2), Comment("รหัสไปรษณีย์")]
|
||||||
public string zipCode { get; set; } = string.Empty;
|
public string? zipCode { get; set; } = null;
|
||||||
|
|
||||||
// [Column(Order = 3), Comment("สถานะการใช้งาน")]
|
// [Column(Order = 3), Comment("สถานะการใช้งาน")]
|
||||||
// public bool IsActive { get; set; } = true;
|
// public bool IsActive { get; set; } = true;
|
||||||
|
|
|
||||||
9
Request/RecruitDateRequest.cs
Normal file
9
Request/RecruitDateRequest.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Recurit.Exam.Service.Request
|
||||||
|
{
|
||||||
|
public class RecruitDateRequest
|
||||||
|
{
|
||||||
|
public DateTime AccountStartDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Request/RecruitPosTypeRequest.cs
Normal file
18
Request/RecruitPosTypeRequest.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Recurit.Exam.Service.Request
|
||||||
|
{
|
||||||
|
public class RecruitPosRequest
|
||||||
|
{
|
||||||
|
public List<RecruitPosLevelRequest> result { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class RecruitPosLevelRequest
|
||||||
|
{
|
||||||
|
public string posLevelName { get; set; }
|
||||||
|
public RecruitPosTypeRequest posTypes { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class RecruitPosTypeRequest
|
||||||
|
{
|
||||||
|
public string posTypeName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2999,213 +2999,291 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||||
await _contextMetadata.SaveChangesAsync();
|
await _contextMetadata.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateAsyncDisableToPlacement(Guid examId)
|
public async Task UpdateAsyncDisableToPlacement(Guid examId, DateTime accountStartDate)
|
||||||
{
|
{
|
||||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
try
|
||||||
.Where(x => x.CheckDisability == true)
|
|
||||||
.FirstOrDefaultAsync(x => x.Id == examId);
|
|
||||||
|
|
||||||
if (periodExam == null)
|
|
||||||
throw new Exception(GlobalMessages.ExamNotFound);
|
|
||||||
|
|
||||||
var _placement = await _contextMetadata.Placements.AsQueryable()
|
|
||||||
.FirstOrDefaultAsync(x => x.PlacementType.Name == "คัดเลือกคนพิการ" && x.RefId == periodExam.Id);
|
|
||||||
if (_placement != null)
|
|
||||||
throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
|
|
||||||
|
|
||||||
var placement = new Placement
|
|
||||||
{
|
{
|
||||||
Name = periodExam.Name,
|
// 🚀 Prepare HTTP client once
|
||||||
RefId = periodExam.Id,
|
var httpClient1 = new HttpClient();
|
||||||
Round = periodExam.Round == null ? "" : periodExam.Round.ToString(),
|
httpClient1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
|
||||||
Year = (int)(periodExam.Year == null ? 0 : periodExam.Year),
|
httpClient1.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||||
Number = await _context.Disables.AsQueryable().Where(x => x.PeriodExam == periodExam).CountAsync(),
|
var apiUrl1 = $"{_configuration["API"]}/org/pos/level";
|
||||||
PlacementType = await _contextMetadata.PlacementTypes.FirstOrDefaultAsync(x => x.Name.Trim().ToUpper().Contains("คัดเลือกคนพิการ")) == null ? await _contextMetadata.PlacementTypes.FirstOrDefaultAsync() : await _contextMetadata.PlacementTypes.FirstOrDefaultAsync(x => x.Name.Trim().ToUpper().Contains("คัดเลือกคนพิการ")),
|
var response1 = await httpClient1.GetStringAsync(apiUrl1);
|
||||||
StartDate = DateTime.Now,
|
var posOptions = JsonConvert.DeserializeObject<RecruitPosRequest>(response1);
|
||||||
EndDate = DateTime.Now.AddYears(2).AddDays(-1),
|
|
||||||
CreatedAt = DateTime.Now,
|
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||||
CreatedUserId = UserId ?? "",
|
.Where(x => x.CheckDisability == true)
|
||||||
CreatedFullName = FullName ?? "",
|
.FirstOrDefaultAsync(x => x.Id == examId);
|
||||||
LastUpdatedAt = DateTime.Now,
|
|
||||||
LastUpdateUserId = UserId ?? "",
|
if (periodExam == null)
|
||||||
LastUpdateFullName = FullName ?? "",
|
throw new Exception(GlobalMessages.ExamNotFound);
|
||||||
};
|
|
||||||
await _contextMetadata.Placements.AddAsync(placement);
|
var _placement = await _contextMetadata.Placements.AsQueryable()
|
||||||
var candidates = await _context.Disables.AsQueryable()
|
.FirstOrDefaultAsync(x => x.PlacementType.Name == "คัดเลือกคนพิการ" && x.RefId == periodExam.Id);
|
||||||
.Include(x => x.Addresses)
|
if (_placement != null)
|
||||||
.Include(x => x.Certificates)
|
throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
|
||||||
.Include(x => x.Educations)
|
|
||||||
.Include(x => x.Occupations)
|
// 🚀 Pre-load all lookup data once
|
||||||
.Where(x => x.PeriodExam == periodExam)
|
var placementTypesCache = await _contextMetadata.PlacementTypes.ToListAsync();
|
||||||
.ToListAsync();
|
var provincesCache = await _contextOrg.province.ToListAsync();
|
||||||
foreach (var candidate in candidates)
|
var districtsCache = await _contextOrg.district.ToListAsync();
|
||||||
{
|
var subDistrictsCache = await _contextOrg.subDistrict.ToListAsync();
|
||||||
var IsOfficer = false;
|
var educationLevelsCache = await _contextOrg.educationLevel.ToListAsync();
|
||||||
dynamic org = null;
|
|
||||||
var apiUrl = $"{_configuration["API"]}/org/profile/citizenid/position/{candidate.CitizenId}";
|
var placement = new Placement
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
Name = periodExam.Name,
|
||||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
RefId = periodExam.Id,
|
||||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
Round = periodExam.Round?.ToString() ?? "",
|
||||||
var _res = await client.SendAsync(_req);
|
Year = (int)(periodExam.Year ?? 0),
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
Number = await _context.Disables.AsQueryable().Where(x => x.PeriodExam == periodExam).CountAsync(),
|
||||||
|
PlacementType = placementTypesCache.FirstOrDefault(x => x.Name.Trim().ToUpper().Contains("คัดเลือกคนพิการ")) ?? placementTypesCache.First(),
|
||||||
|
StartDate = accountStartDate,
|
||||||
|
EndDate = accountStartDate.AddYears(2).AddDays(-1),
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
CreatedUserId = UserId ?? "",
|
||||||
|
CreatedFullName = FullName ?? "",
|
||||||
|
LastUpdatedAt = DateTime.Now,
|
||||||
|
LastUpdateUserId = UserId ?? "",
|
||||||
|
LastUpdateFullName = FullName ?? "",
|
||||||
|
};
|
||||||
|
await _contextMetadata.Placements.AddAsync(placement);
|
||||||
|
|
||||||
org = JsonConvert.DeserializeObject<dynamic>(_result);
|
// 🚀 Load all related data with single queries
|
||||||
|
var candidates = await _context.Disables.AsQueryable()
|
||||||
|
.Include(x => x.Addresses)
|
||||||
|
.Include(x => x.Certificates)
|
||||||
|
.Include(x => x.Educations)
|
||||||
|
.Include(x => x.Occupations)
|
||||||
|
.Where(x => x.PeriodExam == periodExam)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
if (org == null || org.result == null)
|
|
||||||
{
|
|
||||||
IsOfficer = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IsOfficer = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var Address = candidate.Addresses.FirstOrDefault() == null ? null : $"{candidate.Addresses.FirstOrDefault().Address}";
|
|
||||||
var Moo = candidate.Addresses.FirstOrDefault() == null ? null : $" หมู่ {candidate.Addresses.FirstOrDefault().Moo}";
|
|
||||||
var Soi = candidate.Addresses.FirstOrDefault() == null ? null : $" ซอย {candidate.Addresses.FirstOrDefault().Soi}";
|
|
||||||
var Road = candidate.Addresses.FirstOrDefault() == null ? null : $" ถนน {candidate.Addresses.FirstOrDefault().Road}";
|
|
||||||
var Address1 = candidate.Addresses.FirstOrDefault() == null ? null : $"{candidate.Addresses.FirstOrDefault().Address1}";
|
|
||||||
var Moo1 = candidate.Addresses.FirstOrDefault() == null ? null : $" หมู่ {candidate.Addresses.FirstOrDefault().Moo1}";
|
|
||||||
var Soi1 = candidate.Addresses.FirstOrDefault() == null ? null : $" ซอย {candidate.Addresses.FirstOrDefault().Soi1}";
|
|
||||||
var Road1 = candidate.Addresses.FirstOrDefault() == null ? null : $" ถนน {candidate.Addresses.FirstOrDefault().Road1}";
|
|
||||||
var scoreImport = await _context.ScoreImports.AsQueryable()
|
var scoreImport = await _context.ScoreImports.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.PeriodExam == periodExam);
|
.FirstOrDefaultAsync(x => x.PeriodExam == periodExam);
|
||||||
var disableScore = await _context.DisableScores.AsQueryable()
|
|
||||||
.Where(x => x.ScoreImport == scoreImport)
|
var disableScores = await _context.DisableScores.AsQueryable()
|
||||||
.Where(x => x.ExamId == candidate.ExamId)
|
.Where(x => x.ScoreImport == scoreImport && x.ExamStatus == "ผ่าน")
|
||||||
.Where(x => x.ExamStatus == "ผ่าน")
|
.ToListAsync();
|
||||||
.FirstOrDefaultAsync(x => x.ExamId == candidate.ExamId && x.ScoreImport == scoreImport);
|
|
||||||
if (disableScore == null)
|
var disableScoresDict = disableScores
|
||||||
continue;
|
.Where(x => !string.IsNullOrWhiteSpace(x.ExamId))
|
||||||
var placementProfile = new PlacementProfile
|
.ToDictionary(x => x.ExamId, x => x);
|
||||||
|
|
||||||
|
// 🚀 Prepare HTTP client once
|
||||||
|
var httpClient = new HttpClient();
|
||||||
|
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
|
||||||
|
httpClient.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||||
|
|
||||||
|
// 🚀 Batch HTTP requests
|
||||||
|
var orgTasks = candidates.Select(async candidate =>
|
||||||
{
|
{
|
||||||
Placement = placement,
|
if (string.IsNullOrWhiteSpace(candidate.CitizenId))
|
||||||
PositionCandidate = candidate.PositionName,
|
return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null };
|
||||||
PositionType = candidate.PositionType,
|
|
||||||
PositionLevel = candidate.PositionLevel,
|
|
||||||
Prefix = candidate.Prefix,
|
|
||||||
Firstname = candidate.FirstName,
|
|
||||||
Lastname = candidate.LastName,
|
|
||||||
Gender = candidate.Gendor,
|
|
||||||
Nationality = candidate.National,
|
|
||||||
Race = candidate.Race,
|
|
||||||
Religion = candidate.Religion,
|
|
||||||
DateOfBirth = candidate.DateOfBirth,
|
|
||||||
Relationship = candidate.Marry,
|
|
||||||
CitizenId = candidate.CitizenId,
|
|
||||||
CitizenProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == candidate.CitizenCardIssuer)?.Id ?? null,
|
|
||||||
CitizenDate = candidate.CitizenCardExpireDate,
|
|
||||||
Telephone = candidate?.Addresses?.FirstOrDefault()?.Telephone ?? null,
|
|
||||||
MobilePhone = candidate?.Addresses?.FirstOrDefault()?.Mobile ?? null,
|
|
||||||
RegistAddress = $"{Address}{Moo}{Soi}{Road}",
|
|
||||||
RegistProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Province ?? ""))?.Id ?? null,
|
|
||||||
RegistDistrictId = _contextOrg.district.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.District ?? ""))?.Id ?? null,
|
|
||||||
RegistSubDistrictId = _contextOrg.subDistrict.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Soi ?? ""))?.Id ?? null,
|
|
||||||
RegistZipCode = candidate?.Addresses?.FirstOrDefault()?.ZipCode ?? null,
|
|
||||||
RegistSame = false,
|
|
||||||
CurrentAddress = $"{Address1}{Moo1}{Soi1}{Road1}",
|
|
||||||
CurrentProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Province1 ?? ""))?.Id ?? null,
|
|
||||||
CurrentDistrictId = _contextOrg.district.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.District1 ?? ""))?.Id ?? null,
|
|
||||||
CurrentSubDistrictId = _contextOrg.subDistrict.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Soi1 ?? ""))?.Id ?? null,
|
|
||||||
CurrentZipCode = candidate?.Addresses?.FirstOrDefault()?.ZipCode1 ?? null,
|
|
||||||
Marry = candidate?.Marry?.Contains("สมรส") ?? false,
|
|
||||||
|
|
||||||
OccupationPositionType = "other",
|
var apiUrl = $"{_configuration["API"]}/org/profile/citizenid/position/{candidate.CitizenId}";
|
||||||
OccupationTelephone = candidate?.Occupations?.FirstOrDefault()?.Telephone ?? null,
|
try
|
||||||
OccupationPosition = candidate?.Occupations?.FirstOrDefault()?.Position ?? null,
|
{
|
||||||
|
var response = await httpClient.GetStringAsync(apiUrl);
|
||||||
|
return new { CitizenId = candidate.CitizenId, org = JsonConvert.DeserializeObject<dynamic>(response) };
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null };
|
||||||
|
}
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
PointTotalA = disableScore == null ? null : Convert.ToDouble(disableScore.FullA),
|
var orgResults = await Task.WhenAll(orgTasks);
|
||||||
PointA = disableScore == null ? null : Convert.ToDouble(disableScore.SumA),
|
var orgDict = orgResults.ToDictionary(x => x.CitizenId ?? "", x => x.org);
|
||||||
PointTotalB = disableScore == null ? null : Convert.ToDouble(disableScore.FullB),
|
|
||||||
PointB = disableScore == null ? null : Convert.ToDouble(disableScore.SumB),
|
|
||||||
PointTotalC = disableScore == null ? null : Convert.ToDouble(disableScore.FullC),
|
|
||||||
PointC = disableScore == null ? null : Convert.ToDouble(disableScore.SumC),
|
|
||||||
ExamNumber = disableScore == null || int.TryParse(disableScore.Number, out int n) == false ? null : Convert.ToInt32(disableScore.Number),
|
|
||||||
ExamRound = null,
|
|
||||||
IsRelief = false,
|
|
||||||
PlacementStatus = "UN-CONTAIN",
|
|
||||||
Pass = disableScore == null ? null : disableScore.ExamStatus,
|
|
||||||
RemarkHorizontal = "โดยมีเงื่อนไขว่าต้องปฏิบัติงานให้กรุงเทพมหานครเป็นระยะเวลาไม่น้อยกว่า ๕ ปี นับแต่วันที่ได้รับการบรรจุและแต่งตั้ง โดยห้ามโอนไปหน่วยงานหรือส่วนราชการอื่น เว้นเเต่ลาออกจากราชการ",
|
|
||||||
Amount = org?.result?.amount ?? null,
|
|
||||||
PositionSalaryAmount = org?.result?.positionSalaryAmount ?? null,
|
|
||||||
MouthSalaryAmount = org?.result?.mouthSalaryAmount ?? null,
|
|
||||||
CreatedAt = DateTime.Now,
|
|
||||||
CreatedUserId = UserId ?? "",
|
|
||||||
CreatedFullName = FullName ?? "",
|
|
||||||
LastUpdatedAt = DateTime.Now,
|
|
||||||
LastUpdateUserId = UserId ?? "",
|
|
||||||
LastUpdateFullName = FullName ?? "",
|
|
||||||
IsOfficer = IsOfficer,
|
|
||||||
profileId = org?.result?.profileId ?? null,
|
|
||||||
IsOld = org == null || org.result == null ? false : true,
|
|
||||||
AmountOld = org?.result?.AmountOld ?? null,
|
|
||||||
nodeOld = org?.result?.node ?? null,
|
|
||||||
nodeIdOld = org?.result?.nodeId ?? null,
|
|
||||||
posmasterIdOld = org?.result?.posmasterId ?? null,
|
|
||||||
rootOld = org?.result?.root ?? null,
|
|
||||||
rootIdOld = org?.result?.rootId ?? null,
|
|
||||||
rootShortNameOld = org?.result?.rootShortName ?? null,
|
|
||||||
child1Old = org?.result?.child1 ?? null,
|
|
||||||
child1IdOld = org?.result?.child1Id ?? null,
|
|
||||||
child1ShortNameOld = org?.result?.child1ShortName ?? null,
|
|
||||||
child2Old = org?.result?.child2 ?? null,
|
|
||||||
child2IdOld = org?.result?.child2Id ?? null,
|
|
||||||
child2ShortNameOld = org?.result?.child2ShortName ?? null,
|
|
||||||
child3Old = org?.result?.child3 ?? null,
|
|
||||||
child3IdOld = org?.result?.child3Id ?? null,
|
|
||||||
child3ShortNameOld = org?.result?.child3ShortName ?? null,
|
|
||||||
child4Old = org?.result?.child4 ?? null,
|
|
||||||
child4IdOld = org?.result?.child4Id ?? null,
|
|
||||||
child4ShortNameOld = org?.result?.child4ShortName ?? null,
|
|
||||||
orgRevisionIdOld = org?.result?.orgRevisionId ?? null,
|
|
||||||
posMasterNoOld = org?.result?.posMasterNo ?? null,
|
|
||||||
positionNameOld = org?.result?.position ?? null,
|
|
||||||
posTypeIdOld = org?.result?.posTypeId ?? null,
|
|
||||||
posTypeNameOld = org?.result?.posTypeName ?? null,
|
|
||||||
posLevelIdOld = org?.result?.posLevelId ?? null,
|
|
||||||
posLevelNameOld = org?.result?.posLevelName ?? null,
|
|
||||||
};
|
|
||||||
await _contextMetadata.PlacementProfiles.AddAsync(placementProfile);
|
|
||||||
|
|
||||||
var placementEducation = new PlacementEducation
|
// 🚀 Prepare batch inserts
|
||||||
|
var placementProfiles = new List<PlacementProfile>();
|
||||||
|
var placementEducations = new List<PlacementEducation>();
|
||||||
|
var placementCertificates = new List<PlacementCertificate>();
|
||||||
|
|
||||||
|
foreach (var candidate in candidates)
|
||||||
{
|
{
|
||||||
PlacementProfile = placementProfile,
|
if (string.IsNullOrWhiteSpace(candidate.ExamId) ||
|
||||||
EducationLevelId = _contextOrg.educationLevel.FirstOrDefault(x => x.name == (candidate!.Educations!.FirstOrDefault()!.HighDegree ?? ""))?.Id ?? null,
|
!disableScoresDict.TryGetValue(candidate.ExamId, out var disableScore))
|
||||||
EducationLevelName = _contextOrg.educationLevel.FirstOrDefault(x => x.name == (candidate!.Educations!.FirstOrDefault()!.HighDegree ?? ""))?.name ?? null,
|
continue;
|
||||||
Field = candidate?.Educations?.FirstOrDefault()?.Major ?? null,
|
|
||||||
Gpa = candidate?.Educations?.FirstOrDefault()?.GPA!.ToString() ?? null,
|
|
||||||
Institute = candidate?.Educations?.FirstOrDefault()?.University ?? null,
|
|
||||||
Degree = candidate?.Educations?.FirstOrDefault()?.Degree ?? null,
|
|
||||||
FinishDate = candidate?.Educations?.FirstOrDefault()?.BachelorDate ?? null,
|
|
||||||
IsDate = true,
|
|
||||||
CreatedAt = DateTime.Now,
|
|
||||||
CreatedUserId = UserId ?? "",
|
|
||||||
LastUpdatedAt = DateTime.Now,
|
|
||||||
LastUpdateUserId = UserId ?? "",
|
|
||||||
CreatedFullName = FullName ?? "",
|
|
||||||
LastUpdateFullName = FullName ?? "",
|
|
||||||
};
|
|
||||||
await _contextMetadata.PlacementEducations.AddAsync(placementEducation);
|
|
||||||
|
|
||||||
var placementCertificate = new PlacementCertificate
|
var org = orgDict.TryGetValue(candidate.CitizenId ?? "", out var orgValue) ? orgValue : null;
|
||||||
{
|
var isOfficer = org?.result != null;
|
||||||
PlacementProfile = placementProfile,
|
|
||||||
CertificateNo = candidate?.Certificates?.FirstOrDefault()?.CertificateNo ?? null,
|
// 🚀 Cache repeated calculations
|
||||||
IssueDate = candidate?.Certificates?.FirstOrDefault()?.IssueDate ?? null,
|
var firstAddress = candidate.Addresses?.FirstOrDefault();
|
||||||
ExpireDate = candidate?.Certificates?.FirstOrDefault()?.ExpiredDate ?? null,
|
var firstEducation = candidate.Educations?.FirstOrDefault();
|
||||||
CertificateType = candidate?.Certificates?.FirstOrDefault()?.Description ?? null,
|
var firstCertificate = candidate.Certificates?.FirstOrDefault();
|
||||||
CreatedAt = DateTime.Now,
|
var firstOccupation = candidate.Occupations?.FirstOrDefault();
|
||||||
CreatedUserId = UserId ?? "",
|
|
||||||
LastUpdatedAt = DateTime.Now,
|
var registAddress = string.Join("", new[] {
|
||||||
LastUpdateUserId = UserId ?? "",
|
firstAddress?.Address ?? "",
|
||||||
CreatedFullName = FullName ?? "",
|
string.IsNullOrWhiteSpace(firstAddress?.Moo) ? "" : $" หมู่ {firstAddress.Moo}",
|
||||||
LastUpdateFullName = FullName ?? "",
|
string.IsNullOrWhiteSpace(firstAddress?.Soi) ? "" : $" ซอย {firstAddress.Soi}",
|
||||||
};
|
string.IsNullOrWhiteSpace(firstAddress?.Road) ? "" : $" ถนน {firstAddress.Road}"
|
||||||
await _contextMetadata.PlacementCertificates.AddAsync(placementCertificate);
|
});
|
||||||
|
|
||||||
|
var currentAddress = string.Join("", new[] {
|
||||||
|
firstAddress?.Address1 ?? "",
|
||||||
|
string.IsNullOrWhiteSpace(firstAddress?.Moo1) ? "" : $" หมู่ {firstAddress.Moo1}",
|
||||||
|
string.IsNullOrWhiteSpace(firstAddress?.Soi1) ? "" : $" ซอย {firstAddress.Soi1}",
|
||||||
|
string.IsNullOrWhiteSpace(firstAddress?.Road1) ? "" : $" ถนน {firstAddress.Road1}"
|
||||||
|
});
|
||||||
|
|
||||||
|
// หาค่า posLevelName หลังสุด
|
||||||
|
var posLevelObject = posOptions?.result?.FirstOrDefault(x =>
|
||||||
|
!string.IsNullOrWhiteSpace(x.posLevelName) &&
|
||||||
|
!string.IsNullOrWhiteSpace(candidate.PositionName) &&
|
||||||
|
candidate.PositionName.Contains(x.posLevelName));
|
||||||
|
|
||||||
|
// เก็บเฉพาะค่า posLevelName
|
||||||
|
var posLevelName = posLevelObject?.posLevelName;
|
||||||
|
|
||||||
|
// สร้างตัวแปร PositionName ที่ตัดค่า posLevelName ออก
|
||||||
|
var positionNameWithoutLevel = candidate.PositionName ?? "";
|
||||||
|
if (!string.IsNullOrWhiteSpace(posLevelName))
|
||||||
|
{
|
||||||
|
positionNameWithoutLevel = positionNameWithoutLevel.Replace(posLevelName, "").Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
var placementProfile = new PlacementProfile
|
||||||
|
{
|
||||||
|
Placement = placement,
|
||||||
|
PositionCandidate = positionNameWithoutLevel ?? "",
|
||||||
|
PositionType = posLevelObject?.posTypes?.posTypeName ?? "",
|
||||||
|
PositionLevel = posLevelName ?? "",
|
||||||
|
Prefix = candidate.Prefix ?? "",
|
||||||
|
Firstname = candidate.FirstName ?? "",
|
||||||
|
Lastname = candidate.LastName ?? "",
|
||||||
|
Gender = candidate.Gendor ?? "",
|
||||||
|
Nationality = candidate.National ?? "",
|
||||||
|
Race = candidate.Race ?? "",
|
||||||
|
Religion = candidate.Religion ?? "",
|
||||||
|
DateOfBirth = candidate.DateOfBirth,
|
||||||
|
Relationship = candidate.Marry ?? "",
|
||||||
|
CitizenId = candidate.CitizenId ?? "",
|
||||||
|
CitizenProvinceId = provincesCache.FirstOrDefault(x => x.name == candidate.CitizenCardIssuer)?.Id,
|
||||||
|
CitizenDate = candidate.CitizenCardExpireDate,
|
||||||
|
Telephone = firstAddress?.Telephone ?? "",
|
||||||
|
MobilePhone = firstAddress?.Mobile ?? "",
|
||||||
|
RegistAddress = registAddress,
|
||||||
|
RegistProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province)?.Id,
|
||||||
|
RegistDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.District)?.Id,
|
||||||
|
RegistSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.Soi)?.Id,
|
||||||
|
RegistZipCode = firstAddress?.ZipCode ?? "",
|
||||||
|
RegistSame = false,
|
||||||
|
CurrentAddress = currentAddress,
|
||||||
|
CurrentProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province1)?.Id,
|
||||||
|
CurrentDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.District1)?.Id,
|
||||||
|
CurrentSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.Soi1)?.Id,
|
||||||
|
CurrentZipCode = firstAddress?.ZipCode1,
|
||||||
|
Marry = candidate.Marry?.Contains("สมรส") ?? false,
|
||||||
|
OccupationPositionType = "other",
|
||||||
|
OccupationTelephone = firstOccupation?.Telephone ?? "",
|
||||||
|
OccupationPosition = firstOccupation?.Position ?? "",
|
||||||
|
PointTotalA = Convert.ToDouble(disableScore.FullA),
|
||||||
|
PointA = Convert.ToDouble(disableScore.SumA),
|
||||||
|
PointTotalB = Convert.ToDouble(disableScore.FullB),
|
||||||
|
PointB = Convert.ToDouble(disableScore.SumB),
|
||||||
|
PointTotalC = Convert.ToDouble(disableScore.FullC),
|
||||||
|
PointC = Convert.ToDouble(disableScore.SumC),
|
||||||
|
ExamNumber = !string.IsNullOrWhiteSpace(disableScore.Number) && int.TryParse(disableScore.Number, out int n) ? n : null,
|
||||||
|
ExamRound = null,
|
||||||
|
IsRelief = false,
|
||||||
|
PlacementStatus = "UN-CONTAIN",
|
||||||
|
Pass = disableScore.ExamStatus ?? "",
|
||||||
|
RemarkHorizontal = "โดยมีเงื่อนไขว่าต้องปฏิบัติงานให้กรุงเทพมหานครเป็นระยะเวลาไม่น้อยกว่า ๕ ปี นับแต่วันที่ได้รับการบรรจุและแต่งตั้ง โดยห้ามโอนไปหน่วยงานหรือส่วนราชการอื่น เว้นเเต่ลาออกจากราชการ",
|
||||||
|
Amount = org?.result?.amount,
|
||||||
|
PositionSalaryAmount = org?.result?.positionSalaryAmount,
|
||||||
|
MouthSalaryAmount = org?.result?.mouthSalaryAmount,
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
CreatedUserId = UserId ?? "",
|
||||||
|
CreatedFullName = FullName ?? "",
|
||||||
|
LastUpdatedAt = DateTime.Now,
|
||||||
|
LastUpdateUserId = UserId ?? "",
|
||||||
|
LastUpdateFullName = FullName ?? "",
|
||||||
|
IsOfficer = isOfficer,
|
||||||
|
profileId = org?.result?.profileId ?? "",
|
||||||
|
IsOld = org?.result != null,
|
||||||
|
AmountOld = org?.result?.AmountOld,
|
||||||
|
nodeOld = org?.result?.node ?? "",
|
||||||
|
nodeIdOld = org?.result?.nodeId ?? "",
|
||||||
|
posmasterIdOld = org?.result?.posmasterId ?? "",
|
||||||
|
rootOld = org?.result?.root ?? "",
|
||||||
|
rootIdOld = org?.result?.rootId ?? "",
|
||||||
|
rootShortNameOld = org?.result?.rootShortName ?? "",
|
||||||
|
child1Old = org?.result?.child1 ?? "",
|
||||||
|
child1IdOld = org?.result?.child1Id ?? "",
|
||||||
|
child1ShortNameOld = org?.result?.child1ShortName ?? "",
|
||||||
|
child2Old = org?.result?.child2 ?? "",
|
||||||
|
child2IdOld = org?.result?.child2Id ?? "",
|
||||||
|
child2ShortNameOld = org?.result?.child2ShortName ?? "",
|
||||||
|
child3Old = org?.result?.child3 ?? "",
|
||||||
|
child3IdOld = org?.result?.child3Id ?? "",
|
||||||
|
child3ShortNameOld = org?.result?.child3ShortName ?? "",
|
||||||
|
child4Old = org?.result?.child4 ?? "",
|
||||||
|
child4IdOld = org?.result?.child4Id ?? "",
|
||||||
|
child4ShortNameOld = org?.result?.child4ShortName ?? "",
|
||||||
|
orgRevisionIdOld = org?.result?.orgRevisionId ?? "",
|
||||||
|
posMasterNoOld = org?.result?.posMasterNo,
|
||||||
|
positionNameOld = org?.result?.position ?? "",
|
||||||
|
posTypeIdOld = org?.result?.posTypeId ?? "",
|
||||||
|
posTypeNameOld = org?.result?.posTypeName ?? "",
|
||||||
|
posLevelIdOld = org?.result?.posLevelId ?? "",
|
||||||
|
posLevelNameOld = org?.result?.posLevelName ?? "",
|
||||||
|
};
|
||||||
|
placementProfiles.Add(placementProfile);
|
||||||
|
|
||||||
|
var placementEducation = new PlacementEducation
|
||||||
|
{
|
||||||
|
PlacementProfile = placementProfile,
|
||||||
|
EducationLevelId = educationLevelsCache.FirstOrDefault(x => x.name == firstEducation?.HighDegree)?.Id,
|
||||||
|
EducationLevelName = educationLevelsCache.FirstOrDefault(x => x.name == firstEducation?.HighDegree)?.name,
|
||||||
|
Field = firstEducation?.Major ?? "",
|
||||||
|
Gpa = firstEducation?.GPA.ToString() ?? "",
|
||||||
|
Institute = firstEducation?.University ?? "",
|
||||||
|
Degree = firstEducation?.Degree ?? "",
|
||||||
|
FinishDate = firstEducation?.BachelorDate,
|
||||||
|
IsDate = true,
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
CreatedUserId = UserId ?? "",
|
||||||
|
LastUpdatedAt = DateTime.Now,
|
||||||
|
LastUpdateUserId = UserId ?? "",
|
||||||
|
CreatedFullName = FullName ?? "",
|
||||||
|
LastUpdateFullName = FullName ?? "",
|
||||||
|
};
|
||||||
|
placementEducations.Add(placementEducation);
|
||||||
|
|
||||||
|
var placementCertificate = new PlacementCertificate
|
||||||
|
{
|
||||||
|
PlacementProfile = placementProfile,
|
||||||
|
CertificateNo = firstCertificate?.CertificateNo ?? "",
|
||||||
|
IssueDate = firstCertificate?.IssueDate,
|
||||||
|
ExpireDate = firstCertificate?.ExpiredDate,
|
||||||
|
CertificateType = firstCertificate?.Description ?? "",
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
CreatedUserId = UserId ?? "",
|
||||||
|
LastUpdatedAt = DateTime.Now,
|
||||||
|
LastUpdateUserId = UserId ?? "",
|
||||||
|
CreatedFullName = FullName ?? "",
|
||||||
|
LastUpdateFullName = FullName ?? "",
|
||||||
|
};
|
||||||
|
placementCertificates.Add(placementCertificate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🚀 Batch insert all records
|
||||||
|
await _contextMetadata.PlacementProfiles.AddRangeAsync(placementProfiles);
|
||||||
|
await _contextMetadata.PlacementEducations.AddRangeAsync(placementEducations);
|
||||||
|
await _contextMetadata.PlacementCertificates.AddRangeAsync(placementCertificates);
|
||||||
|
|
||||||
|
// 🚀 Single SaveChanges at the end
|
||||||
|
await _contextMetadata.SaveChangesAsync();
|
||||||
|
|
||||||
|
httpClient.Dispose();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
await _contextMetadata.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue