no message

This commit is contained in:
kittapath 2024-10-29 17:48:41 +07:00
parent 248d400666
commit 6f3d6f9d72
12 changed files with 19409 additions and 75 deletions

View file

@ -151,6 +151,55 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.Reason,
p.ApproveReason,
p.RejectReason,
p.CancelReason,
p.Status,
p.RetirementResignCancels,//xxxxxxxxxxxxxxxxxxxxxxxxx
p.IsActive,
})
.ToListAsync();
return Success(retirementResigns);
}
}
/// <summary>
/// list รายการลาออกของ User
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("user-cancel")]
public async Task<ActionResult<ResponseObject>> GetListByProfileCancel()
{
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
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.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);
var retirementResigns = await _context.RetirementResignCancels.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.CancelReason,
p.Status,
p.IsActive,
})
@ -200,6 +249,56 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.RemarkHorizontal,
p.ApproveReason,
p.RejectReason,
p.CancelReason,
p.IsActive,
p.CreatedAt,
})
.ToListAsync();
return Success(retirementResigns);
}
/// <summary>
/// list รายการลาออกของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("cancel")]
public async Task<ActionResult<ResponseObject>> GetListByAdminCancel()
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_RESIGN");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
var retirementResigns = await _context.RetirementResignCancels.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.citizenId,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.Status,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.RemarkHorizontal,
p.ApproveReason,
p.RejectReason,
p.CancelReason,
p.IsActive,
p.CreatedAt,
})
@ -224,7 +323,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var createdUserId = await _context.RetirementResigns.AsQueryable()
.Where(x => x.CreatedUserId == UserId)
.FirstOrDefaultAsync();
if (getWorkflow == false && createdUserId ==null)
if (getWorkflow == false && createdUserId == null)
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_RESIGN");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
@ -293,6 +392,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.IsNoDebt,
p.IsNoBurden,
p.IsDiscipline,
p.CancelReason,
// 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 }),
@ -382,6 +482,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
data.IsNoDebt,
data.IsNoBurden,
data.IsDiscipline,
data.CancelReason,
// Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
Docs = retirementResignDocs,
// DocDebts = retirementResignDebtDocs,
@ -390,6 +491,101 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success(_data);
}
/// <summary>
/// get รายละเอียดลาออก
/// </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>
[HttpGet("cancel/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetDetailByUserCancel(Guid id)
{
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "RETIREMENT_CANCEL");
var createdUserId = await _context.RetirementResigns.AsQueryable()
.Where(x => x.CreatedUserId == UserId)
.FirstOrDefaultAsync();
if (getWorkflow == false && createdUserId == null)
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "RETIREMENT_CANCEL");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
}
var data = await _context.RetirementResigns.AsQueryable()
.Where(x => x.Id == id)
.Select(p => new
{
p.Id,
p.prefix,
p.firstName,
p.lastName,
p.profileId,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.Status,
salary = p.AmountOld,
p.ApproveReason,
p.RejectReason,
p.IsActive,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.OligarchReject,
p.OligarchApproveReason,
p.OligarchRejectReason,
p.OligarchRejectDate,
p.CommanderReject,
p.CommanderApproveReason,
p.CommanderRejectReason,
p.CommanderRejectDate,
p.OfficerReject,
p.OfficerApproveReason,
p.OfficerRejectReason,
p.OfficerRejectDate,
p.RemarkHorizontal,
p.rootOld,
p.rootOldId,
p.rootShortNameOld,
p.child1Old,
p.child1OldId,
p.child1ShortNameOld,
p.child2Old,
p.child2OldId,
p.child2ShortNameOld,
p.child3Old,
p.child3OldId,
p.child3ShortNameOld,
p.child4Old,
p.child4OldId,
p.child4ShortNameOld,
p.PositionOld,
p.posMasterNoOld,
p.posTypeOldId,
p.posTypeNameOld,
p.posLevelOldId,
p.posLevelNameOld,
p.IsNoDebt,
p.IsNoBurden,
p.IsDiscipline,
p.CancelReason,
RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างการลาออก
/// </summary>
@ -513,14 +709,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
}
}
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"),
$"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
$"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
"",
"",
true
);
// await _repositoryNoti.PushNotificationAsync(
// Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"),
// $"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
// $"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
// "",
// "",
// true
// );
await _context.SaveChangesAsync();
using (var client = new HttpClient())
{
@ -529,7 +725,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var _res = await client.PostAsJsonAsync($"{_configuration["API"]}/org/workflow/add-workflow", new
{
refId = retirementResign.Id,
sysName = "RETIREMENT_RESIFNATION",
sysName = "SYS_RETIREMENT",
posLevelName = retirementResign.PositionLevelOld,
posTypeName = retirementResign.PositionTypeOld,
});
@ -569,6 +765,38 @@ 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("cancel/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> PutCancel([FromForm] RetirementResignRequest req, Guid id)
{
var updated = await _context.RetirementResignCancels
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.Location = req.Location;
updated.ActiveDate = req.ActiveDate;
updated.Reason = req.Reason;
updated.OrganizationPositionOld = req.OrganizationPositionOld;
updated.RemarkHorizontal = req.RemarkHorizontal;
updated.PositionTypeOld = req.PositionTypeOld;
updated.PositionLevelOld = req.PositionLevelOld;
updated.PositionNumberOld = req.PositionNumberOld;
updated.AmountOld = req.AmountOld;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขรายการตรวจสอบเงื่อนไขต่าง ๆ
@ -665,61 +893,128 @@ namespace BMA.EHR.Retirement.Service.Controllers
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.CancelReason = req.Reason;
if (updated.Status == "DONE")
{
updated.Status = "DONECANCEL";
// 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($"{_configuration["API"]}/org/workflow/add-workflow", new
// {
// refId = retirementResign.Id,
// sysName = "RETIREMENT_RESIFNATION_CANCEL",
// posLevelName = retirementResign.PositionLevelOld,
// posTypeName = retirementResign.PositionTypeOld,
// });
// }
// updated.Status = "CANCEL";
var retirementResignCancel = new RetirementResignCancel
{
Location = updated.Location,
SendDate = updated.SendDate,
ActiveDate = updated.ActiveDate,
Reason = updated.Reason,
OrganizationPositionOld = updated.OrganizationPositionOld,
PositionTypeOld = updated.PositionTypeOld,
PositionLevelOld = updated.PositionLevelOld,
PositionNumberOld = updated.PositionNumberOld,
AmountOld = updated.AmountOld,
ApproveReason = updated.ApproveReason,
RejectReason = updated.RejectReason,
CancelReason = updated.CancelReason,
IsActive = updated.IsActive,
IsNoDebt = updated.IsNoDebt,
IsNoBurden = updated.IsNoBurden,
IsDiscipline = updated.IsDiscipline,
OligarchReject = updated.OligarchReject,
OligarchApproveReason = updated.OligarchApproveReason,
OligarchRejectReason = updated.OligarchRejectReason,
OligarchRejectDate = updated.OligarchRejectDate,
CommanderReject = updated.CommanderReject,
CommanderApproveReason = updated.CommanderApproveReason,
CommanderRejectReason = updated.CommanderRejectReason,
CommanderRejectDate = updated.CommanderRejectDate,
OfficerReject = updated.OfficerReject,
OfficerApproveReason = updated.OfficerApproveReason,
OfficerRejectReason = updated.OfficerRejectReason,
OfficerRejectDate = updated.OfficerRejectDate,
RemarkHorizontal = updated.RemarkHorizontal,
OrganizationOld = updated.OrganizationOld,
PositionOld = updated.PositionOld,
profileId = updated.profileId,
prefix = updated.prefix,
firstName = updated.firstName,
lastName = updated.lastName,
citizenId = updated.citizenId,
rootOld = updated.rootOld,
rootOldId = updated.rootOldId,
rootShortNameOld = updated.rootShortNameOld,
child1Old = updated.child1Old,
child1OldId = updated.child1OldId,
child1ShortNameOld = updated.child1ShortNameOld,
child2Old = updated.child2Old,
child2OldId = updated.child2OldId,
child2ShortNameOld = updated.child2ShortNameOld,
child3Old = updated.child3Old,
child3OldId = updated.child3OldId,
child3ShortNameOld = updated.child3ShortNameOld,
child4Old = updated.child4Old,
child4OldId = updated.child4OldId,
child4ShortNameOld = updated.child4ShortNameOld,
posMasterNoOld = updated.posMasterNoOld,
posTypeOldId = updated.posTypeOldId,
posTypeNameOld = updated.posTypeNameOld,
posLevelOldId = updated.posLevelOldId,
posLevelNameOld = updated.posLevelNameOld,
RetirementResign = updated,
Status = "PENDING",
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.SaveChangesAsync();
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($"{_configuration["API"]}/org/workflow/add-workflow", new
{
refId = retirementResignCancel.Id,
sysName = "RETIREMENT_CANCEL",
posLevelName = retirementResignCancel.PositionLevelOld,
posTypeName = retirementResignCancel.PositionTypeOld,
});
}
}
else
{
updated.Status = "CANCEL";
}
if (updated.OfficerReject != null)
{
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"),
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
"",
"",
true
);
}
if (updated.CommanderReject != null)
{
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"),
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
"",
"",
true
);
}
if (updated.OligarchReject != null)
{
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"),
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
$"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
"",
"",
true
);
}
updated.CancelReason = req.Reason;
// else
// {
updated.Status = "CANCEL";
// }
// if (updated.OfficerReject != null)
// {
// await _repositoryNoti.PushNotificationAsync(
// Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"),
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// "",
// "",
// true
// );
// }
// if (updated.CommanderReject != null)
// {
// await _repositoryNoti.PushNotificationAsync(
// Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"),
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// "",
// "",
// true
// );
// }
// if (updated.OligarchReject != null)
// {
// await _repositoryNoti.PushNotificationAsync(
// Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"),
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้ทำการขอยกเลิก",
// "",
// "",
// true
// );
// }
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
@ -1764,7 +2059,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
result.Add(r);
string? _null = null;
result.Add(new {
result.Add(new
{
No = _null,
FullName = r.RemarkHorizontal,
CitizenId = _null,
@ -1954,7 +2250,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost("leave-cancel/report")]
public async Task<ActionResult<ResponseObject>> PostReportLeaveCancel([FromBody] ReportPersonRequest req)
{
var placementProfiles = await _context.RetirementResigns
var placementProfiles = await _context.RetirementResignCancels
.Where(x => req.refIds.Contains(x.Id.ToString()))
.ToListAsync();
placementProfiles.ForEach(profile => profile.Status = "REPORT");
@ -1973,11 +2269,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost("leave-cancel/report/delete")]
public async Task<ActionResult<ResponseObject>> PostReportDeleteLeaveCancel([FromBody] ReportPersonRequest req)
{
var placementProfiles = await _context.RetirementResigns
var placementProfiles = await _context.RetirementResignCancels
.Where(x => req.refIds.Contains(x.Id.ToString()))
.Where(x => x.Status.ToUpper() == "REPORT")
.ToListAsync();
placementProfiles.ForEach(profile => profile.Status = "DONECANCEL");
placementProfiles.ForEach(profile => profile.Status = "PENDING");
await _context.SaveChangesAsync();
return Success();
}
@ -1999,7 +2295,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
try
{
var report_data = (from p in _context.RetirementResigns
var report_data = (from p in _context.RetirementResignCancels
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToList()
join r in req.refIds
@ -2028,7 +2324,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
result.Add(r);
string? _null = null;
result.Add(new {
result.Add(new
{
No = _null,
FullName = r.RemarkHorizontal,
CitizenId = _null,
@ -2063,9 +2360,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost("leave-cancel/report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecuteLeaveCancel([FromBody] ReportExecuteRequest req)
{
var data = await _context.RetirementResigns
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync();
var data = await _context.RetirementResignCancels
.Include(x => x.RetirementResign)
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync();
string? _null = null;
var resultData = (from p in data
join r in req.refIds
@ -2105,7 +2403,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
var _result = await _res.Content.ReadAsStringAsync();
if (_res.IsSuccessStatusCode)
{
data.ForEach(profile => profile.Status = "DONEREJECT");
data.ForEach(profile => profile.Status = "DONE");
// var _data = await _context.RetirementResigns
// .Where(x => data.Select(x => x.RetirementResign.Id).Contains(x.Id))
// .ToListAsync();
// _data.ForEach(profile => profile.Status = "DONEREJECT");
await _context.SaveChangesAsync();
}
}