Browse Source

预约

bjmzak
DESKTOP-G961P6V\Zhh 1 year ago
parent
commit
b82bc4a6a8
  1. 2
      ThirdPlugIns/Shentun.Peis.PlugIns.Gem/test/Shentun.Peis.PlugIns.Gem.Test/ChargeRequestPlugInsGemTest.cs
  2. 15
      src/Shentun.ColumnReferencePlugIns/WebAppointPatientRegisterInput.cs
  3. 41
      src/Shentun.ColumnReferencePlugIns/WebAppointPlugInsBase.cs
  4. 213
      src/Shentun.ColumnReferencePlugIns/WebAppointWebPeisPlugIns.cs
  5. 15
      src/Shentun.Peis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterPlugInsInputDto.cs
  6. 13
      src/Shentun.Peis.Application.Contracts/WebApiOutDtoExter.cs
  7. 27
      src/Shentun.Peis.Application/ChargeRequests/ChargeRequestAppService.cs
  8. 36
      test/Shentun.Peis.ColumnReference.Tests/WebAppointWebPeisPlugInsTest.cs

2
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"));
}

15
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; }
}
}

41
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<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;
}
}
}

213
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<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();
}
}
}
}
}
}

15
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; }
}
}

13
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<T>
{
public int Code { get; set; }
public string Message { get; set; }
public T? Data { get; set; }
}
}

27
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<ChargeRequestDto> 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;
}
/// <summary>
///
/// </summary>

36
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);
}
}
}
}
Loading…
Cancel
Save