diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index cb320c69..cfade76e 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -8868,6 +8868,57 @@ namespace BMA.EHR.Application.Repositories } } + public async Task UpdateInsigniaRequestProfile(string[] items, string type, Guid? periodId) + { + try + { + if (type.Trim().ToUpper() == "OFFICER") + { + var allProfiles = await _userProfileRepository.GetInsigniaRequestsProfileAsync(items, type, AccessToken); + + if (allProfiles != null && allProfiles.Count > 0) + { + var insigniaRequestProfiles = await _dbContext.Set() + .Where(x => allProfiles.Select(x => x.Id).ToList().Contains(x.ProfileId)) + .ToListAsync(); + + foreach (var insigniaRequestProfile in insigniaRequestProfiles) + { + var profile = allProfiles.FirstOrDefault(p => p.Id == insigniaRequestProfile.ProfileId); + + if (profile != null) + { + insigniaRequestProfile.MarkDiscipline = profile?.MarkDiscipline; + insigniaRequestProfile.MarkLeave = profile?.MarkLeave; + insigniaRequestProfile.MarkRate = profile?.MarkRate; + insigniaRequestProfile.MarkInsignia = profile?.MarkInsignia; + } + } + } + } + //else if (type.Trim().ToUpper() == "EMPLOYEE" && periodId != null) + //{ + // var insigniaRequests = await _dbContext.Set() + // .Where(x => x.Period.Id == periodId) + // .ToListAsync(); + + // var allEmpProfileIds = new List(); + // foreach (var insigniaRequest in insigniaRequests) + // { + // var orgRootId = insigniaRequest.Id.ToString(); + // var allEmpProfiles = await _userProfileRepository.GetInsigniaRequestsProfileEmpAsync(items, orgRootId, AccessToken); + // } + + //} + + await _dbContext.SaveChangesAsync(); + + } + catch + { + throw; + } + } #endregion } } \ No newline at end of file diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 4fbd0128..ab7436e7 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -1073,6 +1073,34 @@ namespace BMA.EHR.Application.Repositories } + public async Task> GetInsigniaRequestsProfileAsync(string[] profileIds, string type, string? accessToken) + { + try + { + var apiPath = $"{_configuration["API"]}/org/dotnet/find/insignia-requests-profile/{type}"; + var apiKey = _configuration["API_KEY"]; + + var body = new + { + profileIds + }; + + var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey); + + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return null; + } + catch + { + throw; + } + } #endregion } } diff --git a/BMA.EHR.Application/Responses/Profiles/GetMarkStatusDto.cs b/BMA.EHR.Application/Responses/Profiles/GetMarkStatusDto.cs new file mode 100644 index 00000000..d419089d --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetMarkStatusDto.cs @@ -0,0 +1,23 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetMarkStatusDto + { + public Guid Id { get; set; } + public bool? MarkDiscipline { get; set; } = false; + public bool? MarkLeave { get; set; } = false; + public bool? MarkRate { get; set; } = false; + public bool? MarkInsignia { get; set; } = false; + + public string? Apr1 { get; set; } + public string? Apr2 { get; set; } + public string? Apr3 { get; set; } + public string? Apr4 { get; set; } + public string? Apr5 { get; set; } + + public string? Oct1 { get; set; } + public string? Oct2 { get; set; } + public string? Oct3 { get; set; } + public string? Oct4 { get; set; } + public string? Oct5 { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetMarkStatusResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetMarkStatusResultDto.cs new file mode 100644 index 00000000..6114f325 --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetMarkStatusResultDto.cs @@ -0,0 +1,12 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetMarkStatusResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public List Result { get; set; } = new(); + + } +} diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index 257b9597..1979fa45 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -2704,5 +2704,59 @@ namespace BMA.EHR.Insignia.Service.Controllers return Success(); } + + /// + /// อัพเดทสถานะ Mark (โทษทางวินัย, ไม่ได้เลื่อนเงินเดือน/ไม่ได้เลื่อนขั้น (เนื่องจากลาเกิน), ผลการประเมินการปฏิบัติราชการในรอบ 5 ปี, ข้อมูลเครื่องราชฯ) + /// + /// Id รอบเครื่องราช + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("update/{insigniaPeriodId:length(36)}")] + public async Task> InsigniaRequestUpdateMark(Guid insigniaPeriodId) + { + try + { + var insigniaPeriod = await _context.InsigniaPeriods + .Include(x => x.InsigniaRequests) + .Include(x => x.InsigniaEmployees) + .FirstOrDefaultAsync(x => x.Id == insigniaPeriodId); + if (insigniaPeriod == null) + return Error(GlobalMessages.InsigniaRequestNotFound); + + if (insigniaPeriod.InsigniaRequests.Count > 0) + { + var allProfileIds = new List(); + foreach (var InsigniaRequest in insigniaPeriod.InsigniaRequests) + { + var profiles = await _context.Set() + .Where(p => p.Request.Id == InsigniaRequest.Id && p.ProfileType.Trim().ToUpper() == "OFFICER").Select(x => x.ProfileId.ToString()).ToListAsync(); + + if (profiles != null && profiles.Count > 0) + { + allProfileIds.AddRange(profiles); + } + } + + if (allProfileIds.Count > 0) + { + await _insigniaPeriodRepository.UpdateInsigniaRequestProfile(allProfileIds.ToArray(), "OFFICER", null); + } + } + + //if (insigniaPeriod.InsigniaEmployees.Count > 0) + //{ + // await _insigniaPeriodRepository.UpdateInsigniaRequestProfile(insigniaPeriod.InsigniaEmployees.Select(x => x.RefId!.ValueOrBlank()).ToArray(), "EMPLOYEE", insigniaPeriod.Id); + //} + + return Success(); + } + catch (Exception ex) + { + return Error(ex); + } + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 71a2f51e..459673a7 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -1049,7 +1049,7 @@ namespace BMA.EHR.Placement.Service.Controllers dateStart = r.commandDateAffect, govAgeAbsent = 0, govAgePlus = 0, - birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth, + birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth, reasonSameDate = (DateTime?)null, ethnicity = p.Race == null ? string.Empty : p.Race, telephoneNumber = (String?)null,