Compare commits

..

No commits in common. "c693364fe128bbb4f2c81e3176411fa79aff2464" and "d3cc0781cfad3ee47a7a9a9961de56f66dd1c064" have entirely different histories.

4 changed files with 16 additions and 169 deletions

View file

@ -186,8 +186,6 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdNewAsync(Guid keycloakId, string? accessToken,CancellationToken cancellationToken = default)
{
try
@ -258,36 +256,6 @@ 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
@ -300,7 +268,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)

View file

@ -1,35 +0,0 @@
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();
}
}

View file

@ -6,7 +6,6 @@ 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;
@ -47,7 +46,6 @@ 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;
@ -96,12 +94,10 @@ namespace BMA.EHR.Leave.Service.Controllers
PermissionRepository permission,
NotificationRepository notificationRepository,
CheckInJobStatusRepository checkInJobStatusRepository,
HttpClient httpClient,
ApplicationDBContext appDbContext)
HttpClient httpClient)
{
_dutyTimeRepository = dutyTimeRepository;
_context = context;
_appDbContext = appDbContext;
_httpContextAccessor = httpContextAccessor;
_hostingEnvironment = hostingEnvironment;
_configuration = configuration;
@ -932,31 +928,16 @@ 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";
@ -970,19 +951,6 @@ 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);
}
@ -992,16 +960,6 @@ 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);
}
@ -1021,18 +979,6 @@ 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);
}
@ -1171,18 +1117,6 @@ 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);
}
@ -1191,18 +1125,6 @@ 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);
}
@ -1353,19 +1275,11 @@ 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)
{

View file

@ -1389,57 +1389,57 @@ namespace BMA.EHR.Leave.Service.Controllers
var sickDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-001");
var sickDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-001");
var sickDayCount = sickDaySum != null ? sickDaySum.LeaveDaysUsed : 0;
var sickCount = sickDaySum != null ? sickDaySum.LeaveCount : 0;
var sickCount = sickDay != null ? sickDay.CountLeaveDay : 0;
var personalDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-002");
var personalDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-002");
var personalDayCount = personalDaySum != null ? personalDaySum.LeaveDaysUsed : 0;
var personalCount = personalDaySum != null ? personalDaySum.LeaveCount : 0;
var personalCount = personalDay != null ? personalDay.CountLeaveDay : 0;
var maternityDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-003");
var maternityDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-003");
var maternityDayCount = maternityDaySum != null ? maternityDaySum.LeaveDaysUsed : 0;
var maternityCount = maternityDaySum != null ? maternityDaySum.LeaveCount : 0;
var maternityCount = maternityDay != null ? maternityDay.CountLeaveDay : 0;
var wifeDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-004");
var wifeDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-004");
var wifeDayCount = wifeDaySum != null ? wifeDaySum.LeaveDaysUsed : 0;
var wifeCount = wifeDaySum != null ? wifeDaySum.LeaveCount : 0;
var wifeCount = wifeDay != null ? wifeDay.CountLeaveDay : 0;
var restDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-005");
var restDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-005");
var restDayCount = restDaySum != null ? restDaySum.LeaveDaysUsed : 0;
var restCount = restDaySum != null ? restDaySum.LeaveCount : 0;
var restCount = restDay != null ? restDay.CountLeaveDay : 0;
var ordainDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-006");
var ordainDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-006");
var ordainDayCount = ordainDaySum != null ? ordainDaySum.LeaveDaysUsed : 0;
var ordainCount = ordainDaySum != null ? ordainDaySum.LeaveCount : 0;
var ordainCount = ordainDay != null ? ordainDay.CountLeaveDay : 0;
var absentDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-007");
var absentDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-007");
var absentDayCount = absentDaySum != null ? absentDaySum.LeaveDaysUsed : 0;
var absentCount = absentDaySum != null ? absentDaySum.LeaveCount : 0;
var absentCount = absentDay != null ? absentDay.CountLeaveDay : 0;
var studyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-008");
var studyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-008");
var studyDayCount = studyDaySum != null ? studyDaySum.LeaveDaysUsed : 0;
var studyCount = studyDaySum != null ? studyDaySum.LeaveCount : 0;
var studyCount = studyDay != null ? studyDay.CountLeaveDay : 0;
var agencyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-009");
var agencyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-009");
var agencyDayCount = agencyDaySum != null ? agencyDaySum.LeaveDaysUsed : 0;
var agencyCount = agencyDaySum != null ? agencyDaySum.LeaveCount : 0;
var agencyCount = agencyDay != null ? agencyDay.CountLeaveDay : 0;
var coupleDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-010");
var coupleDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-010");
var coupleDayCount = coupleDaySum != null ? coupleDaySum.LeaveDaysUsed : 0;
var coupleCount = coupleDaySum != null ? coupleDaySum.LeaveCount : 0;
var coupleCount = coupleDay != null ? coupleDay.CountLeaveDay : 0;
var therapyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-011");
var therapyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-011");
var therapyDayCount = therapyDaySum != null ? therapyDaySum.LeaveDaysUsed : 0;
var therapyCount = therapyDaySum != null ? therapyDaySum.LeaveCount : 0;
var therapyCount = therapyDay != null ? therapyDay.CountLeaveDay : 0;
var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate);