แก้ api พ้นราชการ

This commit is contained in:
Kittapath 2024-05-21 19:41:55 +07:00
parent 2a3a151f34
commit 63b02dcc4c
19 changed files with 54771 additions and 431 deletions

View file

@ -572,10 +572,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
(org.result.child2 == null ? "" : org.result.child2 + "/") +
(org.result.child1 == null ? "" : org.result.child1 + "/") +
(org.result.root == null ? "" : org.result.root + "/");
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
}
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
await _context.SaveChangesAsync();
}

View file

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Security.Cryptography;
@ -30,18 +31,21 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public RetirementResignController(RetirementRepository repository,
NotificationRepository repositoryNoti,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{
_repository = repository;
_repositoryNoti = repositoryNoti;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#region " Properties "
@ -49,63 +53,64 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
#endregion
private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
{
try
{
var ocList = new List<string>();
// private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
// {
// try
// {
// var ocList = new List<string>();
var oc = (from o in _context.Organizations.Include(x => x.Parent).Include(x => x.OrganizationOrganization).Where(x => x.OrganizationOrganization != null).AsQueryable()
join oc_name in _context.OrganizationOrganizations.AsQueryable() on o.OrganizationOrganization.Id equals oc_name.Id
where o.Parent != null
select new
{
Id = o.Id,
Name = oc_name.Name,
o.IsActive,
o.Parent
}).FirstOrDefault(x => x.Id == id && x.IsActive);
// var oc = (from o in _context.Organizations.Include(x => x.Parent).Include(x => x.OrganizationOrganization).Where(x => x.OrganizationOrganization != null).AsQueryable()
// join oc_name in _context.OrganizationOrganizations.AsQueryable() on o.OrganizationOrganization.Id equals oc_name.Id
// where o.Parent != null
// select new
// {
// Id = o.Id,
// Name = oc_name.Name,
// o.IsActive,
// o.Parent
// }).FirstOrDefault(x => x.Id == id && x.IsActive);
if (oc == null)
return ocList;
// if (oc == null)
// return ocList;
ocList.Add(oc.Name);
// ocList.Add(oc.Name);
if (oc.Parent?.Id != null)
{
ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot));
}
// if (oc.Parent?.Id != null)
// {
// ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot));
// }
return ocList;
}
catch
{
throw;
}
}
private string FindOCFullPath(Guid id, bool showRoot = false)
{
try
{
var ocList = GetOcNameFullPath(id, showRoot);
var ret = String.Empty;
foreach (var oc in ocList)
{
ret = oc + "/" + ret;
}
// return ocList;
// }
// catch
// {
// throw;
// }
// }
// private string FindOCFullPath(Guid id, bool showRoot = false)
// {
// try
// {
// var ocList = GetOcNameFullPath(id, showRoot);
// var ret = String.Empty;
// foreach (var oc in ocList)
// {
// ret = oc + "/" + ret;
// }
if (ret.Length > 2)
ret = ret.Substring(0, ret.Length - 1);
// if (ret.Length > 2)
// ret = ret.Substring(0, ret.Length - 1);
return ret;
}
catch
{
throw;
}
}
// return ret;
// }
// catch
// {
// throw;
// }
// }
/// <summary>
/// list รายการลาออกของ User
@ -118,29 +123,38 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet("user")]
public async Task<ActionResult<ResponseObject>> GetListByProfile()
{
var profile = await _context.Profiles
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var retirementResigns = await _context.RetirementResigns.AsQueryable()
.Where(x => x.Profile == profile)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.ApproveReason,
p.RejectReason,
p.Status,
p.IsActive,
})
.ToListAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
return Success(retirementResigns);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
var retirementResigns = await _context.RetirementResigns.AsQueryable()
.Where(x => x.profileId == org.result.profileId)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.ApproveReason,
p.RejectReason,
p.Status,
p.IsActive,
})
.ToListAsync();
return Success(retirementResigns);
}
}
/// <summary>
@ -160,10 +174,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
p.Id,
ProfileId = p.Profile.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.Location,
p.SendDate,
p.ActiveDate,
@ -202,11 +216,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
p.prefix,
p.firstName,
p.lastName,
p.profileId,
p.Location,
p.SendDate,
p.ActiveDate,
@ -230,8 +243,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.CommanderRejectReason,
p.CommanderRejectDate,
p.RemarkHorizontal,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
// Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
RetirementResignDebtDocs = p.RetirementResignDebtDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
})
.FirstOrDefaultAsync();
if (data == null)
@ -243,18 +257,30 @@ namespace BMA.EHR.Retirement.Service.Controllers
var _doc = new
{
FileName = doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
PathName = await _documentService.ImagesPath(doc.Id),
doc.Id,
};
retirementResignDocs.Add(_doc);
}
var retirementResignDebtDocs = new List<dynamic>();
foreach (var doc in data.RetirementResignDebtDocs)
{
var _doc = new
{
FileName = doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id),
doc.Id,
};
retirementResignDebtDocs.Add(_doc);
}
var _data = new
{
data.Id,
data.ProfileId,
data.Prefix,
data.PrefixId,
data.FirstName,
data.LastName,
data.profileId,
data.prefix,
// data.PrefixId,
data.firstName,
data.lastName,
data.Location,
data.SendDate,
data.ActiveDate,
@ -278,8 +304,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
data.CommanderRejectReason,
data.CommanderRejectDate,
data.RemarkHorizontal,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
// Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
Docs = retirementResignDocs,
DocDebts = retirementResignDebtDocs,
};
return Success(_data);
@ -296,29 +323,29 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementResignRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
// var profile = await _context.Profiles
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionType)
// .Include(x => x.PosNo)
// .Include(x => x.Salaries)
// .Include(x => x.Position)
// .Include(x => x.Prefix)
// .FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
// if (profile == null)
// return Error(GlobalMessages.DataNotFound, 404);
var retirementResign = new RetirementResign
{
Profile = profile,
// Profile = profile,
Location = req.Location,
SendDate = req.SendDate,
ActiveDate = req.ActiveDate,
Reason = req.Reason,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
// AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
// PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
// PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
// PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
// OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
IsActive = true,
CreatedFullName = FullName ?? "System Administrator",
@ -328,6 +355,58 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementResign.profileId = org.result.profileId;
retirementResign.prefix = org.result.prefix;
retirementResign.firstName = org.result.firstName;
retirementResign.lastName = org.result.lastName;
retirementResign.citizenId = org.result.citizenId;
retirementResign.root = org.result.root;
retirementResign.rootId = org.result.rootId;
retirementResign.rootShortName = org.result.rootShortName;
retirementResign.child1 = org.result.child1;
retirementResign.child1Id = org.result.child1Id;
retirementResign.child1ShortName = org.result.child1ShortName;
retirementResign.child2 = org.result.child2;
retirementResign.child2Id = org.result.child2Id;
retirementResign.child2ShortName = org.result.child2ShortName;
retirementResign.child3 = org.result.child3;
retirementResign.child3Id = org.result.child3Id;
retirementResign.child3ShortName = org.result.child3ShortName;
retirementResign.child4 = org.result.child4;
retirementResign.child4Id = org.result.child4Id;
retirementResign.child4ShortName = org.result.child4ShortName;
retirementResign.posMasterNo = org.result.posMasterNo;
retirementResign.position = org.result.position;
retirementResign.posTypeId = org.result.posTypeId;
retirementResign.posTypeName = org.result.posTypeName;
retirementResign.posLevelId = org.result.posLevelId;
retirementResign.posLevelName = org.result.posLevelName;
retirementResign.PositionOld = org.result.position;
retirementResign.PositionLevelOld = org.result.posLevelName;
retirementResign.PositionTypeOld = org.result.posTypeName;
retirementResign.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "/") +
(org.result.child3 == null ? "" : org.result.child3 + "/") +
(org.result.child2 == null ? "" : org.result.child2 + "/") +
(org.result.child1 == null ? "" : org.result.child1 + "/") +
(org.result.root == null ? "" : org.result.root + "/");
retirementResign.OrganizationPositionOld = org.result.position + "-" + retirementResign.OrganizationOld;
}
await _context.RetirementResigns.AddAsync(retirementResign);
await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
@ -358,8 +437,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"),
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นขอลาออก",
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นขอลาออก",
$"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
$"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
"",
true
);
@ -402,6 +481,108 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success();
}
/// <summary>
/// แก้ไขรายการตรวจสอบเงื่อนไขต่าง ๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("debt/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Debt([FromForm] RetirementResignDebtRequest req, Guid id)
{
var updated = await _context.RetirementResigns.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.IsNoDebt = req.IsNoDebt;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
foreach (var file in Request.Form.Files)
{
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var retirementResignDebtDoc = new RetirementResignDebtDoc
{
RetirementResign = updated,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementResignDebtDocs.AddAsync(retirementResignDebtDoc);
}
}
}
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขรายการตรวจสอบเงื่อนไขต่าง ๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("debt/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> DebtDelete(Guid id)
{
var deleted = await _context.RetirementResignDocs.AsQueryable()
.FirstOrDefaultAsync(x => x.Document.Id == id);
if (deleted == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
_context.RetirementResignDocs.Remove(deleted);
var _deleted = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (_deleted == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
_context.Documents.Remove(_deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ยกเลิกลาออก
/// </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>
[HttpPut("cancel/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Cancel([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.Status = "CANCEL";
updated.CancelReason = req.Reason;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบลาออก
/// </summary>
@ -439,7 +620,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> AdminConfirm([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -467,7 +647,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> AdminReject([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -495,8 +674,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> CommanderConfirm([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -509,15 +686,15 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
"",
true
);
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
"",
true
);
@ -539,8 +716,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> CommanderReject([FromBody] RetirementReasonDateRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -555,15 +730,15 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
"",
true
);
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
"",
true
);
@ -584,8 +759,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> OligarchConfirm([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -596,10 +769,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync(
updated.Profile.Id,
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
await _repositoryNoti.PushNotificationAsyncV2(
updated.CreatedUserId,
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
"",
true
);
@ -621,8 +794,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> OligarchReject([FromBody] RetirementReasonDateRequest req, Guid id)
{
var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -635,10 +806,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync(
updated.Profile.Id,
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้มีอำนาจ",
await _repositoryNoti.PushNotificationAsyncV2(
updated.CreatedUserId,
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ",
"",
true
);
@ -691,7 +862,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
Id = p.Id,
Fullname = $"{(p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name)}{p.RetirementResign.Profile.FirstName} {p.RetirementResign.Profile.LastName}",
Fullname = $"{p.RetirementResign.prefix}{p.RetirementResign.firstName} {p.RetirementResign.lastName}",
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
ReasonWorkOther = p.ReasonWorkOther,
TimeThink = p.TimeThink,
@ -733,13 +904,12 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
Id = p.Id,
PrefixId = p.RetirementResign.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Prefix.Id,
Position = p.RetirementResign.Profile.Position == null ? null : p.RetirementResign.Profile.Position.Name,
PositionLevel = p.RetirementResign.Profile.PositionLevel == null ? null : p.RetirementResign.Profile.PositionLevel.Name,
Org = p.RetirementResign.Profile.OcId == null ? null : p.RetirementResign.Profile.OcId,
Fullname = $"{(p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name)}{p.RetirementResign.Profile.FirstName} {p.RetirementResign.Profile.LastName}",
Prefix = p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name,
Avatar = p.RetirementResign.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Avatar.Id,
Prefix = p.RetirementResign.prefix,
Position = p.RetirementResign.position,
PositionLevel = p.RetirementResign.posLevelName,
Org = p.RetirementResign.OrganizationOld,
Fullname = $"{p.RetirementResign.prefix}{p.RetirementResign.firstName} {p.RetirementResign.lastName}",
// Avatar = p.RetirementResign.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Avatar.Id,
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
ReasonWorkOther = p.ReasonWorkOther,
TimeThink = p.TimeThink,
@ -777,51 +947,51 @@ namespace BMA.EHR.Retirement.Service.Controllers
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.RetirementQuestionNotFound, 404);
var _data = new
{
data.Id,
data.PrefixId,
data.Position,
data.PositionLevel,
Org = data.Org == null ? null : FindOCFullPath(data.Org.Value, true),
data.Fullname,
data.Prefix,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
data.ReasonWork,
data.ReasonWorkOther,
data.TimeThink,
data.ExitFactor,
data.ExitFactorOther,
data.Adjust,
data.AdjustOther,
data.RealReason,
data.NotExitFactor,
data.Havejob,
data.HavejobReason,
data.SuggestFriends,
data.SuggestFriendsReason,
data.FutureWork,
data.FutureWorkReason,
data.Suggestion,
data.AppointDate,
data.OrganizationPositionOld,
data.LastUpdatedAt,
data.CreatedAt,
data.Score1,
data.Score2,
data.Score3,
data.Score4,
data.Score5,
data.Score6,
data.Score7,
data.Score8,
data.Score9,
data.Score10,
data.ScoreTotal,
data.Comment,
};
// var _data = new
// {
// data.Id,
// // data.PrefixId,
// data.Position,
// data.PositionLevel,
// data.Org,
// data.Fullname,
// data.Prefix,
// // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
// data.ReasonWork,
// data.ReasonWorkOther,
// data.TimeThink,
// data.ExitFactor,
// data.ExitFactorOther,
// data.Adjust,
// data.AdjustOther,
// data.RealReason,
// data.NotExitFactor,
// data.Havejob,
// data.HavejobReason,
// data.SuggestFriends,
// data.SuggestFriendsReason,
// data.FutureWork,
// data.FutureWorkReason,
// data.Suggestion,
// data.AppointDate,
// data.OrganizationPositionOld,
// data.LastUpdatedAt,
// data.CreatedAt,
// data.Score1,
// data.Score2,
// data.Score3,
// data.Score4,
// data.Score5,
// data.Score6,
// data.Score7,
// data.Score8,
// data.Score9,
// data.Score10,
// data.ScoreTotal,
// data.Comment,
// };
return Success(_data);
return Success(data);
}
/// <summary>
@ -996,7 +1166,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var uppdated = await _context.RetirementQuestions.AsQueryable()
.Include(x => x.RetirementResign)
.ThenInclude(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementQuestionNotFound);
@ -1005,8 +1174,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync(
uppdated.RetirementResign.Profile.Id,
await _repositoryNoti.PushNotificationAsyncV2(
uppdated.RetirementResign.CreatedUserId,
$"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}",
$"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}",
"",