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.Http;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
@ -30,6 +32,7 @@ namespace BMA.EHR.Application.Repositories.Reports
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly NotificationRepository _repositoryNoti;
private readonly InsigniaPeriodsRepository _repositoryInsignia;
private readonly IConfiguration _configuration;
private readonly string CRLF = "\r\n";
private readonly UserProfileRepository _userProfileRepository;
@ -44,6 +47,7 @@ namespace BMA.EHR.Application.Repositories.Reports
InsigniaPeriodsRepository repositoryInsignia,
NotificationRepository repositoryNoti,
IWebHostEnvironment hostEnvironment,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
IHttpContextAccessor httpContextAccessor)
{
@ -54,6 +58,7 @@ namespace BMA.EHR.Application.Repositories.Reports
_repositoryInsignia = repositoryInsignia;
_userProfileRepository = userProfileRepository;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#endregion
@ -1070,7 +1075,6 @@ namespace BMA.EHR.Application.Repositories.Reports
.Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null);
/*.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ");*/
if (type == "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");
}
Console.WriteLine(">>>>>>>logs", data_insigniaQuery.ToQueryString);
switch (node)
{
case 0:
@ -1106,63 +1112,84 @@ namespace BMA.EHR.Application.Repositories.Reports
break;
}
var data = await data_insigniaQuery
.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
.Select(x => new
{
RowNo = (index + 1).ToNumericText().ToThaiNumber(),
FullName = r.FullName,
RequestInsigniaName = r.RequestInsigniaName,
ResultY1APR = "-",
ResultY1OCT = "-",
ResultY2APR = "-",
ResultY2OCT = "-",
ResultY3APR = "-",
ResultY3OCT = "-",
ResultY4APR = "-",
ResultY4OCT = "-",
ResultY5APR = "-",
ResultY5OCT = "-",
Remark = "",
}).ToList();
ProfileId = x.ProfileId,
FullName = $"{x.Prefix}{x.FirstName} {x.LastName}",
RequestInsigniaName = x.RequestInsignia.Name, // Name of the Insignia
})
.ToListAsync();
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 ยื่นเสนอคน