Compare commits
55 commits
leave-dev1
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2fe424b87 | ||
|
|
5021c00dd3 | ||
|
|
bf5dc2cf19 | ||
|
|
f6c8b4f754 | ||
|
|
65ca175f98 | ||
|
|
5f678b2898 | ||
|
|
ae417e4777 | ||
|
|
a2dc4b5b82 | ||
|
|
c55648a3cc | ||
|
|
bc29952e83 | ||
|
|
f4f56b1c21 | ||
|
|
baf828ac85 | ||
|
|
be1f6dd84e | ||
|
|
fcea84bdb8 | ||
|
|
5d090fa7bd | ||
|
|
030098c0b9 | ||
|
|
6843e3ff3f | ||
|
|
2cdae3578e | ||
|
|
71966eb4e9 | ||
|
|
e926866918 | ||
|
|
35179d8cfc | ||
|
|
4a8d349415 | ||
|
|
7d2be029b6 | ||
|
|
d75cf39d7b | ||
|
|
db3d531aa9 | ||
|
|
e17895de81 | ||
|
|
e09a6d0ea6 | ||
|
|
4c44bdf237 | ||
| 6f1ca58f04 | |||
| a956f0b0dd | |||
|
|
f0c493a026 | ||
|
|
fe5c2cd7c1 | ||
|
|
c4209400ff | ||
|
|
d6a7f1a5ca | ||
|
|
f50efc632b | ||
| 5f9c49f479 | |||
| 48aab28e04 | |||
| 1f7951dc4c | |||
|
|
d3a174faa0 | ||
|
|
afa5c85393 | ||
| 077b60b1c3 | |||
| efc96dfb6d | |||
|
|
4827906d1d | ||
|
|
8ae822d05b | ||
|
|
71a4748d39 | ||
|
|
ad70043264 | ||
|
|
513956c861 | ||
|
|
a48f3fa804 | ||
|
|
dc5ac329e2 | ||
|
|
3f98e07419 | ||
| ce4558c240 | |||
| 6a38f000ba | |||
|
|
f50ad38503 | ||
| aeb2ceea6f | |||
| e96f606c85 |
37 changed files with 2971 additions and 1066 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -374,3 +374,9 @@ MigrationBackup/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code C# Dev Kit cache
|
||||||
|
*.lscache
|
||||||
|
|
||||||
|
# Claude Code
|
||||||
|
.claude/
|
||||||
|
|
@ -9,6 +9,7 @@ using BMA.EHR.Domain.Shared;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +24,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly EmailSenderService _emailSenderService;
|
private readonly EmailSenderService _emailSenderService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keyed locks to serialize get-or-create for LeaveBeginning rows by (ProfileId, LeaveYear, LeaveTypeId).
|
||||||
|
/// Prevents duplicate inserts when concurrent requests (e.g. UI calling /user/check twice) hit the same key.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly ConcurrentDictionary<string, SemaphoreSlim> _getOrAddLocks = new();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Constructor and Destuctor "
|
#region " Constructor and Destuctor "
|
||||||
|
|
@ -121,6 +128,30 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task ProcessEarlyLeaveRequest(int year)
|
||||||
|
{
|
||||||
|
// Get Early Leave Request (กรองตามปีงบประมาณ: 1 ต.ค. (year-1) – 30 ก.ย. (year))
|
||||||
|
var fiscalStart = new DateTime(year - 1, 10, 1);
|
||||||
|
var fiscalEnd = new DateTime(year, 9, 30);
|
||||||
|
|
||||||
|
var leaveReq = await _dbContext.Set<LeaveRequest>()
|
||||||
|
.Include(x => x.Type)
|
||||||
|
.Where(x => x.LeaveStatus == "APPROVE")
|
||||||
|
.Where(x => x.LeaveStartDate.Date <= fiscalEnd && x.LeaveEndDate.Date >= fiscalStart)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var leave in leaveReq)
|
||||||
|
{
|
||||||
|
await GetByYearAndTypeIdForUserWithUpdateAsync(year, leave.Type.Id, leave.KeycloakUserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ProcessEarlyLeaveRequestSchedule()
|
||||||
|
{
|
||||||
|
int year = DateTime.Now.Year;
|
||||||
|
await ProcessEarlyLeaveRequest(year);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserAsync(int year, Guid typeId, Guid userId)
|
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserAsync(int year, Guid typeId, Guid userId)
|
||||||
{
|
{
|
||||||
// var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
// var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
||||||
|
|
@ -134,22 +165,22 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||||
|
|
||||||
var data = await _dbContext.Set<LeaveBeginning>()
|
LeaveBeginning Factory()
|
||||||
.Include(x => x.LeaveType)
|
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
|
||||||
|
|
||||||
if (data == null)
|
|
||||||
{
|
{
|
||||||
var limit = 0.0;
|
var limit = 0.0;
|
||||||
|
|
||||||
var prev = await _dbContext.Set<LeaveBeginning>()
|
var prev = _dbContext.Set<LeaveBeginning>()
|
||||||
.Include(x => x.LeaveType)
|
.Include(x => x.LeaveType)
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
.FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
||||||
|
|
||||||
|
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||||
|
var isCurrentYear = DateTime.Now.Year == year;
|
||||||
|
|
||||||
|
|
||||||
var prevRemain = 0.0;
|
var prevRemain = 0.0;
|
||||||
if (prev != null)
|
if (prev != null)
|
||||||
{
|
{
|
||||||
prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0);
|
prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (govAge >= 180)
|
if (govAge >= 180)
|
||||||
|
|
@ -170,7 +201,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
limit = 0.0;
|
limit = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new LeaveBeginning
|
return new LeaveBeginning
|
||||||
{
|
{
|
||||||
LeaveYear = year,
|
LeaveYear = year,
|
||||||
LeaveTypeId = typeId,
|
LeaveTypeId = typeId,
|
||||||
|
|
@ -186,36 +217,110 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
Child3DnaId = pf.Child3DnaId,
|
Child3DnaId = pf.Child3DnaId,
|
||||||
Child4DnaId = pf.Child4DnaId
|
Child4DnaId = pf.Child4DnaId
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
_dbContext.Set<LeaveBeginning>().Add(data);
|
return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserWithUpdateAsync(int year, Guid typeId, Guid userId)
|
||||||
|
{
|
||||||
|
// var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
||||||
|
var pf = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken);
|
||||||
|
if (pf == null)
|
||||||
|
{
|
||||||
|
throw new Exception(GlobalMessages.DataNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
||||||
|
|
||||||
|
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||||
|
|
||||||
|
|
||||||
|
var limit = 0.0;
|
||||||
|
|
||||||
|
var prev = _dbContext.Set<LeaveBeginning>()
|
||||||
|
.Include(x => x.LeaveType)
|
||||||
|
.FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
||||||
|
|
||||||
|
var prevRemain = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (prev != null)
|
||||||
|
{
|
||||||
|
prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (govAge >= 180)
|
||||||
|
{
|
||||||
|
if (govAge >= 3650)
|
||||||
|
{
|
||||||
|
limit = 10 + prevRemain;
|
||||||
|
if (limit > 30) limit = 30;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
limit = 10 + prevRemain;
|
||||||
|
if (limit > 20) limit = 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
limit = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = await _dbContext.Set<LeaveBeginning>()
|
||||||
|
.Where(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
data.LeaveDays = leaveType?.Code == "LV-005" ? limit : 0;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return new LeaveBeginning
|
||||||
|
// {
|
||||||
|
// LeaveYear = year,
|
||||||
|
// LeaveTypeId = typeId,
|
||||||
|
// ProfileId = pf.Id,
|
||||||
|
// Prefix = pf.Prefix,
|
||||||
|
// FirstName = pf.FirstName,
|
||||||
|
// LastName = pf.LastName,
|
||||||
|
// LeaveDaysUsed = 0,
|
||||||
|
// LeaveDays = leaveType?.Code == "LV-005" ? limit : 0,
|
||||||
|
// RootDnaId = pf.RootDnaId,
|
||||||
|
// Child1DnaId = pf.Child1DnaId,
|
||||||
|
// Child2DnaId = pf.Child2DnaId,
|
||||||
|
// Child3DnaId = pf.Child3DnaId,
|
||||||
|
// Child4DnaId = pf.Child4DnaId
|
||||||
|
// };
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUser(int year, Guid typeId, GetProfileByKeycloakIdDto? pf)
|
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUser(int year, Guid typeId, GetProfileByKeycloakIdDto? pf)
|
||||||
{
|
{
|
||||||
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
||||||
|
|
||||||
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||||
|
|
||||||
var data = await _dbContext.Set<LeaveBeginning>()
|
LeaveBeginning Factory()
|
||||||
.Include(x => x.LeaveType)
|
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
|
||||||
|
|
||||||
if (data == null)
|
|
||||||
{
|
{
|
||||||
var limit = 0.0;
|
var limit = 0.0;
|
||||||
|
|
||||||
var prev = await _dbContext.Set<LeaveBeginning>()
|
var prev = _dbContext.Set<LeaveBeginning>()
|
||||||
.Include(x => x.LeaveType)
|
.Include(x => x.LeaveType)
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
.FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
||||||
|
|
||||||
|
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||||
|
var isCurrentYear = DateTime.Now.Year == year;
|
||||||
|
|
||||||
var prevRemain = 0.0;
|
var prevRemain = 0.0;
|
||||||
if (prev != null)
|
if (prev != null)
|
||||||
{
|
{
|
||||||
prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0);
|
prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (govAge >= 180)
|
if (govAge >= 180)
|
||||||
|
|
@ -236,7 +341,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
limit = 0.0;
|
limit = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new LeaveBeginning
|
return new LeaveBeginning
|
||||||
{
|
{
|
||||||
LeaveYear = year,
|
LeaveYear = year,
|
||||||
LeaveTypeId = typeId,
|
LeaveTypeId = typeId,
|
||||||
|
|
@ -252,12 +357,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
Child3DnaId = pf.Child3DnaId,
|
Child3DnaId = pf.Child3DnaId,
|
||||||
Child4DnaId = pf.Child4DnaId
|
Child4DnaId = pf.Child4DnaId
|
||||||
};
|
};
|
||||||
|
|
||||||
_dbContext.Set<LeaveBeginning>().Add(data);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUser2Async(int year, Guid typeId, Guid userId)
|
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUser2Async(int year, Guid typeId, Guid userId)
|
||||||
|
|
@ -273,22 +375,21 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||||
|
|
||||||
var data = await _dbContext.Set<LeaveBeginning>()
|
LeaveBeginning Factory()
|
||||||
.Include(x => x.LeaveType)
|
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
|
||||||
|
|
||||||
if (data == null)
|
|
||||||
{
|
{
|
||||||
var limit = 0.0;
|
var limit = 0.0;
|
||||||
|
|
||||||
var prev = await _dbContext.Set<LeaveBeginning>()
|
var prev = _dbContext.Set<LeaveBeginning>()
|
||||||
.Include(x => x.LeaveType)
|
.Include(x => x.LeaveType)
|
||||||
.FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
.FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
||||||
|
|
||||||
|
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||||
|
var isCurrentYear = DateTime.Now.Year == year;
|
||||||
|
|
||||||
var prevRemain = 0.0;
|
var prevRemain = 0.0;
|
||||||
if (prev != null)
|
if (prev != null)
|
||||||
{
|
{
|
||||||
prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0);
|
prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (govAge >= 180)
|
if (govAge >= 180)
|
||||||
|
|
@ -309,7 +410,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
limit = 0.0;
|
limit = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new LeaveBeginning
|
return new LeaveBeginning
|
||||||
{
|
{
|
||||||
LeaveYear = year,
|
LeaveYear = year,
|
||||||
LeaveTypeId = typeId,
|
LeaveTypeId = typeId,
|
||||||
|
|
@ -325,18 +426,60 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
Child3DnaId = pf.Child3DnaId,
|
Child3DnaId = pf.Child3DnaId,
|
||||||
Child4DnaId = pf.Child4DnaId
|
Child4DnaId = pf.Child4DnaId
|
||||||
};
|
};
|
||||||
|
|
||||||
_dbContext.Set<LeaveBeginning>().Add(data);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get-or-create a LeaveBeginning row for (ProfileId, LeaveYear, LeaveTypeId) with concurrency protection.
|
||||||
|
/// Uses a keyed SemaphoreSlim to serialize within-process requests, and re-queries after acquiring the lock.
|
||||||
|
/// If a cross-process insert wins (unique index violation), the duplicate key exception is caught and the row
|
||||||
|
/// created by the winner is returned.
|
||||||
|
/// </summary>
|
||||||
|
private async Task<LeaveBeginning?> GetOrAddForUserAsync(int year, Guid typeId, Guid profileId, Func<LeaveBeginning> factory)
|
||||||
|
{
|
||||||
|
var key = $"{profileId}_{year}_{typeId}";
|
||||||
|
var semaphore = _getOrAddLocks.GetOrAdd(key, _ => new SemaphoreSlim(1, 1));
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Re-query inside the lock — another thread may have created it while we waited.
|
||||||
|
var existing = await _dbContext.Set<LeaveBeginning>()
|
||||||
|
.Include(x => x.LeaveType)
|
||||||
|
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == profileId);
|
||||||
|
if (existing != null)
|
||||||
|
{
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = factory();
|
||||||
|
_dbContext.Set<LeaveBeginning>().Add(entity);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
// Cross-process/cross-server race hit the unique index (IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId).
|
||||||
|
// Detach the failed insert and return the row created by the winner.
|
||||||
|
_dbContext.Detach(entity);
|
||||||
|
var winner = await _dbContext.Set<LeaveBeginning>()
|
||||||
|
.Include(x => x.LeaveType)
|
||||||
|
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == profileId);
|
||||||
|
return winner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
semaphore.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<LeaveBeginning>> GetAllByYearAndTypeAsync(int year, Guid typeId, List<ProfileData> userIdList)
|
public async Task<List<LeaveBeginning>> GetAllByYearAndTypeAsync(int year, Guid typeId, List<ProfileData> userIdList)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var updateList = new List<LeaveBeginning>();
|
var updateList = new List<LeaveBeginning>();
|
||||||
var result = new List<LeaveBeginning>();
|
var result = new List<LeaveBeginning>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1935,14 +1935,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
|
// startDate/endDate คือขอบเขตปีงบประมาณ (fiscalStart/fiscalEnd) ที่ caller ส่งมา
|
||||||
|
// ใช้ LeaveStartDate เป็นหลักในการ filter เพื่อให้กรณียื่นลาล่วงหน้าข้ามปีงบประมาณ
|
||||||
|
// ถูกนับในปีงบประมาณของวันลาจริง (ไม่ใช้วันที่ยื่นลา)
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
@ -1952,14 +1955,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.ProfileId == profileId)
|
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
@ -1969,28 +1972,45 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.ProfileId == profileId)
|
.Where(x => x.ProfileId == profileId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
|
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (data.Count > 0)
|
||||||
|
return data.Sum(x => x.LeaveTotal);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
|
.Include(x => x.Type)
|
||||||
|
.Where(x => x.ProfileId == profileId)
|
||||||
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return data.Count;
|
return data.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
@ -2004,16 +2024,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
/// <param name="leaveTypeId"></param>
|
/// <param name="leaveTypeId"></param>
|
||||||
/// <param name="startDate"></param>
|
/// <param name="startDate"></param>
|
||||||
/// <param name="endDate"></param>
|
/// <param name="endDate"></param>
|
||||||
|
/// <param name="sendLeaveDate"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<double> GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<double> GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt).Date >= startDate
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
&& (x.DateSendLeave ?? x.CreatedAt).Date < endDate))
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
|
||||||
.Where(x => x.LeaveStatus == "DRAFT")
|
.Where(x => x.LeaveStatus == "DRAFT")
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
@ -2031,14 +2051,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
/// <param name="startDate"></param>
|
/// <param name="startDate"></param>
|
||||||
/// <param name="endDate"></param>
|
/// <param name="endDate"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<double> GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
public async Task<double> GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
.Include(x => x.Type)
|
.Include(x => x.Type)
|
||||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
.Where(x => x.Type.Id == leaveTypeId)
|
.Where(x => x.Type.Id == leaveTypeId)
|
||||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) < endDate))
|
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||||
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||||
.Where(x => (x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING"))
|
.Where(x => (x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING"))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,11 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<List<CheckInJobStatus>> GetStalePendingOrProcessingJobsAsync(int timeoutMinutes = 30)
|
public async Task<List<CheckInJobStatus>> GetStalePendingOrProcessingJobsAsync(int timeoutMinutes = 30)
|
||||||
{
|
{
|
||||||
|
//var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes);
|
||||||
var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes);
|
var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes);
|
||||||
var staleJobs = await _dbContext.Set<CheckInJobStatus>()
|
var staleJobs = await _dbContext.Set<CheckInJobStatus>()
|
||||||
.Where(x => (x.Status == "PENDING" || x.Status == "PROCESSING")
|
.Where(x => (x.Status == "PENDING" || x.Status == "PROCESSING")
|
||||||
&& x.CreatedDate < cutoffDate)
|
&& x.CreatedDate <= cutoffDate)
|
||||||
.OrderBy(x => x.CreatedDate)
|
.OrderBy(x => x.CreatedDate)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
@ -135,6 +136,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
public async Task<List<CheckInJobStatus>> GetStalePendingOrProcessingJobsByUserAsync(Guid userId, int timeoutMinutes = 30)
|
public async Task<List<CheckInJobStatus>> GetStalePendingOrProcessingJobsByUserAsync(Guid userId, int timeoutMinutes = 30)
|
||||||
{
|
{
|
||||||
var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes);
|
var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes);
|
||||||
|
//var cutoffDate = new DateTime(2026, 5, 28, 23, 59, 59);
|
||||||
var staleJobs = await _dbContext.Set<CheckInJobStatus>()
|
var staleJobs = await _dbContext.Set<CheckInJobStatus>()
|
||||||
.Where(x => x.KeycloakUserId == userId
|
.Where(x => x.KeycloakUserId == userId
|
||||||
&& (x.Status == "PENDING" || x.Status == "PROCESSING")
|
&& (x.Status == "PENDING" || x.Status == "PROCESSING")
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,44 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetMyProfileIdAsync()
|
||||||
|
{
|
||||||
|
var apiUrl = $"{_configuration["API"]}/org/dotnet/get-profileId";
|
||||||
|
var response = await GetExternalAPIAsync(apiUrl, AccessToken!, _configuration["API_KEY"]!);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(response))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
var org = JsonConvert.DeserializeObject<OrgRequest>(response);
|
||||||
|
if (org == null || org.result == null)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
return org.result.profileId ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAllMyNotificationsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var profileId = await GetMyProfileIdAsync();
|
||||||
|
if (string.IsNullOrEmpty(profileId))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var notifications = await _dbContext.Set<Notification>()
|
||||||
|
.Where(x => x.ReceiverUserId == Guid.Parse(profileId))
|
||||||
|
.Where(x => x.DeleteDate == null)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_dbContext.Set<Notification>().RemoveRange(notifications);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
return notifications.Count;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task PushNotificationAsync(Guid ReceiverUserId, string Subject, string Body, string Payload = "", string NotiLink = "", bool IsSendInbox = false, bool IsSendMail = false)
|
public async Task PushNotificationAsync(Guid ReceiverUserId, string Subject, string Body, string Payload = "", string NotiLink = "", bool IsSendInbox = false, bool IsSendMail = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,40 @@
|
||||||
using BMA.EHR.Domain.Models.Placement;
|
using BMA.EHR.Domain.Models.Placement;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories
|
namespace BMA.EHR.Application.Repositories
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Response model จาก Org API (check-isLeave)
|
||||||
|
/// </summary>
|
||||||
|
public class OrgProfileResult
|
||||||
|
{
|
||||||
|
public string citizenId { get; set; } = "";
|
||||||
|
public string? profileId { get; set; }
|
||||||
|
public bool isLeave { get; set; }
|
||||||
|
public bool isActive { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class PlacementRepository : GenericRepository<Guid, Placement>
|
public class PlacementRepository : GenericRepository<Guid, Placement>
|
||||||
{
|
{
|
||||||
#region " Fields "
|
#region " Fields "
|
||||||
|
|
||||||
private readonly IApplicationDBContext _dbContext;
|
private readonly IApplicationDBContext _dbContext;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Constructor and Destructor "
|
#region " Constructor and Destructor "
|
||||||
|
|
||||||
public PlacementRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
public PlacementRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor, IConfiguration configuration) : base(dbContext, httpContextAccessor)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -76,6 +92,148 @@ namespace BMA.EHR.Application.Repositories
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Job อัพเดทสถานะผู้สอบผ่านที่ลาออกไปแล้วแต่ยังไม่ส่งไปออกคำสั่ง
|
||||||
|
/// และอัพเดทบุคคลภายนอกที่เข้ามาอยู่ในระบบแล้ว
|
||||||
|
/// ทำงานทุกวันเวลา 05:00 น.
|
||||||
|
/// </summary>
|
||||||
|
public async Task UpdateStatusPlacementProfiles()
|
||||||
|
{
|
||||||
|
Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === STARTED ===");
|
||||||
|
|
||||||
|
// 1. Query ทั้ง 2 กรณี: ทุกคนที่ยังไม่ DONE
|
||||||
|
var allCitizenIds = await _dbContext.Set<PlacementProfile>()
|
||||||
|
.Where(p => !string.IsNullOrEmpty(p.CitizenId)
|
||||||
|
&& p.PlacementStatus != "DONE"
|
||||||
|
// && p.CitizenId == "2536721883131"
|
||||||
|
)
|
||||||
|
.Select(p => new { p.CitizenId, p.IsOfficer })
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (!allCitizenIds.Any())
|
||||||
|
{
|
||||||
|
Console.WriteLine("[Job:UpdateStatusPlacementProfiles] No profiles to process");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var officerCount = allCitizenIds.Count(x => x.IsOfficer == true);
|
||||||
|
var notOfficerCount = allCitizenIds.Count(x => x.IsOfficer == false);
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบข้าราชการ {officerCount} คน, บุคคลภายนอก {notOfficerCount} คน");
|
||||||
|
|
||||||
|
// 2. ส่ง citizenIds ทั้งหมดไป Org API ครั้งเดียว
|
||||||
|
var citizenIds = allCitizenIds.Select(x => x.CitizenId).Distinct().ToList();
|
||||||
|
var apiUrl = $"{_configuration["API"]}/org/dotnet/check-isLeave";
|
||||||
|
|
||||||
|
List<OrgProfileResult> orgResults = new();
|
||||||
|
|
||||||
|
using (var client = new HttpClient())
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
|
||||||
|
var payload = new { citizenIds };
|
||||||
|
var jsonPayload = JsonConvert.SerializeObject(payload);
|
||||||
|
var content = new StringContent(jsonPayload, System.Text.Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await client.PostAsync(apiUrl, content);
|
||||||
|
var result = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
var responseObj = JsonConvert.DeserializeAnonymousType(result, new
|
||||||
|
{
|
||||||
|
status = 0,
|
||||||
|
message = "",
|
||||||
|
result = new List<OrgProfileResult>()
|
||||||
|
});
|
||||||
|
|
||||||
|
orgResults = responseObj?.result ?? new();
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Org API ตอบกลับ {orgResults.Count} รายการ");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Call API failed: {ex.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!orgResults.Any())
|
||||||
|
{
|
||||||
|
Console.WriteLine("[Job:UpdateStatusPlacementProfiles] ไม่มีรายการต้องอัปเดต");
|
||||||
|
Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === COMPLETED ===");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. แยกข้อมูลตามเงื่อนไข
|
||||||
|
var leaveCitizenIds = orgResults.Where(x => x.isLeave).Select(x => x.citizenId).ToList();
|
||||||
|
var inSystemProfiles = orgResults.Where(x => x.isActive && !x.isLeave && !string.IsNullOrEmpty(x.profileId)).ToList();
|
||||||
|
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] ลาออก {leaveCitizenIds.Count} รายการ, อยู่ที่ทะเบียนประวัติ {inSystemProfiles.Count} รายการ");
|
||||||
|
|
||||||
|
// 4. Split Batch Update (500 รายการ/batch)
|
||||||
|
var batchSize = 500;
|
||||||
|
var totalUpdated = 0;
|
||||||
|
|
||||||
|
// 4.1 Update คนลาออก → IsOfficer = false
|
||||||
|
if (leaveCitizenIds.Any())
|
||||||
|
{
|
||||||
|
var totalBatches = (int)Math.Ceiling((double)leaveCitizenIds.Count / batchSize);
|
||||||
|
for (int i = 0; i < totalBatches; i++)
|
||||||
|
{
|
||||||
|
var batch = leaveCitizenIds.Skip(i * batchSize).Take(batchSize).ToList();
|
||||||
|
|
||||||
|
var profilesToUpdate = await _dbContext.Set<PlacementProfile>()
|
||||||
|
.Where(p => !string.IsNullOrEmpty(p.CitizenId)
|
||||||
|
&& batch.Contains(p.CitizenId)
|
||||||
|
&& p.IsOfficer == true)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var profile in profilesToUpdate)
|
||||||
|
{
|
||||||
|
profile.profileId = null;
|
||||||
|
profile.IsOfficer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
totalUpdated += profilesToUpdate.Count;
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] [ลาออก] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4.2 Update คนที่อยู่ในทะเบียนประวัติ → profileId + IsOfficer = true
|
||||||
|
if (inSystemProfiles.Any())
|
||||||
|
{
|
||||||
|
var totalBatches = (int)Math.Ceiling((double)inSystemProfiles.Count / batchSize);
|
||||||
|
for (int i = 0; i < totalBatches; i++)
|
||||||
|
{
|
||||||
|
var batch = inSystemProfiles.Skip(i * batchSize).Take(batchSize).ToList();
|
||||||
|
var batchCitizenIds = batch.Select(x => x.citizenId).ToList();
|
||||||
|
|
||||||
|
var profilesToUpdate = await _dbContext.Set<PlacementProfile>()
|
||||||
|
.Where(p => !string.IsNullOrEmpty(p.CitizenId)
|
||||||
|
&& batchCitizenIds.Contains(p.CitizenId)
|
||||||
|
&& p.IsOfficer == false)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var profile in profilesToUpdate)
|
||||||
|
{
|
||||||
|
var orgProfile = batch.FirstOrDefault(x => x.citizenId == profile.CitizenId);
|
||||||
|
if (orgProfile != null)
|
||||||
|
{
|
||||||
|
profile.profileId = orgProfile.profileId;
|
||||||
|
profile.IsOfficer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
totalUpdated += profilesToUpdate.Count;
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] [เข้าระบบ] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] อัปเดตรวมทั้งหมด {totalUpdated} รายการ");
|
||||||
|
Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === COMPLETED ===");
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1062,6 +1062,42 @@ namespace BMA.EHR.Application.Repositories
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<GetProfileByKeycloakIdRootDto>> GetEmployeeByAdminRolev2(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var apiPath = $"{_configuration["API"]}/org/dotnet/employee-by-admin-rolev2";
|
||||||
|
var apiKey = _configuration["API_KEY"];
|
||||||
|
var body = new
|
||||||
|
{
|
||||||
|
node = node,
|
||||||
|
nodeId = nodeId,
|
||||||
|
role = role,
|
||||||
|
// isRetirement
|
||||||
|
reqNode = reqNode,
|
||||||
|
reqNodeId = reqNodeId,
|
||||||
|
date = endDate
|
||||||
|
};
|
||||||
|
Console.WriteLine(body);
|
||||||
|
|
||||||
|
var profiles = new List<SearchProfileDto>();
|
||||||
|
|
||||||
|
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
|
||||||
|
if (apiResult != null)
|
||||||
|
{
|
||||||
|
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
|
||||||
|
if (raw != null)
|
||||||
|
return raw.Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new List<GetProfileByKeycloakIdRootDto>();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<GetProfileByKeycloakIdRootAddTotalDto> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node,string? selectedNodeId,int? selectedNode )
|
public async Task<GetProfileByKeycloakIdRootAddTotalDto> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node,string? selectedNodeId,int? selectedNode )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
24
BMA.EHR.CheckInConsumer/.dockerignore
Normal file
24
BMA.EHR.CheckInConsumer/.dockerignore
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Build artifacts
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
|
||||||
|
# IDE / tooling
|
||||||
|
Properties/
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Source control
|
||||||
|
.git/
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.md
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
83
BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md
Normal file
83
BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
# สรุปการปรับปรุงระบบลงเวลา (CheckInConsumer)
|
||||||
|
|
||||||
|
วันที่แก้ไข: 23 มิถุนายน 2026
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ปัญหาเดิม
|
||||||
|
|
||||||
|
ตอนที่พนักงานลงเวลาพร้อมกันจำนวนมาก (ประมาณ 2,000 รายการ) ระบบประมวลผลทีละรายการ ทำให้ต้องรอคิวนานถึง **22 นาที** กว่าจะประมวลผลเสร็จทั้งหมด
|
||||||
|
|
||||||
|
เปรียบเทียบเหมือน **โต๊ะบัญชี 1 คน รับคิวทีละคน** ทั้งที่มีคนรอ 2,000 คน → คิวยาวมาก
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## วิธีที่แก้ (เข้าใจง่าย ๆ)
|
||||||
|
|
||||||
|
### 1. เพิ่มคนช่วยประมวลผลพร้อมกัน (Concurrency)
|
||||||
|
- **ก่อน:** ประมวลผลทีละรายการ (เหมือนมีโต๊ะบัญชี 1 โต๊ะ)
|
||||||
|
- **หลัง:** ประมวลผลพร้อมกันได้สูงสุด **5 รายการ** (เหมือนเปิดโต๊ะบัญชี 5 โต๊ะ)
|
||||||
|
|
||||||
|
> ผลที่ได้: เวลารอคิวลดลงจาก **22 นาที → ประมาณ 4–5 นาที**
|
||||||
|
|
||||||
|
### 2. จัดคิวล่วงหน้าให้ RabbitMQ (Prefetch)
|
||||||
|
- **ก่อน:** ระบบดึงข้อมูลมาทีละชิ้น ทำให้เสียเวลารอส่งต่อ
|
||||||
|
- **หลัง:** ระบบดึงข้อมูลมาเป็นชุด ๆ ละ 20 ชิ้นไว้เตรียมพร้อม → ลดเวลารอระหว่างรายการ
|
||||||
|
|
||||||
|
### 3. ลดเวลารอเมื่อ API มีปัญหา (Timeout)
|
||||||
|
- **ก่อน:** ถ้า API ค้าง ระบบจะรอนานถึง **5 นาที** ต่อรายการ
|
||||||
|
- **หลัง:** ลดเหลือ **1 นาที** → รายการที่มีปัญหาจะถูกปฏิเสธเร็วขึ้น ไม่ทำให้คิวค้าง
|
||||||
|
|
||||||
|
### 4. ปรับปรุงการเชื่อมต่อ HTTP
|
||||||
|
- เปลี่ยนระบบเชื่อมต่อให้รองรับการส่งคำขอหลายรายการพร้อมกันโดยไม่สะดุด
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ตัวเลขเปรียบเทียบ
|
||||||
|
|
||||||
|
| รายการ | ก่อนแก้ | หลังแก้ |
|
||||||
|
|---|---|---|
|
||||||
|
| จำนวนรายการที่ประมวลผลพร้อมกัน | 1 | 5 |
|
||||||
|
| เวลารอคิวสูงสุด (2,000 รายการ) | ~22 นาที | ~4–5 นาที |
|
||||||
|
| เวลารอเมื่อ API มีปัญหา | 5 นาที | 1 นาที |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ไฟล์ที่แก้ไข
|
||||||
|
|
||||||
|
1. **`Program.cs`** — โค้ดหลักของตัวประมวลผลคิว
|
||||||
|
2. **`appsettings.json`** — ไฟล์ตั้งค่าระบบ
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## วิธีปรับความเร็วเพิ่มเติม (ไม่ต้องเขียนโค้ดใหม่)
|
||||||
|
|
||||||
|
ถ้าหลังทดสอบแล้วเห็นว่าระบบรับได้ และอยากให้เร็วขึ้นอีก ให้แก้ไขไฟล์ `appsettings.json` แล้ว restart โปรแกรมได้เลย:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"MaxConcurrency": 10, ← เพิ่มจาก 5 เป็น 10 (ประมวลผลพร้อมกัน 10 รายการ)
|
||||||
|
"PrefetchCount": 50, ← ควรตั้งเป็น ประมาณ MaxConcurrency × 2 ขึ้นไป
|
||||||
|
"HttpTimeoutSeconds": 60 ← เวลารอ API วินาที
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**ค่าที่ใช้และผลที่คาดการณ์:**
|
||||||
|
- `MaxConcurrency = 5` → ใช้เวลา ~4–5 นาที (ค่าเริ่มต้นปลอดภัย)
|
||||||
|
- `MaxConcurrency = 10` → ใช้เวลา ~2–3 นาที
|
||||||
|
- `MaxConcurrency = 20` → ใช้เวลา ~1–2 นาที (ต้องตรวจสอบว่าระบบหลังบ้านรับไหวก่อน)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ข้อควรระวัง / คำแนะนำ
|
||||||
|
|
||||||
|
1. **ควรทดสอบในระบบทดสอบก่อน** โดยดูว่า
|
||||||
|
- ไม่มี error ในระบบหลัก (API)
|
||||||
|
- ฐานข้อมูลไม่ช้าผิดปกติ
|
||||||
|
- ไม่พบปัญหาลงเวลาซ้ำซ้อน
|
||||||
|
|
||||||
|
2. ถ้าพบปัญหา เช่น
|
||||||
|
- มี error ใน API → **ลด** `MaxConcurrency` เหลือ 2 หรือ 3
|
||||||
|
- ลงเวลาซ้ำ → แจ้งทีมเทคนิคเพื่อแก้ฝั่ง API เพิ่มเติม
|
||||||
|
|
||||||
|
3. **ค่า `MaxConcurrency = 5` เป็นค่าปลอดภัย** เพราะระบบ API ด้านหลังยังมีข้อจำกัดอยู่บางส่วน หากต้องการเพิ่มให้สูงกว่านี้ (เช่น 20–50) ควรปรึกษาทีมเทคนิคเพื่อปรับปรุงฝั่ง API ก่อน
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
## See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
## See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
#
|
#
|
||||||
## This stage is used when running from VS in fast mode (Default for Debug configuration)
|
## This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||||
#FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
|
#FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#ARG BUILD_CONFIGURATION=Release
|
#ARG BUILD_CONFIGURATION=Release
|
||||||
#RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
#RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
#
|
#
|
||||||
|
|
||||||
## This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
## This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||||
#FROM base AS final
|
#FROM base AS final
|
||||||
#WORKDIR /app
|
#WORKDIR /app
|
||||||
|
|
@ -29,30 +30,25 @@
|
||||||
|
|
||||||
|
|
||||||
# ใช้ official .NET SDK image สำหรับการ build
|
# ใช้ official .NET SDK image สำหรับการ build
|
||||||
|
# Note: Build context = repository root (ตามที่ GitHub Actions ใช้)
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
|
||||||
# กำหนด working directory ภายใน container
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# คัดลอกไฟล์ .csproj และ restore dependencies
|
# copy เฉพาะ .csproj ก่อน เพื่อใช้ layer caching (restore เร็ว เก็บ cache นาน)
|
||||||
# COPY *.csproj ./
|
COPY BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj ./BMA.EHR.CheckInConsumer/
|
||||||
COPY . ./
|
WORKDIR /src/BMA.EHR.CheckInConsumer
|
||||||
RUN dotnet restore
|
RUN dotnet restore "BMA.EHR.CheckInConsumer.csproj"
|
||||||
|
|
||||||
# คัดลอกไฟล์ทั้งหมดและ build
|
# คัดลอก source ที่เหลือแล้ว publish
|
||||||
COPY . ./
|
COPY BMA.EHR.CheckInConsumer/ ./
|
||||||
RUN dotnet build -c Release -o /app/build
|
RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||||
# WORKDIR "/src/BMA.EHR.CheckInConsumer"
|
|
||||||
# RUN dotnet build "BMA.EHR.CheckInConsumer.csproj" -c Release -o /app/build
|
|
||||||
|
|
||||||
# ใช้ stage ใหม่สำหรับการ runtime
|
# ใช้ stage ใหม่สำหรับ runtime (image เล็กลง)
|
||||||
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
|
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
|
||||||
|
|
||||||
# กำหนด working directory สำหรับ runtime
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# คัดลอกไฟล์จาก build stage มายัง runtime stage
|
COPY --from=build /app/publish .
|
||||||
COPY --from=build /app/build .
|
|
||||||
|
|
||||||
# ระบุ entry point ของแอปพลิเคชัน
|
|
||||||
ENTRYPOINT ["dotnet", "BMA.EHR.CheckInConsumer.dll"]
|
ENTRYPOINT ["dotnet", "BMA.EHR.CheckInConsumer.dll"]
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,13 @@ var user = configuration["Rabbit:User"] ?? "";
|
||||||
var pass = configuration["Rabbit:Password"] ?? "";
|
var pass = configuration["Rabbit:Password"] ?? "";
|
||||||
var queue = configuration["Rabbit:Queue"] ?? "basic-queue";
|
var queue = configuration["Rabbit:Queue"] ?? "basic-queue";
|
||||||
|
|
||||||
|
// Concurrency & prefetch (configurable via appsettings.json)
|
||||||
|
var maxConcurrency = int.TryParse(configuration["MaxConcurrency"], out var c) && c > 0 ? c : 5;
|
||||||
|
var prefetchCount = ushort.TryParse(configuration["PrefetchCount"], out var p) && p > 0 ? p : (ushort)20;
|
||||||
|
var httpTimeoutSec = int.TryParse(configuration["HttpTimeoutSeconds"], out var t) && t > 0 ? t : 60;
|
||||||
|
|
||||||
|
WriteToConsole($"Config -> MaxConcurrency: {maxConcurrency}, PrefetchCount: {prefetchCount}, HttpTimeout: {httpTimeoutSec}s");
|
||||||
|
|
||||||
// create connection
|
// create connection
|
||||||
var factory = new ConnectionFactory()
|
var factory = new ConnectionFactory()
|
||||||
{
|
{
|
||||||
|
|
@ -32,39 +39,61 @@ using var channel = connection.CreateModel();
|
||||||
|
|
||||||
channel.QueueDeclare(queue: queue, durable: true, exclusive: false, autoDelete: false, arguments: null);
|
channel.QueueDeclare(queue: queue, durable: true, exclusive: false, autoDelete: false, arguments: null);
|
||||||
|
|
||||||
// Create a SINGLE static HttpClient instance to prevent socket exhaustion
|
// Prefetch: RabbitMQ จะส่ง message หลายตัวมาที่ consumer พร้อมกัน (ลด network round-trip)
|
||||||
using var httpClient = new HttpClient();
|
channel.BasicQos(prefetchSize: 0, prefetchCount: prefetchCount, global: false);
|
||||||
httpClient.Timeout = TimeSpan.FromSeconds(300); // 5 นาที
|
|
||||||
|
// HttpClient แบบ SocketsHttpHandler พร้อม connection pooling รองรับ concurrent requests
|
||||||
|
var socketsHandler = new SocketsHttpHandler
|
||||||
|
{
|
||||||
|
MaxConnectionsPerServer = maxConcurrency * 2,
|
||||||
|
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
|
||||||
|
PooledConnectionIdleTimeout = TimeSpan.FromSeconds(30)
|
||||||
|
};
|
||||||
|
using var httpClient = new HttpClient(socketsHandler);
|
||||||
|
httpClient.Timeout = TimeSpan.FromSeconds(httpTimeoutSec);
|
||||||
|
|
||||||
|
// SemaphoreSlim คุมจำนวน message ที่ประมวลผลพร้อมกัน (เนื่องจาก API มีข้อจำกัดเรื่อง concurrency)
|
||||||
|
using var semaphore = new SemaphoreSlim(maxConcurrency, maxConcurrency);
|
||||||
|
|
||||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||||
|
|
||||||
consumer.Received += async (model, ea) =>
|
consumer.Received += (model, ea) =>
|
||||||
{
|
{
|
||||||
try
|
// รอ semaphore ก่อนเริ่มประมวลผล
|
||||||
|
semaphore.WaitAsync().ContinueWith(async _ =>
|
||||||
{
|
{
|
||||||
var body = ea.Body.ToArray();
|
try
|
||||||
var message = Encoding.UTF8.GetString(body);
|
|
||||||
|
|
||||||
WriteToConsole($"Received message: {message}");
|
|
||||||
|
|
||||||
var success = await CallRestApi(message, httpClient, configuration);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
channel.BasicAck(ea.DeliveryTag, multiple: false);
|
var body = ea.Body.ToArray();
|
||||||
WriteToConsole("Message processed successfully");
|
var message = Encoding.UTF8.GetString(body);
|
||||||
|
|
||||||
|
WriteToConsole($"Received message: {message}");
|
||||||
|
|
||||||
|
var success = await CallRestApi(message, httpClient, configuration);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
channel.BasicAck(ea.DeliveryTag, multiple: false);
|
||||||
|
WriteToConsole("Message processed successfully");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false);
|
||||||
|
WriteToConsole("Message processing failed - message rejected");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
WriteToConsole($"Error processing message: {ex.Message}");
|
||||||
channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false);
|
channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false);
|
||||||
WriteToConsole("Message processing failed - message rejected");
|
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
semaphore.Release();
|
||||||
WriteToConsole($"Error processing message: {ex.Message}");
|
}
|
||||||
channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false);
|
}, TaskScheduler.Default).ConfigureAwait(false);
|
||||||
}
|
|
||||||
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
channel.BasicConsume(queue: queue, autoAck: false, consumer: consumer);
|
channel.BasicConsume(queue: queue, autoAck: false, consumer: consumer);
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,8 @@
|
||||||
"Password": "12345678",
|
"Password": "12345678",
|
||||||
"Queue": "hrms-checkin-queue-dev"
|
"Queue": "hrms-checkin-queue-dev"
|
||||||
},
|
},
|
||||||
"API": "https://localhost:7283/api/v1"
|
"API": "https://localhost:7283/api/v1",
|
||||||
|
"MaxConcurrency": 5,
|
||||||
|
"PrefetchCount": 20,
|
||||||
|
"HttpTimeoutSeconds": 60
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -50,7 +50,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Document");
|
b.ToTable("Document", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b =>
|
||||||
|
|
@ -116,7 +116,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("LeaveTypes");
|
b.ToTable("LeaveTypes", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b =>
|
||||||
|
|
@ -226,7 +226,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasIndex("LeaveTypeId");
|
b.HasIndex("LeaveTypeId");
|
||||||
|
|
||||||
b.ToTable("LeaveBeginnings");
|
b.ToTable("LeaveBeginnings", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b =>
|
||||||
|
|
@ -288,7 +288,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasIndex("LeaveRequestId");
|
b.HasIndex("LeaveRequestId");
|
||||||
|
|
||||||
b.ToTable("LeaveDocuments");
|
b.ToTable("LeaveDocuments", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b =>
|
||||||
|
|
@ -667,7 +667,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasIndex("TypeId");
|
b.HasIndex("TypeId");
|
||||||
|
|
||||||
b.ToTable("LeaveRequests");
|
b.ToTable("LeaveRequests", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b =>
|
||||||
|
|
@ -786,7 +786,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasIndex("LeaveRequestId");
|
b.HasIndex("LeaveRequestId");
|
||||||
|
|
||||||
b.ToTable("LeaveRequestApprovers");
|
b.ToTable("LeaveRequestApprovers", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b =>
|
||||||
|
|
@ -901,7 +901,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("AdditionalCheckRequests");
|
b.ToTable("AdditionalCheckRequests", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.CheckInJobStatus", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.CheckInJobStatus", b =>
|
||||||
|
|
@ -994,7 +994,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("CheckInJobStatuses");
|
b.ToTable("CheckInJobStatuses", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b =>
|
||||||
|
|
@ -1079,7 +1079,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("DutyTimes");
|
b.ToTable("DutyTimes", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.LeaveProcessJobStatus", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.LeaveProcessJobStatus", b =>
|
||||||
|
|
@ -1164,7 +1164,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("LeaveProcessJobStatuses");
|
b.ToTable("LeaveProcessJobStatuses", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b =>
|
||||||
|
|
@ -1375,7 +1375,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("ProcessUserTimeStamps");
|
b.ToTable("ProcessUserTimeStamps", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b =>
|
||||||
|
|
@ -1436,7 +1436,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("UserCalendars");
|
b.ToTable("UserCalendars", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b =>
|
||||||
|
|
@ -1525,7 +1525,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasIndex("DutyTimeId");
|
b.HasIndex("DutyTimeId");
|
||||||
|
|
||||||
b.ToTable("UserDutyTimes");
|
b.ToTable("UserDutyTimes", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b =>
|
||||||
|
|
@ -1719,7 +1719,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("UserTimeStamps");
|
b.ToTable("UserTimeStamps", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b =>
|
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b =>
|
||||||
|
|
|
||||||
|
|
@ -410,8 +410,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
if (req.LeaveDaysUsed is null || req.LeaveCount is null)
|
if (req.LeaveDaysUsed is null || req.LeaveCount is null)
|
||||||
{
|
{
|
||||||
var systemLeaveDays = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate);
|
var systemLeaveDays = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1));
|
||||||
var systemLeaveCount = await _leaveRequestRepository.GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate);
|
var systemLeaveCount = await _leaveRequestRepository.GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1));
|
||||||
|
|
||||||
leaveBeginning.LeaveDaysUsed = req.BeginningLeaveDays + systemLeaveDays;
|
leaveBeginning.LeaveDaysUsed = req.BeginningLeaveDays + systemLeaveDays;
|
||||||
leaveBeginning.LeaveCount = req.BeginningLeaveCount + systemLeaveCount;
|
leaveBeginning.LeaveCount = req.BeginningLeaveCount + systemLeaveCount;
|
||||||
|
|
|
||||||
|
|
@ -3818,6 +3818,148 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPut("admin/edit/approve-list")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> ApproveRequestListAsync([FromBody] List<ApproveRequestListItemDto> reqs)
|
||||||
|
{
|
||||||
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_CHECKIN_SPECIAL");
|
||||||
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||||
|
if (jsonData["status"]?.ToString() != "200")
|
||||||
|
{
|
||||||
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var req in reqs)
|
||||||
|
{
|
||||||
|
if (req.Reason == null || req.Reason == string.Empty)
|
||||||
|
{
|
||||||
|
return Error("กรุณากรอกเหตุผล", StatusCodes.Status400BadRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestData = await _additionalCheckRequestRepository.GetByIdAsync(req.RecId);
|
||||||
|
if (requestData == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestData.Status = "APPROVE";
|
||||||
|
requestData.Comment = req.Reason;
|
||||||
|
await _additionalCheckRequestRepository.UpdateAsync(requestData);
|
||||||
|
|
||||||
|
// change user timestamp
|
||||||
|
var processTimeStamp = await _processUserTimeStampRepository.GetTimestampByDateAsync(requestData.KeycloakUserId, requestData.CheckDate.Date);
|
||||||
|
|
||||||
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(requestData.KeycloakUserId, AccessToken);
|
||||||
|
|
||||||
|
if (processTimeStamp == null)
|
||||||
|
{
|
||||||
|
processTimeStamp = new ProcessUserTimeStamp
|
||||||
|
{
|
||||||
|
KeycloakUserId = requestData.KeycloakUserId,
|
||||||
|
CheckIn = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckInTime}"),
|
||||||
|
CheckOut = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckOutTime}"),
|
||||||
|
CheckInRemark = req.Reason,
|
||||||
|
CheckOutRemark = req.Reason,
|
||||||
|
|
||||||
|
CheckInLat = 0,
|
||||||
|
CheckInLon = 0,
|
||||||
|
CheckOutLat = 0,
|
||||||
|
CheckOutLon = 0,
|
||||||
|
CheckInPOI = "",
|
||||||
|
CheckOutPOI = "",
|
||||||
|
CheckInStatus = req.CheckInStatus,
|
||||||
|
CheckOutStatus = req.CheckOutStatus,
|
||||||
|
|
||||||
|
Prefix = profile.Prefix,
|
||||||
|
FirstName = profile.FirstName,
|
||||||
|
LastName = profile.LastName,
|
||||||
|
|
||||||
|
// Add ข้อมูลจาก profile
|
||||||
|
CitizenId = profile.CitizenId,
|
||||||
|
ProfileType = profile.ProfileType,
|
||||||
|
Root = profile.Root,
|
||||||
|
RootId = profile.RootId,
|
||||||
|
Child1 = profile.Child1,
|
||||||
|
Child1Id = profile.Child1Id,
|
||||||
|
Child2 = profile.Child2,
|
||||||
|
Child2Id = profile.Child2Id,
|
||||||
|
Child3 = profile.Child3,
|
||||||
|
Child3Id = profile.Child3Id,
|
||||||
|
Child4 = profile.Child4,
|
||||||
|
Child4Id = profile.Child4Id,
|
||||||
|
Gender = profile.Gender,
|
||||||
|
ProfileId = profile.Id,
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
processTimeStamp.EditStatus = "APPROVE";
|
||||||
|
processTimeStamp.EditReason = req.Reason;
|
||||||
|
|
||||||
|
if (requestData.CheckInEdit)
|
||||||
|
{
|
||||||
|
processTimeStamp.CheckInPOI = requestData.POI ?? "";
|
||||||
|
processTimeStamp.CheckInLat = requestData.Latitude ?? 0;
|
||||||
|
processTimeStamp.CheckInLon = requestData.Longitude ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestData.CheckOutEdit)
|
||||||
|
{
|
||||||
|
processTimeStamp.CheckOutPOI = requestData.POI ?? "";
|
||||||
|
processTimeStamp.CheckOutLat = requestData.Latitude ?? 0;
|
||||||
|
processTimeStamp.CheckOutLon = requestData.Longitude ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _processUserTimeStampRepository.AddAsync(processTimeStamp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (requestData.CheckInEdit)
|
||||||
|
{
|
||||||
|
processTimeStamp.CheckIn = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckInTime}");
|
||||||
|
processTimeStamp.CheckInRemark = req.Reason;
|
||||||
|
//processTimeStamp.CheckInLat = 0;
|
||||||
|
//processTimeStamp.CheckInLon = 0;
|
||||||
|
//processTimeStamp.CheckInPOI = "ลงเวลากรณีพิเศษ";
|
||||||
|
processTimeStamp.CheckInStatus = req.CheckInStatus;
|
||||||
|
|
||||||
|
processTimeStamp.CheckInPOI = requestData.POI ?? "";
|
||||||
|
processTimeStamp.CheckInLat = requestData.Latitude ?? 0;
|
||||||
|
processTimeStamp.CheckInLon = requestData.Longitude ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestData.CheckOutEdit)
|
||||||
|
{
|
||||||
|
processTimeStamp.CheckOut = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckOutTime}");
|
||||||
|
processTimeStamp.CheckOutRemark = req.Reason;
|
||||||
|
//processTimeStamp.CheckOutLat = 0;
|
||||||
|
//processTimeStamp.CheckOutLon = 0;
|
||||||
|
//processTimeStamp.CheckOutPOI = "ลงเวลากรณีพิเศษ";
|
||||||
|
processTimeStamp.CheckOutStatus = req.CheckOutStatus;
|
||||||
|
|
||||||
|
processTimeStamp.CheckOutPOI = requestData.POI ?? "";
|
||||||
|
processTimeStamp.CheckOutLat = requestData.Latitude ?? 0;
|
||||||
|
processTimeStamp.CheckOutLon = requestData.Longitude ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
processTimeStamp.EditStatus = "APPROVE";
|
||||||
|
processTimeStamp.EditReason = req.Reason;
|
||||||
|
|
||||||
|
await _processUserTimeStampRepository.UpdateAsync(processTimeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
var recvId = new List<Guid> { profile.Id };
|
||||||
|
await _notificationRepository.PushNotificationsAsync(recvId.ToArray(), "ลงเวลากรณีพิเศษ",
|
||||||
|
"การขอลงเวลากรณีพิเศษของคุณได้รับการอนุมัติ", "", "", true, false);
|
||||||
|
}
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LV1_020 - ไม่อนุมัติลงเวลากรณีพิเศษ (ADMIN)
|
/// LV1_020 - ไม่อนุมัติลงเวลากรณีพิเศษ (ADMIN)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -156,15 +156,20 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync2(data.KeycloakUserId,
|
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync2(data.KeycloakUserId,
|
||||||
data.Type.Id, data.CreatedAt);
|
data.Type.Id, data.CreatedAt);
|
||||||
|
|
||||||
|
var fiscalYear = data.LeaveStartDate.Month >= 10 ? data.LeaveStartDate.Year + 1 : data.LeaveStartDate.Year;
|
||||||
|
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||||
|
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||||
|
|
||||||
var startFiscalYear = (new DateTime(data.LeaveStartDate.Year - 1, 10, 1)).Date;
|
var startFiscalYear = (new DateTime(data.LeaveStartDate.Year - 1, 10, 1)).Date;
|
||||||
var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt);
|
var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt);
|
||||||
|
var sendLeaveDate = data.DateSendLeave ?? data.CreatedAt;
|
||||||
|
|
||||||
var thisYear = data.LeaveStartDate.Year;
|
var thisYear = data.LeaveStartDate.Year;
|
||||||
var toDay = data.LeaveStartDate.Date;
|
var toDay = data.LeaveStartDate.Date;
|
||||||
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
|
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
|
||||||
thisYear = thisYear + 1;
|
thisYear = thisYear + 1;
|
||||||
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId);
|
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId);
|
||||||
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate);
|
||||||
if (leaveData != null)
|
if (leaveData != null)
|
||||||
{
|
{
|
||||||
sumLeave += leaveData.BeginningLeaveDays;
|
sumLeave += leaveData.BeginningLeaveDays;
|
||||||
|
|
@ -218,6 +223,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
LeaveLastStart = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveStartDate.Date.ToThaiShortDate().ToThaiNumber(),
|
LeaveLastStart = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveStartDate.Date.ToThaiShortDate().ToThaiNumber(),
|
||||||
LeaveLastEnd = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveEndDate.Date.ToThaiShortDate().ToThaiNumber(),
|
LeaveLastEnd = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveEndDate.Date.ToThaiShortDate().ToThaiNumber(),
|
||||||
|
|
||||||
|
LeaveLastTotal = lastLeaveRequest == null ? "0".ToThaiNumber() : lastLeaveRequest.LeaveTotal.ToString().ToThaiNumber(),
|
||||||
|
|
||||||
LeaveSummary = sumLeave.ToString().ToThaiNumber(),
|
LeaveSummary = sumLeave.ToString().ToThaiNumber(),
|
||||||
LeaveRemain = (data.Type.Limit - sumLeave).ToString().ToThaiNumber(),
|
LeaveRemain = (data.Type.Limit - sumLeave).ToString().ToThaiNumber(),
|
||||||
LeaveAll = (data.LeaveTotal + sumLeave).ToString().ToThaiNumber(),
|
LeaveAll = (data.LeaveTotal + sumLeave).ToString().ToThaiNumber(),
|
||||||
|
|
@ -332,21 +339,26 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
|
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
|
||||||
|
|
||||||
var startFiscalYear = new DateTime(data.LeaveStartDate.Year - 1, 10, 1);
|
var startFiscalYear = new DateTime(data.LeaveStartDate.Year - 1, 10, 1);
|
||||||
var endFiscalYear = data.CreatedAt;
|
var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt);
|
||||||
|
|
||||||
|
var fiscalYear = data.LeaveStartDate.Month >= 10 ? data.LeaveStartDate.Year + 1 : data.LeaveStartDate.Year;
|
||||||
|
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||||
|
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||||
|
|
||||||
var thisYear = data.LeaveStartDate.Year;
|
var thisYear = data.LeaveStartDate.Year;
|
||||||
var toDay = data.LeaveStartDate.Date;
|
var toDay = data.LeaveStartDate.Date;
|
||||||
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
|
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
|
||||||
thisYear = thisYear + 1;
|
thisYear = thisYear + 1;
|
||||||
|
|
||||||
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId);
|
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(fiscalYear, data.Type.Id, data.KeycloakUserId);
|
||||||
//var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId);
|
//var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId);
|
||||||
//var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
//var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
||||||
|
|
||||||
//var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
//var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
||||||
|
|
||||||
|
var sendLeaveDate = data.DateSendLeave ?? data.CreatedAt;
|
||||||
|
|
||||||
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
|
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate);
|
||||||
if (leaveData != null)
|
if (leaveData != null)
|
||||||
{
|
{
|
||||||
sumLeave += leaveData.BeginningLeaveDays;
|
sumLeave += leaveData.BeginningLeaveDays;
|
||||||
|
|
@ -1352,7 +1364,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
profile = await _userProfileRepository.GetEmployeeByAdminRole(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date);
|
profile = await _userProfileRepository.GetEmployeeByAdminRolev2(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date);
|
||||||
}
|
}
|
||||||
// get leave day
|
// get leave day
|
||||||
var leaveDays = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRange(req.StartDate, req.EndDate);
|
var leaveDays = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRange(req.StartDate, req.EndDate);
|
||||||
|
|
@ -2380,7 +2392,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
profile = await _userProfileRepository.GetEmployeeByAdminRole(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date);
|
profile = await _userProfileRepository.GetEmployeeByAdminRolev2(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date);
|
||||||
}
|
}
|
||||||
// Child กรองตามที่ fe ส่งมาอีกชั้น
|
// Child กรองตามที่ fe ส่งมาอีกชั้น
|
||||||
if ((role == "ROOT" || role == "OWNER" || role == "CHILD" || role == "PARENT" || role == "BROTHER") /*&& req.node > profileAdmin?.Node*/)
|
if ((role == "ROOT" || role == "OWNER" || role == "CHILD" || role == "PARENT" || role == "BROTHER") /*&& req.node > profileAdmin?.Node*/)
|
||||||
|
|
@ -2444,6 +2456,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var workTotal = 0;
|
var workTotal = 0;
|
||||||
var seminarTotal = 0;
|
var seminarTotal = 0;
|
||||||
|
|
||||||
|
var wfaTotal = 0; //ปฏิบัติงานนอกสถานที่
|
||||||
|
var outOfficeTotal = 0; //ขออนุญาติิิออกนอกสถานที่
|
||||||
|
var oneStopSrvrTotal = 0; //จุดบริการด่วนมหานคร
|
||||||
|
var otherTotal = 0; //อื่นๆ
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
if (defaultRound == null)
|
if (defaultRound == null)
|
||||||
{
|
{
|
||||||
|
|
@ -2627,10 +2648,19 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
workTotal += 1;
|
workTotal += 1;
|
||||||
if (!timeStamps.IsLocationCheckIn)
|
if (!timeStamps.IsLocationCheckIn)
|
||||||
{
|
{
|
||||||
if (timeStamps.CheckInLocationName == "ปฏิบัติงานที่บ้าน")
|
if (timeStamps.CheckInLocationName!.Contains("ปฏิบัติงานที่บ้าน"))
|
||||||
wfhTotal += 1;
|
wfhTotal += 1;
|
||||||
else if (timeStamps.CheckInLocationName == "ไปประชุม / อบรม / สัมมนา")
|
else if (timeStamps.CheckInLocationName == "ไปประชุม / อบรม / สัมมนา")
|
||||||
seminarTotal += 1;
|
seminarTotal += 1;
|
||||||
|
else if (timeStamps.CheckInLocationName.Contains("ปฏิบัติงานนอกสถานที่"))
|
||||||
|
wfaTotal += 1;
|
||||||
|
else if (timeStamps.CheckInLocationName.Contains("ขออนุญาตออกนอกสถานที่"))
|
||||||
|
outOfficeTotal += 1;
|
||||||
|
else if (timeStamps.CheckInLocationName.Contains("ปฏิบัติงานในจุดบริการด่วนมหานคร"))
|
||||||
|
oneStopSrvrTotal += 1;
|
||||||
|
else otherTotal += 1;
|
||||||
|
// else if (timeStamps.CheckInLocationName.Contains("อื่นๆ"))
|
||||||
|
// otherTotal += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2781,19 +2811,36 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
worksheet.Cells[lastRow + 2, 8].Value = "อบรม ประชุม สัมมนาฯ";
|
worksheet.Cells[lastRow + 2, 8].Value = "อบรม ประชุม สัมมนาฯ";
|
||||||
worksheet.Cells[lastRow + 2, 9].Value = seminarTotal;
|
worksheet.Cells[lastRow + 2, 9].Value = seminarTotal;
|
||||||
worksheet.Cells[lastRow + 2, 10].Value = "คน";
|
worksheet.Cells[lastRow + 2, 10].Value = "คน";
|
||||||
|
worksheet.Cells[lastRow + 3, 8].Value = "ปฎิบัติงานนอกสถานที่";
|
||||||
|
worksheet.Cells[lastRow + 3, 9].Value = wfaTotal;
|
||||||
|
worksheet.Cells[lastRow + 3, 10].Value = "คน";
|
||||||
|
worksheet.Cells[lastRow + 4, 8].Value = "ขออนุญาตออกนอกสถานที่";
|
||||||
|
worksheet.Cells[lastRow + 4, 9].Value = outOfficeTotal;
|
||||||
|
worksheet.Cells[lastRow + 4, 10].Value = "คน";
|
||||||
|
worksheet.Cells[lastRow + 5, 8].Value = "ปฎิบัติงานในจุดบริการด่วนมหานคร";
|
||||||
|
worksheet.Cells[lastRow + 5, 9].Value = oneStopSrvrTotal;
|
||||||
|
worksheet.Cells[lastRow + 5, 10].Value = "คน";
|
||||||
|
worksheet.Cells[lastRow + 6, 8].Value = "อื่นๆ";
|
||||||
|
worksheet.Cells[lastRow + 6, 9].Value = otherTotal;
|
||||||
|
worksheet.Cells[lastRow + 6, 10].Value = "คน";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
worksheet.Cells[lastRow + 3, 2].Value = "ลาป่วย/ลากิจ";
|
worksheet.Cells[lastRow + 3, 2].Value = "ลาป่วย/ลากิจ";
|
||||||
worksheet.Cells[lastRow + 3, 5].Value = sickTotal;
|
worksheet.Cells[lastRow + 3, 5].Value = sickTotal;
|
||||||
worksheet.Cells[lastRow + 3, 6].Value = "คน";
|
worksheet.Cells[lastRow + 3, 6].Value = "คน";
|
||||||
worksheet.Cells[lastRow + 4, 2].Value = "มาสาย";
|
worksheet.Cells[lastRow + 4, 2].Value = "มาสาย";
|
||||||
worksheet.Cells[lastRow + 4, 5].Value = lateTotal;
|
worksheet.Cells[lastRow + 4, 5].Value = lateTotal;
|
||||||
worksheet.Cells[lastRow + 4, 6].Value = "คน";
|
worksheet.Cells[lastRow + 4, 6].Value = "คน";
|
||||||
worksheet.Cells[lastRow + 6, 2].Value = "เรียน";
|
worksheet.Cells[lastRow + 8, 2].Value = "เรียน";
|
||||||
worksheet.Cells[lastRow + 7, 2].Value = "เพื่อโปรดทราบ";
|
worksheet.Cells[lastRow + 9, 2].Value = "เพื่อโปรดทราบ";
|
||||||
worksheet.Cells[lastRow + 7, 9].Value = "ทราบ";
|
worksheet.Cells[lastRow + 9, 9].Value = "ทราบ";
|
||||||
worksheet.Cells[lastRow + 7, 9].Style.Font.Bold = true;
|
worksheet.Cells[lastRow + 9, 9].Style.Font.Bold = true;
|
||||||
worksheet.Cells[lastRow + 7, 9].Style.Font.Size = 22;
|
worksheet.Cells[lastRow + 9, 9].Style.Font.Size = 22;
|
||||||
worksheet.Cells[lastRow + 8, 2].Value = "................................";
|
worksheet.Cells[lastRow + 10, 2].Value = "................................";
|
||||||
worksheet.Cells[lastRow + 8, 9].Value = "................................";
|
worksheet.Cells[lastRow + 10, 9].Value = "................................";
|
||||||
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
||||||
var fileBytes = package.GetAsByteArray();
|
var fileBytes = package.GetAsByteArray();
|
||||||
return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "TimeStampRecords.xlsx");
|
return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "TimeStampRecords.xlsx");
|
||||||
|
|
|
||||||
|
|
@ -928,8 +928,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
var leaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
var leaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
||||||
|
|
||||||
var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate);
|
|
||||||
var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate);
|
var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1));
|
||||||
|
var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1));
|
||||||
|
|
||||||
var result = new GetUserLeaveProfileResultDto
|
var result = new GetUserLeaveProfileResultDto
|
||||||
{
|
{
|
||||||
|
|
@ -1016,6 +1017,30 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ทดสอบประมวลผล beginning
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("process-beginning/{year:int}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<ActionResult<ResponseObject>> ProcessBeginningByYearAsync([FromRoute] int year)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _leaveBeginningRepository.ProcessEarlyLeaveRequest(year);
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LV2_003 - เช็คการยืนขอลา (USER)
|
/// LV2_003 - เช็คการยืนขอลา (USER)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1661,10 +1686,12 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
var thisYear = DateTime.Now.Year;
|
var thisYear = DateTime.Now.Year;
|
||||||
|
|
||||||
|
|
||||||
if (rawData == null)
|
if (rawData == null)
|
||||||
{
|
{
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
var fiscalYear = rawData.LeaveStartDate.Month >= 10 ? rawData.LeaveStartDate.Year + 1 : rawData.LeaveStartDate.Year;
|
||||||
|
|
||||||
// var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
|
// var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
|
||||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(rawData.KeycloakUserId, AccessToken);
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(rawData.KeycloakUserId, AccessToken);
|
||||||
|
|
@ -1710,10 +1737,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var restDayOld = 0.0;
|
var restDayOld = 0.0;
|
||||||
|
|
||||||
//restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays + leaveData.BeginningLeaveDays - 10);
|
//restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays + leaveData.BeginningLeaveDays - 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays - 10);
|
restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays - 10);
|
||||||
if (restDayOld < 0) restDayOld = 0;
|
if (restDayOld < 0) restDayOld = 0;
|
||||||
var restDayCurrent = govAge < 180 ? 0 : 10;
|
var restDayCurrent = govAge < 180 ? 0 : 10;
|
||||||
|
|
||||||
|
if (thisYear < fiscalYear)
|
||||||
|
restDayOld = 0;
|
||||||
|
|
||||||
var result = new GetLeaveRequestByIdDto
|
var result = new GetLeaveRequestByIdDto
|
||||||
{
|
{
|
||||||
|
|
@ -2134,6 +2166,45 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API ลบรายการการลา (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/{id:guid}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteLeaveRequestForAdminAsync(Guid id)
|
||||||
|
{
|
||||||
|
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_LEAVE_LIST");
|
||||||
|
if (jsonData!.status != 200)
|
||||||
|
{
|
||||||
|
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||||
|
if (jsonData.result.privilege != "OWNER")
|
||||||
|
{
|
||||||
|
return Error("ไม่มีสิทธิ์ในการลบรายการขอลา", StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
var deleted = await _leaveRequestRepository.GetByIdAsync(id);
|
||||||
|
if (deleted == null)
|
||||||
|
return Error(GlobalMessages.DataNotFound);
|
||||||
|
|
||||||
|
// ห้ามลบเฉพาะสถานะ APPROVE, DELETING, DELETE
|
||||||
|
if (new[] { "APPROVE", "DELETING", "DELETE" }.Contains(deleted.LeaveStatus))
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถลบรายการขอลาสถานะนี้ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
await _leaveRequestRepository.DeleteAsync(deleted);
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LV2_014 - รายการขอยกเลิกการลา (ADMIN)
|
/// LV2_014 - รายการขอยกเลิกการลา (ADMIN)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -2841,15 +2912,21 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId);
|
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId);
|
||||||
|
|
||||||
|
var currentYear = DateTime.Now.Year;
|
||||||
|
|
||||||
|
var fiscalYear = rawData.LeaveStartDate.Month >= 10 ? rawData.LeaveStartDate.Year + 1 : rawData.LeaveStartDate.Year;
|
||||||
|
var fiscalStart = new DateTime((fiscalYear - 1), 10, 1);
|
||||||
|
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||||
|
|
||||||
var startFiscalYear = new DateTime(rawData.LeaveStartDate.Year - 1, 10, 1);
|
var startFiscalYear = new DateTime(rawData.LeaveStartDate.Year - 1, 10, 1);
|
||||||
var endFiscalYear = rawData.DateSendLeave ?? rawData.CreatedAt;
|
var sendLeaveDate = rawData.DateSendLeave ?? rawData.CreatedAt;
|
||||||
var endFiscalYear2 = new DateTime(rawData.LeaveStartDate.Year, 9, 30);
|
var endFiscalYear2 = new DateTime(rawData.LeaveStartDate.Year, 9, 30);
|
||||||
//var endFiscalYear3 = rawData.DateSendLeave ?? rawData.CreatedAt;
|
//var endFiscalYear3 = rawData.DateSendLeave ?? rawData.CreatedAt;
|
||||||
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear);
|
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate);
|
||||||
|
|
||||||
// วันลาแบบร่างและที่ยื่นลาไปแล้ว
|
// วันลาแบบร่างและที่ยื่นลาไปแล้ว
|
||||||
var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear2);
|
var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, fiscalEnd.AddDays(1));
|
||||||
var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear2);
|
var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, fiscalEnd.AddDays(1));
|
||||||
|
|
||||||
//var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
//var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed;
|
||||||
if (leaveData != null)
|
if (leaveData != null)
|
||||||
|
|
@ -2862,6 +2939,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
leaveLimit = leaveData == null ? 0.0 : leaveData.LeaveDays;
|
leaveLimit = leaveData == null ? 0.0 : leaveData.LeaveDays;
|
||||||
extendLeave = leaveLimit <= 0 ? 0 : leaveLimit - 10;
|
extendLeave = leaveLimit <= 0 ? 0 : leaveLimit - 10;
|
||||||
|
if (thisYear < fiscalYear)
|
||||||
|
extendLeave = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new GetLeaveRequestForAdminByIdDto
|
var result = new GetLeaveRequestForAdminByIdDto
|
||||||
|
|
@ -3086,6 +3165,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
leaveBeginningDict.TryGetValue(leaveType.Id, out var leaveData);
|
leaveBeginningDict.TryGetValue(leaveType.Id, out var leaveData);
|
||||||
var approve = leaveData?.LeaveDaysUsed ?? 0;
|
var approve = leaveData?.LeaveDaysUsed ?? 0;
|
||||||
|
var approveCount = leaveData?.LeaveCount ?? 0;
|
||||||
|
|
||||||
// fix issue : SIT ระบบบันทึกการลา>> สิทธิ์การลา(โอนสิทธิ์การลา) #974
|
// fix issue : SIT ระบบบันทึกการลา>> สิทธิ์การลา(โอนสิทธิ์การลา) #974
|
||||||
var extendLeave = 0.0;
|
var extendLeave = 0.0;
|
||||||
|
|
@ -3108,6 +3188,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
LeaveCountApprove = approve,
|
LeaveCountApprove = approve,
|
||||||
LeaveCountReject = reject,
|
LeaveCountReject = reject,
|
||||||
LeaveCountDelete = delete,
|
LeaveCountDelete = delete,
|
||||||
|
LeaveCountApproveCount = approveCount,
|
||||||
};
|
};
|
||||||
result.Add(data);
|
result.Add(data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,21 @@
|
||||||
|
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ApproveRequestListItemDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// id ของ record รายการคำขอลงเวลาพิเศษนั้นๆ
|
||||||
|
/// </summary>
|
||||||
|
public Guid RecId { get; set; }
|
||||||
|
public string CheckInTime { get; set; }
|
||||||
|
|
||||||
|
public string CheckOutTime { get; set; }
|
||||||
|
|
||||||
|
public string CheckInStatus { get; set; }
|
||||||
|
|
||||||
|
public string CheckOutStatus { get; set; }
|
||||||
|
|
||||||
|
public string Reason { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ using System.Text;
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.MySql;
|
using Hangfire.MySql;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
|
||||||
using BMA.EHR.Leave.Service.Filters;
|
using BMA.EHR.Leave.Service.Filters;
|
||||||
using Hangfire.Common;
|
using Hangfire.Common;
|
||||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||||
|
|
@ -194,9 +195,27 @@ app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
||||||
var manager = new RecurringJobManager();
|
var manager = new RecurringJobManager();
|
||||||
if (manager != null)
|
if (manager != null)
|
||||||
{
|
{
|
||||||
manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression<UserDutyTimeRepository>(x => x.UpdateUserDutyTime()), "0 1 * * *", bangkokTimeZone);
|
manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression<UserDutyTimeRepository>(x => x.UpdateUserDutyTime()), "0 1 * * *",
|
||||||
|
new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = bangkokTimeZone,
|
||||||
|
QueueName = "leave"
|
||||||
|
});
|
||||||
// ทำความสะอาดข้อมูล CheckIn Job Status ที่เก่ากว่า 30 วัน - รันทุกวันเวลา 02:00 น.
|
// ทำความสะอาดข้อมูล CheckIn Job Status ที่เก่ากว่า 30 วัน - รันทุกวันเวลา 02:00 น.
|
||||||
manager.AddOrUpdate("ทำความสะอาดข้อมูล CheckIn Job Status", Job.FromExpression<CheckInJobStatusRepository>(x => x.CleanupOldJobsAsync(30)), "0 2 * * *", bangkokTimeZone);
|
manager.AddOrUpdate("ทำความสะอาดข้อมูล CheckIn Job Status", Job.FromExpression<CheckInJobStatusRepository>(x => x.CleanupOldJobsAsync(30)), "0 2 * * *",
|
||||||
|
new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = bangkokTimeZone,
|
||||||
|
QueueName = "leave"
|
||||||
|
});
|
||||||
|
|
||||||
|
manager.AddOrUpdate("Proceess Beginning สำหรับการลาล่วงหน้า", Job.FromExpression<LeaveBeginningRepository>(x => x.ProcessEarlyLeaveRequestSchedule()), "0 1 1 10 *",
|
||||||
|
new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = bangkokTimeZone,
|
||||||
|
QueueName = "leave"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// ตรวจสอบและ mark งาน CheckIn ที่ค้างเกิน 30 นาทีเป็น FAILED - รันทุก 15 นาที
|
// ตรวจสอบและ mark งาน CheckIn ที่ค้างเกิน 30 นาทีเป็น FAILED - รันทุก 15 นาที
|
||||||
// manager.AddOrUpdate("ตรวจสอบงาน CheckIn ที่ค้างเกินเวลา", Job.FromExpression<CheckInJobStatusRepository>(x => x.MarkStaleJobsAsFailedAsync(30)), "*/15 * * * *",
|
// manager.AddOrUpdate("ตรวจสอบงาน CheckIn ที่ค้างเกินเวลา", Job.FromExpression<CheckInJobStatusRepository>(x => x.MarkStaleJobsAsFailedAsync(30)), "*/15 * * * *",
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@
|
||||||
"ExamConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_exam;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;",
|
"ExamConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_exam;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;",
|
||||||
"LeaveConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_leave;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;"
|
"LeaveConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_leave;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;"
|
||||||
|
|
||||||
// "DefaultConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;",
|
// "DefaultConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;",
|
||||||
// "ExamConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;",
|
// "ExamConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;",
|
||||||
// "LeaveConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms_leave;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;"
|
// "LeaveConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms_leave;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;"
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Key": "j7C9RO_p4nRtuwCH4z9Db_A_6We42tkD_p4lZtDrezc",
|
"Key": "j7C9RO_p4nRtuwCH4z9Db_A_6We42tkD_p4lZtDrezc",
|
||||||
"Issuer": "https://hrmsbkk-id.case-collection.com/realms/hrms"
|
"Issuer": "https://hrmsbkk-id.case-collection.com/realms/hrms"
|
||||||
// "Key": "xY2VR-EFvvNPsMs39u8ooVBWQL6mPwrNJOh3koJFTgU",
|
// "Key": "xY2VR-EFvvNPsMs39u8ooVBWQL6mPwrNJOh3koJFTgU",
|
||||||
// "Issuer": "https://hrms-id.bangkok.go.th/realms/hrms"
|
// "Issuer": "https://hrms-id.bangkok.go.th/realms/hrms"
|
||||||
},
|
},
|
||||||
"EPPlus": {
|
"EPPlus": {
|
||||||
"ExcelPackage": {
|
"ExcelPackage": {
|
||||||
|
|
@ -43,6 +43,10 @@
|
||||||
"AccessKey": "iwvzjyjgz0BKtLPmMpPu",
|
"AccessKey": "iwvzjyjgz0BKtLPmMpPu",
|
||||||
"SecretKey": "Yv56vwctYdIspDknRJ46xztcBDzteGF3elZiDcAr",
|
"SecretKey": "Yv56vwctYdIspDknRJ46xztcBDzteGF3elZiDcAr",
|
||||||
"BucketName": "hrms-fpt"
|
"BucketName": "hrms-fpt"
|
||||||
|
// "Endpoint": "https://hrms-s3.bangkok.go.th/",
|
||||||
|
// "AccessKey": "frappet",
|
||||||
|
// "SecretKey": "FPTadmin2357",
|
||||||
|
// "BucketName": "bma-ehr-fpt"
|
||||||
},
|
},
|
||||||
"Protocol": "HTTPS",
|
"Protocol": "HTTPS",
|
||||||
"Node": {
|
"Node": {
|
||||||
|
|
@ -54,11 +58,11 @@
|
||||||
"Password": "12345678",
|
"Password": "12345678",
|
||||||
"Queue": "hrms-checkin-queue-dev",
|
"Queue": "hrms-checkin-queue-dev",
|
||||||
"URL": "http://192.168.1.63:9122/api/queues/%2F/"
|
"URL": "http://192.168.1.63:9122/api/queues/%2F/"
|
||||||
// "Host": "172.27.17.68",
|
// "Host": "172.27.17.68",
|
||||||
// "User": "admin",
|
// "User": "admin",
|
||||||
// "Password": "admin123456",
|
// "Password": "admin123456",
|
||||||
// "Queue": "hrms-checkin-queue",
|
// "Queue": "hrms-checkin-queue",
|
||||||
// "URL": "http://172.27.17.68:9122/api/queues/%2F/"
|
// "URL": "http://172.27.17.68:9122/api/queues/%2F/"
|
||||||
},
|
},
|
||||||
"Mail": {
|
"Mail": {
|
||||||
"Server": "mail.bangkok.go.th",
|
"Server": "mail.bangkok.go.th",
|
||||||
|
|
@ -72,10 +76,10 @@
|
||||||
"API": "https://hrmsbkk.case-collection.com/api/v1",
|
"API": "https://hrmsbkk.case-collection.com/api/v1",
|
||||||
"APIV2": "https://hrmsbkk.case-collection.com/api/v2",
|
"APIV2": "https://hrmsbkk.case-collection.com/api/v2",
|
||||||
"VITE_URL_MGT": "https://hrmsbkk-mgt.case-collection.com",
|
"VITE_URL_MGT": "https://hrmsbkk-mgt.case-collection.com",
|
||||||
// "Domain": "https://hrms-exam.bangkok.go.th",
|
// "Domain": "https://hrms.bangkok.go.th",
|
||||||
// "APIPROBATION": "https://hrms.bangkok.go.th/api/v1/probation",
|
// "APIPROBATION": "https://hrms.bangkok.go.th/api/v1/probation",
|
||||||
// "API": "https://hrms.bangkok.go.th/api/v1",
|
// "API": "https://hrms.bangkok.go.th/api/v1",
|
||||||
// "APIV2": "https://hrms.bangkok.go.th/api/v2",
|
// "APIV2": "https://hrms.bangkok.go.th/api/v2",
|
||||||
// "VITE_URL_MGT": "https://hrms-mgt.bangkok.go.th",
|
// "VITE_URL_MGT": "https://hrms-mgt.bangkok.go.th",
|
||||||
"API_KEY": "fKRL16yyEgbyTEJdsMw2h64tGSCmkW685PRtM3CygzX1JOSdptT9UJtpgWwKM8FybRTJups3GTFwj27ZRvlPdIkv3XgCoVJaD5LmR06ozuEPvCCRSdp2WFthg08V5xHc56fTPfZLpr1VmXrhd6dvYhHIqKkQUJR02Rlkss11cLRWEQOssEFVA4xdu2J5DIRO1EM5m7wRRvEwcDB4mYRXD9HH52SMq6iYqUWEWsMwLdbk7QW9yYESUEuzMW5gWrb6vIeWZxJV5bTz1PcWUyR7eO9Fyw1F5DiQYc9JgzTC1mW7cv31fEtTtrfbJYKIb5EbWilqIEUKC6A0UKBDDek35ML0006cqRVm0pvdOH6jeq7VQyYrhdXe59dBEyhYGUIfozoVBvW7Up4QBuOMjyPjSqJPlMBKwaseptfrblxQV1AOOivSBpf1ZcQyOZ8JktRtKUDSuXsmG0lsXwFlI3JCeSHdpVdgZWFYcJPegqfrB6KotR02t9AVkpLs1ZWrixwz"
|
"API_KEY": "fKRL16yyEgbyTEJdsMw2h64tGSCmkW685PRtM3CygzX1JOSdptT9UJtpgWwKM8FybRTJups3GTFwj27ZRvlPdIkv3XgCoVJaD5LmR06ozuEPvCCRSdp2WFthg08V5xHc56fTPfZLpr1VmXrhd6dvYhHIqKkQUJR02Rlkss11cLRWEQOssEFVA4xdu2J5DIRO1EM5m7wRRvEwcDB4mYRXD9HH52SMq6iYqUWEWsMwLdbk7QW9yYESUEuzMW5gWrb6vIeWZxJV5bTz1PcWUyR7eO9Fyw1F5DiQYc9JgzTC1mW7cv31fEtTtrfbJYKIb5EbWilqIEUKC6A0UKBDDek35ML0006cqRVm0pvdOH6jeq7VQyYrhdXe59dBEyhYGUIfozoVBvW7Up4QBuOMjyPjSqJPlMBKwaseptfrblxQV1AOOivSBpf1ZcQyOZ8JktRtKUDSuXsmG0lsXwFlI3JCeSHdpVdgZWFYcJPegqfrB6KotR02t9AVkpLs1ZWrixwz"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,31 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ลบ Notification ทั้งหมดของ user ที่ login (Hard delete)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>จำนวนรายการที่ถูกลบ</returns>
|
||||||
|
/// <response code="200">เมื่อทำการลบข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("my-notifications")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> PermanentDeleteAllMyNotificationsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var affectedRows = await _notificationRepository.DeleteAllMyNotificationsAsync();
|
||||||
|
|
||||||
|
return Success(affectedRows);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
placementAppointment.positionAreaOld = org.result.positionArea;
|
placementAppointment.positionAreaOld = org.result.positionArea;
|
||||||
placementAppointment.PositionLevelOld = org.result.posLevelName;
|
placementAppointment.PositionLevelOld = org.result.posLevelName;
|
||||||
placementAppointment.PositionTypeOld = org.result.posTypeName;
|
placementAppointment.PositionTypeOld = org.result.posTypeName;
|
||||||
placementAppointment.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
placementAppointment.PositionNumberOld = org.result.posNo;
|
||||||
placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -1011,7 +1011,9 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
positionExecutive = p.PositionExecutive,
|
positionExecutive = p.PositionExecutive,
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
positionArea = p.positionArea,
|
positionArea = p.positionArea,
|
||||||
|
positionTypeId = p.posTypeId,
|
||||||
positionType = p.posTypeName,
|
positionType = p.posTypeName,
|
||||||
|
positionLevelId = p.posLevelId,
|
||||||
positionLevel = p.posLevelName,
|
positionLevel = p.posLevelName,
|
||||||
posmasterId = p.posmasterId,
|
posmasterId = p.posmasterId,
|
||||||
positionId = p.positionId,
|
positionId = p.positionId,
|
||||||
|
|
@ -1039,24 +1041,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1225,7 +1242,9 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
positionExecutive = p.PositionExecutive,
|
positionExecutive = p.PositionExecutive,
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
positionArea = p.positionArea,
|
positionArea = p.positionArea,
|
||||||
|
positionTypeId = p.posTypeId,
|
||||||
positionType = p.posTypeName,
|
positionType = p.posTypeName,
|
||||||
|
positionLevelId = p.posLevelId,
|
||||||
positionLevel = p.posLevelName,
|
positionLevel = p.posLevelName,
|
||||||
posmasterId = p.posmasterId,
|
posmasterId = p.posmasterId,
|
||||||
positionId = p.positionId,
|
positionId = p.positionId,
|
||||||
|
|
@ -1253,24 +1272,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1453,24 +1487,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1658,24 +1707,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1856,7 +1920,9 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
positionExecutive = p.PositionExecutive,
|
positionExecutive = p.PositionExecutive,
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
positionArea = p.positionArea,
|
positionArea = p.positionArea,
|
||||||
|
positionTypeId = p.posTypeId,
|
||||||
positionType = p.posTypeName,
|
positionType = p.posTypeName,
|
||||||
|
positionLevelId = p.posLevelId,
|
||||||
positionLevel = p.posLevelName,
|
positionLevel = p.posLevelName,
|
||||||
posmasterId = p.posmasterId,
|
posmasterId = p.posmasterId,
|
||||||
positionId = p.positionId,
|
positionId = p.positionId,
|
||||||
|
|
@ -1884,24 +1950,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1993,7 +2074,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ออกคำสั่ง C-PM-47
|
/// ออกคำสั่ง C-PM-47 โปรดเกล้าฯ แต่งตั้งให้ดำรงตำแหน่ง
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
|
|
@ -2047,24 +2128,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
{
|
return Success(resultData);
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -542,7 +542,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
placementAppointment.positionOld = org.result.position;
|
placementAppointment.positionOld = org.result.position;
|
||||||
placementAppointment.PositionLevelOld = org.result.posLevelName;
|
placementAppointment.PositionLevelOld = org.result.posLevelName;
|
||||||
placementAppointment.PositionTypeOld = org.result.posTypeName;
|
placementAppointment.PositionTypeOld = org.result.posTypeName;
|
||||||
placementAppointment.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
placementAppointment.PositionNumberOld = org.result.posNo;
|
||||||
placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
|
||||||
|
|
@ -1989,49 +1989,70 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
Console.WriteLine($"[RecruitReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
|
Console.WriteLine($"[RecruitReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
|
||||||
|
#region Old: Circular Flow
|
||||||
|
// Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
|
||||||
|
// var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
// {
|
||||||
|
// data = resultData
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}");
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles");
|
||||||
|
// placementProfile.ForEach(profile =>
|
||||||
|
// {
|
||||||
|
// profile.PlacementStatus = "DONE";
|
||||||
|
// if (req.refIds.Length > 0)
|
||||||
|
// {
|
||||||
|
// profile.commandId = req.refIds[0].commandId;
|
||||||
|
// profile.refCommandCode = req.refIds[0].commandCode;
|
||||||
|
// profile.refCommandDate = req.refIds[0].commandDateAffect;
|
||||||
|
// profile.refCommandName = req.refIds[0].commandName;
|
||||||
|
// profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
||||||
|
// profile.templateDoc = req.refIds[0].remark;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// Console.WriteLine("[RecruitReportExcecute] Database save completed successfully");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}");
|
||||||
|
// Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
|
// New: Linear Flow
|
||||||
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
var now = DateTime.Now;
|
||||||
using (var client = new HttpClient())
|
placementProfile.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.PlacementStatus = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrl, new
|
profile.LastUpdatedAt = now;
|
||||||
|
if (req.refIds.Length > 0)
|
||||||
{
|
{
|
||||||
data = resultData
|
profile.commandId = req.refIds[0].commandId;
|
||||||
});
|
profile.refCommandCode = req.refIds[0].commandCode;
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
profile.refCommandDate = req.refIds[0].commandDateAffect;
|
||||||
Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}");
|
profile.refCommandName = req.refIds[0].commandName;
|
||||||
if (_res.IsSuccessStatusCode)
|
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
||||||
{
|
profile.templateDoc = req.refIds[0].remark;
|
||||||
Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles");
|
|
||||||
placementProfile.ForEach(profile =>
|
|
||||||
{
|
|
||||||
profile.PlacementStatus = "DONE";
|
|
||||||
if (req.refIds.Length > 0)
|
|
||||||
{
|
|
||||||
profile.commandId = req.refIds[0].commandId;
|
|
||||||
profile.refCommandCode = req.refIds[0].commandCode;
|
|
||||||
profile.refCommandDate = req.refIds[0].commandDateAffect;
|
|
||||||
profile.refCommandName = req.refIds[0].commandName;
|
|
||||||
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
|
||||||
profile.templateDoc = req.refIds[0].remark;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
Console.WriteLine("[RecruitReportExcecute] Database save completed successfully");
|
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
|
||||||
Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}");
|
await _context.SaveChangesAsync();
|
||||||
Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"[RecruitReportExcecute] Process completed successfully at {DateTime.Now}");
|
Console.WriteLine($"[RecruitReportExcecute] Process completed successfully at {DateTime.Now}");
|
||||||
return Success();
|
return Success(resultData);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -2198,8 +2219,11 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
[HttpPost("candidate/report/excecute")]
|
[HttpPost("candidate/report/excecute")]
|
||||||
public async Task<ActionResult<ResponseObject>> PostReportExecuteCandidate([FromBody] ReportExecuteRequest req)
|
public async Task<ActionResult<ResponseObject>> PostReportExecuteCandidate([FromBody] ReportExecuteRequest req)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"[CandidateReportExcecute] Starting execution at {DateTime.Now}");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"[CandidateReportExcecute] Request received with {req?.refIds?.Length ?? 0} refIds");
|
||||||
var placementProfile = await _context.PlacementProfiles
|
var placementProfile = await _context.PlacementProfiles
|
||||||
.Include(x => x.PlacementCertificates)
|
.Include(x => x.PlacementCertificates)
|
||||||
.Include(x => x.PlacementEducations)
|
.Include(x => x.PlacementEducations)
|
||||||
|
|
@ -2207,8 +2231,15 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
Console.WriteLine($"[CandidateReportExcecute] Found {placementProfile?.Count ?? 0} placement profiles");
|
||||||
|
|
||||||
if (placementProfile == null)
|
if (placementProfile == null)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("[CandidateReportExcecute] PlacementProfile is null - returning NotFound");
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("[CandidateReportExcecute] Building resultData from placement profiles and refIds");
|
||||||
|
|
||||||
var resultData = (from p in placementProfile
|
var resultData = (from p in placementProfile
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -2366,43 +2397,78 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
},
|
},
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
Console.WriteLine($"[CandidateReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
|
||||||
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
|
||||||
var _res = await client.PostAsJsonAsync(apiUrl, new
|
|
||||||
{
|
|
||||||
data = resultData
|
|
||||||
});
|
|
||||||
var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
if (_res.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
placementProfile.ForEach(profile =>
|
|
||||||
{
|
|
||||||
profile.PlacementStatus = "DONE";
|
|
||||||
if (req.refIds.Length > 0)
|
|
||||||
{
|
|
||||||
profile.commandId = req.refIds[0].commandId;
|
|
||||||
profile.refCommandCode = req.refIds[0].commandCode;
|
|
||||||
profile.refCommandDate = req.refIds[0].commandDateAffect;
|
|
||||||
profile.refCommandName = req.refIds[0].commandName;
|
|
||||||
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
|
||||||
profile.templateDoc = req.refIds[0].remark;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// // update placementstatus
|
#region Old: Circular Flow
|
||||||
// placementProfile.ForEach(profile => profile.PlacementStatus = "DONE");
|
// Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
|
||||||
// await _context.SaveChangesAsync();
|
// var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
||||||
return Success();
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
// {
|
||||||
|
// data = resultData
|
||||||
|
// });
|
||||||
|
// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}");
|
||||||
|
// if (_res.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles");
|
||||||
|
// placementProfile.ForEach(profile =>
|
||||||
|
// {
|
||||||
|
// profile.PlacementStatus = "DONE";
|
||||||
|
// if (req.refIds.Length > 0)
|
||||||
|
// {
|
||||||
|
// profile.commandId = req.refIds[0].commandId;
|
||||||
|
// profile.refCommandCode = req.refIds[0].commandCode;
|
||||||
|
// profile.refCommandDate = req.refIds[0].commandDateAffect;
|
||||||
|
// profile.refCommandName = req.refIds[0].commandName;
|
||||||
|
// profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
||||||
|
// profile.templateDoc = req.refIds[0].remark;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
|
||||||
|
// await _context.SaveChangesAsync();
|
||||||
|
// Console.WriteLine("[CandidateReportExcecute] Database save completed successfully");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}");
|
||||||
|
// Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow
|
||||||
|
var now = DateTime.Now;
|
||||||
|
placementProfile.ForEach(profile =>
|
||||||
|
{
|
||||||
|
profile.PlacementStatus = "DONE";
|
||||||
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
|
profile.LastUpdatedAt = now;
|
||||||
|
if (req.refIds.Length > 0)
|
||||||
|
{
|
||||||
|
profile.commandId = req.refIds[0].commandId;
|
||||||
|
profile.refCommandCode = req.refIds[0].commandCode;
|
||||||
|
profile.refCommandDate = req.refIds[0].commandDateAffect;
|
||||||
|
profile.refCommandName = req.refIds[0].commandName;
|
||||||
|
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
||||||
|
profile.templateDoc = req.refIds[0].remark;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
Console.WriteLine($"[CandidateReportExcecute] Process completed successfully at {DateTime.Now}");
|
||||||
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
|
return Success(resultData);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine($"[CandidateReportExcecute] Error occurred: {ex.Message}");
|
||||||
|
Console.Error.WriteLine($"[CandidateReportExcecute] Stack trace: {ex.StackTrace}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2587,9 +2653,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -2604,7 +2667,9 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
positionExecutive = p.PositionExecutive,
|
positionExecutive = p.PositionExecutive,
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
positionArea = p.positionArea,
|
positionArea = p.positionArea,
|
||||||
|
positionTypeId = p.posTypeId,
|
||||||
positionType = p.posTypeName,
|
positionType = p.posTypeName,
|
||||||
|
positionLevelId = p.posLevelId,
|
||||||
positionLevel = p.posLevelName,
|
positionLevel = p.posLevelName,
|
||||||
posmasterId = p.posmasterId,
|
posmasterId = p.posmasterId,
|
||||||
positionId = p.positionId,
|
positionId = p.positionId,
|
||||||
|
|
@ -2632,24 +2697,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// //// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// //// if (_res.IsSuccessStatusCode)
|
||||||
|
// //// {
|
||||||
|
// //// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
||||||
|
// //// await _context.SaveChangesAsync();
|
||||||
|
// //// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.PlacementStatus = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
//// var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
//// if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
//// {
|
return Success(resultData);
|
||||||
//// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
//// await _context.SaveChangesAsync();
|
|
||||||
//// }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -2830,9 +2910,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -2847,7 +2924,9 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
positionExecutive = p.PositionExecutive,
|
positionExecutive = p.PositionExecutive,
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
positionArea = p.positionArea,
|
positionArea = p.positionArea,
|
||||||
|
positionTypeId = p.posTypeId,
|
||||||
positionType = p.posTypeName,
|
positionType = p.posTypeName,
|
||||||
|
positionLevelId = p.posLevelId,
|
||||||
positionLevel = p.posLevelName,
|
positionLevel = p.posLevelName,
|
||||||
posmasterId = p.posmasterId,
|
posmasterId = p.posmasterId,
|
||||||
positionId = p.positionId,
|
positionId = p.positionId,
|
||||||
|
|
@ -2875,24 +2954,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// //// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// //// if (_res.IsSuccessStatusCode)
|
||||||
|
// //// {
|
||||||
|
// //// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
||||||
|
// //// await _context.SaveChangesAsync();
|
||||||
|
// //// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.PlacementStatus = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
//// var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
//// if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
//// {
|
return Success(resultData);
|
||||||
//// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
//// await _context.SaveChangesAsync();
|
|
||||||
//// }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -3058,9 +3152,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -3103,24 +3194,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// //// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// //// if (_res.IsSuccessStatusCode)
|
||||||
|
// //// {
|
||||||
|
// //// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
||||||
|
// //// await _context.SaveChangesAsync();
|
||||||
|
// //// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.PlacementStatus = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
//// var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
//// if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
//// {
|
return Success(resultData);
|
||||||
//// data.ForEach(profile => profile.PlacementStatus = "DONE");
|
|
||||||
//// await _context.SaveChangesAsync();
|
|
||||||
//// }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
p.child4OldId,
|
p.child4OldId,
|
||||||
p.child4ShortNameOld,
|
p.child4ShortNameOld,
|
||||||
p.PositionOld,
|
p.PositionOld,
|
||||||
|
p.PositionNumberOld,
|
||||||
p.PositionExecutiveOld,
|
p.PositionExecutiveOld,
|
||||||
p.positionExecutiveFieldOld,
|
p.positionExecutiveFieldOld,
|
||||||
p.positionAreaOld,
|
p.positionAreaOld,
|
||||||
|
|
@ -493,7 +494,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
placementOfficer.positionAreaOld = org.result.positionArea;
|
placementOfficer.positionAreaOld = org.result.positionArea;
|
||||||
placementOfficer.PositionLevelOld = org.result.posLevelName;
|
placementOfficer.PositionLevelOld = org.result.posLevelName;
|
||||||
placementOfficer.PositionTypeOld = org.result.posTypeName;
|
placementOfficer.PositionTypeOld = org.result.posTypeName;
|
||||||
placementOfficer.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
placementOfficer.PositionNumberOld = org.result.posNo;
|
||||||
placementOfficer.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
placementOfficer.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -759,16 +760,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
var firstRef = req.refIds.FirstOrDefault();
|
|
||||||
var commandNoText = firstRef != null ? $"{firstRef.commandNo}/{firstRef.commandYear.ToThaiYear()}" : null;
|
|
||||||
foreach (var profile in data)
|
|
||||||
{
|
|
||||||
profile.Status = "DONE";
|
|
||||||
profile.commandNo = commandNoText;
|
|
||||||
}
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
on p.Id.ToString() equals r.refId
|
on p.Id.ToString() equals r.refId
|
||||||
|
|
@ -810,28 +801,46 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// //// var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// //// if (_res.IsSuccessStatusCode)
|
||||||
|
// //// {
|
||||||
|
// //// foreach (var profile in data)
|
||||||
|
// //// {
|
||||||
|
// //// profile.Status = "DONE";
|
||||||
|
// //// profile.commandNo = resultData.Count > 0 ? $"{resultData[0].commandNo}/{resultData[0].commandYear.ToThaiYear()}" : null;
|
||||||
|
// //// }
|
||||||
|
// //// await _context.SaveChangesAsync();
|
||||||
|
// //// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var firstRef = req.refIds.FirstOrDefault();
|
||||||
|
var commandNoText = firstRef != null ? $"{firstRef.commandNo}/{firstRef.commandYear.ToThaiYear()}" : null;
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.commandNo = commandNoText;
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
{
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
data = resultData,
|
profile.LastUpdatedAt = now;
|
||||||
});
|
});
|
||||||
//// var _result = await _res.Content.ReadAsStringAsync();
|
await _context.SaveChangesAsync();
|
||||||
//// if (_res.IsSuccessStatusCode)
|
|
||||||
//// {
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
//// foreach (var profile in data)
|
return Success(resultData);
|
||||||
//// {
|
|
||||||
//// profile.Status = "DONE";
|
|
||||||
//// profile.commandNo = resultData.Count > 0 ? $"{resultData[0].commandNo}/{resultData[0].commandYear.ToThaiYear()}" : null;
|
|
||||||
//// }
|
|
||||||
//// await _context.SaveChangesAsync();
|
|
||||||
//// }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -514,9 +514,8 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
{
|
{
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
Console.Write($"[PlacementReceiveController] Check-Citizen API-Key : {_configuration["API_KEY"]}");
|
||||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new
|
var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -541,6 +540,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
Console.Write("[PlacementReceiveController] Check-Position");
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||||
var _res = await client.SendAsync(_req);
|
var _res = await client.SendAsync(_req);
|
||||||
|
|
@ -831,7 +831,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new
|
var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new
|
||||||
|
|
||||||
|
|
@ -923,6 +923,61 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API ลบรายการรับโอน (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id รับโอน</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/{id:length(36)}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteForAdminAsync(Guid id)
|
||||||
|
{
|
||||||
|
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_TRANSFER_RECEIVE");
|
||||||
|
if (jsonData!.status != 200)
|
||||||
|
{
|
||||||
|
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||||
|
if (jsonData.result.privilege != "OWNER")
|
||||||
|
{
|
||||||
|
return Error("ไม่มีสิทธิ์ในการลบรายการรับโอน", StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
var deleted = await _context.PlacementReceives.AsQueryable()
|
||||||
|
.Include(x => x.PlacementReceiveDocs)
|
||||||
|
.ThenInclude(x => x.Document)
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (deleted == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
// ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE
|
||||||
|
if (new[] { "REPORT", "WAITING", "DONE" }.Contains(deleted.Status))
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถลบรายการรับโอนสถานะนี้ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
var placementReceiveDocs = new List<dynamic>();
|
||||||
|
foreach (var doc in deleted.PlacementReceiveDocs)
|
||||||
|
{
|
||||||
|
if (doc.Document != null)
|
||||||
|
placementReceiveDocs.Add(doc.Document.Id);
|
||||||
|
}
|
||||||
|
_context.PlacementReceiveDocs.RemoveRange(deleted.PlacementReceiveDocs);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_context.PlacementReceives.Remove(deleted);
|
||||||
|
foreach (var doc in placementReceiveDocs)
|
||||||
|
{
|
||||||
|
if (doc != null)
|
||||||
|
await _documentService.DeleteFileAsync(doc);
|
||||||
|
}
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// สั่งรายชื่อไปออกคำสั่ง
|
/// สั่งรายชื่อไปออกคำสั่ง
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1126,127 +1181,150 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
[HttpPost("command/report/excecute")]
|
[HttpPost("command/report/excecute")]
|
||||||
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
|
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
|
||||||
{
|
{
|
||||||
var data = await _context.PlacementReceives
|
Console.WriteLine($"[ReceiveReportExcecute] Starting execution at {DateTime.Now}");
|
||||||
.Include(x => x.Avatar)
|
try
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
||||||
.ToListAsync();
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
|
||||||
join r in req.refIds
|
|
||||||
on p.Id.ToString() equals r.refId
|
|
||||||
select new
|
|
||||||
{
|
|
||||||
bodyProfile = new
|
|
||||||
{
|
|
||||||
rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank,
|
|
||||||
prefix = p.prefix == null ? string.Empty : p.prefix,
|
|
||||||
firstName = p.firstName == null ? string.Empty : p.firstName,
|
|
||||||
lastName = p.lastName == null ? string.Empty : p.lastName,
|
|
||||||
citizenId = p.citizenId == null ? string.Empty : p.citizenId,
|
|
||||||
position = p.position == null ? string.Empty : p.position,
|
|
||||||
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
|
|
||||||
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
|
|
||||||
email = (String?)null,
|
|
||||||
phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber,
|
|
||||||
keycloak = string.Empty,
|
|
||||||
isProbation = false,
|
|
||||||
isLeave = false,
|
|
||||||
dateRetire = (DateTime?)null,
|
|
||||||
dateAppoint = r.commandDateAffect,
|
|
||||||
dateStart = r.commandDateAffect,
|
|
||||||
govAgeAbsent = 0,
|
|
||||||
govAgePlus = 0,
|
|
||||||
birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth,
|
|
||||||
reasonSameDate = (DateTime?)null,
|
|
||||||
ethnicity = p.Race == null ? string.Empty : p.Race,
|
|
||||||
telephoneNumber = (String?)null,
|
|
||||||
nationality = p.Nationality == null ? string.Empty : p.Nationality,
|
|
||||||
gender = p.Gender == null ? string.Empty : p.Gender,
|
|
||||||
relationship = p.Relationship == null ? string.Empty : p.Relationship,
|
|
||||||
religion = p.Religion == null ? string.Empty : p.Religion,
|
|
||||||
bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup,
|
|
||||||
registrationAddress = (String?)null,
|
|
||||||
registrationProvinceId = (String?)null,
|
|
||||||
registrationDistrictId = (String?)null,
|
|
||||||
registrationSubDistrictId = (String?)null,
|
|
||||||
registrationZipCode = (String?)null,
|
|
||||||
currentAddress = (String?)null,
|
|
||||||
currentProvinceId = (String?)null,
|
|
||||||
currentDistrictId = (String?)null,
|
|
||||||
currentSubDistrictId = (String?)null,
|
|
||||||
currentZipCode = (String?)null,
|
|
||||||
amount = r.amount,
|
|
||||||
amountSpecial = r.amountSpecial,
|
|
||||||
objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null,
|
|
||||||
},
|
|
||||||
bodySalarys = new
|
|
||||||
{
|
|
||||||
profileId = p.profileId,
|
|
||||||
amount = r.amount,
|
|
||||||
amountSpecial = r.amountSpecial,
|
|
||||||
positionSalaryAmount = r.positionSalaryAmount,
|
|
||||||
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
||||||
positionExecutive = p.PositionExecutive,
|
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
|
||||||
positionArea = p.positionArea,
|
|
||||||
positionType = p.posTypeName,
|
|
||||||
positionLevel = p.posLevelName,
|
|
||||||
commandId = r.commandId,
|
|
||||||
orgRoot = p.root,
|
|
||||||
orgChild1 = p.child1,
|
|
||||||
orgChild2 = p.child2,
|
|
||||||
orgChild3 = p.child3,
|
|
||||||
orgChild4 = p.child4,
|
|
||||||
commandNo = r.commandNo,
|
|
||||||
commandYear = r.commandYear,
|
|
||||||
posNo = p.posMasterNo?.ToString(),
|
|
||||||
posNoAbb = p.node == 4 ? $"{p.child4ShortName}" :
|
|
||||||
p.node == 3 ? $"{p.child3ShortName}" :
|
|
||||||
p.node == 2 ? $"{p.child2ShortName}" :
|
|
||||||
p.node == 1 ? $"{p.child1ShortName}" :
|
|
||||||
p.node == 0 ? $"{p.rootShortName}" : "",
|
|
||||||
commandDateAffect = r.commandDateAffect,
|
|
||||||
commandDateSign = r.commandDateSign,
|
|
||||||
positionName = p.position,
|
|
||||||
commandCode = r.commandCode,
|
|
||||||
commandName = r.commandName,
|
|
||||||
remark = r.remark,
|
|
||||||
},
|
|
||||||
bodyPosition = new
|
|
||||||
{
|
|
||||||
posmasterId = p.posmasterId,
|
|
||||||
positionId = p.positionId,
|
|
||||||
positionName = p.position,
|
|
||||||
positionField = p.positionField,
|
|
||||||
posTypeId = p.posTypeId,
|
|
||||||
posLevelId = p.posLevelId,
|
|
||||||
posExecutiveId = p.posExecutiveId,
|
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
|
||||||
positionArea = p.positionArea,
|
|
||||||
}
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
|
||||||
var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
var data = await _context.PlacementReceives
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
.Include(x => x.Avatar)
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var resultData = (from p in data
|
||||||
|
join r in req.refIds
|
||||||
|
on p.Id.ToString() equals r.refId
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
bodyProfile = new
|
||||||
|
{
|
||||||
|
rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank,
|
||||||
|
prefix = p.prefix == null ? string.Empty : p.prefix,
|
||||||
|
firstName = p.firstName == null ? string.Empty : p.firstName,
|
||||||
|
lastName = p.lastName == null ? string.Empty : p.lastName,
|
||||||
|
citizenId = p.citizenId == null ? string.Empty : p.citizenId,
|
||||||
|
position = p.position == null ? string.Empty : p.position,
|
||||||
|
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
|
||||||
|
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
|
||||||
|
email = (String?)null,
|
||||||
|
phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber,
|
||||||
|
keycloak = string.Empty,
|
||||||
|
isProbation = false,
|
||||||
|
isLeave = false,
|
||||||
|
dateRetire = (DateTime?)null,
|
||||||
|
dateAppoint = r.commandDateAffect,
|
||||||
|
dateStart = r.commandDateAffect,
|
||||||
|
govAgeAbsent = 0,
|
||||||
|
govAgePlus = 0,
|
||||||
|
birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth,
|
||||||
|
reasonSameDate = (DateTime?)null,
|
||||||
|
ethnicity = p.Race == null ? string.Empty : p.Race,
|
||||||
|
telephoneNumber = (String?)null,
|
||||||
|
nationality = p.Nationality == null ? string.Empty : p.Nationality,
|
||||||
|
gender = p.Gender == null ? string.Empty : p.Gender,
|
||||||
|
relationship = p.Relationship == null ? string.Empty : p.Relationship,
|
||||||
|
religion = p.Religion == null ? string.Empty : p.Religion,
|
||||||
|
bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup,
|
||||||
|
registrationAddress = (String?)null,
|
||||||
|
registrationProvinceId = (String?)null,
|
||||||
|
registrationDistrictId = (String?)null,
|
||||||
|
registrationSubDistrictId = (String?)null,
|
||||||
|
registrationZipCode = (String?)null,
|
||||||
|
currentAddress = (String?)null,
|
||||||
|
currentProvinceId = (String?)null,
|
||||||
|
currentDistrictId = (String?)null,
|
||||||
|
currentSubDistrictId = (String?)null,
|
||||||
|
currentZipCode = (String?)null,
|
||||||
|
amount = r.amount,
|
||||||
|
amountSpecial = r.amountSpecial,
|
||||||
|
objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null,
|
||||||
|
},
|
||||||
|
bodySalarys = new
|
||||||
|
{
|
||||||
|
profileId = p.profileId,
|
||||||
|
amount = r.amount,
|
||||||
|
amountSpecial = r.amountSpecial,
|
||||||
|
positionSalaryAmount = r.positionSalaryAmount,
|
||||||
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
||||||
|
positionExecutive = p.PositionExecutive,
|
||||||
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
|
positionArea = p.positionArea,
|
||||||
|
positionType = p.posTypeName,
|
||||||
|
positionLevel = p.posLevelName,
|
||||||
|
commandId = r.commandId,
|
||||||
|
orgRoot = p.root,
|
||||||
|
orgChild1 = p.child1,
|
||||||
|
orgChild2 = p.child2,
|
||||||
|
orgChild3 = p.child3,
|
||||||
|
orgChild4 = p.child4,
|
||||||
|
commandNo = r.commandNo,
|
||||||
|
commandYear = r.commandYear,
|
||||||
|
posNo = p.posMasterNo?.ToString(),
|
||||||
|
posNoAbb = p.node == 4 ? $"{p.child4ShortName}" :
|
||||||
|
p.node == 3 ? $"{p.child3ShortName}" :
|
||||||
|
p.node == 2 ? $"{p.child2ShortName}" :
|
||||||
|
p.node == 1 ? $"{p.child1ShortName}" :
|
||||||
|
p.node == 0 ? $"{p.rootShortName}" : "",
|
||||||
|
commandDateAffect = r.commandDateAffect,
|
||||||
|
commandDateSign = r.commandDateSign,
|
||||||
|
positionName = p.position,
|
||||||
|
commandCode = r.commandCode,
|
||||||
|
commandName = r.commandName,
|
||||||
|
remark = r.remark,
|
||||||
|
},
|
||||||
|
bodyPosition = new
|
||||||
|
{
|
||||||
|
posmasterId = p.posmasterId,
|
||||||
|
positionId = p.positionId,
|
||||||
|
positionName = p.position,
|
||||||
|
positionField = p.positionField,
|
||||||
|
posTypeId = p.posTypeId,
|
||||||
|
posLevelId = p.posLevelId,
|
||||||
|
posExecutiveId = p.posExecutiveId,
|
||||||
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
|
positionArea = p.positionArea,
|
||||||
|
}
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
Console.WriteLine($"[ReceiveReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
|
||||||
|
#region Old: Circular Flow
|
||||||
|
// var baseAPIOrg = _configuration["API"];
|
||||||
|
// var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
data = resultData,
|
profile.Status = "DONE";
|
||||||
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
|
profile.LastUpdatedAt = now;
|
||||||
});
|
});
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
Console.WriteLine($"[ReceiveReportExcecute] Saving changes to database for {data.Count} profiles");
|
||||||
// // if (_res.IsSuccessStatusCode)
|
await _context.SaveChangesAsync();
|
||||||
// // {
|
Console.WriteLine($"[ReceiveReportExcecute] Process completed successfully at {DateTime.Now}");
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
return Success(resultData);
|
||||||
// // await _context.SaveChangesAsync();
|
}
|
||||||
// // }
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"[ReceiveReportExcecute] Error occurred: {ex.Message}");
|
||||||
|
Console.Error.WriteLine($"[ReceiveReportExcecute] Stack trace: {ex.StackTrace}");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
placementRepatriation.positionAreaOld = org.result.positionArea;
|
placementRepatriation.positionAreaOld = org.result.positionArea;
|
||||||
placementRepatriation.PositionLevelOld = org.result.posLevelName;
|
placementRepatriation.PositionLevelOld = org.result.posLevelName;
|
||||||
placementRepatriation.PositionTypeOld = org.result.posTypeName;
|
placementRepatriation.PositionTypeOld = org.result.posTypeName;
|
||||||
placementRepatriation.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
placementRepatriation.PositionNumberOld = org.result.posNo;
|
||||||
placementRepatriation.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
placementRepatriation.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -623,9 +623,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
var data = await _context.PlacementRepatriations
|
var data = await _context.PlacementRepatriations
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
string? _null = null;
|
string? _null = null;
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
|
|
@ -668,25 +665,39 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
commandName = r.commandName,
|
commandName = r.commandName,
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
#region Old: Circular Flow
|
||||||
|
// var baseAPIOrg = _configuration["API"];
|
||||||
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
// New: Linear Flow - Task #224ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
var now = DateTime.Now;
|
||||||
using (var client = new HttpClient())
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // {
|
return Success(resultData);
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -932,6 +932,60 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API ลบรายการคำขอโอน (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id คำขอโอน</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/{id:length(36)}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteForAdminAsync(Guid id)
|
||||||
|
{
|
||||||
|
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_TRANSFER_REQ");
|
||||||
|
if (jsonData!.status != 200)
|
||||||
|
{
|
||||||
|
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||||
|
if (jsonData.result.privilege != "OWNER")
|
||||||
|
{
|
||||||
|
return Error("ไม่มีสิทธิ์ในการลบรายการคำขอโอน", StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
var deleted = await _context.PlacementTransfers.AsQueryable()
|
||||||
|
.Include(x => x.PlacementTransferDocs)
|
||||||
|
.ThenInclude(x => x.Document)
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (deleted == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
// ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE
|
||||||
|
if (new[] { "REPORT", "WAITING", "DONE" }.Contains(deleted.Status))
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถลบรายการคำขอโอนสถานะนี้ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
var placementTransferDocs = new List<dynamic>();
|
||||||
|
foreach (var doc in deleted.PlacementTransferDocs)
|
||||||
|
{
|
||||||
|
if (doc.Document != null)
|
||||||
|
placementTransferDocs.Add(doc.Document.Id);
|
||||||
|
}
|
||||||
|
_context.PlacementTransferDocs.RemoveRange(deleted.PlacementTransferDocs);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_context.PlacementTransfers.Remove(deleted);
|
||||||
|
foreach (var doc in placementTransferDocs)
|
||||||
|
{
|
||||||
|
if (doc != null)
|
||||||
|
await _documentService.DeleteFileAsync(doc);
|
||||||
|
}
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// สั่งรายชื่อไปออกคำสั่ง
|
/// สั่งรายชื่อไปออกคำสั่ง
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1094,9 +1148,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
var data = await _context.PlacementTransfers
|
var data = await _context.PlacementTransfers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -1140,24 +1191,38 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // if (_res.IsSuccessStatusCode)
|
return Success(resultData);
|
||||||
// // {
|
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ using System.Text;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
using BMA.EHR.Placement.Service.Filters;
|
using BMA.EHR.Placement.Service.Filters;
|
||||||
using BMA.EHR.Application.Repositories.Reports;
|
using BMA.EHR.Application.Repositories.Reports;
|
||||||
|
using BMA.EHR.Application.Repositories;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
{
|
{
|
||||||
|
|
@ -164,6 +165,8 @@ var app = builder.Build();
|
||||||
if (manager != null)
|
if (manager != null)
|
||||||
{
|
{
|
||||||
manager.AddOrUpdate("แจ้งเตือนระบบทดลองงาน", Job.FromExpression<ProbationReportRepository>(x => x.NotifyProbation()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
manager.AddOrUpdate("แจ้งเตือนระบบทดลองงาน", Job.FromExpression<ProbationReportRepository>(x => x.NotifyProbation()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||||
|
// Job: อัพเดทสถานะผู้สอบผ่านที่ลาออกไปแล้วแต่ยังไม่ส่งไปออกคำสั่ง ทำงานทุกวันเวลา 05:00 น.
|
||||||
|
manager.AddOrUpdate("ประมวลผลข้าราชการฯ กทม.", Job.FromExpression<PlacementRepository>(x => x.UpdateStatusPlacementProfiles()), Cron.Daily(5), TimeZoneInfo.Local);
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply migrations
|
// apply migrations
|
||||||
|
|
|
||||||
|
|
@ -448,12 +448,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
retirementOther.positionAreaOld = org.result.positionArea;
|
retirementOther.positionAreaOld = org.result.positionArea;
|
||||||
retirementOther.PositionLevelOld = org.result.posLevelName;
|
retirementOther.PositionLevelOld = org.result.posLevelName;
|
||||||
retirementOther.PositionTypeOld = org.result.posTypeName;
|
retirementOther.PositionTypeOld = org.result.posTypeName;
|
||||||
retirementOther.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
retirementOther.PositionNumberOld = org.result.posNo;
|
||||||
retirementOther.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
retirementOther.OrganizationOld = org.result.org ?? "";
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
|
||||||
(org.result.child1 == null ? "" : org.result.child1 + "\n") +
|
|
||||||
(org.result.root == null ? "" : org.result.root);
|
|
||||||
retirementOther.OrganizationPositionOld = org.result.position + "\n" +
|
retirementOther.OrganizationPositionOld = org.result.position + "\n" +
|
||||||
(retirementOther.PositionExecutiveOld == null ? "" : (retirementOther.positionExecutiveField == null ? retirementOther.PositionExecutiveOld + "\n" : retirementOther.PositionExecutiveOld + "(" + retirementOther.positionExecutiveField + ")" + "\n"))
|
(retirementOther.PositionExecutiveOld == null ? "" : (retirementOther.positionExecutiveField == null ? retirementOther.PositionExecutiveOld + "\n" : retirementOther.PositionExecutiveOld + "(" + retirementOther.positionExecutiveField + ")" + "\n"))
|
||||||
+ retirementOther.OrganizationOld;
|
+ retirementOther.OrganizationOld;
|
||||||
|
|
@ -846,9 +842,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
var data = await _context.RetirementOthers
|
var data = await _context.RetirementOthers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
string? _null = null;
|
string? _null = null;
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
|
|
@ -912,24 +905,39 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
orgChild4New = p.child4
|
orgChild4New = p.child4
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // {
|
return Success(resultData);
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1098,9 +1106,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
var data = await _context.RetirementOthers
|
var data = await _context.RetirementOthers
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
string? _null = null;
|
string? _null = null;
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
|
|
@ -1164,24 +1169,39 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
orgChild4New = p.child4
|
orgChild4New = p.child4
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // {
|
return Success(resultData);
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -629,7 +629,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ออกคำสั่ง C-PM-18 คำสั่งให้ออกจากราชการ
|
/// ออกคำสั่ง C-PM-18 ให้ออกจากราชการ && C-PM-43 ให้ลูกจ้างออกจากราชการ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
|
|
@ -642,10 +642,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
var data = await _context.RetirementOuts
|
var data = await _context.RetirementOuts
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
on p.Id.ToString() equals r.refId
|
on p.Id.ToString() equals r.refId
|
||||||
|
|
@ -688,31 +684,46 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
resignId = p.Id,
|
resignId = p.Id,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
if (data.Count > 0)
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
|
// if (data.Count > 0)
|
||||||
|
// {
|
||||||
|
// if (data[0].profileType == "EMPLOYEE")
|
||||||
|
// {
|
||||||
|
// apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
if (data[0].profileType == "EMPLOYEE")
|
profile.Status = "DONE";
|
||||||
{
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
}
|
profile.LastUpdatedAt = now;
|
||||||
}
|
});
|
||||||
using (var client = new HttpClient())
|
await _context.SaveChangesAsync();
|
||||||
{
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
return Success(resultData);
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
||||||
{
|
|
||||||
data = resultData,
|
|
||||||
});
|
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
|
||||||
// // {
|
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
||||||
|
|
||||||
var retirementResigns = await _context.RetirementResigns.AsQueryable()
|
var retirementResigns = await _context.RetirementResigns.AsQueryable()
|
||||||
.Where(x => x.profileId == org.result.profileId)
|
.Where(x => x.Status != "DELETE" && x.profileId == org.result.profileId)
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
.Select(p => new
|
.Select(p => new
|
||||||
{
|
{
|
||||||
|
|
@ -1290,7 +1290,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
retirementResign.positionAreaOld = org.result.positionArea;
|
retirementResign.positionAreaOld = org.result.positionArea;
|
||||||
retirementResign.PositionLevelOld = org.result.posLevelName;
|
retirementResign.PositionLevelOld = org.result.posLevelName;
|
||||||
retirementResign.PositionTypeOld = org.result.posTypeName;
|
retirementResign.PositionTypeOld = org.result.posTypeName;
|
||||||
retirementResign.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
retirementResign.PositionNumberOld = org.result.posNo;
|
||||||
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -1439,7 +1439,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
retirementResign.positionAreaOld = org.result.positionArea;
|
retirementResign.positionAreaOld = org.result.positionArea;
|
||||||
retirementResign.PositionLevelOld = org.result.posLevelName;
|
retirementResign.PositionLevelOld = org.result.posLevelName;
|
||||||
retirementResign.PositionTypeOld = org.result.posTypeName;
|
retirementResign.PositionTypeOld = org.result.posTypeName;
|
||||||
retirementResign.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
retirementResign.PositionNumberOld = org.result.posNo;
|
||||||
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -1513,7 +1513,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
||||||
|
|
||||||
updated.Location = req.Location;
|
updated.Location = req.Location;
|
||||||
updated.ActiveDate = req.ActiveDate;
|
if (req.SendDate != null)
|
||||||
|
{
|
||||||
|
updated.SendDate = req.SendDate;
|
||||||
|
}
|
||||||
// updated.Reason = req.Reason;
|
// updated.Reason = req.Reason;
|
||||||
updated.Remark = req.Remark;
|
updated.Remark = req.Remark;
|
||||||
updated.ReasonResign = req.Reason;
|
updated.ReasonResign = req.Reason;
|
||||||
|
|
@ -1811,6 +1814,47 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API ลบรายการลาออก (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id ลาออก</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/{id:length(36)}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteForAdminAsync(Guid id)
|
||||||
|
{
|
||||||
|
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_RESIGN");
|
||||||
|
if (jsonData!.status != 200)
|
||||||
|
{
|
||||||
|
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||||
|
if (jsonData.result.privilege != "OWNER")
|
||||||
|
{
|
||||||
|
return Error("ไม่มีสิทธิ์ในการลบรายการลาออก", StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
var deleted = await _context.RetirementResigns.AsQueryable()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (deleted == null)
|
||||||
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
||||||
|
|
||||||
|
// ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE, CANCELING, CANCEL
|
||||||
|
if (new[] { "REPORT", "WAITING", "DONE", "CANCELING", "CANCEL" }.Contains(deleted.Status))
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถลบรายการลาออกสถานะนี้ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
deleted.Status = "DELETE";
|
||||||
|
deleted.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
deleted.LastUpdateUserId = UserId ?? "";
|
||||||
|
deleted.LastUpdatedAt = DateTime.Now;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// อนุมัติคำลาออก
|
/// อนุมัติคำลาออก
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -2863,10 +2907,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
var data = await _context.RetirementResigns
|
var data = await _context.RetirementResigns
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
on p.Id.ToString() equals r.refId
|
on p.Id.ToString() equals r.refId
|
||||||
|
|
@ -2911,25 +2951,239 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
remark = r.remark,
|
remark = r.remark,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // {
|
return Success(resultData);
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
}
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
/// <summary>
|
||||||
}
|
/// ส่งรายชื่อออกคำสั่ง C-PM-48
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("command48/report")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> PostReport48([FromBody] ReportPersonRequest req)
|
||||||
|
{
|
||||||
|
var resigns = await _context.RetirementResigns
|
||||||
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
||||||
|
.ToListAsync();
|
||||||
|
resigns.ForEach(profile => profile.Status = req.status.Trim().ToUpper());
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// ลบรายชื่อออกคำสั่ง C-PM-48
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("command48/report/delete")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> PostReportDelete48([FromBody] ReportPersonRequest req)
|
||||||
|
{
|
||||||
|
var resigns = await _context.RetirementResigns
|
||||||
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
||||||
|
.Where(x => x.Status.ToUpper() == "REPORT")
|
||||||
|
.ToListAsync();
|
||||||
|
resigns.ForEach(profile => profile.Status = "APPROVE");
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// เอกสารแนบท้าย C-PM-48
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Record Id ของคำสั่ง</param>
|
||||||
|
/// <param name="exportType">pdf, docx หรือ xlsx</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("command48/report/attachment")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> PostReportAttachment48([FromBody] ReportAttachmentRequest req)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var report_data = (from p in _context.RetirementResigns
|
||||||
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
|
.ToList()
|
||||||
|
join r in req.refIds
|
||||||
|
on p.Id.ToString() equals r.refId
|
||||||
|
orderby r.Sequence
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
No = r.Sequence.ToString().ToThaiNumber(),
|
||||||
|
CitizenId = r.CitizenId == null ? "-" : r.CitizenId.ToThaiNumber(),
|
||||||
|
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
||||||
|
PositionName = p.PositionOld ?? "-",
|
||||||
|
Organization = p.OrganizationPositionOld ?? "-",
|
||||||
|
PositionLevel = p.PositionLevelOld ?? "-",
|
||||||
|
PositionType = p.PositionTypeOld ?? "-",
|
||||||
|
PositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(),
|
||||||
|
ActiveDate = p.ActiveDate == null ? "-" : p.ActiveDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
||||||
|
Salary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
||||||
|
Remark = p.Reason ?? "-",
|
||||||
|
RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(),
|
||||||
|
RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber()
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var result = new List<dynamic>();
|
||||||
|
|
||||||
|
foreach (var r in report_data)
|
||||||
|
{
|
||||||
|
result.Add(r);
|
||||||
|
string? _null = null;
|
||||||
|
if (r.RemarkHorizontal != null && r.RemarkHorizontal != "")
|
||||||
|
{
|
||||||
|
result.Add(new
|
||||||
|
{
|
||||||
|
No = _null,
|
||||||
|
FullName = r.RemarkHorizontal,
|
||||||
|
CitizenId = _null,
|
||||||
|
PositionName = _null,
|
||||||
|
Organization = _null,
|
||||||
|
PositionLevel = _null,
|
||||||
|
PositionType = _null,
|
||||||
|
PositionNumber = _null,
|
||||||
|
ActiveDate = _null,
|
||||||
|
Salary = _null,
|
||||||
|
Remark = _null,
|
||||||
|
RemarkHorizontal = _null,
|
||||||
|
RemarkVertical = _null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ออกคำสั่ง C-PM-48 คำสั่งอนุญาตให้ลาออกไปรับราชการทหาร
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("command48/report/excecute")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> PostReportExecute48([FromBody] ReportExecuteRequest req)
|
||||||
|
{
|
||||||
|
var data = await _context.RetirementResigns
|
||||||
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
|
.ToListAsync();
|
||||||
|
var resultData = (from p in data
|
||||||
|
join r in req.refIds
|
||||||
|
on p.Id.ToString() equals r.refId
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
profileId = p.profileId,
|
||||||
|
amount = r.amount,
|
||||||
|
amountSpecial = r.amountSpecial,
|
||||||
|
positionSalaryAmount = r.positionSalaryAmount,
|
||||||
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
||||||
|
positionExecutive = p.PositionExecutiveOld,
|
||||||
|
positionExecutiveField = p.positionExecutiveFieldOld,
|
||||||
|
positionArea = p.positionAreaOld,
|
||||||
|
positionType = p.PositionTypeOld,
|
||||||
|
positionLevel = p.PositionLevelOld,
|
||||||
|
isLeave = p.IsCancel == true ? false : true,
|
||||||
|
leaveReason = p.ReasonResign == "อื่น ๆ"
|
||||||
|
? string.IsNullOrWhiteSpace(p.Remark) ? p.ReasonResign : $"{p.ReasonResign}({p.Remark})"
|
||||||
|
: p.ReasonResign,
|
||||||
|
dateLeave = r.commandDateAffect,
|
||||||
|
commandId = r.commandId,
|
||||||
|
isGovernment = false,
|
||||||
|
orgRoot = p.rootOld,
|
||||||
|
orgChild1 = p.child1Old,
|
||||||
|
orgChild2 = p.child2Old,
|
||||||
|
orgChild3 = p.child3Old,
|
||||||
|
orgChild4 = p.child4Old,
|
||||||
|
commandNo = r.commandNo,
|
||||||
|
commandYear = r.commandYear,
|
||||||
|
posNo = p.posMasterNoOld?.ToString(),
|
||||||
|
posNoAbb = p.child4ShortNameOld != null ? $"{p.child4ShortNameOld}" :
|
||||||
|
p.child3ShortNameOld != null ? $"{p.child3ShortNameOld}" :
|
||||||
|
p.child2ShortNameOld != null ? $"{p.child2ShortNameOld}" :
|
||||||
|
p.child1ShortNameOld != null ? $"{p.child1ShortNameOld}" :
|
||||||
|
p.rootShortNameOld != null ? $"{p.rootShortNameOld}" : "",
|
||||||
|
commandDateAffect = r.commandDateAffect,
|
||||||
|
commandDateSign = r.commandDateSign,
|
||||||
|
positionName = p.PositionOld,
|
||||||
|
commandCode = r.commandCode,
|
||||||
|
commandName = r.commandName,
|
||||||
|
remark = r.remark,
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
#region Old: Circular Flow
|
||||||
|
// var baseAPIOrg = _configuration["API"];
|
||||||
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
|
{
|
||||||
|
profile.Status = "DONE";
|
||||||
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
|
profile.LastUpdatedAt = now;
|
||||||
|
});
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
|
return Success(resultData);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ส่งรายชื่อออกคำสั่ง C-PM-41
|
/// ส่งรายชื่อออกคำสั่ง C-PM-41
|
||||||
|
|
@ -3066,11 +3320,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
.Include(x => x.RetirementResign)
|
.Include(x => x.RetirementResign)
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
data.ForEach(profile => profile.RetirementResign.Status = "CANCEL");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
string? _null = null;
|
string? _null = null;
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -3114,7 +3363,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
resignId = p.RetirementResign.Id,
|
resignId = p.RetirementResign.Id,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
|
// var baseAPIOrg = _configuration["API"];
|
||||||
//var reportDone = false;
|
//var reportDone = false;
|
||||||
//if (data.Where(profile => profile.Status == "DONE").Any())
|
//if (data.Where(profile => profile.Status == "DONE").Any())
|
||||||
//{
|
//{
|
||||||
|
|
@ -3122,23 +3372,23 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
//}
|
//}
|
||||||
//if (reportDone == true)
|
//if (reportDone == true)
|
||||||
//{
|
//{
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
||||||
using (var client = new HttpClient())
|
// using (var client = new HttpClient())
|
||||||
{
|
// {
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
{
|
// {
|
||||||
data = resultData,
|
// data = resultData,
|
||||||
});
|
// });
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
// // {
|
// // // {
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
// // data.ForEach(profile => profile.RetirementResign.Status = "CANCEL");
|
// // // data.ForEach(profile => profile.RetirementResign.Status = "CANCEL");
|
||||||
// // await _context.SaveChangesAsync();
|
// // // await _context.SaveChangesAsync();
|
||||||
// // }
|
// // // }
|
||||||
}
|
// }
|
||||||
//}
|
//}
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
|
|
@ -3160,7 +3410,22 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
return Success();
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
|
{
|
||||||
|
profile.Status = "DONE";
|
||||||
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
|
profile.LastUpdatedAt = now;
|
||||||
|
});
|
||||||
|
data.ForEach(profile => profile.RetirementResign.Status = "CANCEL");
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
|
return Success(resultData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 33-แบบฟอร์มหนังสือขอลาออกจากราชการ
|
#region 33-แบบฟอร์มหนังสือขอลาออกจากราชการ
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
||||||
|
|
||||||
var retirementResignEmployees = await _context.RetirementResignEmployees.AsQueryable()
|
var retirementResignEmployees = await _context.RetirementResignEmployees.AsQueryable()
|
||||||
.Where(x => x.profileId == org.result.profileId)
|
.Where(x => x.Status != "DELETE" && x.profileId == org.result.profileId)
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
.Select(p => new
|
.Select(p => new
|
||||||
{
|
{
|
||||||
|
|
@ -1227,7 +1227,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
retirementResignEmployee.PositionOld = org.result.position;
|
retirementResignEmployee.PositionOld = org.result.position;
|
||||||
retirementResignEmployee.PositionLevelOld = org.result.posLevelName;
|
retirementResignEmployee.PositionLevelOld = org.result.posLevelName;
|
||||||
retirementResignEmployee.PositionTypeOld = org.result.posTypeName;
|
retirementResignEmployee.PositionTypeOld = org.result.posTypeName;
|
||||||
retirementResignEmployee.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
retirementResignEmployee.PositionNumberOld = org.result.posNo;
|
||||||
retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -1381,7 +1381,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
retirementResignEmployee.PositionOld = org.result.position;
|
retirementResignEmployee.PositionOld = org.result.position;
|
||||||
retirementResignEmployee.PositionLevelOld = org.result.posLevelName;
|
retirementResignEmployee.PositionLevelOld = org.result.posLevelName;
|
||||||
retirementResignEmployee.PositionTypeOld = org.result.posTypeName;
|
retirementResignEmployee.PositionTypeOld = org.result.posTypeName;
|
||||||
retirementResignEmployee.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo;
|
retirementResignEmployee.PositionNumberOld = org.result.posNo;
|
||||||
retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
|
||||||
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
|
||||||
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
|
||||||
|
|
@ -1450,7 +1450,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Error(GlobalMessages.RetirementResignEmployeeNotFound, 404);
|
return Error(GlobalMessages.RetirementResignEmployeeNotFound, 404);
|
||||||
|
|
||||||
updated.Location = req.Location;
|
updated.Location = req.Location;
|
||||||
updated.ActiveDate = req.ActiveDate;
|
if (req.SendDate != null)
|
||||||
|
{
|
||||||
|
updated.SendDate = req.SendDate;
|
||||||
|
}
|
||||||
// updated.Reason = req.Reason;
|
// updated.Reason = req.Reason;
|
||||||
updated.Remark = req.Remark;
|
updated.Remark = req.Remark;
|
||||||
updated.ReasonResign = req.Reason;
|
updated.ReasonResign = req.Reason;
|
||||||
|
|
@ -1719,6 +1722,47 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API ลบรายการลาออกลูกจ้าง (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id ลาออก</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/{id:length(36)}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteForAdminAsync(Guid id)
|
||||||
|
{
|
||||||
|
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_RESIGN_EMP");
|
||||||
|
if (jsonData!.status != 200)
|
||||||
|
{
|
||||||
|
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||||
|
if (jsonData.result.privilege != "OWNER")
|
||||||
|
{
|
||||||
|
return Error("ไม่มีสิทธิ์ในการลบรายการลาออกลูกจ้าง", StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
var deleted = await _context.RetirementResignEmployees.AsQueryable()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (deleted == null)
|
||||||
|
return Error(GlobalMessages.RetirementResignEmployeeNotFound, 404);
|
||||||
|
|
||||||
|
// ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE, CANCELING, CANCEL
|
||||||
|
if (new[] { "REPORT", "WAITING", "DONE", "CANCELING", "CANCEL" }.Contains(deleted.Status))
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถลบรายการลาออกลูกจ้างสถานะนี้ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
deleted.Status = "DELETE";
|
||||||
|
deleted.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
deleted.LastUpdateUserId = UserId ?? "";
|
||||||
|
deleted.LastUpdatedAt = DateTime.Now;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// อนุมัติคำลาออก
|
/// อนุมัติคำลาออก
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -2361,10 +2405,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
var data = await _context.RetirementResignEmployees
|
var data = await _context.RetirementResignEmployees
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
on p.Id.ToString() equals r.refId
|
on p.Id.ToString() equals r.refId
|
||||||
|
|
@ -2407,24 +2447,39 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
resignId = p.Id,
|
resignId = p.Id,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
// var baseAPIOrg = _configuration["API"];
|
||||||
using (var client = new HttpClient())
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
||||||
|
// using (var client = new HttpClient())
|
||||||
|
// {
|
||||||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
|
// {
|
||||||
|
// data = resultData,
|
||||||
|
// });
|
||||||
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
|
// // // {
|
||||||
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
|
// // // await _context.SaveChangesAsync();
|
||||||
|
// // // }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
profile.Status = "DONE";
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
{
|
profile.LastUpdatedAt = now;
|
||||||
data = resultData,
|
});
|
||||||
});
|
await _context.SaveChangesAsync();
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
// // {
|
return Success(resultData);
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
// // await _context.SaveChangesAsync();
|
|
||||||
// // }
|
|
||||||
}
|
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -2560,11 +2615,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
.Include(x => x.RetirementResignEmployee)
|
.Include(x => x.RetirementResignEmployee)
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
string? _null = null;
|
string? _null = null;
|
||||||
var resultData = (from p in data
|
var resultData = (from p in data
|
||||||
join r in req.refIds
|
join r in req.refIds
|
||||||
|
|
@ -2606,7 +2656,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
resignId = p.RetirementResignEmployee.Id
|
resignId = p.RetirementResignEmployee.Id
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var baseAPIOrg = _configuration["API"];
|
#region Old: Circular Flow
|
||||||
|
// var baseAPIOrg = _configuration["API"];
|
||||||
//var reportDone = false;
|
//var reportDone = false;
|
||||||
//if (data.Where(profile => profile.Status == "DONE").Any())
|
//if (data.Where(profile => profile.Status == "DONE").Any())
|
||||||
//{
|
//{
|
||||||
|
|
@ -2615,23 +2666,23 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
|
|
||||||
//if (reportDone == true)
|
//if (reportDone == true)
|
||||||
//{
|
//{
|
||||||
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
// var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave";
|
||||||
using (var client = new HttpClient())
|
// using (var client = new HttpClient())
|
||||||
{
|
// {
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
// client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||||
{
|
// {
|
||||||
data = resultData,
|
// data = resultData,
|
||||||
});
|
// });
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
// // // var _result = await _res.Content.ReadAsStringAsync();
|
||||||
// // if (_res.IsSuccessStatusCode)
|
// // // if (_res.IsSuccessStatusCode)
|
||||||
// // {
|
// // // {
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
// // // data.ForEach(profile => profile.Status = "DONE");
|
||||||
// // data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL");
|
// // // data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL");
|
||||||
// // await _context.SaveChangesAsync();
|
// // // await _context.SaveChangesAsync();
|
||||||
// // }
|
// // // }
|
||||||
}
|
// }
|
||||||
//}
|
//}
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
|
|
@ -2653,7 +2704,22 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
return Success();
|
#endregion
|
||||||
|
|
||||||
|
// New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
||||||
|
var now = DateTime.Now;
|
||||||
|
data.ForEach(profile =>
|
||||||
|
{
|
||||||
|
profile.Status = "DONE";
|
||||||
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
||||||
|
profile.LastUpdateUserId = UserId ?? "";
|
||||||
|
profile.LastUpdatedAt = now;
|
||||||
|
});
|
||||||
|
data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL");
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Return resultData for Node to process directly (Linear Flow)
|
||||||
|
return Success(resultData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -54,5 +54,6 @@ namespace BMA.EHR.Retirement.Service.Requests
|
||||||
public DateTime? leaveDate { get; set; }
|
public DateTime? leaveDate { get; set; }
|
||||||
public string? education { get; set; }
|
public string? education { get; set; }
|
||||||
public double? salary { get; set; }
|
public double? salary { get; set; }
|
||||||
|
public string? org { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ namespace BMA.EHR.Retirement.Service.Requests
|
||||||
public class RetirementResignEmployeeRequest
|
public class RetirementResignEmployeeRequest
|
||||||
{
|
{
|
||||||
public string? Location { get; set; }
|
public string? Location { get; set; }
|
||||||
// public DateTime? SendDate { get; set; }
|
public DateTime? SendDate { get; set; }
|
||||||
public DateTime? ActiveDate { get; set; }
|
public DateTime? ActiveDate { get; set; }
|
||||||
public string? Reason { get; set; }
|
public string? Reason { get; set; }
|
||||||
public string? Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace BMA.EHR.Retirement.Service.Requests
|
||||||
public class RetirementResignRequest
|
public class RetirementResignRequest
|
||||||
{
|
{
|
||||||
public string? Location { get; set; }
|
public string? Location { get; set; }
|
||||||
// public DateTime? SendDate { get; set; }
|
public DateTime? SendDate { get; set; }
|
||||||
public DateTime? ActiveDate { get; set; }
|
public DateTime? ActiveDate { get; set; }
|
||||||
public string? Reason { get; set; }
|
public string? Reason { get; set; }
|
||||||
public string? Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue