report discipline
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Bright 2025-01-17 15:06:28 +07:00
parent 1bec091856
commit d692ea4359
3 changed files with 91 additions and 21 deletions

View file

@ -9,10 +9,12 @@ namespace BMA.EHR.Application.Responses.Profiles
public string? Prefix { get; set; } public string? Prefix { get; set; }
public string? FirstName { get; set; } public string? FirstName { get; set; }
public string? LastName { get; set; } public string? LastName { get; set; }
public string? CitizenId { get; set; }
public Guid? Keycloak { get; set; } public Guid? Keycloak { get; set; }
public string? PosNo { get; set; } public string? PosNo { get; set; }
public string? Position { get; set; } public string? Position { get; set; }
public string? PositionLevel { get; set; } public string? PositionLevel { get; set; }
public string? PositionType { get; set; }
public string? Oc { get; set; } public string? Oc { get; set; }
} }
} }

View file

@ -1,9 +1,12 @@
using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Discipline.Service.Requests; using BMA.EHR.Discipline.Service.Requests;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Discipline; using BMA.EHR.Domain.Models.Discipline;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
// using BMA.EHR.Placement.Service.Requests; // using BMA.EHR.Placement.Service.Requests;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -28,17 +31,20 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
private readonly MinIODisciplineService _documentService; private readonly MinIODisciplineService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly PermissionRepository _permission; private readonly PermissionRepository _permission;
private readonly UserProfileRepository _userProfileRepository;
public DisciplineReportController(DisciplineDbContext context, public DisciplineReportController(DisciplineDbContext context,
MinIODisciplineService documentService, MinIODisciplineService documentService,
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
PermissionRepository permission) PermissionRepository permission,
UserProfileRepository userProfileRepository)
{ {
// _repository = repository; // _repository = repository;
_context = context; _context = context;
_documentService = documentService; _documentService = documentService;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_permission = permission; _permission = permission;
_userProfileRepository = userProfileRepository;
} }
#region " Properties " #region " Properties "
@ -46,6 +52,8 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
#endregion #endregion
@ -60,39 +68,99 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
[HttpPost("{type}")] [HttpPost("{type}")]
public async Task<ActionResult<ResponseObject>> GetReportDiscipline([FromBody] DisciplineReportRequest req, string type) public async Task<ActionResult<ResponseObject>> GetReportDiscipline([FromBody] DisciplineReportRequest req, string type)
{ {
// var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
// .Include(x => x.DisciplineDisciplinary)
// .Where(x => x.Id == d.id)
// .FirstOrDefaultAsync();
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_REPORT"); var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_REPORT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission); var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200") if (jsonData["status"]?.ToString() != "200")
{ {
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
} }
var profile = new List<GetProfileByKeycloakIdRootDto>();
if (type.Trim().ToUpper() == "OFFICER")
{
profile = await _userProfileRepository.GetProfileWithKeycloakAllOfficer(AccessToken, req.node, req.nodeId, jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD");
}
else
{
profile = await _userProfileRepository.GetProfileWithKeycloakAllEmployee(AccessToken, req.node, req.nodeId, jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD");
}
// var profile = new List<GetProfileByKeycloakIdRootDto>(); if (req.posLevel != null || req.posType != null)
// if (type.Trim().ToUpper() == "OFFICER") {
// { profile = profile.Where(x => x.PositionType == req.posType || x.PositionLevel == req.posLevel).ToList();
// profile = await _userProfileRepository.GetProfileWithKeycloakAllOfficer(AccessToken, req.node, req.nodeId, jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD"); }
// }
// else var data_search = await _context.DisciplineDisciplinarys
// { .Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
// profile = await _userProfileRepository.GetProfileWithKeycloakAllEmployee(AccessToken, req.node, req.nodeId, jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD"); .OrderByDescending(x => x.CreatedAt)
// } .ToListAsync();
if (req.status.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Status.Contains(req.status.Trim().ToUpper())).ToList();
if (req.offenseDetail.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.OffenseDetails.Contains(req.status.Trim().ToUpper())).ToList();
if (req.disciplinaryFaultLevel.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.DisciplinaryFaultLevel.Contains(req.status.Trim().ToUpper())).ToList();
var mapData = data_search
.SelectMany((d) => d.DisciplineDisciplinary_ProfileComplaintInvestigates.Select((profile) => new
{
fullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}",
citizenId = profile.CitizenId,
position = profile.Position,
posLevel = profile.posLevelName,
oc = profile.Organization,
CreatedAt = profile.CreatedAt,
offense = d.OffenseDetails != null && d.OffenseDetails != ""
? d.OffenseDetails == "NOT_SPECIFIED"
? "ความผิดวินัยยังไม่ระบุ"
: d.OffenseDetails == "NOT_DEADLY"
? "ความผิดวินัยไม่ร้ายแรง"
: d.OffenseDetails == "DEADLY"
? "ความผิดวินัยร้ายแรง"
: ""
: "",
faultLevel = d.DisciplinaryFaultLevel,
}))
.Where(x =>
x.citizenId != null && profile.Any(p => p.CitizenId == x.citizenId))
.OrderByDescending(x => x.CreatedAt)
.ToList();
var count = 1;
var employees = new List<dynamic>();
foreach (var p in mapData)
{
var emp = new
{
no = count,
fullName = p.fullName,
citizenId = p.citizenId,
position = p.position,
posLevel = p.posLevel,
oc = profile.FirstOrDefault(x => x.CitizenId == p.citizenId)?.Oc ?? "",
offense = p.offense,
faultLevel = p.faultLevel,
one = 0,
two = 0,
three = 0,
};
employees.Add(emp);
count++;
}
var result = new var result = new
{ {
template = "reportDiscipline", template = "reportDiscipline",
reportName = "reportDiscipline", reportName = "xlsx-report",
data = new data = new
{ {
year = req.year + 543, year = (req.year + 543).ToString().ToThaiNumber(),
data = new List<dynamic>() dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
data = employees
} }
}; };
return Success(result); return Success(result);
} }
} }

View file

@ -17,8 +17,8 @@ namespace BMA.EHR.Discipline.Service.Requests
public string status { get; set; } public string status { get; set; }
public string posType { get; set; } public string? posType { get; set; }
public string posLevel { get; set; } public string? posLevel { get; set; }
} }
} }