14 changed files with 583 additions and 51 deletions
-
1Shentun.PeisReport.Api/Controllers/PeisController.cs
-
255Shentun.PeisReport.Api/Controllers/ReportBusinessController.cs
-
3Shentun.PeisReport.Api/Controllers/ReportController.cs
-
33Shentun.PeisReport.Api/Controllers/WeatherForecastController.cs
-
41Shentun.PeisReport.Api/Dto/ReportBusiness/GetLisReportByIdNoDto.cs
-
15Shentun.PeisReport.Api/Dto/ReportBusiness/GetLisReportByIdNoInputDto.cs
-
46Shentun.PeisReport.Api/Dto/ReportBusiness/GetPeisReportByIdNoDto.cs
-
15Shentun.PeisReport.Api/Dto/ReportBusiness/GetPeisReportByIdNoInputDto.cs
-
47Shentun.PeisReport.Api/Jwt/JwtConfig.cs
-
85Shentun.PeisReport.Api/Jwt/JwtHelper.cs
-
61Shentun.PeisReport.Api/Program.cs
-
1Shentun.PeisReport.Api/Shentun.PeisReport.Api.csproj
-
13Shentun.PeisReport.Api/WeatherForecast.cs
-
18Shentun.PeisReport.Api/appsettings.json
@ -0,0 +1,255 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Shentun.PeisReport.Api.Dto; |
|||
using Shentun.PeisReport.Api.Dto.ReportBusiness; |
|||
using Shentun.PeisReport.Api.Jwt; |
|||
using SqlSugar; |
|||
using System.Data; |
|||
using System.Security.Claims; |
|||
|
|||
namespace Shentun.PeisReport.Api.Controllers |
|||
{ |
|||
/// <summary>
|
|||
/// 监利医院
|
|||
/// </summary>
|
|||
[Route("api/[controller]/[action]")]
|
|||
[ApiController] |
|||
[ApiExplorerSettings(GroupName ="JianLiApi")] |
|||
//[Authorize]
|
|||
public class ReportBusinessController : ControllerBase |
|||
{ |
|||
|
|||
private readonly SqlSugarClient _peisDb; |
|||
private readonly SqlSugarClient _lisDb; |
|||
private readonly IConfiguration _configuration; |
|||
private readonly ILogger<ReportBusinessController> _logger; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public ReportBusinessController( |
|||
ILogger<ReportBusinessController> logger, |
|||
IConfiguration configuration |
|||
) |
|||
{ |
|||
_logger = logger; |
|||
_configuration = configuration; |
|||
_peisDb = new SqlSugarClient(new ConnectionConfig() |
|||
{ |
|||
ConnectionString = _configuration.GetSection("ConnectionStrings:Default").Value, |
|||
DbType = SqlSugar.DbType.SqlServer, |
|||
IsAutoCloseConnection = true |
|||
}); |
|||
_lisDb = new SqlSugarClient(new ConnectionConfig() |
|||
{ |
|||
ConnectionString = _configuration.GetSection("ConnectionStrings:Lis").Value, |
|||
DbType = SqlSugar.DbType.SqlServer, |
|||
IsAutoCloseConnection = true |
|||
}); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据身份证号码获取体检报告
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
public async Task<GetPeisReportByIdNoDto> GetPeisReportByIdNoAsync(GetPeisReportByIdNoInputDto input) |
|||
{ |
|||
|
|||
var result = new GetPeisReportByIdNoDto |
|||
{ |
|||
Code = 100, |
|||
Message = "请求失败" |
|||
}; |
|||
|
|||
|
|||
if (string.IsNullOrWhiteSpace(input.IdNo)) |
|||
{ |
|||
result.Message = "身份证不能为空"; |
|||
|
|||
return result; |
|||
} |
|||
|
|||
try |
|||
{ |
|||
|
|||
var query = await _peisDb.Ado.GetDataTableAsync($"select top {input.ReportCount} patient_register_id,barcode_no,medical_times,id_card_no," + |
|||
$"medical_start_date,mobile_telephone,name as patient_name" + |
|||
$" from patient_register " + |
|||
$" where id_card_no='{input.IdNo}' and create_pdf_flag='1' order by patient_register_id desc "); |
|||
if (query.Rows.Count > 0) |
|||
{ |
|||
List<GetPeisReportByIdNoResultDataDto> patientRegisterList = new List<GetPeisReportByIdNoResultDataDto>(); |
|||
|
|||
foreach (DataRow row in query.Rows) |
|||
{ |
|||
var patientRegister = new GetPeisReportByIdNoResultDataDto |
|||
{ |
|||
BarcodeNo = row["barcode_no"].ToString(), |
|||
MedicalDate = Convert.ToDateTime(row["medical_start_date"].ToString()).ToString("yyyy-MM-dd"), |
|||
MedicalTimes = row["medical_times"].ToString(), |
|||
MobileTelephone = row["mobile_telephone"].ToString(), |
|||
PatientName = row["patient_name"].ToString(), |
|||
IdNo = row["id_card_no"].ToString() |
|||
}; |
|||
|
|||
|
|||
var patientRegisterId = row["patient_register_id"].ToString(); |
|||
string directoryDate = patientRegisterId.Substring(0, 6); |
|||
string hostAddress = _configuration.GetSection("HostAddress").Value; |
|||
string reportVirtual = _configuration.GetSection("ReportVirtualPath:RequestPath").Value; |
|||
string reportUrl = $"{hostAddress + reportVirtual}/{directoryDate}/{patientRegisterId}({patientRegister.PatientName}).pdf"; |
|||
|
|||
patientRegister.ReportUrl = reportUrl; |
|||
|
|||
patientRegisterList.Add(patientRegister); |
|||
} |
|||
|
|||
result.Message = "请求成功"; |
|||
result.Data = patientRegisterList; |
|||
result.Code = 200; |
|||
|
|||
} |
|||
else |
|||
{ |
|||
result.Code = 100; |
|||
result.Message = "身份证号未查到体检数据"; |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
result.Message = ex.Message; |
|||
_logger.LogError($"访问GetPeisReportByIdNoAsync异常,异常信息:{ex.Message}"); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 根据身份证号码获取检验报告
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
public async Task<GetLisReportByIdNoDto> GetLisReportByIdNoAsync(GetLisReportByIdNoInputDto input) |
|||
{ |
|||
|
|||
var result = new GetLisReportByIdNoDto |
|||
{ |
|||
Code = 100, |
|||
Message = "请求失败" |
|||
}; |
|||
|
|||
|
|||
if (string.IsNullOrWhiteSpace(input.IdNo)) |
|||
{ |
|||
result.Message = "身份证不能为空"; |
|||
|
|||
return result; |
|||
} |
|||
|
|||
try |
|||
{ |
|||
|
|||
var query = await _lisDb.Ado.GetDataTableAsync($" select patient_register_id,patient_name,inspection_purpose,telephone,send_datetime from patient_register" + |
|||
$" where upload_web_flag='Y' and inspection_datetime>= DATEADD(DAY,-{input.ReportDay},GETDATE()) " + |
|||
$" and recieve_source_primarykey in " + |
|||
$" (select recieve_source_primarykey from patient_request where id_card_no='{input.IdNo}' ) order by patient_register_id desc "); |
|||
if (query.Rows.Count > 0) |
|||
{ |
|||
List<GetLisReportByIdNoResultDataDto> patientRegisterList = new List<GetLisReportByIdNoResultDataDto>(); |
|||
|
|||
foreach (DataRow row in query.Rows) |
|||
{ |
|||
var patientRegister = new GetLisReportByIdNoResultDataDto |
|||
{ |
|||
InspectionPurpose = row["inspection_purpose"].ToString(), |
|||
SendDateTime = Convert.ToDateTime(row["send_datetime"].ToString()).ToString("yyyy-MM-dd"), |
|||
MobileTelephone = row["telephone"].ToString(), |
|||
PatientName = row["patient_name"].ToString(), |
|||
IdNo = input.IdNo |
|||
}; |
|||
|
|||
var patientRegisterId = row["patient_register_id"].ToString(); |
|||
string hostAddress = _configuration.GetSection("HostAddress").Value; |
|||
string reportVirtual = _configuration.GetSection("LisReportVirtualPath:RequestPath").Value; |
|||
string reportUrl = $"{hostAddress + reportVirtual}/{patientRegisterId}.pdf"; |
|||
|
|||
patientRegister.ReportUrl = reportUrl; |
|||
|
|||
patientRegisterList.Add(patientRegister); |
|||
} |
|||
|
|||
result.Message = "请求成功"; |
|||
result.Data = patientRegisterList; |
|||
result.Code = 200; |
|||
|
|||
} |
|||
else |
|||
{ |
|||
result.Code = 100; |
|||
result.Message = "身份证号未查到检验报告数据"; |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
result.Message = ex.Message; |
|||
_logger.LogError($"访问GetLisReportByIdNoAsync异常,异常信息:{ex.Message}"); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
#region 身份验证
|
|||
|
|||
///// <summary>
|
|||
///// 登陆
|
|||
///// </summary>
|
|||
///// <returns></returns>
|
|||
//[HttpPost]
|
|||
//[AllowAnonymous]
|
|||
//public ActionResult<string> Logon()
|
|||
//{
|
|||
// var userId = "001";
|
|||
// var userName = "wenxiande";
|
|||
// var roleName = "Bus";
|
|||
|
|||
// var claims = new List<Claim>()
|
|||
// {
|
|||
// new Claim("UserId",userId),
|
|||
// new Claim(ClaimTypes.Sid,userId),
|
|||
// new Claim("UserName",userName),
|
|||
// new Claim(ClaimTypes.Name,userName)
|
|||
// };
|
|||
|
|||
// claims.Add(new Claim(ClaimTypes.Role, roleName));
|
|||
|
|||
// JwtHelper jwtHelper = new JwtHelper();
|
|||
// return jwtHelper.GetJwt(claims);
|
|||
|
|||
//}
|
|||
|
|||
///// <summary>
|
|||
///// 查询测试
|
|||
///// </summary>
|
|||
///// <returns></returns>
|
|||
//[HttpPost]
|
|||
//[Authorize(Roles = "Bus")]
|
|||
//public PublicResultDto TestSqlAsync()
|
|||
//{
|
|||
|
|||
// var result = new PublicResultDto
|
|||
// {
|
|||
// Code = 200,
|
|||
// Message = "请求成功"
|
|||
// };
|
|||
|
|||
// return result;
|
|||
//}
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace Shentun.PeisReport.Api.Controllers |
|||
{ |
|||
[ApiController] |
|||
[Route("[controller]")]
|
|||
public class WeatherForecastController : ControllerBase |
|||
{ |
|||
private static readonly string[] Summaries = new[] |
|||
{ |
|||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" |
|||
}; |
|||
|
|||
private readonly ILogger<WeatherForecastController> _logger; |
|||
|
|||
public WeatherForecastController(ILogger<WeatherForecastController> logger) |
|||
{ |
|||
_logger = logger; |
|||
} |
|||
|
|||
[HttpGet(Name = "GetWeatherForecast")] |
|||
public IEnumerable<WeatherForecast> Get() |
|||
{ |
|||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast |
|||
{ |
|||
Date = DateTime.Now.AddDays(index), |
|||
TemperatureC = Random.Shared.Next(-20, 55), |
|||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] |
|||
}) |
|||
.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
namespace Shentun.PeisReport.Api.Dto.ReportBusiness |
|||
{ |
|||
public class GetLisReportByIdNoDto : PublicResultDto |
|||
{ |
|||
public List<GetLisReportByIdNoResultDataDto> Data { get; set; } = new List<GetLisReportByIdNoResultDataDto>(); |
|||
} |
|||
|
|||
public class GetLisReportByIdNoResultDataDto |
|||
{ |
|||
/// <summary>
|
|||
/// 检验目的
|
|||
/// </summary>
|
|||
public string InspectionPurpose { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 报告发布时间
|
|||
/// </summary>
|
|||
public string SendDateTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 报告地址
|
|||
/// </summary>
|
|||
public string ReportUrl { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace Shentun.PeisReport.Api.Dto.ReportBusiness |
|||
{ |
|||
public class GetLisReportByIdNoInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 查询报告的时间 单位为天 默认30天
|
|||
/// </summary>
|
|||
public int ReportDay { get; set; } = 30; |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
namespace Shentun.PeisReport.Api.Dto.ReportBusiness |
|||
{ |
|||
public class GetPeisReportByIdNoDto: PublicResultDto |
|||
{ |
|||
public List<GetPeisReportByIdNoResultDataDto> Data { get; set; } = new List<GetPeisReportByIdNoResultDataDto>(); |
|||
} |
|||
|
|||
public class GetPeisReportByIdNoResultDataDto |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// 条码号
|
|||
/// </summary>
|
|||
public string BarcodeNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 体检次数
|
|||
/// </summary>
|
|||
public string MedicalTimes { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 体检日期 格式(2024-02-20)
|
|||
/// </summary>
|
|||
public string MedicalDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 报告地址
|
|||
/// </summary>
|
|||
public string ReportUrl { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace Shentun.PeisReport.Api.Dto.ReportBusiness |
|||
{ |
|||
public class GetPeisReportByIdNoInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 查询报告的数量 默认2次
|
|||
/// </summary>
|
|||
public int ReportCount { get; set; } = 2; |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
namespace Shentun.PeisReport.Api.Jwt |
|||
{ |
|||
/// <summary>
|
|||
/// Jwt配置
|
|||
/// </summary>
|
|||
public class JwtConfig |
|||
{ |
|||
private readonly IConfigurationSection _configSection; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public JwtConfig() |
|||
{ |
|||
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json"); |
|||
var configuration = builder.Build(); |
|||
_configSection = configuration.GetSection("Jwt"); |
|||
} |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="configuration"></param>
|
|||
public JwtConfig(IConfiguration configuration) |
|||
{ |
|||
|
|||
_configSection = configuration.GetSection("Jwt"); |
|||
} |
|||
/// <summary>
|
|||
/// 颁发者
|
|||
/// </summary>
|
|||
public string Issuer => _configSection.GetValue("Issuer", "Shentun"); |
|||
/// <summary>
|
|||
/// 颁发对象
|
|||
/// </summary>
|
|||
public string Audience => _configSection.GetValue("Audience", "Client"); |
|||
|
|||
/// <summary>
|
|||
/// 安全密钥
|
|||
/// </summary>
|
|||
public string SecurityKey => _configSection.GetValue("SecurityKey", "Shentun8Shentun8Shentun8Shentun8"); |
|||
|
|||
/// <summary>
|
|||
/// Web端过期时间
|
|||
/// </summary>
|
|||
public double WebExpiration => _configSection.GetValue<double>("WebExpiration", 100); |
|||
} |
|||
} |
|||
@ -0,0 +1,85 @@ |
|||
using Microsoft.IdentityModel.Tokens; |
|||
using System.IdentityModel.Tokens.Jwt; |
|||
using System.Security.Claims; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.PeisReport.Api.Jwt |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public class JwtHelper |
|||
{ |
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public JwtHelper() |
|||
{ |
|||
|
|||
} |
|||
/// <summary>
|
|||
/// 获取JWT令牌
|
|||
/// </summary>
|
|||
/// <param name="claims"></param>
|
|||
/// <returns></returns>
|
|||
public string GetJwt(IEnumerable<Claim> claims) |
|||
{ |
|||
var dateTime = DateTime.UtcNow;//世界时间
|
|||
//秘钥
|
|||
var jwtConfig = new JwtConfig(); |
|||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConfig.SecurityKey)); |
|||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); |
|||
// 过期时间
|
|||
double expMin= jwtConfig.WebExpiration; |
|||
|
|||
DateTime expTime = dateTime.AddMinutes(expMin); |
|||
var jwt = new JwtSecurityToken( |
|||
issuer: jwtConfig.Issuer,//颁发者
|
|||
audience: jwtConfig.Audience,//颁发给
|
|||
claims: claims, //声明集合
|
|||
notBefore: dateTime,//生效时间,这里必须使用世界时间
|
|||
expires: expTime,//过期时间,这里必须使用世界时间
|
|||
signingCredentials: creds); |
|||
|
|||
var jwtHandler = new JwtSecurityTokenHandler().WriteToken(jwt); |
|||
|
|||
return jwtHandler; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取TokenValidationParameters
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public TokenValidationParameters GetTokenValidationParameters() |
|||
{ |
|||
var jwtConfig = new JwtConfig(); |
|||
TokenValidationParameters tokenValidationParameters = new TokenValidationParameters |
|||
{ |
|||
ValidIssuer = jwtConfig.Issuer,//颁发者
|
|||
ValidAudience = jwtConfig.Audience,//颁发给
|
|||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConfig.SecurityKey)), |
|||
|
|||
/***********************************TokenValidationParameters的参数默认值***********************************/ |
|||
RequireSignedTokens = true, |
|||
// SaveSigninToken = false,
|
|||
// ValidateActor = false,
|
|||
// 将下面两个参数设置为false,可以不验证Issuer和Audience,但是不建议这样做。
|
|||
ValidateAudience = true,//颁发给验证
|
|||
ValidateIssuer = true,//颁发者验证
|
|||
ValidateIssuerSigningKey = true, |
|||
// 是否要求Token的Claims中必须包含 Expires
|
|||
RequireExpirationTime = true, |
|||
// 允许的服务器时间偏移量
|
|||
ClockSkew = TimeSpan.FromSeconds(300), |
|||
// 是否验证Token有效期,使用当前时间与Token的Claims中的NotBefore和Expires对比
|
|||
ValidateLifetime = true |
|||
}; |
|||
return tokenValidationParameters; |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
namespace Shentun.PeisReport.Api |
|||
{ |
|||
public class WeatherForecast |
|||
{ |
|||
public DateTime Date { get; set; } |
|||
|
|||
public int TemperatureC { get; set; } |
|||
|
|||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |
|||
|
|||
public string? Summary { get; set; } |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue