add endpoint report

This commit is contained in:
AdisakKanthawilang 2025-02-11 20:21:49 +07:00
parent fd17afb145
commit 7843da3bde
2 changed files with 230 additions and 58 deletions

View file

@ -13,7 +13,9 @@ using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Metadata; using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Net; using System.Net;
@ -30,6 +32,7 @@ namespace BMA.EHR.Application.Repositories.Reports
private readonly OrganizationCommonRepository _organizationCommonRepository; private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly NotificationRepository _repositoryNoti; private readonly NotificationRepository _repositoryNoti;
private readonly InsigniaPeriodsRepository _repositoryInsignia; private readonly InsigniaPeriodsRepository _repositoryInsignia;
private readonly IConfiguration _configuration;
private readonly string CRLF = "\r\n"; private readonly string CRLF = "\r\n";
private readonly UserProfileRepository _userProfileRepository; private readonly UserProfileRepository _userProfileRepository;
@ -44,6 +47,7 @@ namespace BMA.EHR.Application.Repositories.Reports
InsigniaPeriodsRepository repositoryInsignia, InsigniaPeriodsRepository repositoryInsignia,
NotificationRepository repositoryNoti, NotificationRepository repositoryNoti,
IWebHostEnvironment hostEnvironment, IWebHostEnvironment hostEnvironment,
IConfiguration configuration,
UserProfileRepository userProfileRepository, UserProfileRepository userProfileRepository,
IHttpContextAccessor httpContextAccessor) IHttpContextAccessor httpContextAccessor)
{ {
@ -54,6 +58,7 @@ namespace BMA.EHR.Application.Repositories.Reports
_repositoryInsignia = repositoryInsignia; _repositoryInsignia = repositoryInsignia;
_userProfileRepository = userProfileRepository; _userProfileRepository = userProfileRepository;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_configuration = configuration;
} }
#endregion #endregion
@ -1070,7 +1075,6 @@ namespace BMA.EHR.Application.Repositories.Reports
.Where(x => x.Status == "PENDING") .Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null); .Where(x => x.RequestInsignia.InsigniaType != null);
/*.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ");*/ /*.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ");*/
if (type == "officer") if (type == "officer")
{ {
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "officer"); data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "officer");
@ -1080,6 +1084,8 @@ namespace BMA.EHR.Application.Repositories.Reports
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "employee"); data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "employee");
} }
Console.WriteLine(">>>>>>>logs", data_insigniaQuery.ToQueryString);
switch (node) switch (node)
{ {
case 0: case 0:
@ -1106,63 +1112,84 @@ namespace BMA.EHR.Application.Repositories.Reports
break; break;
} }
var data = await data_insigniaQuery var data = await data_insigniaQuery
.Select(x => new .Select(x => new
{
FullName = $"{x.Prefix}{x.FirstName} {x.LastName}",
RequestInsigniaName = x.RequestInsignia.Name, // Name of the Insignia
})
.ToListAsync();
/* var seq = 1;
foreach (var d in response!.result)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
_client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
};
seq++;
resultData.Add(receiver);
}
}*/
var insignia = data.Select((r, index) => new
{ {
RowNo = (index + 1).ToNumericText().ToThaiNumber(), ProfileId = x.ProfileId,
FullName = r.FullName, FullName = $"{x.Prefix}{x.FirstName} {x.LastName}",
RequestInsigniaName = r.RequestInsigniaName, RequestInsigniaName = x.RequestInsignia.Name, // Name of the Insignia
ResultY1APR = "-", })
ResultY1OCT = "-", .ToListAsync();
ResultY2APR = "-",
ResultY2OCT = "-",
ResultY3APR = "-",
ResultY3OCT = "-",
ResultY4APR = "-",
ResultY4OCT = "-",
ResultY5APR = "-",
ResultY5OCT = "-",
Remark = "",
}).ToList();
return insignia; var seq = 1;
foreach (var d in data)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/unauthorize/calculateEvaluation";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
if (_res.IsSuccessStatusCode)
{
/*var orgResponse = JsonConvert.DeserializeObject<dynamic>(_result);*/
var orgResponse = JObject.Parse(_result);
var resultItems = orgResponse["result"];
/* if (orgResponse != null && orgResponse.result != null)
{*/
var matchedData = resultItems
.Where(item => item["profileId"].ToString() == d.ProfileId.ToString())
.FirstOrDefault();
/*
if (matchedData != null)
{
// แสดงข้อมูลที่ตรงกัน
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = matchedData.citizenId ?? "",
Prefix = matchedData.prefix ?? "",
FirstName = matchedData.firstName ?? "",
LastName = matchedData.lastName ?? "",
RefPlacementProfileId = Guid.Parse(matchedData.profileId.ToString()),
};
seq++;
resultData.Add(receiver);
}*/
/*}*/
return matchedData;
}
else
{
return $"Error: {_res.StatusCode} - {_res.ReasonPhrase}";
}
}
}
/* var insignia = data.Select((r, index) => new
{
RowNo = (index + 1).ToNumericText().ToThaiNumber(),
ProfileId = r.,
FullName = r.FullName,
RequestInsigniaName = r.RequestInsigniaName,
ResultY1APR = "-",
ResultY1OCT = "-",
ResultY2APR = "-",
ResultY2OCT = "-",
ResultY3APR = "-",
ResultY3OCT = "-",
ResultY4APR = "-",
ResultY4OCT = "-",
ResultY5APR = "-",
ResultY5OCT = "-",
Remark = "",
}).ToList();*/
return data;
} }
//noti ยื่นเสนอคน //noti ยื่นเสนอคน

View file

@ -219,7 +219,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report2/{type}")] [HttpPost("report2/{type}")]
public async Task<ActionResult<ResponseObject>> GetInsigniaReport3Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type) public async Task<ActionResult<ResponseObject>> GetInsigniaReport2Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
{ {
try try
{ {
@ -265,7 +265,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report3/{type}")] [HttpPost("report3/{type}")]
public async Task<ActionResult<ResponseObject>> GetInsigniaReport2Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type) public async Task<ActionResult<ResponseObject>> GetInsigniaReport3Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
{ {
try try
{ {
@ -316,6 +316,151 @@ namespace BMA.EHR.Insignia.Service.Controllers
} }
#endregion #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 date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
var result = new
{
template = "reportInsignia4",
reportName = "reportInsignia4",
data = new
{
yearInsignalPeriod = "",
date = date,
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("report5/{type}")]
public async Task<ActionResult<ResponseObject>> GetInsigniaReport5Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
{
try
{
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
var result = new
{
template = "reportInsignia5",
reportName = "reportInsignia5",
data = new
{
yearInsignalPeriod = "",
date = date,
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("report6/{type}")]
public async Task<ActionResult<ResponseObject>> GetInsigniaReport6Async([FromBody] GetInsigniaDetailByNodeReportDto req, string type)
{
try
{
var date = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}";
var result = new
{
template = "reportInsignia6",
reportName = "reportInsignia6",
data = new
{
yearInsignalPeriod = "",
date = date,
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("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
} }
} }