Add GetProfileByProfileIdNoAuthAsync method and update related controller logic
This commit is contained in:
parent
a2ac05ed61
commit
e5e7c77880
4 changed files with 49 additions and 7 deletions
|
|
@ -341,6 +341,31 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<GetProfileByKeycloakIdDto?> GetProfileByProfileIdNoAuthAsync(Guid profileId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var apiPath = $"{_configuration["API"]}/api/v1/org/unauthorize/profile/{profileId}";
|
||||
var apiKey = _configuration["API_KEY"];
|
||||
|
||||
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate, string? accessToken)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -500,11 +500,11 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
[HttpPut("schedule")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> ScheduleLeaveBeginning([FromBody] EditLeaveBeginningDto req)
|
||||
public async Task<ActionResult<ResponseObject>> ScheduleUpdateLeaveBeginningAsync([FromBody] EditLeaveBeginningDto req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken);
|
||||
var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken);
|
||||
if(profile == null)
|
||||
{
|
||||
return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
}
|
||||
|
||||
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
|
||||
|
||||
|
||||
var lastLeaveRequest =
|
||||
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(data.KeycloakUserId,
|
||||
|
|
@ -156,7 +157,18 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
var startFiscalYear = new DateTime(data.LeaveStartDate.Year - 1, 10, 1);
|
||||
var endFiscalYear = data.LeaveStartDate.Date.AddDays(-1); // นับจากวันที่ยื่นลา
|
||||
|
||||
var thisYear = data.LeaveStartDate.Year;
|
||||
var toDay = data.LeaveStartDate.Date;
|
||||
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
|
||||
thisYear = thisYear + 1;
|
||||
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId);
|
||||
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
||||
if (leaveData != null)
|
||||
{
|
||||
sumLeave += leaveData.BeginningLeaveDays;
|
||||
}
|
||||
|
||||
var Oc = profile.isCommission == false
|
||||
? profile.Oc.ToThaiNumber()
|
||||
: profile.Oc.Replace("สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร", "สำนักงาน ก.ก.").ToThaiNumber();
|
||||
|
|
@ -334,6 +346,10 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
|
||||
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
||||
if (leaveData != null)
|
||||
{
|
||||
sumLeave += leaveData.BeginningLeaveDays;
|
||||
}
|
||||
|
||||
//var sumLeave = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
||||
var leaveLimit = leaveData == null ? 0.0 : leaveData.LeaveDays;
|
||||
|
|
|
|||
|
|
@ -1579,7 +1579,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
|
||||
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUserAsync(thisYear, rawData.Type.Id, rawData.KeycloakUserId);
|
||||
var restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : leaveData.LeaveDays - 10;
|
||||
var restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays + leaveData.BeginningLeaveDays - 10);
|
||||
if (restDayOld < 0) restDayOld = 0;
|
||||
var restDayCurrent = govAge < 180 ? 0 : 10;
|
||||
|
||||
|
||||
|
|
@ -2509,6 +2510,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var endFiscalYear = rawData.LeaveStartDate.Date.AddDays(-1); // นับจากวันที่ยื่นลา
|
||||
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear);
|
||||
//var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
||||
if (leaveData != null)
|
||||
leaveSummary += leaveData.LeaveDaysUsed;
|
||||
|
||||
var extendLeave = 0.0;
|
||||
var leaveLimit = (double)rawData.Type.Limit;
|
||||
|
|
@ -2516,7 +2519,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (rawData.Type.Code == "LV-005")
|
||||
{
|
||||
leaveLimit = leaveData == null ? 0.0 : leaveData.LeaveDays;
|
||||
extendLeave = leaveLimit - 10;
|
||||
extendLeave = leaveLimit <= 0 ? 0 : leaveLimit - 10;
|
||||
}
|
||||
|
||||
var result = new GetLeaveRequestForAdminByIdDto
|
||||
|
|
@ -2615,8 +2618,6 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
//OrganizationName = rawData.OrganizationName ?? "",
|
||||
// fix SIT ระบบบันทึกการลา>>รายการลา (ข้อมูลผู้สังกัดและเรียนไม่แสดง) #971
|
||||
|
||||
|
||||
|
||||
ApproveStep = rawData.ApproveStep ?? "-",
|
||||
|
||||
LeaveLimit = rawData.Type.Limit + extendLeave,
|
||||
|
|
@ -2742,7 +2743,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (leaveType.Code == "LV-005")
|
||||
{
|
||||
leaveLimit = leaveData?.LeaveDays ?? 0.0;
|
||||
extendLeave = leaveLimit - 10;
|
||||
extendLeave = leaveLimit <= 0 ? 0 : leaveLimit - 10;
|
||||
}
|
||||
|
||||
var data = new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue