แก้ defect

add send noti when create ลงเวลากรณีพิเศษ
This commit is contained in:
Suphonchai Phoonsawat 2024-01-17 12:42:19 +07:00
parent bb637bca36
commit ee4ef41547
8 changed files with 144 additions and 12 deletions

View file

@ -2,6 +2,7 @@
using BMA.EHR.Domain.Models.Base;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.IO.Pipes;
using System.Security.Claims;
namespace BMA.EHR.Application.Repositories.Leaves
@ -24,7 +25,6 @@ namespace BMA.EHR.Application.Repositories.Leaves
_dbContext = dbContext;
_dbSet = _dbContext.Set<T>();
_httpContextAccessor = httpContextAccessor;
}
#endregion

View file

@ -146,7 +146,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
return await rawData.ToListAsync();
}
public async Task<List<LeaveRequest>> GetLeaveRequestForAdminAsync(int year, Guid type, string status)
public async Task<List<LeaveRequest>> GetLeaveRequestForAdminAsync(int year, Guid type, string status, DateTime startDate, DateTime endDate)
{
var rawData = _dbContext.Set<LeaveRequest>()
.Include(x => x.Type)
@ -164,6 +164,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
if (status.Trim().ToUpper() != "ALL")
rawData = rawData.Where(x => x.LeaveStatus == status);
if (startDate != DateTime.MinValue)
rawData = rawData.Where(x => x.LeaveStartDate >= startDate);
if (endDate != DateTime.MinValue)
rawData = rawData.Where(x => x.LeaveEndDate <= endDate);
return await rawData.ToListAsync();
}
@ -570,7 +576,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
.Include(x => x.Type)
.Where(x => x.KeycloakUserId == keycloakUserId)
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
.Where(x => x.LeaveStatus == "DELETE" && x.LeaveStatus == "REJECT")
.Where(x => x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING" || x.LeaveStatus == "APPROVE")
.ToListAsync();
return data.Count > 0;

View file

@ -1,6 +1,9 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using BMA.EHR.Domain.Models.Notifications;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@ -18,6 +21,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
private readonly UserProfileRepository _userProfileRepository;
private readonly IConfiguration _configuration;
private readonly EmailSenderService _emailSenderService;
private readonly IApplicationDBContext _appContext;
private readonly CommandRepository _commandRepository;
#endregion
@ -28,7 +33,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
EmailSenderService emailSenderService,
IApplicationDBContext appContext,
CommandRepository commandRepository) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
@ -36,6 +43,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
_userProfileRepository = userProfileRepository;
_configuration = configuration;
_emailSenderService = emailSenderService;
_appContext = appContext;
_commandRepository = commandRepository;
}
#endregion
@ -57,6 +66,57 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
#region " Methods "
public override async Task<AdditionalCheckRequest> AddAsync(AdditionalCheckRequest entity)
{
await base.AddAsync(entity);
var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty;
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
var profile_id = profile == null ? Guid.Empty : profile.Id;
var rootOc = _userProfileRepository.GetRootOcId(profile_id);
var approver = string.Empty;
var list = new List<OrganizationApproverResponse>();
if (rootOc != null)
{
list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
}
if (list.Count > 0)
{
var appr = list.FirstOrDefault();
// send inbox and notification
var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ";
var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
var subject = subject_str;
var body = body_str;
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = subject_str,
Body = body_str,
ReceiverUserId = appr.Id,
Payload = "",
};
_appContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = body_str,
ReceiverUserId = appr.Id,
Type = "",
Payload = "",
};
_appContext.Set<Notification>().Add(noti);
await _appContext.SaveChangesAsync();
}
return entity;
}
public async Task<List<AdditionalCheckRequest>> GetAdditionalCheckRequestsByUserId(Guid keycloakId, int year, int month)
{
try

View file

@ -1,6 +1,7 @@
using System.Security.Cryptography.X509Certificates;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
@ -29,7 +30,29 @@ namespace BMA.EHR.Application.Repositories
#region " Methods "
public async Task<OrganizationEntity?> GetOrganizationById(Guid id)
{
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
return data;
}
public async Task<OrganizationAgency?> GetOrgAgencyById(Guid id)
{
var data = await _dbContext.Set<OrganizationAgency>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
return data;
}
public async Task<OrganizationGovernmentAgency?> GetOrgGovAgencyById(Guid id)
{
var data = await _dbContext.Set<OrganizationGovernmentAgency>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
return data;
}
public async Task<Profile?> GetProfileByKeycloakIdAsync(Guid keycloakId)
{

View file

@ -1,5 +1,7 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using BMA.EHR.Domain.Shared;
@ -41,6 +43,8 @@ namespace BMA.EHR.Leave.Service.Controllers
private readonly UserCalendarRepository _userCalendarRepository;
private readonly CommandRepository _commandRepository;
private readonly string _bucketName = "check-in";
#endregion
@ -58,7 +62,8 @@ namespace BMA.EHR.Leave.Service.Controllers
ProcessUserTimeStampRepository processUserTimeStampRepository,
UserDutyTimeRepository userDutyTimeRepository,
AdditionalCheckRequestRepository additionalCheckRequestRepository,
UserCalendarRepository userCalendarRepository)
UserCalendarRepository userCalendarRepository,
CommandRepository commandRepository)
{
_dutyTimeRepository = dutyTimeRepository;
_context = context;
@ -72,6 +77,7 @@ namespace BMA.EHR.Leave.Service.Controllers
_userDutyTimeRepository = userDutyTimeRepository;
_additionalCheckRequestRepository = additionalCheckRequestRepository;
_userCalendarRepository = userCalendarRepository;
_commandRepository = commandRepository;
}
#endregion
@ -1086,6 +1092,7 @@ namespace BMA.EHR.Leave.Service.Controllers
Description = req.Description,
};
await _additionalCheckRequestRepository.AddAsync(request);
return Success();
}

View file

@ -119,7 +119,7 @@ namespace BMA.EHR.Leave.Service.Controllers
var isDuplicate = await _leaveRequestRepository.CheckDuplicateLeave(userId, req.LeaveStartDate.Date, req.LeaveEndDate.Date);
if (isDuplicate)
{
return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้");
return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้ เนื่องจากมีการขอลาในช่วงเวลาดังกล่าวแล้ว");
}
var thisYear = DateTime.Now.Year;
@ -980,13 +980,24 @@ namespace BMA.EHR.Leave.Service.Controllers
public async Task<ActionResult<ResponseObject>> GetLeaveRequestForAdminAsync(
[FromBody] GetLeaveRequestForAdminDto req)
{
var rawData = await _leaveRequestRepository.GetLeaveRequestForAdminAsync(req.Year, req.Type, req.Status);
var rawData = await _leaveRequestRepository.GetLeaveRequestForAdminAsync(req.Year, req.Type, req.Status, req.StartDate, req.EndDate);
var result = new List<GetLeaveRequestForAdminResultDto>();
foreach (var item in rawData)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId);
// Get Organization
var org = await _userProfileRepository.GetOrganizationById(profile.OcId ?? Guid.Empty);
var agency_id = org == null ? Guid.Empty : org.OrganizationAgencyId ?? Guid.Empty;
var gov_agency_id = org == null ? Guid.Empty : org.OrganizationGovernmentAgencyId ?? Guid.Empty;
var agency = await _userProfileRepository.GetOrgAgencyById(agency_id);
var gov_agency = await _userProfileRepository.GetOrgGovAgencyById(gov_agency_id);
var res = new GetLeaveRequestForAdminResultDto
{
Id = item.Id,
@ -994,7 +1005,14 @@ namespace BMA.EHR.Leave.Service.Controllers
LeaveTypeName = item.Type.Name,
FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}",
DateSendLeave = item.CreatedAt.Date,
Status = item.LeaveStatus
Status = item.LeaveStatus,
CitizenId = profile.CitizenId ?? "",
LeaveStartDate = item.LeaveStartDate,
LeaveEndDate = item.LeaveEndDate,
Position = profile.Position == null ? "" : profile.Position.Name,
Level = profile.PositionLevel == null ? "" : profile.PositionLevel.Name,
Agency = agency == null ? "" : agency.Name,
Org = gov_agency == null ? "" : gov_agency.Name
};
result.Add(res);
}
@ -1524,17 +1542,17 @@ namespace BMA.EHR.Leave.Service.Controllers
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("user/file/document/{id:guid}")]
[HttpDelete("user/file/document/{id:guid}/{docId:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> DeleteLeaveDocumentByIdAsync(Guid id, [FromBody] DeleteLeaveDocumentDto req)
public async Task<ActionResult<ResponseObject>> DeleteLeaveDocumentByIdAsync(Guid id, Guid docId)
{
var leaveReq = await _leaveRequestRepository.GetByIdAsync(id);
if (leaveReq == null)
return Error(GlobalMessages.DataNotFound);
var doc = leaveReq.LeaveDocument.Where(x => x.Document.Id == req.DocId).FirstOrDefault();
var doc = leaveReq.LeaveDocument.Where(x => x.Document.Id == docId).FirstOrDefault();
if (doc != null)
{
await _minIOService.DeleteFileAsync(doc.Document.Id);

View file

@ -21,5 +21,9 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
public int PageSize { get; set; } = 10;
public string Keyword { get; set; } = string.Empty;
public DateTime StartDate { get; set; } = DateTime.MinValue;
public DateTime EndDate { get; set; } = DateTime.MinValue;
}
}

View file

@ -12,6 +12,20 @@
public DateTime DateSendLeave { get; set; } = DateTime.MinValue;
public string Status { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string CitizenId { get; set; } = string.Empty;
public DateTime LeaveStartDate { get; set; } = DateTime.MinValue;
public DateTime LeaveEndDate { get; set; } = DateTime.MinValue;
public string Agency { get; set; } = string.Empty;
public string Org { get; set; } = string.Empty;
public string Position { get; set; } = string.Empty;
public string Level { get; set; } = string.Empty;
}
}