8 changed files with 361 additions and 1 deletions
			
			
		- 
					2ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs
 - 
					15src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs
 - 
					41src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs
 - 
					213src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs
 - 
					15src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs
 - 
					13src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs
 - 
					27src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs
 - 
					36test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.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; } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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<List<AppointPatientRegisterDto>> GetListByFilterAsync(AppointPatientRegisterPlugInsInputDto input) | 
				
			|||
        { | 
				
			|||
            //_thirdInterfaceRepository
 | 
				
			|||
            return new List<AppointPatientRegisterDto>(); | 
				
			|||
 | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        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; | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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<List<AppointPatientRegisterDto>> 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<WebAppointPatientRegisterInput, List<AppointPatientRegisterDto>>(_webPeisGetListByFilterUrl, | 
				
			|||
                webAppointPatientRegisterInput); | 
				
			|||
            return appointPatientRegisterDtos; | 
				
			|||
 | 
				
			|||
        } | 
				
			|||
        public async virtual Task<LoginOutDto> 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<LoginOutDto> 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<LoginOutDto>(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<TOut> CallWePeisAppServiceAsync<TInput, TOut>(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<WebApiOutDtoExter<TOut>>(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(); | 
				
			|||
                    } | 
				
			|||
 | 
				
			|||
                } | 
				
			|||
 | 
				
			|||
            } | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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; } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,13 @@ | 
				
			|||
using System; | 
				
			|||
using System.Collections.Generic; | 
				
			|||
using System.Text; | 
				
			|||
 | 
				
			|||
namespace Shentun.Peis | 
				
			|||
{ | 
				
			|||
    public class WebApiOutDtoExter<T> | 
				
			|||
    { | 
				
			|||
        public int Code { get; set; } | 
				
			|||
        public string Message { get; set; } | 
				
			|||
        public T? Data { get; set; } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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); | 
				
			|||
            } | 
				
			|||
 | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue