lookup province, district, subDistrict IDs with parent filtering

This commit is contained in:
harid 2026-06-09 10:49:00 +07:00
parent 6f9cde1811
commit f76275400e
3 changed files with 33 additions and 6 deletions

View file

@ -11,6 +11,9 @@ namespace BMA.EHR.MetaData.Service.Models
[Required, MaxLength(150), Column(Order = 1), Comment("เขต/อำเภอ")] [Required, MaxLength(150), Column(Order = 1), Comment("เขต/อำเภอ")]
public string name { get; set; } = string.Empty; public string name { get; set; } = string.Empty;
[Column(Order = 2), Comment("รหัสอ้างอิงจังหวัด")]
public Guid? provinceId { get; set; } = null;
// [Column(Order = 2), Comment("สถานะการใช้งาน")] // [Column(Order = 2), Comment("สถานะการใช้งาน")]
// public bool IsActive { get; set; } = true; // public bool IsActive { get; set; } = true;

View file

@ -14,6 +14,9 @@ namespace BMA.EHR.MetaData.Service.Models
[MaxLength(10), Column(Order = 2), Comment("รหัสไปรษณีย์")] [MaxLength(10), Column(Order = 2), Comment("รหัสไปรษณีย์")]
public string? zipCode { get; set; } = null; public string? zipCode { get; set; } = null;
[Column(Order = 3), Comment("รหัสอ้างอิงอำเภอ")]
public Guid? districtId { get; set; } = null;
// [Column(Order = 3), Comment("สถานะการใช้งาน")] // [Column(Order = 3), Comment("สถานะการใช้งาน")]
// public bool IsActive { get; set; } = true; // public bool IsActive { get; set; } = true;

View file

@ -341,6 +341,27 @@ namespace BMA.EHR.Recruit.Services
{ {
positionNameWithoutLevel = positionNameWithoutLevel.Replace(posLevelName, "").Trim(); positionNameWithoutLevel = positionNameWithoutLevel.Replace(posLevelName, "").Trim();
} }
// lookup province, district, subDistrict IDs with parent filtering
var registProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province)?.Id;
var registDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur && x.provinceId == registProvinceId)?.Id;
var registSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District && x.districtId == registDistrictId)?.Id;
var currentProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province1)?.Id;
var currentDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur1 && x.provinceId == currentProvinceId)?.Id;
var currentSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District1 && x.districtId == currentDistrictId)?.Id;
// log warning when address lookup fails
if (registProvinceId == null && !string.IsNullOrWhiteSpace(firstAddress?.Province))
Console.WriteLine($"[WARN] Regist province not found: {firstAddress?.Province}");
if (registDistrictId == null && !string.IsNullOrWhiteSpace(firstAddress?.Amphur))
Console.WriteLine($"[WARN] Regist district not found: {firstAddress?.Amphur}, Province: {firstAddress?.Province}");
if (registSubDistrictId == null && !string.IsNullOrWhiteSpace(firstAddress?.District))
Console.WriteLine($"[WARN] Regist subdistrict not found: {firstAddress?.District}, District: {firstAddress?.Amphur}");
if (currentProvinceId == null && !string.IsNullOrWhiteSpace(firstAddress?.Province1))
Console.WriteLine($"[WARN] Current province not found: {firstAddress?.Province1}");
if (currentDistrictId == null && !string.IsNullOrWhiteSpace(firstAddress?.Amphur1))
Console.WriteLine($"[WARN] Current district not found: {firstAddress?.Amphur1}, Province: {firstAddress?.Province1}");
if (currentSubDistrictId == null && !string.IsNullOrWhiteSpace(firstAddress?.District1))
Console.WriteLine($"[WARN] Current subdistrict not found: {firstAddress?.District1}, District: {firstAddress?.Amphur1}");
var placementProfile = new PlacementProfile var placementProfile = new PlacementProfile
{ {
@ -363,15 +384,15 @@ namespace BMA.EHR.Recruit.Services
Telephone = firstAddress?.Telephone ?? "", Telephone = firstAddress?.Telephone ?? "",
MobilePhone = firstAddress?.Mobile ?? "", MobilePhone = firstAddress?.Mobile ?? "",
RegistAddress = registAddress ?? "", RegistAddress = registAddress ?? "",
RegistProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province)?.Id, RegistProvinceId = registProvinceId,
RegistDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur)?.Id, RegistDistrictId = registDistrictId,
RegistSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District)?.Id, RegistSubDistrictId = registSubDistrictId,
RegistZipCode = firstAddress?.ZipCode ?? "", RegistZipCode = firstAddress?.ZipCode ?? "",
RegistSame = false, RegistSame = false,
CurrentAddress = currentAddress, CurrentAddress = currentAddress,
CurrentProvinceId = provincesCache.FirstOrDefault(x => x.name == firstAddress?.Province1)?.Id, CurrentProvinceId = currentProvinceId,
CurrentDistrictId = districtsCache.FirstOrDefault(x => x.name == firstAddress?.Amphur1)?.Id, CurrentDistrictId = currentDistrictId,
CurrentSubDistrictId = subDistrictsCache.FirstOrDefault(x => x.name == firstAddress?.District1)?.Id, CurrentSubDistrictId = currentSubDistrictId,
CurrentZipCode = firstAddress?.ZipCode1, CurrentZipCode = firstAddress?.ZipCode1,
Marry = candidate.Marry?.Contains("สมรส") ?? false, Marry = candidate.Marry?.Contains("สมรส") ?? false,
OccupationPositionType = "other", OccupationPositionType = "other",