867 lines
44 KiB
C#
867 lines
44 KiB
C#
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 Elasticsearch.Net;
|
|
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.Globalization;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
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.GetCoinReport(req.roundId, type, req.node, req.nodeId);
|
|
var yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId);
|
|
var yearLastTwoDigits = yearInsignalPeriod.Substring(yearInsignalPeriod.Length - 2);
|
|
|
|
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]),
|
|
Root = dataList[i].GetType().GetProperty("Root").GetValue(dataList[i]),
|
|
RootId = dataList[i].GetType().GetProperty("RootId").GetValue(dataList[i]),
|
|
Child1 = dataList[i].GetType().GetProperty("Child1").GetValue(dataList[i]),
|
|
Child1Id = dataList[i].GetType().GetProperty("Child1Id").GetValue(dataList[i]),
|
|
Child2 = dataList[i].GetType().GetProperty("Child2").GetValue(dataList[i]),
|
|
Child2Id = dataList[i].GetType().GetProperty("Child2Id").GetValue(dataList[i]),
|
|
Child3 = dataList[i].GetType().GetProperty("Child3").GetValue(dataList[i]),
|
|
Child3Id = dataList[i].GetType().GetProperty("Child3Id").GetValue(dataList[i]),
|
|
Child4 = dataList[i].GetType().GetProperty("Child4").GetValue(dataList[i]),
|
|
Child4Id = dataList[i].GetType().GetProperty("Child4Id").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;
|
|
var maxRow = Math.Max(left.Count(), right.Count());
|
|
|
|
for (int i = 0; i < maxRow; i++)
|
|
{
|
|
var leftItem = i < left.Count() ? left.ElementAt(i) : null;
|
|
var rightItem = i < right.Count() ? right.ElementAt(i) : null;
|
|
|
|
// ข้ามถ้าไม่มีข้อมูลทั้งสองฝั่ง
|
|
if (leftItem == null && rightItem == null)
|
|
continue;
|
|
|
|
var insigniaName = leftItem != null
|
|
? leftItem.GetType().GetProperty("InsigniaName").GetValue(leftItem)
|
|
: rightItem.GetType().GetProperty("InsigniaName").GetValue(rightItem);
|
|
|
|
male = detailList.Count(x => x.Male == 1 && x.InsigniaName == insigniaName);
|
|
female = detailList.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 = mergeList.Count + 1;
|
|
stop = start + (countGroup - countGroupTemp) - 1;
|
|
range = (countGroup - countGroupTemp) != 1 ? $"{start} - {stop}" : $"{start}";
|
|
|
|
mergeList.Add(new
|
|
{
|
|
ColLeft = colLeft > 0 ? colLeft.ToString().ToThaiNumber() : "",
|
|
NameLeft = leftItem?.GetType().GetProperty("FullName").GetValue(leftItem),
|
|
RootLeft = leftItem?.GetType().GetProperty("Root").GetValue(leftItem),
|
|
Child1Left = leftItem?.GetType().GetProperty("Child1").GetValue(leftItem),
|
|
Child2Left = leftItem?.GetType().GetProperty("Child2").GetValue(leftItem),
|
|
Child3Left = leftItem?.GetType().GetProperty("Child3").GetValue(leftItem),
|
|
Child4Left = leftItem?.GetType().GetProperty("Child4").GetValue(leftItem),
|
|
|
|
ColRight = colRight > 0 ? colRight.ToString().ToThaiNumber() : "",
|
|
NameRight = rightItem?.GetType().GetProperty("FullName").GetValue(rightItem),
|
|
RootRight = rightItem?.GetType().GetProperty("Root").GetValue(rightItem),
|
|
Child1Right = rightItem?.GetType().GetProperty("Child1").GetValue(rightItem),
|
|
Child2Right = rightItem?.GetType().GetProperty("Child2").GetValue(rightItem),
|
|
Child3Right = rightItem?.GetType().GetProperty("Child3").GetValue(rightItem),
|
|
Child4Right = rightItem?.GetType().GetProperty("Child4").GetValue(rightItem),
|
|
|
|
InsigniaInitial = leftItem?.GetType().GetProperty("InsigniaInitial").GetValue(leftItem)
|
|
?? rightItem?.GetType().GetProperty("InsigniaInitial").GetValue(rightItem),
|
|
InsigniaName = insigniaName,
|
|
Range = range.ToThaiNumber(),
|
|
Male = male.ToString().ToThaiNumber(),
|
|
Female = female.ToString().ToThaiNumber()
|
|
});
|
|
}
|
|
|
|
dataResult = mergeList;
|
|
}
|
|
|
|
var groupedByOrg = detailList
|
|
.GroupBy(x =>
|
|
{
|
|
string child4Id = x.Child4Id?.ToString() ?? "";
|
|
string child3Id = x.Child3Id?.ToString() ?? "";
|
|
string child2Id = x.Child2Id?.ToString() ?? "";
|
|
string child1Id = x.Child1Id?.ToString() ?? "";
|
|
string rootId = x.RootId?.ToString() ?? "";
|
|
|
|
|
|
if (!string.IsNullOrEmpty(child4Id)) return child4Id;
|
|
if (!string.IsNullOrEmpty(child3Id)) return child3Id;
|
|
if (!string.IsNullOrEmpty(child2Id)) return child2Id;
|
|
if (!string.IsNullOrEmpty(child1Id)) return child1Id;
|
|
return rootId;
|
|
})
|
|
.Where(g => !string.IsNullOrWhiteSpace(g.Key))
|
|
.Select(orgGroup =>
|
|
{
|
|
var first = orgGroup.FirstOrDefault();
|
|
|
|
var org = !string.IsNullOrWhiteSpace(first?.Child4) ? first.Child4.Trim() :
|
|
!string.IsNullOrWhiteSpace(first?.Child3) ? first.Child3.Trim() :
|
|
!string.IsNullOrWhiteSpace(first?.Child2) ? first.Child2.Trim() :
|
|
!string.IsNullOrWhiteSpace(first?.Child1) ? first.Child1.Trim() :
|
|
first.Root.Trim();
|
|
|
|
// Group by InsigniaName
|
|
var groupedByInsignia = orgGroup
|
|
.GroupBy(x => x.InsigniaName)
|
|
.Select(insigniaGroup =>
|
|
{
|
|
if (!insigniaGroup.Any(x => !string.IsNullOrWhiteSpace(x.FullName)))
|
|
return null;
|
|
|
|
var insigniaName = insigniaGroup.Key;
|
|
var left = insigniaGroup.Where(x => x.status == false).ToList();
|
|
var right = insigniaGroup.Where(x => x.status == true).ToList();
|
|
|
|
var male = insigniaGroup.Count(x => x.Male == 1);
|
|
var female = insigniaGroup.Count(x => x.Female == 1);
|
|
var countGroup = insigniaGroup.Count();
|
|
var countGroupTemp = insigniaGroup.Count(x => x.FullName == "");
|
|
|
|
var start = 1;
|
|
var stop = countGroup - countGroupTemp;
|
|
var range = stop == 1 ? $"{start}" : $"{start} - {stop}";
|
|
range = range.ToThaiNumber();
|
|
|
|
var people = new List<object>();
|
|
|
|
int colLeft = 1;
|
|
int colRight = 26;
|
|
int rowCount = Math.Max(left.Count, right.Count);
|
|
|
|
var allPeople = left.Concat(right).ToList();
|
|
|
|
int colLeftStart = 1;
|
|
int colRightStart = 26;
|
|
|
|
for (int i = 0; i < allPeople.Count; i++)
|
|
{
|
|
var person = allPeople[i];
|
|
|
|
if (string.IsNullOrWhiteSpace(person?.FullName))
|
|
continue;
|
|
|
|
if (i < 25)
|
|
{
|
|
people.Add(new
|
|
{
|
|
ColLeft = colLeftStart.ToString().ToThaiNumber(),
|
|
NameLeft = person.FullName,
|
|
RootLeft = person.Root,
|
|
Child1Left = person.Child1,
|
|
Child2Left = person.Child2,
|
|
Child3Left = person.Child3,
|
|
Child4Left = person.Child4,
|
|
|
|
ColRight = "",
|
|
NameRight = "",
|
|
RootRight = "",
|
|
Child1Right = "",
|
|
Child2Right = "",
|
|
Child3Right = "",
|
|
Child4Right = "",
|
|
|
|
InsigniaInitial = person.InsigniaInitial,
|
|
InsigniaName = insigniaName,
|
|
Range = range,
|
|
Male = male.ToString().ToThaiNumber(),
|
|
Female = female.ToString().ToThaiNumber()
|
|
});
|
|
|
|
colLeftStart++;
|
|
}
|
|
else
|
|
{
|
|
// คำนวณแถวที่จะเอาข้อมูลขวาไปใส่
|
|
int indexToUpdate = i - 25; // ถ้า i=25 จะไปแถว 0, i=26 ไปแถว 1 เป็นต้น
|
|
|
|
// ดึงแถวที่ต้องการมาแก้ไข
|
|
var row = (dynamic)people[indexToUpdate];
|
|
|
|
// สร้าง object ใหม่โดยคัดลอกข้อมูลซ้ายเดิมและเพิ่มข้อมูลขวา
|
|
var updatedRow = new
|
|
{
|
|
ColLeft = row.ColLeft,
|
|
NameLeft = row.NameLeft,
|
|
RootLeft = row.RootLeft,
|
|
Child1Left = row.Child1Left,
|
|
Child2Left = row.Child2Left,
|
|
Child3Left = row.Child3Left,
|
|
Child4Left = row.Child4Left,
|
|
|
|
ColRight = colRightStart.ToString().ToThaiNumber(),
|
|
NameRight = person.FullName,
|
|
RootRight = person.Root,
|
|
Child1Right = person.Child1,
|
|
Child2Right = person.Child2,
|
|
Child3Right = person.Child3,
|
|
Child4Right = person.Child4,
|
|
|
|
InsigniaInitial = person.InsigniaInitial,
|
|
InsigniaName = insigniaName,
|
|
Range = range,
|
|
Male = male.ToString().ToThaiNumber(),
|
|
Female = female.ToString().ToThaiNumber()
|
|
};
|
|
|
|
// แทนที่แถวเดิมด้วยแถวที่อัพเดต
|
|
people[indexToUpdate] = updatedRow;
|
|
|
|
colRightStart++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return new
|
|
{
|
|
name = $"(ชั้นตรา) {insigniaName}",
|
|
shotName = left.FirstOrDefault()?.InsigniaInitial ?? right.FirstOrDefault()?.InsigniaInitial,
|
|
range = range,
|
|
male = male.ToString().ToThaiNumber(),
|
|
female = female.ToString().ToThaiNumber(),
|
|
people = people
|
|
};
|
|
}).ToList();
|
|
|
|
return new
|
|
{
|
|
org = org,
|
|
insignia = groupedByInsignia
|
|
};
|
|
})
|
|
.Where(x => !string.IsNullOrWhiteSpace(x.org) && x.insignia.Any())
|
|
.ToList();
|
|
|
|
|
|
|
|
var result = new
|
|
{
|
|
template = "reportInsignia1",
|
|
reportName = "reportInsignia1",
|
|
data = new
|
|
{
|
|
yearInsignalPeriod = yearInsignalPeriod,
|
|
yearLastTwoDigits = yearLastTwoDigits,
|
|
data = groupedByOrg,
|
|
}
|
|
};
|
|
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("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 yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId);
|
|
|
|
var data = await _repository.GetEvaluationResult5YearReport(req.roundId, type, req.node, req.nodeId);
|
|
var year = ((DateTime.UtcNow.Year) + 543);
|
|
var _agency = data.Count > 0 ? data[0].GetType().GetProperty("Agency").GetValue(data[0]) : null;
|
|
var result = new
|
|
{
|
|
template = "reportInsignia2",
|
|
reportName = "reportInsignia2",
|
|
data = new
|
|
{
|
|
agency = _agency,
|
|
yearInsignalPeriod = yearInsignalPeriod,
|
|
year1 = year.ToString().ToThaiNumber(),
|
|
year2 = (year - 1).ToString().ToThaiNumber(),
|
|
year3 = (year - 2).ToString().ToThaiNumber(),
|
|
year4 = (year - 3).ToString().ToThaiNumber(),
|
|
year5 = (year - 4).ToString().ToThaiNumber(),
|
|
data = data,
|
|
}
|
|
};
|
|
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("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 data = await _repository.GetSummaryCoinReport(req.roundId, type, req.node, req.nodeId);
|
|
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 = "reportInsignia3",
|
|
reportName = "reportInsignia3",
|
|
data = new
|
|
{
|
|
yearInsignalPeriod = yearInsignalPeriod,
|
|
summaryTotal = summaryTotal,
|
|
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("report4/{type}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport4Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
|
{
|
|
try
|
|
{
|
|
var insignalPeriod = await _repository.GetKhr4TotalReport(req.roundId, type, req.node, req.nodeId);
|
|
var year = await _repository.GetYearInsigniaNote(req.roundId);
|
|
var detailList = new List<dynamic>();
|
|
var row = 1;
|
|
var org = "";
|
|
var number = "";
|
|
var citizenId = "0";
|
|
|
|
foreach (var _data in insignalPeriod)
|
|
{
|
|
citizenId = _data.GetType().GetProperty("CitizenId").GetValue(_data);
|
|
org = _data.GetType().GetProperty("Root").GetValue(_data);
|
|
number = _data.GetType().GetProperty("Number").GetValue(_data);
|
|
|
|
var datePayment = _data.GetType().GetProperty("DatePayment").GetValue(_data)?.ToString();
|
|
DateTime? datePayment2 = null;
|
|
|
|
if (!string.IsNullOrEmpty(datePayment))
|
|
{
|
|
DateTime parsedDate;
|
|
if (DateTime.TryParse(datePayment, out parsedDate))
|
|
{
|
|
datePayment2 = parsedDate;
|
|
}
|
|
}
|
|
|
|
detailList.Add(new
|
|
{
|
|
row = row.ToString().ToThaiNumber(),
|
|
citizenId = citizenId.ToString().ToThaiNumber(),
|
|
prefix = _data.GetType().GetProperty("Prefix").GetValue(_data),
|
|
fullName = _data.GetType().GetProperty("FullName").GetValue(_data),
|
|
posTypeName = _data.GetType().GetProperty("PosTypeName").GetValue(_data),
|
|
posLevelName = _data.GetType().GetProperty("PosLevelName").GetValue(_data),
|
|
position = _data.GetType().GetProperty("Position").GetValue(_data),
|
|
root = _data.GetType().GetProperty("Root").GetValue(_data),
|
|
organizationOrganizationReceive = _data.GetType().GetProperty("OrganizationOrganizationReceive").GetValue(_data),
|
|
organizationOrganizationSend = _data.GetType().GetProperty("OrganizationOrganizationSend").GetValue(_data),
|
|
isApprove = _data.GetType().GetProperty("IsApprove").GetValue(_data),
|
|
requestInsignia = _data.GetType().GetProperty("RequestInsignia").GetValue(_data),
|
|
number = number == null ? "" : number.ToString().ToThaiNumber(),
|
|
datePayment = datePayment2.HasValue ? datePayment2.Value.ToThaiShortDate().ToThaiNumber() : ""
|
|
});
|
|
row = row + 1;
|
|
}
|
|
|
|
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
|
|
var result = new
|
|
{
|
|
template = "reportInsignia4",
|
|
reportName = "reportInsignia4",
|
|
data = new
|
|
{
|
|
profileType = type == "employee" ? "ลูกจ้างประจำ" : "ข้าราชการสามัญกรุงเทพมหานคร",
|
|
org = org,
|
|
year = year,
|
|
date = date,
|
|
data = detailList,
|
|
}
|
|
};
|
|
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("report5/{type}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport5Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
|
{
|
|
try
|
|
{
|
|
var insignalPeriod = await _repository.GetKhr5TotalReport(req.roundId, type, req.node, req.nodeId);
|
|
var yearInsignalNote = await _repository.GetYearInsigniaNote(req.roundId);
|
|
var detailList = new List<dynamic>();
|
|
var male = 0;
|
|
var feMale = 0;
|
|
var _male = 0;
|
|
var _feMale = 0;
|
|
var maleSum = 0;
|
|
var feMaleSum = 0;
|
|
var nameType = "";
|
|
var org = "";
|
|
foreach (var _data in insignalPeriod)
|
|
{
|
|
if (nameType != "" && nameType != _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data))
|
|
{
|
|
org = _data.GetType().GetProperty("DepartmentName").GetValue(_data);
|
|
detailList.Add(new
|
|
{
|
|
type = "",
|
|
name = "รวม",
|
|
male = male.ToString().ToThaiNumber(),
|
|
feMale = feMale.ToString().ToThaiNumber(),
|
|
sum = (male + feMale).ToString().ToThaiNumber(),
|
|
});
|
|
maleSum = maleSum + male;
|
|
feMaleSum = maleSum + feMale;
|
|
male = 0;
|
|
feMale = 0;
|
|
}
|
|
nameType = _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data);
|
|
|
|
_male = _data.GetType().GetProperty("Male").GetValue(_data);
|
|
_feMale = _data.GetType().GetProperty("Female").GetValue(_data);
|
|
detailList.Add(new
|
|
{
|
|
type = _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data),
|
|
name = _data.GetType().GetProperty("RequestInsigniaName").GetValue(_data),
|
|
male = _male.ToString().ToThaiNumber(),
|
|
feMale = _feMale.ToString().ToThaiNumber(),
|
|
sum = (_male + _feMale).ToString().ToThaiNumber(),
|
|
});
|
|
male = male + _data.GetType().GetProperty("Male").GetValue(_data);
|
|
feMale = feMale + _data.GetType().GetProperty("Female").GetValue(_data);
|
|
}
|
|
detailList.Add(new
|
|
{
|
|
type = "",
|
|
name = "รวม",
|
|
male = male.ToString().ToThaiNumber(),
|
|
feMale = feMale.ToString().ToThaiNumber(),
|
|
sum = (male + feMale).ToString().ToThaiNumber(),
|
|
});
|
|
maleSum = maleSum + male;
|
|
feMaleSum = maleSum + feMale;
|
|
detailList.Add(new
|
|
{
|
|
type = "",
|
|
name = "รวมทั้งหมด",
|
|
male = maleSum.ToString().ToThaiNumber(),
|
|
feMale = feMaleSum.ToString().ToThaiNumber(),
|
|
sum = (maleSum + feMaleSum).ToString().ToThaiNumber(),
|
|
});
|
|
|
|
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
|
|
var result = new
|
|
{
|
|
template = "reportInsignia5",
|
|
reportName = "reportInsignia5",
|
|
data = new
|
|
{
|
|
profileType = type == "employee" ? "ลูกจ้างประจำ" : "ข้าราชการสามัญกรุงเทพมหานคร",
|
|
org = org,
|
|
year = yearInsignalNote,
|
|
date = date,
|
|
data = detailList,
|
|
}
|
|
};
|
|
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("report6/{type}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport6Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
|
{
|
|
try
|
|
{
|
|
var insignalPeriod = await _repository.GetKhr6TotalReport(req.roundId, type, req.node, req.nodeId);
|
|
var nameNote = await _repository.GetNameInsigniaNote(req.roundId);
|
|
var detailList = new List<dynamic>();
|
|
var pending = 0;
|
|
var done = 0;
|
|
var _pending = 0;
|
|
var _done = 0;
|
|
var pendingSum = 0;
|
|
var doneSum = 0;
|
|
var row = 1;
|
|
var nameType = "";
|
|
var org = "";
|
|
foreach (var _data in insignalPeriod)
|
|
{
|
|
// return Success("result");
|
|
if (nameType != "" && nameType != _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data))
|
|
{
|
|
org = _data.GetType().GetProperty("DepartmentName").GetValue(_data);
|
|
detailList.Add(new
|
|
{
|
|
row = "",
|
|
type = "",
|
|
name = "รวม",
|
|
pending = pending.ToString().ToThaiNumber(),
|
|
done = done.ToString().ToThaiNumber(),
|
|
sum = (pending + done).ToString().ToThaiNumber(),
|
|
});
|
|
pendingSum = pendingSum + pending;
|
|
doneSum = doneSum + done;
|
|
pending = 0;
|
|
done = 0;
|
|
row = 1;
|
|
}
|
|
nameType = _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data);
|
|
|
|
_pending = _data.GetType().GetProperty("Pending").GetValue(_data);
|
|
_done = _data.GetType().GetProperty("Done").GetValue(_data);
|
|
detailList.Add(new
|
|
{
|
|
row = row.ToString().ToThaiNumber(),
|
|
type = _data.GetType().GetProperty("InsigniaTypeName").GetValue(_data),
|
|
name = _data.GetType().GetProperty("RequestInsigniaName").GetValue(_data),
|
|
pending = _pending.ToString().ToThaiNumber(),
|
|
done = _done.ToString().ToThaiNumber(),
|
|
sum = (_pending + _done).ToString().ToThaiNumber(),
|
|
});
|
|
pending = pending + _data.GetType().GetProperty("Pending").GetValue(_data);
|
|
done = done + _data.GetType().GetProperty("Done").GetValue(_data);
|
|
row = row + 1;
|
|
}
|
|
detailList.Add(new
|
|
{
|
|
row = "",
|
|
type = "",
|
|
name = "รวม",
|
|
pending = pending.ToString().ToThaiNumber(),
|
|
done = done.ToString().ToThaiNumber(),
|
|
sum = (pending + done).ToString().ToThaiNumber(),
|
|
});
|
|
pendingSum = pendingSum + pending;
|
|
doneSum = doneSum + done;
|
|
detailList.Add(new
|
|
{
|
|
row = "",
|
|
type = "",
|
|
name = "รวมทั้งหมด",
|
|
pending = pendingSum.ToString().ToThaiNumber(),
|
|
done = doneSum.ToString().ToThaiNumber(),
|
|
sum = (pendingSum + doneSum).ToString().ToThaiNumber(),
|
|
});
|
|
|
|
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
|
|
var result = new
|
|
{
|
|
template = "reportInsignia6",
|
|
reportName = "reportInsignia6",
|
|
data = new
|
|
{
|
|
profileType = type == "employee" ? "ลูกจ้างประจำ" : "ข้าราชการสามัญกรุงเทพมหานคร",
|
|
org = org,
|
|
name = nameNote,
|
|
date = date,
|
|
data = detailList,
|
|
}
|
|
};
|
|
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("report7/{type}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport7Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
|
|
{
|
|
try
|
|
{
|
|
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
|
|
var result = new
|
|
{
|
|
template = "reportInsignia7",
|
|
reportName = "reportInsignia7",
|
|
data = new
|
|
{
|
|
yearInsignalPeriod = "",
|
|
date = date,
|
|
data = "",
|
|
}
|
|
};
|
|
return Success(result);
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา
|
|
/// <summary>
|
|
/// ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา
|
|
/// </summary>
|
|
/// <param name="id">id </param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("report8/{id}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaReport8Async(Guid id)
|
|
{
|
|
|
|
try
|
|
{
|
|
var data = await _repository.GeInsigniaRequestProfiles(id);
|
|
var result = new
|
|
{
|
|
template = "reportInsignia8",
|
|
reportName = "reportInsignia8",
|
|
data = data
|
|
};
|
|
return Success(result);
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|