From 30281ff2ab6306e9c13a64dc2cb56cfe39656e95 Mon Sep 17 00:00:00 2001 From: kittapath Date: Sun, 15 Dec 2024 19:00:38 +0700 Subject: [PATCH] report insignia --- .../Controllers/DisciplineReportController.cs | 99 ++++++ .../Requests/DisciplineReportRequest.cs | 24 ++ .../Controllers/InsigniaReportController.cs | 304 ++++++++++++++++++ .../GetInsigniaDetailByNodeReportDto.cs | 10 + 4 files changed, 437 insertions(+) create mode 100644 BMA.EHR.Discipline.Service/Controllers/DisciplineReportController.cs create mode 100644 BMA.EHR.Discipline.Service/Requests/DisciplineReportRequest.cs create mode 100644 BMA.EHR.Insignia/Controllers/InsigniaReportController.cs create mode 100644 BMA.EHR.Insignia/Requests/GetInsigniaDetailByNodeReportDto.cs diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineReportController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineReportController.cs new file mode 100644 index 00000000..06eeaa4e --- /dev/null +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineReportController.cs @@ -0,0 +1,99 @@ +using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Repositories.MessageQueue; +using BMA.EHR.Discipline.Service.Requests; +using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Models.Discipline; +using BMA.EHR.Domain.Shared; +using BMA.EHR.Infrastructure.Persistence; +// using BMA.EHR.Placement.Service.Requests; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using Swashbuckle.AspNetCore.Annotations; +using System.Security.Claims; + +namespace BMA.EHR.DisciplineSuspend.Service.Controllers +{ + [Route("api/v{version:apiVersion}/discipline/report")] + [ApiVersion("1.0")] + [ApiController] + [Produces("application/json")] + [Authorize] + [SwaggerTag("ระบบวินัยรายงาน")] + public class DisciplineReportController : BaseController + { + private readonly DisciplineDbContext _context; + private readonly MinIODisciplineService _documentService; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly PermissionRepository _permission; + + public DisciplineReportController(DisciplineDbContext context, + MinIODisciplineService documentService, + IHttpContextAccessor httpContextAccessor, + PermissionRepository permission) + { + // _repository = repository; + _context = context; + _documentService = documentService; + _httpContextAccessor = httpContextAccessor; + _permission = permission; + } + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + + /// + /// รายชื่อออกคำสั่งลงโทษ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("{type}")] + public async Task> 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 jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + + // var profile = new List(); + // 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 result = new + { + template = "reportDiscipline", + reportName = "reportDiscipline", + data = new + { + year = req.year + 543, + data = new List() + } + }; + + return Success(result); + } + } +} diff --git a/BMA.EHR.Discipline.Service/Requests/DisciplineReportRequest.cs b/BMA.EHR.Discipline.Service/Requests/DisciplineReportRequest.cs new file mode 100644 index 00000000..2fa79722 --- /dev/null +++ b/BMA.EHR.Discipline.Service/Requests/DisciplineReportRequest.cs @@ -0,0 +1,24 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Discipline.Service.Requests +{ + public class DisciplineReportRequest + { + public string nodeId { get; set; } + + public int node { get; set; } + + public int year { get; set; } + + public string offenseDetail { get; set; } + + public string disciplinaryFaultLevel { get; set; } + + public string status { get; set; } + + public string posType { get; set; } + + public string posLevel { get; set; } + } +} diff --git a/BMA.EHR.Insignia/Controllers/InsigniaReportController.cs b/BMA.EHR.Insignia/Controllers/InsigniaReportController.cs new file mode 100644 index 00000000..8e3efd5a --- /dev/null +++ b/BMA.EHR.Insignia/Controllers/InsigniaReportController.cs @@ -0,0 +1,304 @@ +using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Repositories.MessageQueue; +using BMA.EHR.Application.Repositories.Reports; +using BMA.EHR.Application.Requests; +using BMA.EHR.Application.Responses.Insignias; +using BMA.EHR.Application.Responses.Organizations; +using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; +using BMA.EHR.Domain.Models.Insignias; +using BMA.EHR.Domain.Shared; +using BMA.EHR.Infrastructure.Persistence; +using BMA.EHR.Insignia.Service.Requests; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using OfficeOpenXml; +using RabbitMQ.Client; +using Swashbuckle.AspNetCore.Annotations; +using System.Security.Claims; +using System.Text; + +namespace BMA.EHR.Insignia.Service.Controllers +{ + [Route("api/v{version:apiVersion}/insignia/report")] + [ApiVersion("1.0")] + [ApiController] + [Produces("application/json")] + [Authorize] + [SwaggerTag("เครื่องราชรายงาน")] + public class InsigniaReportController : BaseController + { + private readonly ApplicationDBContext _context; + private readonly IWebHostEnvironment _hostingEnvironment; + private readonly IConfiguration _configuration; + private readonly InsigniaReportRepository _repository; + private readonly PermissionRepository _permission; + private readonly IHttpContextAccessor _httpContextAccessor; + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public InsigniaReportController(ApplicationDBContext context, + IWebHostEnvironment hostingEnvironment, + IConfiguration configuration, + InsigniaReportRepository repository, + IHttpContextAccessor httpContextAccessor, + PermissionRepository permission) + { + _context = context; + _hostingEnvironment = hostingEnvironment; + _configuration = configuration; + _repository = repository; + _permission = permission; + _httpContextAccessor = httpContextAccessor; + } + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + + #endregion + + #region บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา + /// + /// บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา + /// + /// type + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("report1/{type}")] + public async Task> GetInsigniaReport1Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type) + { + try + { + var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + + var data = await _repository.GetCoinReportByNode(req.roundId, req.node, req.nodeId, jsonData["result"]?.ToString()); + var yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId); + + var dataResult = new List(); + var dataList = new List(data); + var detailList = new List(); + var check = 0; + var status = false; + + for (int i = 0; i < dataList.Count; i++) + { + check++; + var gender = dataList[i].GetType().GetProperty("Gender").GetValue(dataList[i]); + detailList.Add(new + { + status = status, + row = detailList.Count + 1, + InsigniaName = dataList[i].GetType().GetProperty("InsigniaName").GetValue(dataList[i]), + FullName = dataList[i].GetType().GetProperty("FullName").GetValue(dataList[i]), + InsigniaInitial = dataList[i].GetType().GetProperty("InsigniaInitial").GetValue(dataList[i]), + Male = gender == "ชาย" ? 1 : 0, + Female = gender == "หญิง" ? 1 : 0, + }); + + if (check == 25) + { + status = true; + } + else if (check == 50) + { + status = false; + check = 0; + } + } + + if (detailList.Count > 0) + { + var left = detailList.Where(x => x.status == false); + var right = detailList.Where(x => x.status == true); + var mergeList = new List(); + var InsigniaName = string.Empty; + var range = string.Empty; + var male = 0; + var female = 0; + var start = 0; + var stop = 0; + var colLeft = 0; + var colRight = 0; + for (int i = 0; i < detailList.Count / 2; i++) + { + if (InsigniaName != (string)left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i))) + { + InsigniaName = (string)left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i)); + male = left.Count(x => x.Male == 1 && x.InsigniaName == InsigniaName) + right.Count(x => x.Male == 1 && x.InsigniaName == InsigniaName); + female = left.Count(x => x.Female == 1 && x.InsigniaName == InsigniaName) + right.Count(x => x.Female == 1 && x.InsigniaName == InsigniaName); + var countGroup = detailList.Count(x => x.InsigniaName == InsigniaName); + var countGroupTemp = detailList.Count(x => x.InsigniaName == InsigniaName && x.FullName == ""); + start = i == 0 ? (mergeList.Count + 1) : (stop + 1); + stop = i == 0 ? (mergeList.Count) + (countGroup - countGroupTemp) : (countGroup - countGroupTemp) == 1 ? start : start + (countGroup - countGroupTemp); + range = countGroup - countGroupTemp != 1 ? $"{start} - {stop}" : $"{start}"; + colLeft = start; + colRight = start + 25; + } + mergeList.Add(new + { + row = mergeList.Count + 1, + ColLeft = colLeft.ToString().ToThaiNumber(), + NameLeft = left.ElementAt(i).GetType().GetProperty("FullName").GetValue(left.ElementAt(i)), + ColRight = colRight.ToString().ToThaiNumber(), + NameRight = right.ElementAt(i).GetType().GetProperty("FullName").GetValue(right.ElementAt(i)), + InsigniaInitial = left.ElementAt(i).GetType().GetProperty("InsigniaInitial").GetValue(left.ElementAt(i)), + InsigniaName = left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i)), + Range = range.ToThaiNumber(), + Male = male.ToString().ToThaiNumber(), + Female = female.ToString().ToThaiNumber(), + }); + if (mergeList.Count % 25 == 0) + { + colLeft = colRight; + colRight = colLeft + 25; + } + colLeft++; + colRight++; + } + dataResult = mergeList; + } + + var result = new + { + template = "reportInsignia1", + reportName = "reportInsignia1", + data = new + { + yearInsignalPeriod, + data = dataResult, + } + }; + return Success(result); + } + catch + { + throw; + } + } + #endregion + + #region บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ + /// + /// บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ + /// + /// type + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("report2/{type}")] + public async Task> GetInsigniaReport2Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type) + { + try + { + var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + var data = await _repository.GetSummaryCoinReport(req.roundId); + var summaryTotal = await _repository.GetSummaryTotalCoinReport(req.roundId); + var yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId); + + var dataResult = new List(); + foreach (var _data in data) + { + dataResult.Add(new + { + RowNo = (dataResult.Count + 1).ToString().ToThaiNumber(), + DepartmentName = _data.GetType().GetProperty("DepartmentName").GetValue(_data), + InsigniaInitial = _data.GetType().GetProperty("InsigniaInitial").GetValue(_data), + G1Male = _data.GetType().GetProperty("G1Male").GetValue(_data), + G1Female = _data.GetType().GetProperty("G1Female").GetValue(_data), + G2Male = _data.GetType().GetProperty("G2Male").GetValue(_data), + G2Female = _data.GetType().GetProperty("G2Female").GetValue(_data), + Remark = _data.GetType().GetProperty("Remark").GetValue(_data), + }); + } + + var result = new + { + template = "reportInsignia2", + reportName = "reportInsignia2", + data = new + { + yearInsignalPeriod, + summaryTotal, + data = dataResult, + } + }; + return Success(result); + + } + catch + { + throw; + } + } + #endregion + + #region บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี + /// + /// บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี + /// + /// type + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("report3/{type}")] + public async Task> GetInsigniaReport3Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type) + { + try + { + var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + + var result = new + { + template = "reportInsignia2", + reportName = "reportInsignia2", + data = new List() + }; + return Success(result); + + } + catch + { + throw; + } + } + #endregion + + + + } +} diff --git a/BMA.EHR.Insignia/Requests/GetInsigniaDetailByNodeReportDto.cs b/BMA.EHR.Insignia/Requests/GetInsigniaDetailByNodeReportDto.cs new file mode 100644 index 00000000..0282b021 --- /dev/null +++ b/BMA.EHR.Insignia/Requests/GetInsigniaDetailByNodeReportDto.cs @@ -0,0 +1,10 @@ + +namespace BMA.EHR.Insignia.Service.Requests +{ + public class GetInsigniaDetailByNodeReportDto + { + public Guid roundId { get; set; } + public int node { get; set; } + public string nodeId { get; set; } + } +} \ No newline at end of file