|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Http.Internal; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Net.Http.Headers; |
|
|
|
@ -9,12 +10,15 @@ using NPOI.SS.Formula.Functions; |
|
|
|
using Shentun.Peis.Enums; |
|
|
|
using Shentun.Peis.Models; |
|
|
|
using Shentun.Peis.PatientRegisters; |
|
|
|
using Spire.Pdf.Exporting.XPS.Schema; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using System.Net.Mime; |
|
|
|
using System.Security.Policy; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Channels; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
@ -236,199 +240,126 @@ namespace Shentun.Peis.ThirdBookingPushs |
|
|
|
[HttpPost("api/app/ThirdBookingPush/PushReportFile")] |
|
|
|
public async Task PushReportFileAsync(PushReportFileInputDto input) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var baseApiAddress = "https://uat-ewp.beijinglife.com.cn"; |
|
|
|
var fileUploadApiAddress = "service/file/fup"; |
|
|
|
//var reportApiAddress = interfaceConfig.GetSection("Interface").GetSection("ReportApiAddress").Value;
|
|
|
|
//var publicKey = interfaceConfig.GetSection("Interface").GetSection("YuanFuPublicKey").Value;
|
|
|
|
//var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value;
|
|
|
|
var aesKey = "MZ20240417UP"; |
|
|
|
//var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
|
|
|
|
//var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value;
|
|
|
|
var iCode = "EXAMINATION_MZ"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 上传文件
|
|
|
|
byte[] filebytes = Convert.FromBase64String(input.ReportBase64); //字节数组
|
|
|
|
byte[] fileDataEncrypt = AesHelper.AESEncrypt(filebytes, aesKey); |
|
|
|
string fileSign = AesHelper.GetMD5Hash2(fileDataEncrypt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileInputParm = new EncryDataRequstDto |
|
|
|
var thirdBookingInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(o => o.ThirdInterfaceType == |
|
|
|
ThirdInterfaceTypeFlag.ThirdBooking); |
|
|
|
if (thirdBookingInterface != null && thirdBookingInterface.IsActive == 'Y') |
|
|
|
{ |
|
|
|
SIGN = fileSign, |
|
|
|
ICODE = iCode |
|
|
|
}; |
|
|
|
|
|
|
|
var fileResultEncry = await CallBookingFileAppServiceAsync<EncryDataResultDto>(baseApiAddress, fileUploadApiAddress, fileInputParm, fileDataEncrypt, "123.txt"); |
|
|
|
|
|
|
|
if (fileResultEncry.FLAG) |
|
|
|
{ |
|
|
|
//验签
|
|
|
|
if (fileResultEncry.SIGN == AesHelper.GetMD5Hash(fileResultEncry.DATA)) |
|
|
|
var parmValue = thirdBookingInterface.ParmValue; |
|
|
|
var configurationBuilder = new ConfigurationBuilder() |
|
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); |
|
|
|
var interfaceConfig = configurationBuilder.Build(); |
|
|
|
var baseApiAddress = interfaceConfig.GetSection("Interface").GetSection("BaseApiAddress").Value; |
|
|
|
var fileUploadApiAddress = interfaceConfig.GetSection("Interface").GetSection("FileUploadApiAddress").Value; |
|
|
|
var reportApiAddress = interfaceConfig.GetSection("Interface").GetSection("ReportApiAddress").Value; |
|
|
|
var publicKey = interfaceConfig.GetSection("Interface").GetSection("YuanFuPublicKey").Value; |
|
|
|
var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value; |
|
|
|
var aesKey = interfaceConfig.GetSection("Interface").GetSection("AesKey").Value; |
|
|
|
var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value; |
|
|
|
var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value; |
|
|
|
var iCode = interfaceConfig.GetSection("Interface").GetSection("ICODE").Value; |
|
|
|
if (!string.IsNullOrWhiteSpace(isActive) |
|
|
|
&& isActive == "Y") |
|
|
|
{ |
|
|
|
//解密
|
|
|
|
string fileResultStr = AesHelper.AESDecrypt(fileResultEncry.DATA, aesKey); //报文ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 推送体检报告
|
|
|
|
///// </summary>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[HttpPost("api/app/ThirdBookingPush/PushReportFile")]
|
|
|
|
//public async Task PushReportFileAsync(PushReportFileInputDto input)
|
|
|
|
//{
|
|
|
|
// var thirdBookingInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(o => o.ThirdInterfaceType ==
|
|
|
|
// ThirdInterfaceTypeFlag.ThirdBooking);
|
|
|
|
// if (thirdBookingInterface != null && thirdBookingInterface.IsActive == 'Y')
|
|
|
|
// {
|
|
|
|
|
|
|
|
// var parmValue = thirdBookingInterface.ParmValue;
|
|
|
|
// var configurationBuilder = new ConfigurationBuilder()
|
|
|
|
// .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
|
|
// var interfaceConfig = configurationBuilder.Build();
|
|
|
|
// var baseApiAddress = interfaceConfig.GetSection("Interface").GetSection("BaseApiAddress").Value;
|
|
|
|
// var fileUploadApiAddress = interfaceConfig.GetSection("Interface").GetSection("FileUploadApiAddress").Value;
|
|
|
|
// var reportApiAddress = interfaceConfig.GetSection("Interface").GetSection("ReportApiAddress").Value;
|
|
|
|
// var publicKey = interfaceConfig.GetSection("Interface").GetSection("YuanFuPublicKey").Value;
|
|
|
|
// var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value;
|
|
|
|
// var aesKey = interfaceConfig.GetSection("Interface").GetSection("AesKey").Value;
|
|
|
|
// var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
|
|
|
|
// var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value;
|
|
|
|
// var iCode = interfaceConfig.GetSection("Interface").GetSection("ICODE").Value;
|
|
|
|
// if (!string.IsNullOrWhiteSpace(isActive)
|
|
|
|
// && isActive == "Y")
|
|
|
|
// {
|
|
|
|
|
|
|
|
// var patientRegisterEnt = await _patientRegisterRepository.GetAsync(input.PatientRegisterId);
|
|
|
|
var patientRegisterEnt = await _patientRegisterRepository.GetAsync(input.PatientRegisterId); |
|
|
|
|
|
|
|
// if (patientRegisterEnt != null
|
|
|
|
// && !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId)
|
|
|
|
// && patientRegisterEnt.CompleteFlag == PatientRegisterCompleteFlag.SumCheck)
|
|
|
|
// {
|
|
|
|
// var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId));
|
|
|
|
// if (thirdBookingEnt != null)
|
|
|
|
// {
|
|
|
|
// if (!string.IsNullOrWhiteSpace(thirdBookingEnt.ICode))
|
|
|
|
// {
|
|
|
|
// iCode = thirdBookingEnt.ICode;
|
|
|
|
// }
|
|
|
|
// if (thirdBookingEnt.MedicalStatus == '2')
|
|
|
|
// {
|
|
|
|
// var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId));
|
|
|
|
if (patientRegisterEnt != null |
|
|
|
&& !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId) |
|
|
|
&& patientRegisterEnt.CompleteFlag == PatientRegisterCompleteFlag.SumCheck) |
|
|
|
{ |
|
|
|
var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId)); |
|
|
|
if (thirdBookingEnt != null) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrWhiteSpace(thirdBookingEnt.ICode)) |
|
|
|
{ |
|
|
|
iCode = thirdBookingEnt.ICode; |
|
|
|
} |
|
|
|
if (thirdBookingEnt.MedicalStatus == '2') |
|
|
|
{ |
|
|
|
var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId)); |
|
|
|
|
|
|
|
|
|
|
|
// #region 上传文件
|
|
|
|
// byte[] filebytes = Convert.FromBase64String(input.ReportBase64); //字节数组
|
|
|
|
// byte[] fileDataEncrypt = AesHelper.AESEncrypt(filebytes, aesKey);
|
|
|
|
// string fileSign = AesHelper.GetMD5Hash2(fileDataEncrypt);
|
|
|
|
#region 上传文件
|
|
|
|
byte[] filebytes = Convert.FromBase64String(input.ReportBase64); //字节数组
|
|
|
|
byte[] fileDataEncrypt = AesHelper.AESEncrypt(filebytes, aesKey); |
|
|
|
string fileSign = AesHelper.GetMD5Hash(fileDataEncrypt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var fileInputParm = new EncryDataRequstDto
|
|
|
|
// {
|
|
|
|
// SIGN = fileSign,
|
|
|
|
// ICODE = thirdBookingEnt.ICode
|
|
|
|
// };
|
|
|
|
var fileInputParm = new EncryDataRequstDto |
|
|
|
{ |
|
|
|
SIGN = fileSign, |
|
|
|
ICODE = thirdBookingEnt.ICode |
|
|
|
}; |
|
|
|
|
|
|
|
// var fileResultEncry = await CallBookingFileAppServiceAsync<EncryDataResultDto>(baseApiAddress, fileUploadApiAddress, fileInputParm, fileDataEncrypt, "006429_民众测试.pdf");
|
|
|
|
var fileResultEncry = await CallBookingFileAppServiceAsync<EncryDataResultDto>(baseApiAddress, fileUploadApiAddress, fileInputParm, fileDataEncrypt, $"{input.PatientRegisterId.ToString()}.pdf"); |
|
|
|
|
|
|
|
// if (fileResultEncry.FLAG)
|
|
|
|
// {
|
|
|
|
// //验签
|
|
|
|
// if (fileResultEncry.SIGN == AesHelper.GetMD5Hash(fileResultEncry.DATA))
|
|
|
|
// {
|
|
|
|
// //解密
|
|
|
|
// string fileResultStr = AesHelper.AESDecrypt(fileResultEncry.DATA, aesKey); //报文ID
|
|
|
|
if (fileResultEncry.FLAG) |
|
|
|
{ |
|
|
|
//验签
|
|
|
|
if (fileResultEncry.SIGN == AesHelper.GetMD5(fileResultEncry.DATA)) |
|
|
|
{ |
|
|
|
//解密
|
|
|
|
string fileId = Encoding.UTF8.GetString(AesHelper.AESDecrypt(fileResultEncry.DATA, aesKey)); //报文ID
|
|
|
|
|
|
|
|
|
|
|
|
// #region 上传报告
|
|
|
|
#region 上传报告
|
|
|
|
|
|
|
|
// var pushMedicalReportInput = new PushMedicalReportInputDto
|
|
|
|
// {
|
|
|
|
// EXAMPACKAGECODE = thirdBookingEnt.CustomerOrgGroupId,
|
|
|
|
// IDNO = thirdBookingEnt.IdNo,
|
|
|
|
// IDTYPE = thirdBookingEnt.IdType,
|
|
|
|
// NAME = patientRegisterEnt.PatientName,
|
|
|
|
// SOURCE = "BjGJ",
|
|
|
|
// YEAR = medicalYear,
|
|
|
|
// BUSINESSID = patientRegisterEnt.Id.ToString(),
|
|
|
|
// JSONBASE64 = "",
|
|
|
|
// ORGCODE = "MINZ",
|
|
|
|
// PDFBASE64 = "",
|
|
|
|
// PDFFILEID = fileResultStr,
|
|
|
|
// PUSHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
|
// };
|
|
|
|
var pushMedicalReportInput = new PushMedicalReportInputDto |
|
|
|
{ |
|
|
|
EXAMPACKAGECODE = thirdBookingEnt.CustomerOrgGroupId, |
|
|
|
IDNO = thirdBookingEnt.IdNo, |
|
|
|
IDTYPE = thirdBookingEnt.IdType, |
|
|
|
NAME = patientRegisterEnt.PatientName, |
|
|
|
SOURCE = "BJGJ", |
|
|
|
YEAR = medicalYear, |
|
|
|
BUSINESSID = patientRegisterEnt.Id.ToString(), |
|
|
|
JSONBASE64 = "", |
|
|
|
ORGCODE = "MINZ", |
|
|
|
PDFBASE64 = "", |
|
|
|
PDFFILEID = fileId, |
|
|
|
PUSHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// var pushMedicalReportInputEncrypt = GetEncryptData(JsonConvert.SerializeObject(pushMedicalReportInput), iCode, publicKey, privateKey);
|
|
|
|
var pushMedicalReportInputEncrypt = GetEncryptData(JsonConvert.SerializeObject(pushMedicalReportInput), iCode, publicKey, privateKey); |
|
|
|
|
|
|
|
// var reportResultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, reportApiAddress, pushMedicalReportInputEncrypt, "application/json;charset=utf-8");
|
|
|
|
var reportResultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, reportApiAddress, pushMedicalReportInputEncrypt, "application/json"); |
|
|
|
|
|
|
|
// if (reportResultPara.FLAG)
|
|
|
|
// {
|
|
|
|
// var decryptDataPara = GetDecryptData<PushReportDecryptDto>(reportResultPara, publicKey, privateKey);
|
|
|
|
// if (decryptDataPara.FLAG == true)
|
|
|
|
// {
|
|
|
|
// thirdBookingEnt.MedicalStatus = '3';
|
|
|
|
// await _thirdBookingRepository.UpdateAsync(thirdBookingEnt);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (reportResultPara.FLAG) |
|
|
|
{ |
|
|
|
var decryptDataPara = GetDecryptData<PushReportDecryptDto>(reportResultPara, publicKey, privateKey); |
|
|
|
if (decryptDataPara.FLAG == true) |
|
|
|
{ |
|
|
|
thirdBookingEnt.MedicalStatus = '3'; |
|
|
|
await _thirdBookingRepository.UpdateAsync(thirdBookingEnt); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// #endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
// #endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -503,73 +434,48 @@ namespace Shentun.Peis.ThirdBookingPushs |
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<TOut> CallBookingFileAppServiceAsync<TOut>(string baseApiAddress, string url, EncryDataRequstDto data, byte[] fileBytes, string fileName) |
|
|
|
{ |
|
|
|
using (var httpClientHandler = new HttpClientHandler()) |
|
|
|
{ |
|
|
|
using (var httpClient = new HttpClient(httpClientHandler)) |
|
|
|
{ |
|
|
|
|
|
|
|
var multipartContent = new MultipartFormDataContent(); |
|
|
|
multipartContent.Add(new StringContent(data.ICODE), "ICODE"); |
|
|
|
multipartContent.Add(new StringContent(data.SIGN), "SIGN"); |
|
|
|
|
|
|
|
httpClient.Timeout = TimeSpan.FromMilliseconds(600000); |
|
|
|
|
|
|
|
httpClient.BaseAddress = new Uri(baseApiAddress); |
|
|
|
ByteArrayContent fileContent = new ByteArrayContent(fileBytes); |
|
|
|
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/octet-stream"); |
|
|
|
fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data"); |
|
|
|
fileContent.Headers.ContentDisposition.Name = "DATA"; |
|
|
|
fileContent.Headers.ContentDisposition.FileName = fileName; |
|
|
|
multipartContent.Add(fileContent); |
|
|
|
|
|
|
|
httpClient.DefaultRequestHeaders.Accept.Add( |
|
|
|
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
|
|
|
|
|
|
|
|
|
|
|
|
var httpClient = new HttpClient(); |
|
|
|
httpClient.Timeout = TimeSpan.FromMinutes(5); |
|
|
|
httpClient.BaseAddress = new Uri(baseApiAddress); |
|
|
|
httpClient.DefaultRequestHeaders.Accept.Add( |
|
|
|
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
|
|
|
|
|
|
|
|
using (MultipartFormDataContent multipartContent = new MultipartFormDataContent()) |
|
|
|
{ |
|
|
|
// 添加文本字段
|
|
|
|
//var icode = new StringContent(data.ICODE);
|
|
|
|
//icode.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
|
|
|
|
//{
|
|
|
|
// Name = "ICODE"
|
|
|
|
//};
|
|
|
|
//var sign = new StringContent(data.SIGN);
|
|
|
|
//icode.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
|
|
|
|
//{
|
|
|
|
// Name = "SIGN"
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
multipartContent.Add(new StringContent(data.ICODE), "ICODE"); |
|
|
|
multipartContent.Add(new StringContent(data.SIGN), "SIGN"); |
|
|
|
// 添加文件
|
|
|
|
ByteArrayContent fileContent = new ByteArrayContent(fileBytes); |
|
|
|
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); |
|
|
|
multipartContent.Add(fileContent, "DATA", fileName); |
|
|
|
|
|
|
|
multipartContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data"); |
|
|
|
|
|
|
|
// multipartContent.Add(fileBytes, "DATA", fileName);
|
|
|
|
HttpResponseMessage response = null; |
|
|
|
|
|
|
|
HttpResponseMessage response = null; |
|
|
|
response = await httpClient.PostAsync(url, multipartContent); |
|
|
|
|
|
|
|
response = await httpClient.PostAsync(url, multipartContent); |
|
|
|
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); |
|
|
|
|
|
|
|
return resultDto; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
return resultDto; |
|
|
|
} |
|
|
|
|
|
|
|
//// 创建MultipartFormDataContent实例
|
|
|
|
//MultipartFormDataContent multipartContent = new MultipartFormDataContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|