From b82bc4a6a8ce1fc9bfaebebb7e8d5c99c90f6d98 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Tue, 4 Jun 2024 18:43:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChargeRequestPlugInsGemTest.cs | 2 +- .../WebAppointPatientRegisterInput.cs | 15 ++ .../WebAppointPlugInsBase.cs | 41 ++++ .../WebAppointWebPeisPlugIns.cs | 213 ++++++++++++++++++ .../AppointPatientRegisterPlugInsInputDto.cs | 15 ++ .../WebApiOutDtoExter.cs | 13 ++ .../ChargeRequests/ChargeRequestAppService.cs | 27 +++ .../WebAppointWebPeisPlugInsTest.cs | 36 +++ 8 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs create mode 100644 src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs create mode 100644 src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs create mode 100644 src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs create mode 100644 src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs create mode 100644 test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.cs diff --git a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs index f3b6d37..ae7104a 100644 --- a/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs +++ b/ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs @@ -23,7 +23,7 @@ namespace Shentun.Peis.PlugIns.Gem.Test var input = new ChargeRequestPlugInsGem(new Guid("1c8cb151-cbc6-4ab5-b50b-0644bf2d515c")); var loginResult = input.LoginAsync().Result; - await input.SyncChargeRequestFlagFromInterfaceAsync(new Guid("3a12cf84-4516-49d6-345f-87c17ed6b252")); + await input.SyncChargeRequestFlagFromInterfaceAsync(new Guid("3a12e00d-7c60-64a8-c02d-1ba915cc601e")); } diff --git a/src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs b/src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs new file mode 100644 index 0000000..7f24c91 --- /dev/null +++ b/src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.PlugIns +{ + public class WebAppointPatientRegisterInput + { + public Guid MedicalCenterId { get; set; } + public string IdNo { get; set; } + public string MobilePhone { get; set; } + public DateTime? AppointStartDate { get; set; } + public DateTime? AppointStopDate { get; set; } + } +} diff --git a/src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs new file mode 100644 index 0000000..5615ebc --- /dev/null +++ b/src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Configuration; +using Npgsql; +using Shentun.Peis.AppointPatientRegisters; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Peis.PlugIns +{ + public class WebAppointPlugInsBase : ThirdPlugInsBase + { + public WebAppointPlugInsBase(Guid thirdInterfaceId) : base(thirdInterfaceId) + { + + } + + public virtual async Task> GetListByFilterAsync(AppointPatientRegisterPlugInsInputDto input) + { + //_thirdInterfaceRepository + return new List(); + + } + + public Guid GetMedicalCenterId() + { + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(_thirdInterfaceDto.ParmValue))); + InterfaceConfig = configurationBuilder.Build(); + + var medicalCenterIdStr = InterfaceConfig.GetSection("Interface").GetSection("MedicalCenterId").Value; + if(!Guid.TryParse(medicalCenterIdStr ,out var medicalCenterId)) + { + throw new Exception("体检中心ID格式不正确"); + } + return medicalCenterId; + } + } +} diff --git a/src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs b/src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs new file mode 100644 index 0000000..d4fd9c2 --- /dev/null +++ b/src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs @@ -0,0 +1,213 @@ +using Azure.Core; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using Shentun.Peis.AppointPatientRegisters; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Peis.PlugIns +{ + public class WebAppointWebPeisPlugIns : WebAppointPlugInsBase + { + private string _webPeisUser; + private string _webPeisPassword; + private string _webPeisBaseAddress; + private string _webPeisToken; + private string _webPeisGetListByFilterUrl; + public WebAppointWebPeisPlugIns(Guid thirdInterfaceId) : base(thirdInterfaceId) + { + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(_thirdInterfaceDto.ParmValue))); + InterfaceConfig = configurationBuilder.Build(); + + _webPeisUser = InterfaceConfig.GetSection("Interface").GetSection("User").Value; + _webPeisPassword = InterfaceConfig.GetSection("Interface").GetSection("Password").Value; + _webPeisGetListByFilterUrl = InterfaceConfig.GetSection("Interface").GetSection("GetListByFilterUrl").Value; + } + + public override async Task> GetListByFilterAsync(AppointPatientRegisterPlugInsInputDto input) + { + var medicalCenterId = GetMedicalCenterId(); + var webAppointPatientRegisterInput = new WebAppointPatientRegisterInput() + { + MedicalCenterId = medicalCenterId, + IdNo = input.IdNo, + MobilePhone = input.MobilePhone, + AppointStartDate = input.AppointStartDate, + AppointStopDate = input.AppointStopDate, + }; + var appointPatientRegisterDtos = await CallWePeisAppServiceAsync>(_webPeisGetListByFilterUrl, + webAppointPatientRegisterInput); + return appointPatientRegisterDtos; + + } + public async virtual Task LoginWebPeisAsync() + { + if (string.IsNullOrWhiteSpace(_webPeisUser)) + { + throw new Exception("WebPeisUser不能为空"); + } + if (string.IsNullOrWhiteSpace(_webPeisPassword)) + { + throw new Exception("WebPeisPassword不能为空"); + } + var relult = await LoginAsync(_webPeisUser, _webPeisPassword); + return relult; + } + + public async Task LoginWebPeisAsync(string userId, string password) + { + if (string.IsNullOrWhiteSpace(userId)) + { + throw new Exception("用户ID不能为空"); + } + if (string.IsNullOrWhiteSpace(password)) + { + throw new Exception("密码不能为空"); + } + using (var httpClientHandler = new HttpClientHandler()) + { + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(_webPeisBaseAddress); + + httpClient.DefaultRequestHeaders.Accept.Add( + new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型 + var url = "api/identity/users/login"; + var loginUser = new LoginInputDto() + { + UserName = userId, + Password = password + }; + var sendData = JsonConvert.SerializeObject(loginUser); + 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 restultDto = JsonConvert.DeserializeObject(result); + if (restultDto == null) + { + throw new Exception("返回结果是空"); + } + if (restultDto.Code != "1") + { + throw new Exception($"登录失败{restultDto.Message}"); + } + _webPeisToken = restultDto.Data.access_token; + return restultDto; + } + + } + } + } + + + public async Task CallWePeisAppServiceAsync(string url, TInput data, string method = "post") + { + if (string.IsNullOrWhiteSpace(_webPeisBaseAddress)) + { + throw new Exception("_webPeisBaseAddress不能为空"); + } + string baseAddress = _webPeisBaseAddress; + await CheckWebPeisLoginAsync(); + 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", _webPeisToken); + IsoDateTimeConverter timeFormat = new IsoDateTimeConverter(); + timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; + var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat); + using (HttpContent httpContent = new StringContent(sendData)) + { + httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + HttpResponseMessage response = null; + if (method == "post") + { + response = await httpClient.PostAsync(url, httpContent); + } + else + { + response = await httpClient.GetAsync(url); + } + + 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>(result); + if (resultDto != null) + { + if (resultDto.Code == -1) + { + throw new Exception($"调用WebApi失败,返回-1,消息:" + resultDto.Message); + } + + return resultDto.Data; + } + return resultDto.Data; + } + + } + } + } + + private async Task CheckWebPeisLoginAsync() + { + if (string.IsNullOrWhiteSpace(_webPeisToken)) + { + await LoginWebPeisAsync(); + } + else + { + var handler = new JwtSecurityTokenHandler(); + var payload = handler.ReadJwtToken(_webPeisToken).Payload; + var claims = payload.Claims; + var exp = claims.First(claim => claim.Type == "exp").Value; + if (exp == null) + { + await LoginWebPeisAsync(); + } + else + { + if (long.TryParse(exp, out var expires)) + { + var expireTime = DateTimeOffset.FromUnixTimeSeconds(expires).LocalDateTime; + if (expireTime <= DateTime.Now) + { + await LoginAsync(); + } + } + else + { + await LoginAsync(); + } + + } + + } + } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs b/src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs new file mode 100644 index 0000000..6669338 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.AppointPatientRegisters +{ + public class AppointPatientRegisterPlugInsInputDto + { + public string IdNo { get; set; } + public string MobilePhone { get; set; } + + public DateTime? AppointStartDate { get; set; } + public DateTime? AppointStopDate { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs b/src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs new file mode 100644 index 0000000..2b2ec1e --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis +{ + public class WebApiOutDtoExter + { + public int Code { get; set; } + public string Message { get; set; } + public T? Data { get; set; } + } +} diff --git a/src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs b/src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs index d63ec87..7f5568e 100644 --- a/src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs +++ b/src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs @@ -194,6 +194,33 @@ namespace Shentun.Peis.ChargeRequests return result; } + + [HttpPost("api/app/ChargeRequest/SyncChargeRequestFlagFromInterface")] + public async Task SyncChargeRequestFlagFromInterfaceAsync(ChargeRequestIdInputDto input) + { + if (input == null) + { + throw new UserFriendlyException("input参数不能为空"); + } + var chargeRequest = await _chargeRequestRepository.GetAsync(input.ChargeRequestId); + + if (chargeRequest.ChargeRequestFlag != ChargeRequestFlag.RefundRequest) + { + throw new UserFriendlyException("状态不是退费申请,不允许同步"); + } + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + await _chargeRequestManager.SendThirChargeRequestAsync(input.ChargeRequestId, "SyncChargeRequestFlagFromInterfaceAsync"); + await unitOfWork.CompleteAsync(); + } + + + + ChargeRequestDto result = new ChargeRequestDto(); + + return result; + } + /// /// /// diff --git a/test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.cs b/test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.cs new file mode 100644 index 0000000..4a66a26 --- /dev/null +++ b/test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit.Abstractions; + +namespace Shentun.Peis.PlugIns.Tests +{ + public class WebAppointWebPeisPlugInsTest + { + private readonly ITestOutputHelper _output; + public WebAppointWebPeisPlugInsTest(ITestOutputHelper testOutputHelper) + { + _output = testOutputHelper; + + } + + [Fact] + public async Task GetListByFilterAsync() + { + + var plugIns = new WebAppointWebPeisPlugIns(new Guid("43a9c3a5-8741-4c64-b869-bc304712d88e")); + var items = await plugIns.GetListByFilterAsync(new AppointPatientRegisters.AppointPatientRegisterPlugInsInputDto() + { + MobilePhone = "18911254911", + AppointStartDate = DateTime.Now.Date.AddDays(-10) + }); + foreach (var item in items) + { + _output.WriteLine(item.PersonName); + } + + } + } +}