Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Services;
|
||||
|
||||
public interface IJinkoSapService : IScopeDependency
|
||||
public interface IJinkoSapService : ISingletonDependency
|
||||
{
|
||||
Task<SapOrganizationResponse> GetSapOrganizationsAsync();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Response;
|
||||
using Dlhis.Sys.Api;
|
||||
@@ -8,22 +9,35 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements;
|
||||
|
||||
public class JinkoSapService : IJinkoSapService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<JinkoSapService> _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
|
||||
public JinkoSapService(IHttpClientFactory httpClientFactory, ILogger<JinkoSapService> logger, ITenantApi tenantApi)
|
||||
{
|
||||
_httpClient = httpClientFactory.CreateClient("jinko:sap");
|
||||
_logger = logger;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
private HttpClient GetHttpClient()
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko:sap");
|
||||
//http://sappidap.jinkosolar.cn:51000
|
||||
httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100");
|
||||
httpClient.Timeout = TimeSpan.FromMinutes(10);
|
||||
var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC");
|
||||
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public async Task<SapOrganizationResponse> GetSapOrganizationsAsync()
|
||||
{
|
||||
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/";
|
||||
string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/";
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -34,9 +48,9 @@ public class JinkoSapService : IJinkoSapService
|
||||
|
||||
public async Task<SapPositionResponse> GetPositionsAsync()
|
||||
{
|
||||
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_POSITION/";
|
||||
string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/";
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -48,7 +62,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
|
||||
public async Task<SapPersonResponse> GetPersonsAsync()
|
||||
{
|
||||
var apiUrl = "http://sappipap01.jinkosolar.cn:50100/RESTAdapter/Rest/EHR_PERSONNEL/";
|
||||
var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/";
|
||||
|
||||
var tenantResult = await _tenantApi.GetTenantsInternalAsync();
|
||||
var tenants = tenantResult.Data;
|
||||
@@ -75,7 +89,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
};
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, content);
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Reference in New Issue
Block a user