report insignia
This commit is contained in:
parent
58f7ab83e3
commit
30281ff2ab
4 changed files with 437 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// รายชื่อออกคำสั่งลงโทษ
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("{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 jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||||
|
if (jsonData["status"]?.ToString() != "200")
|
||||||
|
{
|
||||||
|
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 result = new
|
||||||
|
{
|
||||||
|
template = "reportDiscipline",
|
||||||
|
reportName = "reportDiscipline",
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
year = req.year + 543,
|
||||||
|
data = new List<dynamic>()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
304
BMA.EHR.Insignia/Controllers/InsigniaReportController.cs
Normal file
304
BMA.EHR.Insignia/Controllers/InsigniaReportController.cs
Normal file
|
|
@ -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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="documentService"></param>
|
||||||
|
/// <param name="repository"></param>
|
||||||
|
/// <param name="repositoryNoti"></param>
|
||||||
|
/// <param name="hostingEnvironment"></param>
|
||||||
|
/// <param name="httpContextAccessor"></param>
|
||||||
|
/// <param name="userProfileRepository"></param>
|
||||||
|
/// <param name="insigniaPeriodRepository"></param>
|
||||||
|
/// <param name="producer"></param>
|
||||||
|
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 บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา
|
||||||
|
/// <summary>
|
||||||
|
/// บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">type </param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("report1/{type}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport1Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT");
|
||||||
|
var jsonData = JsonConvert.DeserializeObject<JObject>(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<dynamic>();
|
||||||
|
var dataList = new List<dynamic>(data);
|
||||||
|
var detailList = new List<dynamic>();
|
||||||
|
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<object>();
|
||||||
|
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 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ
|
||||||
|
/// <summary>
|
||||||
|
/// บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">type </param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("report2/{type}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport2Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT");
|
||||||
|
var jsonData = JsonConvert.DeserializeObject<JObject>(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<dynamic>();
|
||||||
|
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 ปี
|
||||||
|
/// <summary>
|
||||||
|
/// บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">type </param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("report3/{type}")]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport3Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_INSIGNIA_REPORT");
|
||||||
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||||
|
if (jsonData["status"]?.ToString() != "200")
|
||||||
|
{
|
||||||
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new
|
||||||
|
{
|
||||||
|
template = "reportInsignia2",
|
||||||
|
reportName = "reportInsignia2",
|
||||||
|
data = new List<dynamic>()
|
||||||
|
};
|
||||||
|
return Success(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue