cronjob + ลงเวลากรณีพิเดศษ
This commit is contained in:
parent
72f64728bb
commit
e76d994098
16 changed files with 1518 additions and 9 deletions
|
|
@ -23,6 +23,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire" Version="1.8.6" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.6" />
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
|
||||
<PackageReference Include="iTextSharp" Version="5.5.13.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9" />
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using BMA.EHR.Domain.Common;
|
|||
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Leave.Service.DTOs.AdditionalCheck;
|
||||
using BMA.EHR.Leave.Service.DTOs.ChangeRound;
|
||||
using BMA.EHR.Leave.Service.DTOs.CheckIn;
|
||||
using BMA.EHR.Leave.Service.DTOs.DutyTime;
|
||||
|
|
@ -38,6 +39,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly MinIOService _minIOService;
|
||||
private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository;
|
||||
private readonly UserDutyTimeRepository _userDutyTimeRepository;
|
||||
private readonly AdditionalCheckRequestRepository _additionalCheckRequestRepository;
|
||||
|
||||
private readonly string _bucketName = "check-in";
|
||||
|
||||
|
|
@ -54,7 +56,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
UserTimeStampRepository userTimeStampRepository,
|
||||
MinIOService minIOService,
|
||||
ProcessUserTimeStampRepository processUserTimeStampRepository,
|
||||
UserDutyTimeRepository userDutyTimeRepository)
|
||||
UserDutyTimeRepository userDutyTimeRepository,
|
||||
AdditionalCheckRequestRepository additionalCheckRequestRepository)
|
||||
{
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_context = context;
|
||||
|
|
@ -66,6 +69,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_minIOService = minIOService;
|
||||
_processUserTimeStampRepository = processUserTimeStampRepository;
|
||||
_userDutyTimeRepository = userDutyTimeRepository;
|
||||
_additionalCheckRequestRepository = additionalCheckRequestRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -714,7 +718,6 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> SearchProfileAsync([FromBody] SearchProfileDto req)
|
||||
{
|
||||
var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName);
|
||||
|
|
@ -798,7 +801,6 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> GetChangeRoundHistoryByProfileIdAsync(Guid id, int page = 1, int pageSize = 10, string keyword = "")
|
||||
{
|
||||
var data = await _userDutyTimeRepository.GetListByProfileIdAsync(id);
|
||||
|
|
@ -829,6 +831,41 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " ขอลงเวลาเป็นกรณีพิเศษ "
|
||||
|
||||
/// <summary>
|
||||
/// LV1_017 - เพิ่มลงเวลากรณีพิเศษ (USER)
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("user/edit")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> CreateAdditionalCheckRequestAsync([FromBody] CreateAdditionalCheckRequestDto req)
|
||||
{
|
||||
if (req.CheckDate.Date > DateTime.Now.Date)
|
||||
{
|
||||
return Error("ไม่สามารถขอลงเวลากรณีพิเศษในวันที่มากกว่าวันที่ปัจจุบันได้", (int)StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
var request = new AdditionalCheckRequest
|
||||
{
|
||||
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
|
||||
CheckDate = req.CheckDate,
|
||||
CheckInEdit = req.CheckInEdit,
|
||||
CheckOutEdit = req.CheckOutEdit,
|
||||
Description = req.Description,
|
||||
};
|
||||
await _additionalCheckRequestRepository.AddAsync(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
namespace BMA.EHR.Leave.Service.DTOs.AdditionalCheck
|
||||
{
|
||||
public class CreateAdditionalCheckRequestDto
|
||||
{
|
||||
public DateTime CheckDate { get; set; }
|
||||
|
||||
public bool CheckInEdit { get; set; }
|
||||
|
||||
public bool CheckOutEdit { get; set;}
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
15
BMA.EHR.Leave.Service/Filters/CustomAuthorizeFilter.cs
Normal file
15
BMA.EHR.Leave.Service/Filters/CustomAuthorizeFilter.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using Hangfire.Dashboard;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Filters
|
||||
{
|
||||
public class CustomAuthorizeFilter : IDashboardAuthorizationFilter
|
||||
{
|
||||
public bool Authorize([NotNull] DashboardContext context)
|
||||
{
|
||||
//var httpcontext = context.GetHttpContext();
|
||||
//return httpcontext.User.Identity.IsAuthenticated;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using BMA.EHR.Application;
|
||||
using BMA.EHR.Application;
|
||||
using BMA.EHR.Leave.Service;
|
||||
using BMA.EHR.Domain.Middlewares;
|
||||
using BMA.EHR.Infrastructure;
|
||||
|
|
@ -15,6 +15,12 @@ using Serilog.Exceptions;
|
|||
using Serilog.Sinks.Elasticsearch;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Hangfire;
|
||||
using Hangfire.MySql;
|
||||
using System.Transactions;
|
||||
using BMA.EHR.Leave.Service.Filters;
|
||||
using Hangfire.Common;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
|
|
@ -93,6 +99,29 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
// Add Hangfire services.
|
||||
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
builder.Services.AddHangfire(configuration => configuration
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseStorage(
|
||||
new MySqlStorage(
|
||||
defaultConnection,
|
||||
new MySqlStorageOptions
|
||||
{
|
||||
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
|
||||
QueuePollInterval = TimeSpan.FromSeconds(15),
|
||||
JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
||||
CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
||||
PrepareSchemaIfNecessary = true,
|
||||
DashboardJobListLimit = 50000,
|
||||
TransactionTimeout = TimeSpan.FromMinutes(1),
|
||||
TablesPrefix = "Hangfire"
|
||||
})));
|
||||
builder.Services.AddHangfireServer();
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
|
|
@ -124,6 +153,18 @@ var app = builder.Build();
|
|||
app.MapControllers();
|
||||
app.UseMiddleware<ErrorHandlerMiddleware>();
|
||||
|
||||
|
||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
||||
{
|
||||
Authorization = new[] { new CustomAuthorizeFilter() }
|
||||
});
|
||||
|
||||
var manager = new RecurringJobManager();
|
||||
if (manager != null)
|
||||
{
|
||||
manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression<UserDutyTimeRepository>(x => x.UpdateUserDutyTime()), Cron.Daily(6, 0), TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
// apply migrations
|
||||
await using var scope = app.Services.CreateAsyncScope();
|
||||
await using var db = scope.ServiceProvider.GetRequiredService<LeaveDbContext>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue