JiShe.CollectBus/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs

72 lines
2.6 KiB
C#
Raw Normal View History

2025-06-06 14:15:31 +08:00
using JiShe.CollectBus.DataChannels;
2025-04-25 17:41:43 +08:00
using JiShe.CollectBus.Interceptors;
2025-04-27 09:16:37 +08:00
using JiShe.CollectBus.Protocol;
2025-04-25 17:41:43 +08:00
using JiShe.CollectBus.ScheduledMeterReading;
2025-06-06 14:15:31 +08:00
using JiShe.CollectBus.Workers;
using JiShe.ServicePro.FreeRedisProvider;
using JiShe.ServicePro.FreeSqlProvider;
using JiShe.ServicePro.IoTDBManagement;
using JiShe.ServicePro.IoTDBManagement.TableModels;
using JiShe.ServicePro.Kafka;
2025-04-25 17:41:43 +08:00
using Microsoft.Extensions.DependencyInjection;
2025-05-12 14:02:22 +08:00
using System.Reflection;
using System.Threading.Channels;
using Volo.Abp;
using Volo.Abp.Application;
2025-04-15 17:57:47 +08:00
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
2024-12-19 16:07:07 +08:00
namespace JiShe.CollectBus;
[DependsOn(
typeof(CollectBusDomainModule),
typeof(CollectBusApplicationContractsModule),
typeof(AbpDddApplicationModule),
typeof(AbpAutoMapperModule),
2025-06-06 14:15:31 +08:00
typeof(ServiceProFreeRedisProviderModule),
typeof(ServiceProFreeSqlProviderModule),
typeof(ServiceProKafkaModule),
typeof(IoTDBManagementApplicationModule),
2025-04-15 17:57:47 +08:00
typeof(AbpAutofacModule),
typeof(CollectBusDomainSharedModule),
typeof(CollectBusProtocolModule)
2025-04-25 17:41:43 +08:00
)]
2024-12-19 16:07:07 +08:00
public class CollectBusApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
2025-04-09 14:33:20 +08:00
var configuration = context.Services.GetConfiguration();
2024-12-19 16:07:07 +08:00
context.Services.AddAutoMapperObjectMapper<CollectBusApplicationModule>();
2025-04-25 17:41:43 +08:00
Configure<AbpAutoMapperOptions>(options => { options.AddMaps<CollectBusApplicationModule>(true); });
2025-04-21 09:54:34 +08:00
2025-06-06 14:15:31 +08:00
context.Services.AddHostedService<ScheduledMeterReadingBackGroundWorkService>();
//context.Services.AddSingleton(new MappingConfiguration()
// .Define(new CollectBusMapping()));
2025-04-21 09:54:34 +08:00
// 注册拦截器
context.Services.OnRegistered(ctx =>
{
var methods = ctx.ImplementationType.GetMethods();
2025-04-25 17:41:43 +08:00
var any = methods.Any(a => a.GetCustomAttribute<LogInterceptAttribute>() != null);
if (any) ctx.Interceptors.TryAdd<LogInterceptor>();
2025-04-21 09:54:34 +08:00
});
2025-06-06 14:15:31 +08:00
2024-12-19 16:07:07 +08:00
}
2025-04-15 17:57:47 +08:00
public override async Task OnApplicationInitializationAsync(
2024-12-19 16:07:07 +08:00
ApplicationInitializationContext context)
2025-04-25 17:41:43 +08:00
{
2025-06-06 14:15:31 +08:00
2025-04-30 12:36:54 +08:00
//下发任务通道构建
DataChannelManage.TaskDataChannel = Channel.CreateUnbounded<ValueTuple<string, List<MeterReadingTelemetryPacketInfo>>>();
2025-06-06 14:15:31 +08:00
2025-04-28 16:37:31 +08:00
//默认初始化表计信息
var dbContext = context.ServiceProvider.GetRequiredService<EnergySystemScheduledMeterReadingService>();
2025-05-20 16:53:36 +08:00
await dbContext.InitAmmeterCacheData("V4-Gather-8890");
2025-05-22 17:29:54 +08:00
await dbContext.InitWatermeterCacheData("V4-Gather-8890");
2024-12-19 16:07:07 +08:00
}
2025-04-25 17:41:43 +08:00
}