@@ -43,11 +43,6 @@ ProjectSection(SolutionItems) = preProject | |||
src\nuget.config = src\nuget.config | |||
EndProjectSection | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".pack", ".pack", "{5CE18647-CEFB-483A-B384-99D4FB47DA29}" | |||
ProjectSection(SolutionItems) = preProject | |||
src\.pack\pack.sh = src\.pack\pack.sh | |||
EndProjectSection | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -114,9 +109,8 @@ Global | |||
{4F48E97A-2DC3-4720-98F7-25935258D79C} = {0265A6CF-0D40-4A59-B6DF-2F25099DA95B} | |||
{CFDFD099-D03F-441A-A3CD-28C7320742C5} = {71207855-D2BE-48D3-86AD-D1E5BC389E64} | |||
{FBE0E584-BF1F-498D-BBFC-66B790EAFC7C} = {FEDACFF6-C6AF-4C34-9575-9456856AEACC} | |||
{5CE18647-CEFB-483A-B384-99D4FB47DA29} = {0265A6CF-0D40-4A59-B6DF-2F25099DA95B} | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {7A177DC6-A13E-4628-97F6-40DC7573252A} | |||
EndGlobalSection | |||
EndGlobal | |||
EndGlobal |
@@ -1,22 +1,23 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.0" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> | |||
<PackageReference Include="BPA.Component.CAP.RabbitMQ" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.8" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Model\BPA.SaaS.BizLog.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Service\BPA.SaaS.BizLog.Api.Service.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Repository\BPA.SaaS.BizLog.Api.Repository.csproj" /> | |||
</ItemGroup> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.0" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> | |||
<PackageReference Include="BPA.Component.CAP.RabbitMQ" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.21" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Model\BPA.SaaS.BizLog.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Service\BPA.SaaS.BizLog.Api.Service.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Repository\BPA.SaaS.BizLog.Api.Repository.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,132 @@ | |||
using System.Net.NetworkInformation; | |||
using System.Net.Sockets; | |||
using System.Text; | |||
using Autofac; | |||
using BPA.Component.ApolloClient; | |||
using BPA.Component.Extensions; | |||
using BPA.Component.LogClient.Extensions; | |||
using BPA.Component.SDKCommon; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.SaaS.BizLog.Api.IService.Queue; | |||
using BPA.SaaS.BizLog.Api.Model; | |||
using BPA.SaaS.BizLog.Api.Repository; | |||
using BPA.SaaS.BizLog.Api.Service.Queue; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.OpenApi.Models; | |||
using IPAddress = System.Net.IPAddress; | |||
namespace BPA.SaaS.BizLog.Api.Bootstrap; | |||
/// <summary> | |||
/// 启动配置 | |||
/// </summary> | |||
public static class SetupBootstrap | |||
{ | |||
private static IConfiguration _configuration; | |||
/// <summary> | |||
/// 添加配置中心 | |||
/// </summary> | |||
/// <param name="configuration"></param> | |||
public static IConfiguration SetupConfiguration(this IConfiguration configuration) | |||
{ | |||
_configuration = configuration; | |||
// 初始化化 apollo配置 | |||
return configuration.AddApolloConfiguration(); | |||
} | |||
/// <summary> | |||
/// DI Inject | |||
/// </summary> | |||
public static IServiceCollection AddBPAMiddlewareServices(this IServiceCollection services, string[] args) | |||
{ | |||
if (services == null) throw new ArgumentNullException(nameof(services)); | |||
services.AddApollo<BizLogApiConfig>(); | |||
services.AddScoped<BizLogMongoDbClient>(); | |||
services.AddBPALog(); | |||
services.AddRedis(); | |||
services.AddRabbitMQ(); | |||
services.AddHttpContextAccessor(); | |||
services.AddControllers(options => { options.AddDefaultMvcOptions(); }); | |||
services.AddEndpointsApiExplorer(); | |||
services.AddServiceSDK(_configuration); | |||
services.AddHealthChecks(); | |||
services.AddSwaggerGen(options => | |||
{ | |||
options.SwaggerDoc("v1", new OpenApiInfo | |||
{ | |||
Title = AppDomain.CurrentDomain.FriendlyName, | |||
Description = AppDomain.CurrentDomain.FriendlyName, | |||
Version = "v1" | |||
}); | |||
options.CustomSchemaIds(type => type.GetDescribe(true, "BPA.", "BPA.SaaS.")); | |||
}); | |||
return services; | |||
} | |||
/// <summary> | |||
/// DI Register | |||
/// </summary> | |||
public static ContainerBuilder SetupConfigureContainer(this ContainerBuilder builder) | |||
{ | |||
// 控制注入实例 | |||
builder.RegisterType<BizLogMongoDbClient>().InstancePerLifetimeScope(); | |||
// 服务层 | |||
builder.RegisterAssemblyTypes(typeof(BizLogConsumerService).Assembly) | |||
.Where(t => t.Name.EndsWith("Service")) | |||
.AsImplementedInterfaces(); | |||
// 仓储层 | |||
builder.RegisterAssemblyTypes(typeof(BizLogRepository).Assembly) | |||
.Where(t => t.Name.EndsWith("Repository")) | |||
.AsImplementedInterfaces(); | |||
return builder; | |||
} | |||
/// <summary> | |||
/// pre run | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
public static void PreHeatRun(this IServiceProvider serviceProvider) | |||
{ | |||
serviceProvider.GetService<BizLogApiConfig>(); | |||
serviceProvider.PreHeatRunRedis(); | |||
serviceProvider.PreHeatRunRabbitMQ(); | |||
serviceProvider.SetDebug(true); | |||
} | |||
/// <summary> | |||
/// APP健康检查 | |||
/// </summary> | |||
/// <param name="app"></param> | |||
public static void UseBpaHealthChecks(this IApplicationBuilder app) | |||
{ | |||
var ips = new List<dynamic>(); | |||
foreach (var network in NetworkInterface.GetAllNetworkInterfaces()) | |||
{ | |||
var ipAddress = network.GetIPProperties() | |||
.UnicastAddresses | |||
.FirstOrDefault(p => p.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(p.Address)) | |||
?.Address.ToString(); | |||
if (ipAddress == null) | |||
continue; | |||
ips.Add(new {name = network.Name, ip = ipAddress}); | |||
} | |||
var ipsJson = ips.ToJson(); | |||
app.UseHealthChecks("/health", new HealthCheckOptions | |||
{ | |||
ResponseWriter = (httpContext, _) => httpContext.Response.WriteAsync(ipsJson, Encoding.UTF8) | |||
}); | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
using BPA.Common.Infrastructure.BizLogs; | |||
using BPA.Common.Infrastructure.Queue; | |||
using BPA.Component.RabbitMQClient.Extensions; | |||
using BPA.Component.RabbitMQClient.Provider; | |||
using BPA.SaaS.BizLog.Api.Model; | |||
using BPA.SaaS.BizLog.Api.Service.Queue; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.BizLog.Api.Bootstrap | |||
{ | |||
/// <summary> | |||
/// RabbitMQ配置 | |||
/// </summary> | |||
public static class SetupRabbitMqConfig | |||
{ | |||
/// <summary> | |||
/// 使用消息队列 | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IServiceCollection AddRabbitMQ(this IServiceCollection services) | |||
{ | |||
services.AddRabbitMQProvider(sp => sp.GetService<BizLogApiConfig>()?.RabbitMqConfig); | |||
services.AddRabbitMQConsumer<BizLogConsumerService, BaseBizLogMsgBody>(); | |||
return services; | |||
} | |||
/// <summary> | |||
/// 预热消息队列 | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
/// <returns></returns> | |||
public static IServiceProvider PreHeatRunRabbitMQ(this IServiceProvider serviceProvider) | |||
{ | |||
var rabbitMqProvider = serviceProvider.UseRabbitMQProvider<RabbitMQProvider>(); | |||
var createBizLogQueueConfig = rabbitMqProvider.BuildQueueConfig(MqNameConfig.BizLogQueue, MqNameConfig.BizLogExchange); | |||
createBizLogQueueConfig.UseQueue(); | |||
createBizLogQueueConfig.UseMultipleConsumer<BaseBizLogMsgBody, BizLogConsumerService>(3); | |||
return serviceProvider; | |||
} | |||
} | |||
} |
@@ -0,0 +1,48 @@ | |||
using BPA.Component.RedisClient; | |||
using BPA.SaaS.BizLog.Api.Model; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.BizLog.Api.Bootstrap; | |||
/// <summary> | |||
/// redis DI配置 | |||
/// </summary> | |||
public static class SetupRedisConfig | |||
{ | |||
/// <summary> | |||
/// 注入redis | |||
/// </summary> | |||
/// <param name="services"></param> | |||
public static void AddRedis(this IServiceCollection services) | |||
{ | |||
services.UseRedisSingleton(sp => GetRedisSingletonConnectionString(sp.GetService<BizLogApiConfig>()!)); | |||
} | |||
/// <summary> | |||
/// 预热redis | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
public static void PreHeatRunRedis(this IServiceProvider serviceProvider) | |||
{ | |||
var config = serviceProvider.GetService<BizLogApiConfig>(); | |||
// 添加配置改变时的事件 | |||
if (config != null) | |||
config.OnConfigChange += (stockWebApiConfig, key, _, _, _) => | |||
{ | |||
if (nameof(stockWebApiConfig.RedisConfig) != key) return; | |||
var conStr = GetRedisSingletonConnectionString(stockWebApiConfig); | |||
//单个redis时 配置变化 触发生成新的实例 | |||
RedisConfigExtensions.OnRedisSingletonConnectionStringChange(conStr); | |||
}; | |||
} | |||
/// <summary> | |||
/// 获取单例 Redis 连接字符串 | |||
/// </summary> | |||
/// <param name="config"></param> | |||
/// <returns></returns> | |||
private static string GetRedisSingletonConnectionString(BizLogApiConfig config) => | |||
config.RedisConfig[new Random().Next(0, config.RedisConfig.Count)]; | |||
} |
@@ -0,0 +1,47 @@ | |||
using BPA.Component.DTOCommon.Langs; | |||
using BPA.Component.SDKCommon; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.BizLog.Api.Bootstrap; | |||
/// <summary> | |||
/// 其他SDK服务 | |||
/// </summary> | |||
public static class SetupServiceSDK | |||
{ | |||
/// <summary> | |||
/// 注入其他SDK | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <param name="configuration"></param> | |||
public static void AddServiceSDK(this IServiceCollection services, IConfiguration configuration) | |||
{ | |||
// 初始化sdk配置和语言获取 | |||
services.AddApiSDK(_ => /*sp.GetService<IHttpContextAccessor>()?.HttpContext?.Request.GetLanguage() ??*/ LangType.Zn); | |||
// 获取当前API启动时定义的环境 | |||
var environment = configuration.GetValue<string>("ASPNETCORE_ENVIRONMENT"); | |||
// 环境选择 | |||
switch (environment) | |||
{ | |||
case "Development": | |||
// 开发本地连集群 | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://[IP]:[port]"); | |||
// 开发集群环境内 | |||
// services.UseApiSDK<WebApi2SDK>(_ => "http://serviceName"); | |||
break; | |||
case "Production": | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://[domainName].com:[80]/[serviceName]"); | |||
break; | |||
case "Testing": | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://test.[domainName].com:[80]/[serviceName]/"); | |||
break; | |||
} | |||
} | |||
} |
@@ -1,11 +1,14 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<VersionPrefix>1.0.1</VersionPrefix> | |||
<PackageReleaseNotes /> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.5" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,11 +1,17 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | |||
<NoWarn>1701;1702;8618</NoWarn> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.5" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,12 @@ | |||
using BPA.Common.Enums.BizLog; | |||
using BPA.Component.Extensions; | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Base | |||
{ | |||
public string BusinessId { get; set; } | |||
public long Id { get; set; } = BPAUniqueIdBulder.NextLong(); | |||
public EnumBizLogType EnumBizLogType { get; set; } | |||
} |
@@ -0,0 +1,19 @@ | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Create : BPA_BizLog_Base | |||
{ | |||
/// <summary> | |||
/// 创建时间 | |||
/// </summary> | |||
public DateTime? CreateDateTime { get; set; } | |||
/// <summary> | |||
/// 创建人 | |||
/// </summary> | |||
public string? CreateBy { get; set; } | |||
/// <summary> | |||
/// 创建数据 | |||
/// </summary> | |||
public Dictionary<string, object>? CreateData { get; set; } | |||
} |
@@ -0,0 +1,14 @@ | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Delete : BPA_BizLog_Base | |||
{ | |||
/// <summary> | |||
/// 删除时间 | |||
/// </summary> | |||
public DateTime? DeleteDateTime { get; set; } | |||
/// <summary> | |||
/// 删除人 | |||
/// </summary> | |||
public string? DeleteBy { get; set; } | |||
} |
@@ -0,0 +1,43 @@ | |||
using BPA.Component.Extensions; | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Execetion_Time | |||
{ | |||
public long Id { get; set; } = BPAUniqueIdBulder.NextLong(); | |||
/// <summary> | |||
/// BusinessIdStr | |||
/// </summary> | |||
public string BusinessIdStr { get; set; } | |||
/// <summary> | |||
/// BusinessId | |||
/// </summary> | |||
public long BusinessId { get; set; } | |||
/// <summary> | |||
/// TrackId | |||
/// </summary> | |||
public string TrackId { get; set; } | |||
/// <summary> | |||
/// TotalSeconds | |||
/// </summary> | |||
public double TotalSeconds { get; set; } | |||
/// <summary> | |||
/// FileName | |||
/// </summary> | |||
public string FileName { get; set; } | |||
/// <summary> | |||
/// FileLine | |||
/// </summary> | |||
public int FileLine { get; set; } | |||
/// <summary> | |||
/// FileMethodName | |||
/// </summary> | |||
public string FirstMethodName { get; set; } | |||
} |
@@ -0,0 +1,24 @@ | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Query : BPA_BizLog_Base | |||
{ | |||
/// <summary> | |||
/// 查询 | |||
/// </summary> | |||
public DateTime? QueryTime { get; set; } | |||
/// <summary> | |||
/// 查询人 | |||
/// </summary> | |||
public string? QueryBy { get; set; } | |||
/// <summary> | |||
/// 查询条件数据 | |||
/// </summary> | |||
public Dictionary<string, object>? QueryConditionData { get; set; } | |||
/// <summary> | |||
/// 查询基础信息 | |||
/// </summary> | |||
public Dictionary<string, object>? QueryConditionBase { get; set; } | |||
} |
@@ -0,0 +1,24 @@ | |||
namespace BPA.SaaS.BizLog.Api.Entity; | |||
public class BPA_BizLog_Update : BPA_BizLog_Base | |||
{ | |||
/// <summary> | |||
/// 更新时间 | |||
/// </summary> | |||
public DateTime? UpdateDateTime { get; set; } | |||
/// <summary> | |||
/// 更新人 | |||
/// </summary> | |||
public string? UpdateBy { get; set; } | |||
/// <summary> | |||
/// 更新之前的数据 | |||
/// </summary> | |||
public Dictionary<string, object>? UpdateBeforeData { get; set; } | |||
/// <summary> | |||
/// 更新之后的数据 | |||
/// </summary> | |||
public Dictionary<string, object>? UpdateAfterData { get; set; } | |||
} |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,7 +6,8 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.8" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Model\BPA.SaaS.BizLog.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Entity\BPA.SaaS.BizLog.Api.Entity.csproj" /> | |||
@@ -0,0 +1,12 @@ | |||
using BPA.Component.MongoClient.Repository; | |||
using BPA.SaaS.BizLog.Api.Entity; | |||
namespace BPA.SaaS.BizLog.Api.IRepository; | |||
public interface IBizLogRepository : IBaseMongoDbRepository<BPA_BizLog_Base> | |||
{ | |||
bool AddCreateBizLog(BPA_BizLog_Create bpaBizLogCreate); | |||
bool AddUpdateBizLog(BPA_BizLog_Update bpaBizLogUpdate); | |||
bool AddDeleteBizLog(BPA_BizLog_Delete bpaBizLogDelete); | |||
bool AddQueryBizLog(BPA_BizLog_Query bpaBizLogCreate); | |||
} |
@@ -0,0 +1,8 @@ | |||
using BPA.SaaS.BizLog.Api.Entity; | |||
namespace BPA.SaaS.BizLog.Api.IRepository; | |||
public interface IBizLogTimeoutRepository | |||
{ | |||
bool AddTimeoutBizLog(BPA_BizLog_Execetion_Time bpaBizLogExecetionTime); | |||
} |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -0,0 +1,6 @@ | |||
namespace BPA.SaaS.BizLog.Api.IService.Queue; | |||
public interface IBizLogConsumerService | |||
{ | |||
} |
@@ -1,17 +1,24 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | |||
<NoWarn>1701;1702;0618;8618</NoWarn> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | |||
<NoWarn>1701;1702;0618</NoWarn> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.ApolloClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.ApolloClient" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.LogClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.7" /> | |||
<PackageReference Include="BPA.Component.RabbitMQClient" Version="1.0.7" /> | |||
<PackageReference Include="BPA.Component.RedisClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.8" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,38 @@ | |||
using BPA.Component.ApolloClient; | |||
using BPA.Component.MongoClient; | |||
using BPA.Component.RabbitMQClient.Connection; | |||
using BPA.Component.RabbitMQClient.Options; | |||
using Com.Ctrip.Framework.Apollo; | |||
using Microsoft.Extensions.Configuration; | |||
namespace BPA.SaaS.BizLog.Api.Model; | |||
/// <summary> | |||
/// BasicWebApiConfig | |||
/// </summary> | |||
// ReSharper disable once ClassNeverInstantiated.Global | |||
public class BizLogApiConfig : ApolloBPAConfig<BizLogApiConfig> | |||
{ | |||
/// <summary> | |||
/// RedisConfig | |||
/// </summary> | |||
[AutoWrite] | |||
public new List<string> RedisConfig { set; get; } | |||
/// <summary> | |||
/// RabbitMQ配置 | |||
/// </summary> | |||
[AutoWrite] | |||
public new RabbitMqConnectionConfig RabbitMqConfig { get; set; } | |||
/// <summary> | |||
/// MongoClient | |||
/// </summary> | |||
[AutoWrite] | |||
public MongoConfig BizLogMongoConfig { get; set; } | |||
public BizLogApiConfig(ApolloConfigurationManager apolloConfigurationManager, IConfiguration configuration) : base( | |||
apolloConfigurationManager, configuration) | |||
{ | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
using BPA.Component.MongoClient; | |||
using Microsoft.Extensions.Logging; | |||
namespace BPA.SaaS.BizLog.Api.Model; | |||
public class BizLogMongoDbClient : BaseMongoDbClient<BizLogMongoDbClient> | |||
{ | |||
private readonly ILogger<BizLogMongoDbClient> _logger; | |||
public BizLogMongoDbClient(BizLogApiConfig config, ILogger<BizLogMongoDbClient> logger) | |||
: base(config.BizLogMongoConfig, logger) | |||
{ | |||
_logger = logger; | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,9 +6,12 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.5" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Model\BPA.SaaS.BizLog.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Entity\BPA.SaaS.BizLog.Api.Entity.csproj" /> | |||
@@ -0,0 +1,21 @@ | |||
using BPA.Component.MongoClient.Repository; | |||
using BPA.SaaS.BizLog.Api.Entity; | |||
using BPA.SaaS.BizLog.Api.IRepository; | |||
using BPA.SaaS.BizLog.Api.Model; | |||
namespace BPA.SaaS.BizLog.Api.Repository; | |||
public class BizLogRepository : BaseMongoDbRepository<BizLogMongoDbClient, BPA_BizLog_Base>, IBizLogRepository | |||
{ | |||
public BizLogRepository(BizLogMongoDbClient mongoDbClient) : base(mongoDbClient) | |||
{ | |||
} | |||
public bool AddCreateBizLog(BPA_BizLog_Create bpaBizLogCreate) => Add(bpaBizLogCreate) > 0; | |||
public bool AddUpdateBizLog(BPA_BizLog_Update bpaBizLogUpdate) => Add(bpaBizLogUpdate) > 0; | |||
public bool AddDeleteBizLog(BPA_BizLog_Delete bpaBizLogDelete) => Add(bpaBizLogDelete) > 0; | |||
public bool AddQueryBizLog(BPA_BizLog_Query bpaBizLogCreate) => Add(bpaBizLogCreate) > 0; | |||
} |
@@ -0,0 +1,15 @@ | |||
using BPA.Component.MongoClient.Repository; | |||
using BPA.SaaS.BizLog.Api.Entity; | |||
using BPA.SaaS.BizLog.Api.IRepository; | |||
using BPA.SaaS.BizLog.Api.Model; | |||
namespace BPA.SaaS.BizLog.Api.Repository; | |||
public class BizLogTimeoutRepository : BaseMongoDbRepository<BizLogMongoDbClient, BPA_BizLog_Execetion_Time>, IBizLogTimeoutRepository | |||
{ | |||
public BizLogTimeoutRepository(BizLogMongoDbClient mongoDbClient) : base(mongoDbClient) | |||
{ | |||
} | |||
public bool AddTimeoutBizLog(BPA_BizLog_Execetion_Time bpaBizLogExecetionTime) => Add(bpaBizLogExecetionTime) > 0; | |||
} |
@@ -1,13 +1,14 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.IService\BPA.SaaS.BizLog.Api.IService.csproj" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
</ItemGroup> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.SaaS.BizLog.Api.DTO" Version="1.0.1" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,8 +6,14 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.7" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.21" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.DTO\BPA.SaaS.BizLog.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Model\BPA.SaaS.BizLog.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.IRepository\BPA.SaaS.BizLog.Api.IRepository.csproj" /> | |||
@@ -0,0 +1,94 @@ | |||
using BPA.Common.Enums.Queue; | |||
using BPA.Component.RabbitMQClient.Base; | |||
using BPA.SaaS.BizLog.Api.IRepository; | |||
using BPA.SaaS.BizLog.Api.IService.Queue; | |||
using Microsoft.Extensions.Logging; | |||
using BPA.Common.Infrastructure.BizLogs; | |||
using BPA.Component.Extensions; | |||
using BPA.SaaS.BizLog.Api.Entity; | |||
using RabbitMQ.Client.Events; | |||
namespace BPA.SaaS.BizLog.Api.Service.Queue; | |||
/// <summary> | |||
/// 业务日志消费者端 | |||
/// </summary> | |||
public class BizLogConsumerService : BaseConsumer<BaseBizLogMsgBody, BizLogConsumerService>, IBizLogConsumerService | |||
{ | |||
private readonly IServiceProvider _serviceProvider; | |||
private readonly ILogger<BizLogConsumerService> _logger; | |||
private readonly IBizLogRepository _bizLogRepository; | |||
private readonly IBizLogTimeoutRepository _bizLogTimeoutRepository; | |||
/// <summary> | |||
/// 构造方法 | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
/// <param name="logger"></param> | |||
/// <param name="bizLogRepository"></param> | |||
/// <param name="bizLogTimeoutRepository"></param> | |||
public BizLogConsumerService(IServiceProvider serviceProvider, ILogger<BizLogConsumerService> logger, | |||
IBizLogRepository bizLogRepository, | |||
IBizLogTimeoutRepository bizLogTimeoutRepository) : | |||
base(logger) | |||
{ | |||
_serviceProvider = serviceProvider; | |||
_logger = logger; | |||
_bizLogRepository = bizLogRepository; | |||
_bizLogTimeoutRepository = bizLogTimeoutRepository; | |||
} | |||
/// <summary> | |||
/// 消费出队 | |||
/// </summary> | |||
/// <param name="msgBody"></param> | |||
/// <param name="eventArgs"></param> | |||
/// <returns></returns> | |||
public override bool Dequeue(BaseBizLogMsgBody msgBody, BasicDeliverEventArgs eventArgs) | |||
{ | |||
_logger.LogDebug("Received message:"); | |||
_logger.LogDebug($"{msgBody.ToJson()}"); | |||
_logger.LogDebug(string.Empty); | |||
return msgBody.EnumMessageType switch | |||
{ | |||
EnumMessageType.BizLog => AddBizLogs(msgBody), | |||
EnumMessageType.BizLogExt => AddBizLogExt(msgBody), | |||
_ => false | |||
}; | |||
} | |||
private bool AddBizLogExt(BaseBizLogMsgBody msgBody) => | |||
_bizLogTimeoutRepository.AddTimeoutBizLog(msgBody.MapTo<BPA_BizLog_Execetion_Time, BaseBizLogMsgBody>()); | |||
private bool AddBizLogs(BaseBizLogMsgBody msgBody) | |||
{ | |||
if (msgBody.CreateDateTime.HasValue && msgBody.CreateBy != null) | |||
{ | |||
var bpaBizLogCreate = msgBody.MapTo<BPA_BizLog_Create, BaseBizLogMsgBody>(); | |||
if (msgBody.EnumBizLogType != null) bpaBizLogCreate.EnumBizLogType = msgBody.EnumBizLogType.Value; | |||
return _bizLogRepository.AddCreateBizLog(bpaBizLogCreate); | |||
} | |||
if (msgBody.UpdateDateTime.HasValue && msgBody.UpdateBy != null) | |||
{ | |||
var bpaBizLogCreate = msgBody.MapTo<BPA_BizLog_Update, BaseBizLogMsgBody>(); | |||
if (msgBody.EnumBizLogType != null) bpaBizLogCreate.EnumBizLogType = msgBody.EnumBizLogType.Value; | |||
return _bizLogRepository.AddUpdateBizLog(bpaBizLogCreate); | |||
} | |||
if (msgBody.DeleteDateTime.HasValue && msgBody.DeleteBy != null) | |||
{ | |||
var bpaBizLogDelete = msgBody.MapTo<BPA_BizLog_Delete, BaseBizLogMsgBody>(); | |||
if (msgBody.EnumBizLogType != null) bpaBizLogDelete.EnumBizLogType = msgBody.EnumBizLogType.Value; | |||
return _bizLogRepository.AddDeleteBizLog(bpaBizLogDelete); | |||
} | |||
if (!msgBody.QueryTime.HasValue || msgBody.QueryBy == null) return false; | |||
{ | |||
var bpaBizLogQuery = msgBody.MapTo<BPA_BizLog_Query, BaseBizLogMsgBody>(); | |||
if (msgBody.EnumBizLogType != null) bpaBizLogQuery.EnumBizLogType = msgBody.EnumBizLogType.Value; | |||
return _bizLogRepository.AddQueryBizLog(bpaBizLogQuery); | |||
} | |||
} | |||
} |
@@ -1,7 +1,20 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0"/> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/> | |||
<PackageReference Include="MSTest.TestFramework" Version="2.2.9"/> | |||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9"/> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Bootstrap\BPA.SaaS.BizLog.Api.Bootstrap.csproj"/> | |||
<ProjectReference Include="..\BPA.SaaS.BizLog.Api.Service\BPA.SaaS.BizLog.Api.Service.csproj"/> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -1,8 +1,38 @@ | |||
using Autofac; | |||
using Autofac.Extensions.DependencyInjection; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.SaaS.BizLog.Api.Bootstrap; | |||
using Microsoft.AspNetCore.Mvc; | |||
var builder = WebApplication.CreateBuilder(args); | |||
builder.Services.AddControllers(); | |||
builder.Configuration.SetupConfiguration(); | |||
// DI | |||
builder.Services.AddBPAMiddlewareServices(args); | |||
// DI config | |||
builder.Services.Configure<ApiBehaviorOptions>(options => { options.AddDefaultBehaviorOptions(); }); | |||
// Use Autofac | |||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); | |||
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder => { containerBuilder.SetupConfigureContainer(); }); | |||
var app = builder.Build(); | |||
if (app.Environment.IsDevelopment()) | |||
{ | |||
app.UseSwagger(); | |||
app.UseSwaggerUI(); | |||
} | |||
// Use module | |||
app.UseRouting(); | |||
app.UseHttpsRedirection(); | |||
app.UseAuthorization(); | |||
app.UseBpaHealthChecks(); | |||
app.MapControllers(); | |||
app.Run(); | |||
app.UseGlobalErrorHandler(); | |||
// PreRun | |||
((IApplicationBuilder) app).ApplicationServices.PreHeatRun(); | |||
app.Run(); |
@@ -1,30 +1,15 @@ | |||
{ | |||
"$schema": "https://json.schemastore.org/launchsettings.json", | |||
"iisSettings": { | |||
"windowsAuthentication": false, | |||
"anonymousAuthentication": true, | |||
"iisExpress": { | |||
"applicationUrl": "http://localhost:11305", | |||
"sslPort": 44315 | |||
} | |||
}, | |||
"profiles": { | |||
"BPA.SaaS.Stock.Api": { | |||
"BPA.SaaS.BizLog.Api": { | |||
"commandName": "Project", | |||
"dotnetRunMessages": true, | |||
"launchBrowser": true, | |||
"launchUrl": "weatherforecast", | |||
"applicationUrl": "https://localhost:7047;http://localhost:5047", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
} | |||
}, | |||
"IIS Express": { | |||
"commandName": "IISExpress", | |||
"launchBrowser": true, | |||
"launchUrl": "weatherforecast", | |||
"applicationUrl": "http://localhost:5017", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
"ASPNETCORE_ENVIRONMENT": "Development", | |||
"APOLLO_META_SERVER_URL": "http://10.2.1.21:28080", | |||
"APOLLO_COMMON_NAMESPACE": "DEV.Common", | |||
"APP_NAME": "BPA.SaaS.BizLog.Api" | |||
} | |||
} | |||
} | |||
@@ -1,8 +0,0 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Information", | |||
"Microsoft.AspNetCore": "Warning" | |||
} | |||
} | |||
} |
@@ -1,9 +0,0 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Information", | |||
"Microsoft.AspNetCore": "Warning" | |||
} | |||
}, | |||
"AllowedHosts": "*" | |||
} |