Browse Source

体检报告传输

bjmzak
DESKTOP-G961P6V\Zhh 1 year ago
parent
commit
7dcbb96d4f
  1. 11
      src/Shentun.Peis.Application.Contracts/WebApiOutDto.cs
  2. 83
      src/Shentun.Peis.Application/TransToWebPeis/TransToWebPeisAppService.cs
  3. 43
      test/Shentun.Peis.Application.Tests/TransToWebPeisAppServiceTest.cs

11
src/Shentun.Peis.Application.Contracts/WebApiOutDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis
{
public class WebApiOutDto: WebApiOutDtoBase
{
public object Data { get; set; }
}
}

83
src/Shentun.Peis.Application/TransToWebPeis/TransToWebPeisAppService.cs

@ -1,8 +1,11 @@
using Microsoft.AspNetCore.Authorization;
using Azure.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Org.BouncyCastle.Utilities;
using Shentun.Peis.CustomerOrgs;
using Shentun.Peis.DataMigrations;
@ -19,6 +22,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
@ -164,8 +169,23 @@ namespace Shentun.Peis.TransToWebPeis
public async Task UploadPeisReportAsync(UploadPeisReportIuputDto input)
{
//同步数据
await TransPatientRegisterByPatientRegisterIdAsync(new PatientRegisterIdInputDto { PatientRegisterId = input.PatientRegisterId });
//await TransPatientRegisterByPatientRegisterIdAsync(new PatientRegisterIdInputDto { PatientRegisterId = input.PatientRegisterId });
//上传报告
var thirdInterfaces = await _thirdInterfaceRepository.GetListAsync(o => o.ThirdInterfaceType ==
ThirdInterfaceTypeFlag.TranToWebPeis);
foreach (var thirdInterface in thirdInterfaces)
{
var parmValue = thirdInterface.ParmValue;
var configurationBuilder = new ConfigurationBuilder()
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
var interfaceConfig = configurationBuilder.Build();
var url = interfaceConfig.GetSection("Interface").GetSection("Url").Value;
var user = interfaceConfig.GetSection("Interface").GetSection("User").Value;
var password = interfaceConfig.GetSection("Interface").GetSection("Password").Value;
var result = await CallAppServiceAsync<UploadPeisReportIuputDto, WebApiOutDto>(url, "", input);
}
}
@ -246,6 +266,65 @@ namespace Shentun.Peis.TransToWebPeis
return interfaceConnctionStr;
}
private string GetUrl(string parmValue)
{
var configurationBuilder = new ConfigurationBuilder()
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
var interfaceConfig = configurationBuilder.Build();
var url = interfaceConfig.GetSection("Interface").GetSection("Url").Value;
return url;
}
public async Task<TOut> CallAppServiceAsync<TInput, TOut>(string appBaseAddress,string url, TInput data)
{
string baseAddress = appBaseAddress;
using (var httpClientHandler = new HttpClientHandler())
{
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.BaseAddress = new Uri(baseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
//httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
string sendData = "";
if (data != null)
{
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
}
using (HttpContent httpContent = new StringContent(sendData))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = await httpClient.PostAsync(url, httpContent);
string result;
if (!response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
}
result = await response.Content.ReadAsStringAsync();
var resultDto = JsonConvert.DeserializeObject<TOut>(result);
if (resultDto is WebApiOutDtoBase)
{
var webApiOutDtoBase = resultDto as WebApiOutDtoBase;
if (webApiOutDtoBase.Code == "-1")
{
throw new Exception($"调用服务失败{webApiOutDtoBase.Message}");
}
}
return resultDto;
}
}
}
}
#region 基础数据

43
test/Shentun.Peis.Application.Tests/TransToWebPeisAppServiceTest.cs

@ -0,0 +1,43 @@
using Shentun.Peis.ChargeRequests;
using Shentun.Peis.Models;
using Shentun.Peis.TransToWebPeis;
using Shentun.Peis.TransToWebPeiss;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using Xunit;
using Xunit.Abstractions;
namespace Shentun.Peis
{
public class TransToWebPeisAppServiceTest : PeisApplicationTestBase
{
private readonly IRepository<ChargeRequest, Guid> _repository;
private readonly TransToWebPeisAppService _appService;
private readonly ITestOutputHelper _output;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public TransToWebPeisAppServiceTest(ITestOutputHelper testOutputHelper)
{
_output = testOutputHelper;
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_repository = GetRequiredService<IRepository<ChargeRequest, Guid>>();
_appService = GetRequiredService<TransToWebPeisAppService > ();
}
[Fact]
public async Task UploadPeisReportAsync()
{
var uploadPeisReportIuputDto = new UploadPeisReportIuputDto()
{
PatientRegisterId = new Guid("3a128197-3e61-23d3-1115-aed602ab82a8"),
//ReportBase64 = Shentun.Utilities.FileHelper.ToBase64("E:\\Whitedolphins\\prog20230709\\体检报告.pdf"),
ReportBase64 = Shentun.Utilities.FileHelper.ToBase64("E:\\Whitedolphins\\upload.pdf"),
};
await _appService.UploadPeisReportAsync(uploadPeisReportIuputDto);
}
}
}
Loading…
Cancel
Save