Merge branch 'develop' into dev
Some checks failed
Build & Deploy on Dev / build (push) Failing after 34m11s
Some checks failed
Build & Deploy on Dev / build (push) Failing after 34m11s
* develop: open noti เช็คซ้ำ แก้บัค สรรหา test test test test test test test test test test test test comment แก้ total raw query to EF query #1833
This commit is contained in:
commit
5a376c1d63
8 changed files with 430 additions and 330 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 }}"
|
||||||
|
}]
|
||||||
|
}'
|
||||||
194
.github/workflows/release.yaml
vendored
194
.github/workflows/release.yaml
vendored
|
|
@ -1,106 +1,106 @@
|
||||||
name: release
|
name: release
|
||||||
run-name: release ${{ github.actor }}
|
run-name: release ${{ github.actor }}
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "version-[0-9]+.[0-9]+.[0-9]+"
|
- "version-[0-9]+.[0-9]+.[0-9]+"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
env:
|
env:
|
||||||
REGISTRY: docker.frappet.com
|
REGISTRY: docker.frappet.com
|
||||||
IMAGE_NAME: ehr/bma-ehr-recruit-service
|
IMAGE_NAME: ehr/bma-ehr-recruit-service
|
||||||
DEPLOY_HOST: frappet.com
|
DEPLOY_HOST: frappet.com
|
||||||
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-recruit
|
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-recruit
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
|
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
# skip Set up QEMU because it fail on act and container
|
# skip Set up QEMU because it fail on act and container
|
||||||
# Gen Version try to get version from tag or inut
|
# Gen Version try to get version from tag or inut
|
||||||
- name: Set output tags
|
- name: Set output tags
|
||||||
id: vars
|
id: vars
|
||||||
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
||||||
- name: Gen Version
|
- name: Gen Version
|
||||||
id: gen_ver
|
id: gen_ver
|
||||||
run: |
|
run: |
|
||||||
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
|
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
|
||||||
IMAGE_VER=${{ steps.vars.outputs.tag }}
|
IMAGE_VER=${{ steps.vars.outputs.tag }}
|
||||||
else
|
else
|
||||||
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
|
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
|
||||||
fi
|
fi
|
||||||
if [[ $IMAGE_VER == '' ]]; then
|
if [[ $IMAGE_VER == '' ]]; then
|
||||||
IMAGE_VER='test-vBeta'
|
IMAGE_VER='test-vBeta'
|
||||||
fi
|
fi
|
||||||
echo '::set-output name=image_ver::'$IMAGE_VER
|
echo '::set-output name=image_ver::'$IMAGE_VER
|
||||||
- name: Check Version
|
- name: Check Version
|
||||||
run: |
|
run: |
|
||||||
echo $GITHUB_REF
|
echo $GITHUB_REF
|
||||||
echo ${{ steps.gen_ver.outputs.image_ver }}
|
echo ${{ steps.gen_ver.outputs.image_ver }}
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
- name: Login in to registry
|
- name: Login in to registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ${{env.REGISTRY}}
|
registry: ${{env.REGISTRY}}
|
||||||
username: ${{secrets.DOCKER_USER}}
|
username: ${{secrets.DOCKER_USER}}
|
||||||
password: ${{secrets.DOCKER_PASS}}
|
password: ${{secrets.DOCKER_PASS}}
|
||||||
- name: Build and push docker image
|
- name: Build and push docker image
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
|
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
|
||||||
|
|
||||||
- name: Reload docker compose
|
- name: Reload docker compose
|
||||||
uses: appleboy/ssh-action@v0.1.8
|
uses: appleboy/ssh-action@v0.1.8
|
||||||
with:
|
with:
|
||||||
host: ${{env.DEPLOY_HOST}}
|
host: ${{env.DEPLOY_HOST}}
|
||||||
username: frappet
|
username: frappet
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
port: 10102
|
port: 10102
|
||||||
script: |
|
script: |
|
||||||
cd "${{env.COMPOSE_PATH}}"
|
cd "${{env.COMPOSE_PATH}}"
|
||||||
docker compose pull
|
docker compose pull
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
||||||
- name: Notify Discord Success
|
- name: Notify Discord Success
|
||||||
if: success()
|
if: success()
|
||||||
run: |
|
run: |
|
||||||
curl -H "Content-Type: application/json" \
|
curl -H "Content-Type: application/json" \
|
||||||
-X POST \
|
-X POST \
|
||||||
-d '{
|
-d '{
|
||||||
"embeds": [{
|
"embeds": [{
|
||||||
"title": "✅ Deployment Success!",
|
"title": "✅ Deployment Success!",
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
||||||
"color": 3066993,
|
"color": 3066993,
|
||||||
"footer": {
|
"footer": {
|
||||||
"text": "Release Notification",
|
"text": "Release Notification",
|
||||||
"icon_url": "https://example.com/success-icon.png"
|
"icon_url": "https://example.com/success-icon.png"
|
||||||
},
|
},
|
||||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
}]
|
}]
|
||||||
}' \
|
}' \
|
||||||
${{ secrets.DISCORD_WEBHOOK }}
|
${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
||||||
- name: Notify Discord Failure
|
- name: Notify Discord Failure
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
curl -H "Content-Type: application/json" \
|
curl -H "Content-Type: application/json" \
|
||||||
-X POST \
|
-X POST \
|
||||||
-d '{
|
-d '{
|
||||||
"embeds": [{
|
"embeds": [{
|
||||||
"title": "❌ Deployment Failed!",
|
"title": "❌ Deployment Failed!",
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
||||||
"color": 15158332,
|
"color": 15158332,
|
||||||
"footer": {
|
"footer": {
|
||||||
"text": "Release Notification",
|
"text": "Release Notification",
|
||||||
"icon_url": "https://example.com/failure-icon.png"
|
"icon_url": "https://example.com/failure-icon.png"
|
||||||
},
|
},
|
||||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
}]
|
}]
|
||||||
}' \
|
}' \
|
||||||
${{ secrets.DISCORD_WEBHOOK }}
|
${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
|
||||||
|
|
@ -1959,103 +1959,87 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var data = new List<dynamic>();
|
var query = _context.Recruits
|
||||||
var p_Id = new MySqlParameter("@id", id);
|
.Include(x => x.RecruitImport)
|
||||||
int total = 0;
|
.Include(x => x.Educations)
|
||||||
|
.Include(x => x.Certificates)
|
||||||
|
.OrderBy(x => x.ExamId)
|
||||||
|
.Where(x => x.RecruitImport != null && x.RecruitImport.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 recruit_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.RecruitScores.Include(x => x.ScoreImport),
|
||||||
|
rc => new { rc.RecruitImport!.Id, rc.ExamId },
|
||||||
|
sc => new { Id = sc.ScoreImport!.RecruitImportId, sc.ExamId },
|
||||||
|
(recruit, scores) => new { recruit, scores }
|
||||||
|
)
|
||||||
|
.SelectMany(
|
||||||
|
x => x.scores.DefaultIfEmpty(),
|
||||||
|
(x, sr) => new
|
||||||
|
{
|
||||||
|
examID = x.recruit.ExamId,
|
||||||
|
profileID = x.recruit.CitizenId,
|
||||||
|
prefix = x.recruit.Prefix,
|
||||||
|
fullName = $"{x.recruit.FirstName} {x.recruit.LastName}",
|
||||||
|
dateOfBirth = x.recruit.DateOfBirth != null && x.recruit.DateOfBirth != DateTime.MinValue
|
||||||
|
? x.recruit.DateOfBirth.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
gender = x.recruit.Gendor,
|
||||||
|
degree = x.recruit.Educations.Any() ? x.recruit.Educations.First().Degree : "",
|
||||||
|
major = x.recruit.Educations.Any() ? x.recruit.Educations.First().Major : "",
|
||||||
|
certificateNo = x.recruit.Certificates.Any()
|
||||||
|
? x.recruit.Certificates.First().CertificateNo ?? ""
|
||||||
|
: "",
|
||||||
|
certificateIssueDate = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null && x.recruit.Certificates.First().IssueDate != DateTime.MinValue
|
||||||
|
? x.recruit.Certificates.First().IssueDate.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
examScore = sr == null ? 0.0 : sr.TotalScore,
|
||||||
|
examResult = sr == null ? "" : sr.ExamStatus,
|
||||||
|
examAttribute = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null
|
||||||
|
? _recruitService.CheckValidCertificate(x.recruit.Certificates.First().IssueDate, 5)
|
||||||
|
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
|
||||||
|
: "ไม่มีคุณสมบัติ",
|
||||||
|
remark = x.recruit.Remark,
|
||||||
|
isSpecial = x.recruit.Isspecial == "Y" ? x.recruit.Isspecial : "",
|
||||||
|
applyDate = x.recruit.ApplyDate != null && x.recruit.ApplyDate != DateTime.MinValue
|
||||||
|
? x.recruit.ApplyDate.ToThaiShortDate()
|
||||||
|
: "",
|
||||||
|
university = x.recruit.Educations.Any() ? x.recruit.Educations.First().University : "",
|
||||||
|
position_name = x.recruit.PositionName,
|
||||||
|
hddPosition = x.recruit.HddPosition,
|
||||||
|
typeTest = x.recruit.typeTest,
|
||||||
|
position_level = x.recruit.PositionLevel,
|
||||||
|
position_type = x.recruit.PositionType,
|
||||||
|
exam_name = x.recruit.RecruitImport!.Name,
|
||||||
|
exam_order = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Order != null
|
||||||
|
? x.recruit.RecruitImport.Order.ToString()
|
||||||
|
: "",
|
||||||
|
score_year = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Year != null
|
||||||
|
? x.recruit.RecruitImport.Year.ToThaiYear().ToString()
|
||||||
|
: "",
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// 3️. ดึงสรุปคะแนน
|
// 3️. ดึงสรุปคะแนน
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
@ -2090,7 +2074,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
header = new
|
header = new
|
||||||
{
|
{
|
||||||
count = _count,
|
count = _count,
|
||||||
pass = 0,
|
pass = 0,
|
||||||
|
|
@ -2099,7 +2083,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
other = 0
|
other = 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// 4️. ดึง period
|
// 4️. ดึง period
|
||||||
|
|
@ -2627,15 +2611,15 @@ namespace BMA.EHR.Recruit.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>> UpdateAsyncRecruitToPlacement(Guid examId)
|
public async Task<ActionResult<ResponseObject>> UpdateAsyncRecruitToPlacement(Guid examId, [FromBody] RecruitDateRequest req)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _recruitService.UpdateAsyncRecruitToPlacement(examId);
|
await _recruitService.UpdateAsyncRecruitToPlacement(examId, req.AccountStartDate);
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ namespace BMA.EHR.MetaData.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;
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ namespace BMA.EHR.MetaData.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;
|
||||||
|
|
|
||||||
7
Requests/Recruits/RecruitDateRequest.cs
Normal file
7
Requests/Recruits/RecruitDateRequest.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace BMA.EHR.Recruit.Service.Requests.Recruits
|
||||||
|
{
|
||||||
|
public class RecruitDateRequest
|
||||||
|
{
|
||||||
|
public DateTime AccountStartDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Requests/Recruits/RecruitPosTypeRequest.cs
Normal file
16
Requests/Recruits/RecruitPosTypeRequest.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
namespace BMA.EHR.Recruit.Service.Requests.Recruits
|
||||||
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ using System.Security.Claims;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using BMA.EHR.Recruit.Service.Requests.Recruits;
|
||||||
|
|
||||||
namespace BMA.EHR.Recruit.Service.Services
|
namespace BMA.EHR.Recruit.Service.Services
|
||||||
{
|
{
|
||||||
|
|
@ -175,10 +176,18 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
await _minIOService.DeleteFileAsync(doc_id);
|
await _minIOService.DeleteFileAsync(doc_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateAsyncRecruitToPlacement(Guid examId)
|
public async Task UpdateAsyncRecruitToPlacement(Guid examId, DateTime accountStartDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 🚀 Prepare HTTP client once
|
||||||
|
var httpClient1 = new HttpClient();
|
||||||
|
httpClient1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
|
||||||
|
httpClient1.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||||
|
var apiUrl1 = $"{_configuration["API"]}/org/pos/level";
|
||||||
|
var response1 = await httpClient1.GetStringAsync(apiUrl1);
|
||||||
|
var posOptions = JsonConvert.DeserializeObject<RecruitPosRequest>(response1);
|
||||||
|
|
||||||
var recruitImport = await _context.RecruitImports.AsQueryable()
|
var recruitImport = await _context.RecruitImports.AsQueryable()
|
||||||
.FirstOrDefaultAsync(x => x.Id == examId);
|
.FirstOrDefaultAsync(x => x.Id == examId);
|
||||||
|
|
||||||
|
|
@ -190,16 +199,23 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
if (_placement != null)
|
if (_placement != null)
|
||||||
throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
|
throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
|
||||||
|
|
||||||
|
// 🚀 Pre-load all lookup data once
|
||||||
|
var placementTypesCache = await _contextMetadata.PlacementTypes.ToListAsync();
|
||||||
|
var provincesCache = await _contextOrg.province.ToListAsync();
|
||||||
|
var districtsCache = await _contextOrg.district.ToListAsync();
|
||||||
|
var subDistrictsCache = await _contextOrg.subDistrict.ToListAsync();
|
||||||
|
var educationLevelsCache = await _contextOrg.educationLevel.ToListAsync();
|
||||||
|
|
||||||
var placement = new Placement
|
var placement = new Placement
|
||||||
{
|
{
|
||||||
Name = recruitImport.Name,
|
Name = recruitImport.Name,
|
||||||
RefId = recruitImport.Id,
|
RefId = recruitImport.Id,
|
||||||
Round = recruitImport.Order == null ? "" : recruitImport.Order.ToString(),
|
Round = recruitImport.Order.ToString() ?? "",
|
||||||
Year = (int)(recruitImport.Year == null ? 0 : recruitImport.Year),
|
Year = recruitImport.Year,
|
||||||
Number = await _context.Recruits.AsQueryable().Where(x => x.RecruitImport == recruitImport).CountAsync(),
|
Number = await _context.Recruits.AsQueryable().Where(x => x.RecruitImport == recruitImport).CountAsync(),
|
||||||
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("สอบแข่งขัน")),
|
PlacementType = placementTypesCache.FirstOrDefault(x => x.Name.Trim().ToUpper().Contains("สอบแข่งขัน")) ?? placementTypesCache.First(),
|
||||||
StartDate = DateTime.Now,
|
StartDate = accountStartDate,
|
||||||
EndDate = DateTime.Now.AddYears(2).AddDays(-1),
|
EndDate = accountStartDate.AddYears(2).AddDays(-1),
|
||||||
CreatedAt = DateTime.Now,
|
CreatedAt = DateTime.Now,
|
||||||
CreatedUserId = UserId ?? "",
|
CreatedUserId = UserId ?? "",
|
||||||
CreatedFullName = FullName ?? "",
|
CreatedFullName = FullName ?? "",
|
||||||
|
|
@ -208,6 +224,8 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
LastUpdateFullName = FullName ?? "",
|
LastUpdateFullName = FullName ?? "",
|
||||||
};
|
};
|
||||||
await _contextMetadata.Placements.AddAsync(placement);
|
await _contextMetadata.Placements.AddAsync(placement);
|
||||||
|
|
||||||
|
// 🚀 Load all related data with single queries
|
||||||
var candidates = await _context.Recruits.AsQueryable()
|
var candidates = await _context.Recruits.AsQueryable()
|
||||||
.Include(x => x.Addresses)
|
.Include(x => x.Addresses)
|
||||||
.Include(x => x.Certificates)
|
.Include(x => x.Certificates)
|
||||||
|
|
@ -215,147 +233,181 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
.Include(x => x.Occupations)
|
.Include(x => x.Occupations)
|
||||||
.Where(x => x.RecruitImport == recruitImport)
|
.Where(x => x.RecruitImport == recruitImport)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
var scoreImport = await _context.ScoreImports.AsQueryable()
|
||||||
|
.FirstOrDefaultAsync(x => x.RecruitImport == recruitImport);
|
||||||
|
|
||||||
|
var recruitScores = await _context.RecruitScores.AsQueryable()
|
||||||
|
.Where(x => x.ScoreImport == scoreImport && x.ExamStatus == "ผ่าน")
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var recruitScoresDict = recruitScores
|
||||||
|
.Where(x => !string.IsNullOrWhiteSpace(x.ExamId))
|
||||||
|
.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 =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(candidate.CitizenId))
|
||||||
|
return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null };
|
||||||
|
|
||||||
|
var apiUrl = $"{_configuration["API"]}/org/profile/citizenid/position/{candidate.CitizenId}";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
var orgResults = await Task.WhenAll(orgTasks);
|
||||||
|
var orgDict = orgResults.ToDictionary(x => x.CitizenId ?? "", x => x.org);
|
||||||
|
|
||||||
|
// 🚀 Prepare batch inserts
|
||||||
|
var placementProfiles = new List<PlacementProfile>();
|
||||||
|
var placementEducations = new List<PlacementEducation>();
|
||||||
|
var placementCertificates = new List<PlacementCertificate>();
|
||||||
|
|
||||||
foreach (var candidate in candidates)
|
foreach (var candidate in candidates)
|
||||||
{
|
{
|
||||||
var IsOfficer = false;
|
if (string.IsNullOrWhiteSpace(candidate.ExamId) ||
|
||||||
dynamic org = null;
|
!recruitScoresDict.TryGetValue(candidate.ExamId, out var recruitScore))
|
||||||
var apiUrl = $"{_configuration["API"]}/org/profile/citizenid/position/{candidate.CitizenId}";
|
|
||||||
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.Get, apiUrl);
|
|
||||||
var _res = await client.SendAsync(_req);
|
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
|
|
||||||
org = JsonConvert.DeserializeObject<dynamic>(_result);
|
|
||||||
|
|
||||||
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()
|
|
||||||
.FirstOrDefaultAsync(x => x.RecruitImport == recruitImport);
|
|
||||||
var recruitScore = await _context.RecruitScores.AsQueryable()
|
|
||||||
.Where(x => x.ScoreImport == scoreImport)
|
|
||||||
.Where(x => x.ExamId == candidate.ExamId)
|
|
||||||
.Where(x => x.ExamStatus == "ผ่าน")
|
|
||||||
.FirstOrDefaultAsync(x => x.ExamId == candidate.ExamId && x.ScoreImport == scoreImport);
|
|
||||||
if (recruitScore == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
var org = orgDict.TryGetValue(candidate.CitizenId ?? "", out var orgValue) ? orgValue : null;
|
||||||
|
var isOfficer = org?.result != null;
|
||||||
|
|
||||||
|
// 🚀 Cache repeated calculations
|
||||||
|
var firstAddress = candidate.Addresses?.FirstOrDefault();
|
||||||
|
var firstEducation = candidate.Educations?.FirstOrDefault();
|
||||||
|
var firstCertificate = candidate.Certificates?.FirstOrDefault();
|
||||||
|
var firstOccupation = candidate.Occupations?.FirstOrDefault();
|
||||||
|
|
||||||
|
var registAddress = BuildAddress(firstAddress?.Address, firstAddress?.Moo, firstAddress?.Soi, firstAddress?.Road);
|
||||||
|
var currentAddress = BuildAddress(firstAddress?.Address1, firstAddress?.Moo1, firstAddress?.Soi1, 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
|
var placementProfile = new PlacementProfile
|
||||||
{
|
{
|
||||||
Placement = placement,
|
Placement = placement,
|
||||||
PositionCandidate = candidate.PositionName,
|
PositionCandidate = positionNameWithoutLevel ?? "",
|
||||||
PositionType = candidate.PositionType,
|
PositionType = posLevelObject?.posTypes?.posTypeName ?? "",
|
||||||
PositionLevel = candidate.PositionLevel,
|
PositionLevel = posLevelName ?? "",
|
||||||
Prefix = candidate.Prefix,
|
Prefix = candidate.Prefix ?? "",
|
||||||
Firstname = candidate.FirstName,
|
Firstname = candidate.FirstName ?? "",
|
||||||
Lastname = candidate.LastName,
|
Lastname = candidate.LastName ?? "",
|
||||||
Gender = candidate.Gendor,
|
Gender = candidate.Gendor ?? "",
|
||||||
Nationality = candidate.National,
|
Nationality = candidate.National ?? "",
|
||||||
Race = candidate.Race,
|
Race = candidate.Race ?? "",
|
||||||
Religion = candidate.Religion,
|
Religion = candidate.Religion ?? "",
|
||||||
DateOfBirth = candidate.DateOfBirth,
|
DateOfBirth = candidate.DateOfBirth,
|
||||||
Relationship = candidate.Marry,
|
Relationship = candidate.Marry ?? "",
|
||||||
CitizenId = candidate.CitizenId,
|
CitizenId = candidate.CitizenId ?? "",
|
||||||
CitizenProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == candidate.CitizenCardIssuer)?.Id ?? null,
|
CitizenProvinceId = provincesCache.FirstOrDefault(x => x.name == candidate.CitizenCardIssuer)?.Id,
|
||||||
CitizenDate = candidate.CitizenCardExpireDate,
|
CitizenDate = candidate.CitizenCardExpireDate,
|
||||||
Telephone = candidate?.Addresses?.FirstOrDefault()?.Telephone ?? null,
|
Telephone = firstAddress?.Telephone ?? "",
|
||||||
MobilePhone = candidate?.Addresses?.FirstOrDefault()?.Mobile ?? null,
|
MobilePhone = firstAddress?.Mobile ?? "",
|
||||||
RegistAddress = $"{Address}{Moo}{Soi}{Road}",
|
RegistAddress = registAddress ?? "",
|
||||||
RegistProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Province ?? ""))?.Id ?? null,
|
RegistProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province)?.Id,
|
||||||
RegistDistrictId = _contextOrg.district.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Amphur ?? ""))?.Id ?? null,
|
RegistDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur)?.Id,
|
||||||
RegistSubDistrictId = _contextOrg.subDistrict.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.District ?? ""))?.Id ?? null,
|
RegistSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District)?.Id,
|
||||||
RegistZipCode = candidate?.Addresses?.FirstOrDefault()?.ZipCode ?? null,
|
RegistZipCode = firstAddress?.ZipCode ?? "",
|
||||||
RegistSame = false,
|
RegistSame = false,
|
||||||
CurrentAddress = $"{Address1}{Moo1}{Soi1}{Road1}",
|
CurrentAddress = currentAddress,
|
||||||
CurrentProvinceId = _contextOrg.province.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Province1 ?? ""))?.Id ?? null,
|
CurrentProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province1)?.Id,
|
||||||
CurrentDistrictId = _contextOrg.district.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.Amphur1 ?? ""))?.Id ?? null,
|
CurrentDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur1)?.Id,
|
||||||
CurrentSubDistrictId = _contextOrg.subDistrict.FirstOrDefault(x => x.name == (candidate!.Addresses!.FirstOrDefault()!.District1 ?? ""))?.Id ?? null,
|
CurrentSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District1)?.Id,
|
||||||
CurrentZipCode = candidate?.Addresses?.FirstOrDefault()?.ZipCode1 ?? null,
|
CurrentZipCode = firstAddress?.ZipCode1,
|
||||||
Marry = candidate?.Marry?.Contains("สมรส") ?? false,
|
Marry = candidate.Marry?.Contains("สมรส") ?? false,
|
||||||
|
|
||||||
OccupationPositionType = "other",
|
OccupationPositionType = "other",
|
||||||
OccupationTelephone = candidate?.Occupations?.FirstOrDefault()?.Telephone ?? null,
|
OccupationTelephone = firstOccupation?.Telephone ?? "",
|
||||||
OccupationPosition = candidate?.Occupations?.FirstOrDefault()?.Position ?? null,
|
OccupationPosition = firstOccupation?.Position ?? "",
|
||||||
|
PointTotalA = recruitScore.FullA, // non-nullable int
|
||||||
PointTotalA = recruitScore == null ? null : Convert.ToDouble(recruitScore.FullA),
|
PointA = recruitScore.SumA, // non-nullable double
|
||||||
PointA = recruitScore == null ? null : Convert.ToDouble(recruitScore.SumA),
|
PointTotalB = recruitScore.FullB ?? 0, // nullable int?
|
||||||
PointTotalB = recruitScore == null ? null : Convert.ToDouble(recruitScore.FullB),
|
PointB = recruitScore.SumB ?? 0, // nullable double?
|
||||||
PointB = recruitScore == null ? null : Convert.ToDouble(recruitScore.SumB),
|
PointTotalC = recruitScore.FullC, // non-nullable int
|
||||||
PointTotalC = recruitScore == null ? null : Convert.ToDouble(recruitScore.FullC),
|
PointC = recruitScore.SumC, // non-nullable double
|
||||||
PointC = recruitScore == null ? null : Convert.ToDouble(recruitScore.SumC),
|
ExamNumber = !string.IsNullOrWhiteSpace(recruitScore.Number) && int.TryParse(recruitScore.Number, out int n) ? n : null,
|
||||||
ExamNumber = recruitScore == null || int.TryParse(recruitScore.Number, out int n) == false ? null : Convert.ToInt32(recruitScore.Number),
|
|
||||||
ExamRound = null,
|
ExamRound = null,
|
||||||
IsRelief = false,
|
IsRelief = false,
|
||||||
PlacementStatus = "UN-CONTAIN",
|
PlacementStatus = "UN-CONTAIN",
|
||||||
Pass = recruitScore == null ? null : recruitScore.ExamStatus,
|
Pass = recruitScore.ExamStatus ?? "",
|
||||||
RemarkHorizontal = "โดยมีเงื่อนไขว่าต้องปฏิบัติงานให้กรุงเทพมหานครเป็นระยะเวลาไม่น้อยกว่า ๕ ปี นับแต่วันที่ได้รับการบรรจุและแต่งตั้ง โดยห้ามโอนไปหน่วยงานหรือส่วนราชการอื่น เว้นเเต่ลาออกจากราชการ",
|
RemarkHorizontal = "โดยมีเงื่อนไขว่าต้องปฏิบัติงานให้กรุงเทพมหานครเป็นระยะเวลาไม่น้อยกว่า ๕ ปี นับแต่วันที่ได้รับการบรรจุและแต่งตั้ง โดยห้ามโอนไปหน่วยงานหรือส่วนราชการอื่น เว้นเเต่ลาออกจากราชการ",
|
||||||
Amount = org?.result?.amount ?? null,
|
Amount = org?.result?.amount,
|
||||||
PositionSalaryAmount = org?.result?.positionSalaryAmount ?? null,
|
PositionSalaryAmount = org?.result?.positionSalaryAmount,
|
||||||
MouthSalaryAmount = org?.result?.mouthSalaryAmount ?? null,
|
MouthSalaryAmount = org?.result?.mouthSalaryAmount,
|
||||||
CreatedAt = DateTime.Now,
|
CreatedAt = DateTime.Now,
|
||||||
CreatedUserId = UserId ?? "",
|
CreatedUserId = UserId ?? "",
|
||||||
CreatedFullName = FullName ?? "",
|
CreatedFullName = FullName ?? "",
|
||||||
LastUpdatedAt = DateTime.Now,
|
LastUpdatedAt = DateTime.Now,
|
||||||
LastUpdateUserId = UserId ?? "",
|
LastUpdateUserId = UserId ?? "",
|
||||||
LastUpdateFullName = FullName ?? "",
|
LastUpdateFullName = FullName ?? "",
|
||||||
IsOfficer = IsOfficer,
|
IsOfficer = isOfficer,
|
||||||
profileId = org?.result?.profileId ?? null,
|
profileId = org?.result?.profileId ?? "",
|
||||||
IsOld = org == null || org.result == null ? false : true,
|
IsOld = org?.result != null,
|
||||||
AmountOld = org?.result?.amount ?? null,
|
AmountOld = org?.result?.amount,
|
||||||
nodeOld = org?.result?.node ?? null,
|
nodeOld = org?.result?.node ?? "",
|
||||||
nodeIdOld = org?.result?.nodeId ?? null,
|
nodeIdOld = org?.result?.nodeId ?? "",
|
||||||
posmasterIdOld = org?.result?.posmasterId ?? null,
|
posmasterIdOld = org?.result?.posmasterId ?? "",
|
||||||
rootOld = org?.result?.root ?? null,
|
rootOld = org?.result?.root ?? "",
|
||||||
rootIdOld = org?.result?.rootId ?? null,
|
rootIdOld = org?.result?.rootId ?? "",
|
||||||
rootShortNameOld = org?.result?.rootShortName ?? null,
|
rootShortNameOld = org?.result?.rootShortName ?? "",
|
||||||
child1Old = org?.result?.child1 ?? null,
|
child1Old = org?.result?.child1 ?? "",
|
||||||
child1IdOld = org?.result?.child1Id ?? null,
|
child1IdOld = org?.result?.child1Id ?? "",
|
||||||
child1ShortNameOld = org?.result?.child1ShortName ?? null,
|
child1ShortNameOld = org?.result?.child1ShortName ?? "",
|
||||||
child2Old = org?.result?.child2 ?? null,
|
child2Old = org?.result?.child2 ?? "",
|
||||||
child2IdOld = org?.result?.child2Id ?? null,
|
child2IdOld = org?.result?.child2Id ?? "",
|
||||||
child2ShortNameOld = org?.result?.child2ShortName ?? null,
|
child2ShortNameOld = org?.result?.child2ShortName ?? "",
|
||||||
child3Old = org?.result?.child3 ?? null,
|
child3Old = org?.result?.child3 ?? "",
|
||||||
child3IdOld = org?.result?.child3Id ?? null,
|
child3IdOld = org?.result?.child3Id ?? "",
|
||||||
child3ShortNameOld = org?.result?.child3ShortName ?? null,
|
child3ShortNameOld = org?.result?.child3ShortName ?? "",
|
||||||
child4Old = org?.result?.child4 ?? null,
|
child4Old = org?.result?.child4 ?? "",
|
||||||
child4IdOld = org?.result?.child4Id ?? null,
|
child4IdOld = org?.result?.child4Id ?? "",
|
||||||
child4ShortNameOld = org?.result?.child4ShortName ?? null,
|
child4ShortNameOld = org?.result?.child4ShortName ?? "",
|
||||||
orgRevisionIdOld = org?.result?.orgRevisionId ?? null,
|
orgRevisionIdOld = org?.result?.orgRevisionId ?? "",
|
||||||
posMasterNoOld = org?.result?.posMasterNo ?? null,
|
posMasterNoOld = org?.result?.posMasterNo,
|
||||||
positionNameOld = org?.result?.position ?? null,
|
positionNameOld = org?.result?.position ?? "",
|
||||||
posTypeIdOld = org?.result?.posTypeId ?? null,
|
posTypeIdOld = org?.result?.posTypeId ?? "",
|
||||||
posTypeNameOld = org?.result?.posTypeName ?? null,
|
posTypeNameOld = org?.result?.posTypeName ?? "",
|
||||||
posLevelIdOld = org?.result?.posLevelId ?? null,
|
posLevelIdOld = org?.result?.posLevelId ?? "",
|
||||||
posLevelNameOld = org?.result?.posLevelName ?? null,
|
posLevelNameOld = org?.result?.posLevelName ?? "",
|
||||||
};
|
};
|
||||||
await _contextMetadata.PlacementProfiles.AddAsync(placementProfile);
|
placementProfiles.Add(placementProfile);
|
||||||
|
|
||||||
var placementEducation = new PlacementEducation
|
var placementEducation = new PlacementEducation
|
||||||
{
|
{
|
||||||
PlacementProfile = placementProfile,
|
PlacementProfile = placementProfile,
|
||||||
EducationLevelId = _contextOrg.educationLevel.FirstOrDefault(x => x.name == (candidate!.Educations!.FirstOrDefault()!.HighDegree ?? ""))?.Id ?? null,
|
EducationLevelId = educationLevelsCache.FirstOrDefault(x => x.name == firstEducation?.HighDegree)?.Id,
|
||||||
EducationLevelName = _contextOrg.educationLevel.FirstOrDefault(x => x.name == (candidate!.Educations!.FirstOrDefault()!.HighDegree ?? ""))?.name ?? null,
|
EducationLevelName = educationLevelsCache.FirstOrDefault(x => x.name == firstEducation?.HighDegree)?.name,
|
||||||
Field = candidate?.Educations?.FirstOrDefault()?.Major ?? null,
|
Field = firstEducation?.Major ?? "",
|
||||||
Gpa = candidate?.Educations?.FirstOrDefault()?.GPA!.ToString() ?? null,
|
Gpa = firstEducation == null || firstEducation?.GPA == null ? "" : firstEducation.GPA.ToString(),
|
||||||
Institute = candidate?.Educations?.FirstOrDefault()?.University ?? null,
|
Institute = firstEducation?.University ?? "",
|
||||||
Degree = candidate?.Educations?.FirstOrDefault()?.Degree ?? null,
|
Degree = firstEducation?.Degree ?? "",
|
||||||
FinishDate = candidate?.Educations?.FirstOrDefault()?.BachelorDate ?? null,
|
FinishDate = firstEducation?.BachelorDate,
|
||||||
IsDate = true,
|
IsDate = true,
|
||||||
CreatedAt = DateTime.Now,
|
CreatedAt = DateTime.Now,
|
||||||
CreatedUserId = UserId ?? "",
|
CreatedUserId = UserId ?? "",
|
||||||
|
|
@ -364,15 +416,15 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
CreatedFullName = FullName ?? "",
|
CreatedFullName = FullName ?? "",
|
||||||
LastUpdateFullName = FullName ?? "",
|
LastUpdateFullName = FullName ?? "",
|
||||||
};
|
};
|
||||||
await _contextMetadata.PlacementEducations.AddAsync(placementEducation);
|
placementEducations.Add(placementEducation);
|
||||||
|
|
||||||
var placementCertificate = new PlacementCertificate
|
var placementCertificate = new PlacementCertificate
|
||||||
{
|
{
|
||||||
PlacementProfile = placementProfile,
|
PlacementProfile = placementProfile,
|
||||||
CertificateNo = candidate?.Certificates?.FirstOrDefault()?.CertificateNo ?? null,
|
CertificateNo = firstCertificate?.CertificateNo ?? "",
|
||||||
IssueDate = candidate?.Certificates?.FirstOrDefault()?.IssueDate ?? null,
|
IssueDate = firstCertificate?.IssueDate,
|
||||||
ExpireDate = candidate?.Certificates?.FirstOrDefault()?.ExpiredDate ?? null,
|
ExpireDate = firstCertificate?.ExpiredDate,
|
||||||
CertificateType = candidate?.Certificates?.FirstOrDefault()?.Description ?? null,
|
CertificateType = firstCertificate?.Description ?? "",
|
||||||
CreatedAt = DateTime.Now,
|
CreatedAt = DateTime.Now,
|
||||||
CreatedUserId = UserId ?? "",
|
CreatedUserId = UserId ?? "",
|
||||||
LastUpdatedAt = DateTime.Now,
|
LastUpdatedAt = DateTime.Now,
|
||||||
|
|
@ -380,15 +432,34 @@ namespace BMA.EHR.Recruit.Service.Services
|
||||||
CreatedFullName = FullName ?? "",
|
CreatedFullName = FullName ?? "",
|
||||||
LastUpdateFullName = FullName ?? "",
|
LastUpdateFullName = FullName ?? "",
|
||||||
};
|
};
|
||||||
await _contextMetadata.PlacementCertificates.AddAsync(placementCertificate);
|
placementCertificates.Add(placementCertificate);
|
||||||
await _contextMetadata.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🚀 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
|
catch
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string BuildAddress(string? address, string? moo, string? soi, string? road)
|
||||||
|
{
|
||||||
|
var parts = new List<string>();
|
||||||
|
if (!string.IsNullOrWhiteSpace(address)) parts.Add(address);
|
||||||
|
if (!string.IsNullOrWhiteSpace(moo)) parts.Add($"หมู่ {moo}");
|
||||||
|
if (!string.IsNullOrWhiteSpace(soi)) parts.Add($"ซอย {soi}");
|
||||||
|
if (!string.IsNullOrWhiteSpace(road)) parts.Add($"ถนน {road}");
|
||||||
|
return string.Join(" ", parts);
|
||||||
|
}
|
||||||
public DateTime CheckDateTime(string Date, string Formate)
|
public DateTime CheckDateTime(string Date, string Formate)
|
||||||
{
|
{
|
||||||
// ตอนนี้ทำไว้ให้รองรับแค่ "dd/MM/yyyy", "yyyy-MM-dd"
|
// ตอนนี้ทำไว้ให้รองรับแค่ "dd/MM/yyyy", "yyyy-MM-dd"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue