LV1_006 - เช็คเวลาต้องลงเวลาเข้าหรือออกงาน (USER)

This commit is contained in:
Suphonchai Phoonsawat 2023-11-10 14:40:53 +07:00
parent c9f68b045b
commit 065314fd6c
20 changed files with 967 additions and 258 deletions

View file

@ -1,7 +1,7 @@
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Repositories.Leaves;
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Repositories.Reports;
using Microsoft.Extensions.DependencyInjection;
@ -36,6 +36,7 @@ namespace BMA.EHR.Application
services.AddTransient<MinIOExamService>();
services.AddTransient<DutyTimeRepository>();
services.AddTransient<UserTimeStampRepository>();
return services;
}

View file

@ -1,11 +1,11 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.Leave;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BMA.EHR.Application.Repositories.Leaves
namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
{
public class DutyTimeRepository : GenericRepository<Guid, DutyTime>
{
@ -61,6 +61,11 @@ namespace BMA.EHR.Application.Repositories.Leaves
return await _dbContext.Set<DutyTime>().Where(x => x.IsActive).ToListAsync();
}
public async Task<DutyTime?> GetDefaultAsync()
{
return await _dbContext.Set<DutyTime>().Where(x => x.IsDefault).FirstOrDefaultAsync();
}
#endregion
}
}

View file

@ -0,0 +1,71 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
{
public class UserTimeStampRepository : GenericRepository<Guid, UserTimeStamp>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
private readonly IConfiguration _configuration;
private readonly EmailSenderService _emailSenderService;
#endregion
#region " Constructor and Destuctor "
public UserTimeStampRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
_configuration = configuration;
_emailSenderService = emailSenderService;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId)
{
var data = await _dbContext.Set<UserTimeStamp>()
.Where(u => u.KeycloakUserId == keycloakId)
.OrderByDescending(u => u.CheckIn)
.FirstOrDefaultAsync();
return data;
}
#endregion
}
}

View file

@ -315,6 +315,40 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task UploadFileAsync(string fileName, string subFolder)
{
try
{
var fileContents = File.ReadAllBytes(fileName);
System.IO.MemoryStream filestream = new System.IO.MemoryStream(fileContents);
//var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
var fileExt = Path.GetExtension(fileName);
var fileType = MimeTypeMap.GetMimeType(fileExt);
var file_name = Path.GetFileName(fileName);
Console.WriteLine($"{_bucketName}{subFolder}");
Console.WriteLine(fileName);
Console.WriteLine(file_name);
Console.WriteLine(filestream);
Console.WriteLine(fileType);
var request = new PutObjectRequest
{
//BucketName = $"{_bucketName}",
BucketName = $"{_bucketName}{subFolder}",
Key = file_name,
InputStream = filestream,
ContentType = fileType,
CannedACL = S3CannedACL.PublicRead
};
await _s3Client.PutObjectAsync(request);
}
catch
{
throw;
}
}
public async Task GenerateJsonFile(string json, string path, string fileName)
{
var tmpDir = Path.Combine("tmp");