fix ส่งรายชื่อผู้ถูกพักราชการไปออกคำสั่ง #2364
All checks were successful
Build & Deploy Discipline Service / build (push) Successful in 2m7s

This commit is contained in:
harid 2026-03-27 14:31:42 +07:00
parent 7ba429bb64
commit d8f1126764

View file

@ -71,6 +71,13 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
// ถ้า FE ส่ง status = PENDING กรอง start/end suspend not null
bool isPending =
!string.IsNullOrEmpty(profileType) &&
!string.IsNullOrEmpty(status) &&
status.Trim().ToUpper() == "PENDING";
// กรองสิทธิ์
string role = jsonData["result"]?.ToString() ?? "";
var nodeId = string.Empty;
@ -109,7 +116,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
var data_search = (from x in _context.DisciplineReport_Profiles.Include(x => x.DisciplineDisciplinary)
where
(
endDate != null && startDate != null?
endDate != null && startDate != null ?
(
(x.StartDateSuspend.Value.Date >= startDate.Value.Date && x.StartDateSuspend.Value.Date <= endDate.Value.Date) ||
(x.EndDateSuspend.Value.Date >= startDate.Value.Date && x.EndDateSuspend.Value.Date <= endDate.Value.Date) ||
@ -137,14 +144,19 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
(
!string.IsNullOrEmpty(status) ? x.Status!.Trim().ToUpper() == status : true
)
// ถ้า FE ส่ง status = PENDING กรอง start/end suspend not null
&&
(
isPending
? x.StartDateSuspend != null && x.EndDateSuspend != null
: true
)
&&
(
role == "OWNER"
? true
: role == "ROOT"
? x.rootDnaId == nodeId
// : role == "PARENT"
// ? x.rootDnaId == nodeId && x.child1DnaId != null
: role == "CHILD"
? (
profileAdmin.Node == 4 ? x.child4DnaId == nodeId :
@ -177,125 +189,119 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
)
select x).ToList();
var query = data_search
.Select(x => new
{
Id = x.Id,
CitizenId = x.CitizenId,
Prefix = x.Prefix,
FirstName = x.FirstName,
LastName = x.LastName,
ProfileId = x.PersonId,
Organization = x.Organization,
root = x.root,
rootId = x.rootId,
rootDnaId = x.rootDnaId,
rootShortName = x.rootShortName,
child1 = x.child1,
child1Id = x.child1Id,
child1DnaId = x.child1DnaId,
child1ShortName = x.child1ShortName,
child2 = x.child2,
child2Id = x.child2Id,
child2DnaId = x.child2DnaId,
child2ShortName = x.child2ShortName,
child3 = x.child3,
child3Id = x.child3Id,
child3DnaId = x.child3DnaId,
child3ShortName = x.child3ShortName,
child4 = x.child4,
child4Id = x.child4Id,
child4DnaId = x.child4DnaId,
child4ShortName = x.child4ShortName,
posMasterNo = x.posMasterNo,
posTypeId = x.posTypeId,
posTypeName = x.posTypeName,
posLevelId = x.posLevelId,
posLevelName = x.posLevelName,
.Select(x => new
{
Id = x.Id,
CitizenId = x.CitizenId,
Prefix = x.Prefix,
FirstName = x.FirstName,
LastName = x.LastName,
ProfileId = x.PersonId,
Organization = x.Organization,
root = x.root,
rootId = x.rootId,
rootDnaId = x.rootDnaId,
rootShortName = x.rootShortName,
child1 = x.child1,
child1Id = x.child1Id,
child1DnaId = x.child1DnaId,
child1ShortName = x.child1ShortName,
child2 = x.child2,
child2Id = x.child2Id,
child2DnaId = x.child2DnaId,
child2ShortName = x.child2ShortName,
child3 = x.child3,
child3Id = x.child3Id,
child3DnaId = x.child3DnaId,
child3ShortName = x.child3ShortName,
child4 = x.child4,
child4Id = x.child4Id,
child4DnaId = x.child4DnaId,
child4ShortName = x.child4ShortName,
posMasterNo = x.posMasterNo,
posTypeId = x.posTypeId,
posTypeName = x.posTypeName,
posLevelId = x.posLevelId,
posLevelName = x.posLevelName,
Position = x.Position,
PosNo = x.PosNo,
PositionLevel = x.PositionLevel == null ? "" : x.PositionLevel,
PositionType = x.PositionType == null ? "" : x.PositionType,
Salary = x.Salary,
Status = x.Status,
DescriptionSuspend = x.DescriptionSuspend,
StartDateSuspend = x.StartDateSuspend,
EndDateSuspend = x.EndDateSuspend,
Title = x.DisciplineDisciplinary.Title,
OffenseDetails = x.DisciplineDisciplinary.OffenseDetails,//ลักษณะความผิด
DisciplinaryFaultLevel = x.DisciplineDisciplinary.DisciplinaryFaultLevel,//ระดับโทษความผิด
DisciplinaryCaseFault = x.DisciplineDisciplinary.DisciplinaryCaseFault,//กรณีความผิด
profileType = x.profileType,
CreatedAt = x.CreatedAt,
});
Position = x.Position,
PosNo = x.PosNo,
PositionLevel = x.PositionLevel == null ? "" : x.PositionLevel,
PositionType = x.PositionType == null ? "" : x.PositionType,
Salary = x.Salary,
Status = x.Status,
DescriptionSuspend = x.DescriptionSuspend,
StartDateSuspend = x.StartDateSuspend,
EndDateSuspend = x.EndDateSuspend,
Title = x.DisciplineDisciplinary.Title,
OffenseDetails = x.DisciplineDisciplinary.OffenseDetails,//ลักษณะความผิด
DisciplinaryFaultLevel = x.DisciplineDisciplinary.DisciplinaryFaultLevel,//ระดับโทษความผิด
DisciplinaryCaseFault = x.DisciplineDisciplinary.DisciplinaryCaseFault,//กรณีความผิด
profileType = x.profileType,
CreatedAt = x.CreatedAt,
});
bool desc = descending ?? false;
if (!string.IsNullOrEmpty(sortBy))
{
if (sortBy == "title")
{
query = desc ? query.OrderByDescending(x => x.Title)
: query.OrderBy(x => x.Title);
}
else if (sortBy == "prefix" || sortBy == "firstName" || sortBy == "lastName")
{
query = desc ?
query
//.OrderByDescending(x => x.Prefix)
.OrderByDescending(x => x.FirstName)
.ThenByDescending(x => x.LastName) :
query
//.OrderBy(x => x.Prefix)
.OrderBy(x => x.FirstName)
.ThenBy(x => x.LastName);
}
else if (sortBy == "position")
{
query = desc ? query.OrderByDescending(x => x.Position)
: query.OrderBy(x => x.Position);
}
else if (sortBy == "positionType" || sortBy == "positionLevel")
{
query = desc ?
query
.OrderByDescending(x => x.PositionType)
.ThenByDescending(x => x.PositionLevel) :
query
.OrderBy(x => x.PositionType)
.ThenBy(x => x.PositionLevel);
}
else if (sortBy == "organization")
{
query = desc ? query.OrderByDescending(x => x.Organization)
: query.OrderBy(x => x.Organization);
}
else if (sortBy == "startDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.StartDateSuspend)
: query.OrderBy(x => x.StartDateSuspend);
}
else if (sortBy == "endDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.EndDateSuspend)
: query.OrderBy(x => x.EndDateSuspend);
}
else if (sortBy == "descriptionSuspend")
{
query = desc ? query.OrderByDescending(x => x.DescriptionSuspend)
: query.OrderBy(x => x.DescriptionSuspend);
}
else
{
query = query.OrderByDescending(x => x.profileType)
.ThenByDescending(x => x.CreatedAt)
.ThenByDescending(x => x.CitizenId);
}
}
bool desc = descending ?? false;
if (!string.IsNullOrEmpty(sortBy))
{
if (sortBy == "title")
{
query = desc ? query.OrderByDescending(x => x.Title)
: query.OrderBy(x => x.Title);
}
else if (sortBy == "prefix" || sortBy == "firstName" || sortBy == "lastName")
{
query = desc ?
query.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.LastName) :
query.OrderBy(x => x.FirstName).ThenBy(x => x.LastName);
}
else if (sortBy == "position")
{
query = desc ? query.OrderByDescending(x => x.Position)
: query.OrderBy(x => x.Position);
}
else if (sortBy == "positionType" || sortBy == "positionLevel")
{
query = desc ?
query
.OrderByDescending(x => x.PositionType)
.ThenByDescending(x => x.PositionLevel) :
query
.OrderBy(x => x.PositionType)
.ThenBy(x => x.PositionLevel);
}
else if (sortBy == "organization")
{
query = desc ? query.OrderByDescending(x => x.Organization)
: query.OrderBy(x => x.Organization);
}
else if (sortBy == "startDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.StartDateSuspend)
: query.OrderBy(x => x.StartDateSuspend);
}
else if (sortBy == "endDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.EndDateSuspend)
: query.OrderBy(x => x.EndDateSuspend);
}
else if (sortBy == "descriptionSuspend")
{
query = desc ? query.OrderByDescending(x => x.DescriptionSuspend)
: query.OrderBy(x => x.DescriptionSuspend);
}
else
{
query = query.OrderByDescending(x => x.profileType)
.ThenByDescending(x => x.CreatedAt)
.ThenByDescending(x => x.CitizenId);
}
}
var data = query
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
var data = query
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data, total = data_search.Count() });
}