7 changed files with 357 additions and 1 deletions
-
222Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs
-
61src/Shentun.WebPeis.Application.Contracts/QueueRegisters/GetAppQueueRegisterByPersonIdDto.cs
-
14src/Shentun.WebPeis.Application.Contracts/QueueRegisters/IdNoInputDto.cs
-
52src/Shentun.WebPeis.Application/QueueRegisters/QueueRegisterAppService.cs
-
1src/Shentun.WebPeis.Application/Shentun.WebPeis.Application.csproj
-
2src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj
-
6src/Shentun.WebPeis.HttpApi.Host/appsettings.json
@ -0,0 +1,222 @@ |
|||
using Azure.Core; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Identity.Client; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Shentun.Utilities; |
|||
using Shentun.WebPeis.PatientRegisters; |
|||
using Shentun.WebPeis.PlugIns; |
|||
using Shentun.WebPeis.QueueRegisters; |
|||
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.WebPeis.Plugins |
|||
{ |
|||
public class AppQueueRegisterPlugIns |
|||
{ |
|||
protected IConfiguration? AppConfig; |
|||
private string? _appBaseAddress; |
|||
private static string? _accesToken; |
|||
private string? _appUser; |
|||
private string? _appPassword; |
|||
private string? _appQueueRegisterUrl; |
|||
|
|||
public AppQueueRegisterPlugIns() |
|||
{ |
|||
Init(); |
|||
} |
|||
|
|||
public void Init() |
|||
{ |
|||
AppConfig = new ConfigurationBuilder() |
|||
.SetBasePath(DirectoryHelper.GetAppDirectory()) // 设置基础路径为当前目录
|
|||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
|||
.Build(); |
|||
_appBaseAddress = AppConfig.GetSection("Peis") |
|||
.GetSection("PeisBaseUrl").Value; |
|||
_appUser = AppConfig.GetSection("Peis") |
|||
.GetSection("AppUser").Value; |
|||
_appPassword = AppConfig.GetSection("Peis") |
|||
.GetSection("AppPassWord").Value; |
|||
_appQueueRegisterUrl = AppConfig.GetSection("Peis") |
|||
.GetSection("AppQueueRegisterUrl").Value; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 小程序获取当前排队信息
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
public async Task<GetAppQueueRegisterByPersonIdDto> GetAppQueueRegisterByIdNoAsync(IdNoInputDto input) |
|||
{ |
|||
var appQueueRegisterByPersonIdDtos = await CallAppServiceAsync<IdNoInputDto, GetAppQueueRegisterByPersonIdDto>(_appQueueRegisterUrl, |
|||
input); |
|||
|
|||
return appQueueRegisterByPersonIdDtos; |
|||
} |
|||
|
|||
|
|||
public async Task<TOut> CallAppServiceAsync<TInput, TOut>(string url, TInput data, string method = "post") |
|||
{ |
|||
string baseAddress = _appBaseAddress; |
|||
await CheckLoginAsync(); |
|||
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); |
|||
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter(); |
|||
timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; |
|||
var sendData = JsonConvert.SerializeObject(data, 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<WebApiOutDto<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 CheckLoginAsync() |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(_accesToken)) |
|||
{ |
|||
await LoginAsync(); |
|||
} |
|||
else |
|||
{ |
|||
var handler = new JwtSecurityTokenHandler(); |
|||
var payload = handler.ReadJwtToken(_accesToken).Payload; |
|||
var claims = payload.Claims; |
|||
var exp = claims.First(claim => claim.Type == "exp").Value; |
|||
if (exp == null) |
|||
{ |
|||
await LoginAsync(); |
|||
} |
|||
else |
|||
{ |
|||
if (long.TryParse(exp, out var expires)) |
|||
{ |
|||
var expireTime = DateTimeOffset.FromUnixTimeSeconds(expires).LocalDateTime; |
|||
if (expireTime <= DateTime.Now) |
|||
{ |
|||
await LoginAsync(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
await LoginAsync(); |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public async Task<WebApiOutDto<LoginOutDataDto>> LoginAsync() |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(_appUser)) |
|||
{ |
|||
throw new Exception("SelfUser不能为空"); |
|||
} |
|||
if (string.IsNullOrWhiteSpace(_appPassword)) |
|||
{ |
|||
throw new Exception("SelfPassword不能为空"); |
|||
} |
|||
var relult = await LoginAsync(_appUser, _appPassword); |
|||
return relult; |
|||
} |
|||
|
|||
public async Task<WebApiOutDto<LoginOutDataDto>> LoginAsync(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(_appBaseAddress); |
|||
|
|||
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<WebApiOutDto<LoginOutDataDto>>(result); |
|||
if (restultDto == null) |
|||
{ |
|||
throw new Exception("返回结果是空"); |
|||
} |
|||
if (restultDto.Code != 1) |
|||
{ |
|||
throw new Exception($"登录失败{restultDto.Message}"); |
|||
} |
|||
_accesToken = restultDto.Data.access_token; |
|||
return restultDto; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.WebPeis.QueueRegisters |
|||
{ |
|||
public class GetAppQueueRegisterByPersonIdDto |
|||
{ |
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 人员条码号
|
|||
/// </summary>
|
|||
public string PatientRegisterNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 性别
|
|||
/// </summary>
|
|||
public string SexName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 婚姻状况
|
|||
/// </summary>
|
|||
public string MaritalStatusName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 照片
|
|||
/// </summary>
|
|||
public string Photo { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 排队房间名称
|
|||
/// </summary>
|
|||
public string RoomName { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 候诊人数
|
|||
/// </summary>
|
|||
public int QueueCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 完成标志 (o=候诊 1=已呼 2=过号)
|
|||
/// </summary>
|
|||
public char CompleteFlag { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.WebPeis.QueueRegisters |
|||
{ |
|||
public class IdNoInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Shentun.WebPeis.Models; |
|||
using Shentun.WebPeis.PatientRegisters; |
|||
using Shentun.WebPeis.Persons; |
|||
using Shentun.WebPeis.Plugins; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Shentun.WebPeis.QueueRegisters |
|||
{ |
|||
/// <summary>
|
|||
/// 获取排队信息
|
|||
/// </summary>
|
|||
[ApiExplorerSettings(GroupName = "Work")] |
|||
[Authorize] |
|||
public class QueueRegisterAppService : ApplicationService |
|||
{ |
|||
private readonly IRepository<Person> _personRepository; |
|||
public QueueRegisterAppService( |
|||
IRepository<Person> personRepository |
|||
) |
|||
{ |
|||
_personRepository = personRepository; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 小程序获取当前排队信息
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/QueueRegister/GetAppQueueRegisterByPersonId")] |
|||
public async Task<GetAppQueueRegisterByPersonIdDto> GetAppQueueRegisterByPersonIdAsync(PersonIdInputDto input) |
|||
{ |
|||
var msg = new GetAppQueueRegisterByPersonIdDto(); |
|||
|
|||
//获取身份证号码
|
|||
var personEnt = await _personRepository.FirstOrDefaultAsync(f => f.PersonId == input.PersonId); |
|||
if (personEnt == null) |
|||
throw new UserFriendlyException("人员不存在"); |
|||
var appQueueRegisterPlugIns = new AppQueueRegisterPlugIns(); |
|||
msg = await appQueueRegisterPlugIns.GetAppQueueRegisterByIdNoAsync(new IdNoInputDto { IdNo = personEnt.IdNo }); |
|||
return msg; |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue