Add GetOCStaffAsync method to UserProfileRepository and create GetOcStaff response models
This commit is contained in:
parent
d3cc0781cf
commit
4f18a97d0b
3 changed files with 158 additions and 5 deletions
|
|
@ -186,6 +186,8 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdNewAsync(Guid keycloakId, string? accessToken,CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
|
|
@ -256,6 +258,36 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<GetOcStaff>?> GetOCStaffAsync(Guid profileId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/find-staff";
|
||||
var apiKey = _configuration["API_KEY"];
|
||||
var body = new
|
||||
{
|
||||
assignId = "SYS_LEAVE_LIST",
|
||||
profileId = profileId
|
||||
};
|
||||
|
||||
//var profiles = new List<GetOcStaff>();
|
||||
|
||||
var apiResult = await PostExternalAPIAsync(apiPath, accessToken ?? "", body, apiKey);
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetOcStaffResultDto>(apiResult);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<GetProfileLeaveByKeycloakDto?> GetProfileLeaveReportByKeycloakIdAsync(Guid keycloakId, string? accessToken, string? report)
|
||||
{
|
||||
try
|
||||
|
|
@ -268,7 +300,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
report = report
|
||||
};
|
||||
|
||||
var profiles = new List<SearchProfileDto>();
|
||||
//var profiles = new List<SearchProfileDto>();
|
||||
|
||||
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
|
||||
if (apiResult != null)
|
||||
|
|
|
|||
35
BMA.EHR.Application/Responses/Profiles/GetOcStaff.cs
Normal file
35
BMA.EHR.Application/Responses/Profiles/GetOcStaff.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetOcStaff
|
||||
{
|
||||
public Guid ProfileId { get; set; }
|
||||
public Guid Keycloak { get; set; }
|
||||
public string FullName { get; set; } = null!;
|
||||
public Guid? RootId { get; set; }
|
||||
public Guid? OrgChild1Id { get; set; }
|
||||
public Guid? OrgChild2Id { get; set; }
|
||||
public Guid? OrgChild3Id { get; set; }
|
||||
public Guid? OrgChild4Id { get; set; }
|
||||
public Guid? RootDnaId { get; set; }
|
||||
public Guid? Child1DnaId { get; set; }
|
||||
public Guid? Child2DnaId { get; set; }
|
||||
public Guid? Child3DnaId { get; set; }
|
||||
public Guid? Child4DnaId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class GetOcStaffResultDto
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
public int Status { get; set; } = -1;
|
||||
|
||||
public List<GetOcStaff> Result { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ using BMA.EHR.Application.Repositories.MessageQueue;
|
|||
using BMA.EHR.Application.Responses.Profiles;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Leave.Service.DTOs.AdditionalCheck;
|
||||
|
|
@ -46,6 +47,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
private readonly DutyTimeRepository _dutyTimeRepository;
|
||||
private readonly LeaveDbContext _context;
|
||||
private readonly ApplicationDBContext _appDbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
|
@ -94,10 +96,12 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
PermissionRepository permission,
|
||||
NotificationRepository notificationRepository,
|
||||
CheckInJobStatusRepository checkInJobStatusRepository,
|
||||
HttpClient httpClient)
|
||||
HttpClient httpClient,
|
||||
ApplicationDBContext appDbContext)
|
||||
{
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_context = context;
|
||||
_appDbContext = appDbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_configuration = configuration;
|
||||
|
|
@ -928,16 +932,31 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (profile == null)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลผู้ใช้");
|
||||
//var staffList = await _userProfileRepository.GetOCStaffAsync(profile)
|
||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
var currentDate = data.CurrentDate ?? DateTime.Now;
|
||||
|
||||
if (data.CheckInFileName == "no-file")
|
||||
{
|
||||
//throw new Exception(GlobalMessages.NoFileToUpload);
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, GlobalMessages.NoFileToUpload);
|
||||
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจาก {GlobalMessages.NoFileToUpload}",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
return Error(GlobalMessages.NoFileToUpload, StatusCodes.Status400BadRequest);
|
||||
}
|
||||
var currentDate = data.CurrentDate ?? DateTime.Now;
|
||||
|
||||
|
||||
var check_status = data.CheckInId == null ? "check-in-picture" : "check-out-picture";
|
||||
|
||||
|
|
@ -951,6 +970,19 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
catch (Exception ex)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, $"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}");
|
||||
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
|
||||
return Error($"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}", StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
|
||||
|
|
@ -960,6 +992,16 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (defaultRound == null)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบรอบการลงเวลาทำงาน Default");
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบรอบการลงเวลาทำงาน Default",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
return Error("ไม่พบรอบการลงเวลาทำงาน Default", StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
|
|
@ -979,6 +1021,18 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (currentCheckIn != null)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่สามารถลงเวลาได้ เนื่องจากมีการลงเวลาในวันนี้แล้ว");
|
||||
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากมีการลงเวลาในวันนี้แล้ว",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
return Error(new Exception("ไม่สามารถลงเวลาได้ เนื่องจากมีการลงเวลาในวันนี้แล้ว!"), StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
|
|
@ -1117,6 +1171,18 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (checkout == null)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการลงเวลาทำงาน");
|
||||
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการลงเวลาทำงาน",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
|
|
@ -1125,6 +1191,18 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (currentCheckInProcess == null)
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการประมวลผลเวลาทำงาน (CheckIn)");
|
||||
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน (CheckIn)",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
|
|
@ -1275,11 +1353,19 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
else
|
||||
{
|
||||
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการประมวลผลเวลาทำงาน");
|
||||
// send notification to user
|
||||
var noti1 = new Notification
|
||||
{
|
||||
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน",
|
||||
ReceiverUserId = profile.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// อัปเดตสถานะเป็น COMPLETED
|
||||
if (taskId != Guid.Empty)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue