|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
using ReZero;
|
|
|
|
using ReZero.Configuration;
|
|
|
|
using ReZero.SuperAPI;
|
|
|
|
using SqlSugar;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Text;
|
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
using medical.transfomer.business;
|
|
|
|
using medical.transfomer.service;
|
|
|
|
using medical.insu.transfomer;
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
|
|
// 注册HttpClient工厂
|
|
|
|
builder.Services.AddHttpClient();
|
|
|
|
|
|
|
|
// 添加医保服务配置
|
|
|
|
// 假设医保服务的基础URL在配置文件中或者使用默认值
|
|
|
|
string medicalInsuranceBaseUrl = builder.Configuration["MedicalInsurance:BaseUrl"] ?? "http://localhost:8080";
|
|
|
|
builder.Services.AddMedicalInsuranceServices(medicalInsuranceBaseUrl);
|
|
|
|
|
|
|
|
// 注册医保交易服务
|
|
|
|
builder.Services.AddScoped<MedicalInsuranceTransactionService>();
|
|
|
|
|
|
|
|
//注册db: 这个不写代码可以不注册
|
|
|
|
builder.Services.AddScoped<ISqlSugarClient>(it =>
|
|
|
|
{
|
|
|
|
var config = ApiConfiguration.GetJsonValue<ReZeroJson>("ReZero");
|
|
|
|
return new SqlSugarClient(new ConnectionConfig()
|
|
|
|
{
|
|
|
|
DbType = config!.BasicDatabase!.DbType,
|
|
|
|
ConnectionString = config!.BasicDatabase!.ConnectionString,
|
|
|
|
IsAutoCloseConnection = true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//builder.Services.AddCors();
|
|
|
|
|
|
|
|
|
|
|
|
//注册ReZero.Api
|
|
|
|
builder.Services.AddReZeroServices(api =>
|
|
|
|
{
|
|
|
|
|
|
|
|
//有重载可换json文件
|
|
|
|
var apiObj = SuperAPIOptions.GetOptions();
|
|
|
|
|
|
|
|
//IOC业务等所有需要的所有集程集
|
|
|
|
var assemblyList = Assembly.GetExecutingAssembly()
|
|
|
|
.GetAllDependentAssemblies(it => it.Contains("medical.insu.transfomer") ||
|
|
|
|
it.Contains("medical.transfomer"))
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
apiObj!.DependencyInjectionOptions = new DependencyInjectionOptions(assemblyList);
|
|
|
|
|
|
|
|
// 配置不需要验证的接口
|
|
|
|
apiObj!.InterfaceOptions!.NoAuthorizationFunc = (context) => {
|
|
|
|
// 使用特性判断方法检查是否需要验证
|
|
|
|
var isNoAuth = NoAuthPaths.IsSkipAuthByAttribute(context);
|
|
|
|
|
|
|
|
if (isNoAuth)
|
|
|
|
{
|
|
|
|
Console.WriteLine($"跳过验证: {context.HttpContext.Request.Path}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return isNoAuth;
|
|
|
|
};
|
|
|
|
|
|
|
|
//启用超级API
|
|
|
|
api.EnableSuperApi(apiObj);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|