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

99 lines
3.6 KiB
C#
Raw Normal View History

2025-05-12 14:02:22 +08:00
using Cassandra.Mapping;
2025-04-15 17:57:47 +08:00
using JiShe.CollectBus.Cassandra;
2025-04-30 12:36:54 +08:00
using JiShe.CollectBus.DataChannels;
2025-04-17 20:28:50 +08:00
using JiShe.CollectBus.FreeRedis;
2025-04-25 17:41:43 +08:00
using JiShe.CollectBus.FreeSql;
using JiShe.CollectBus.Interceptors;
2025-04-17 20:28:50 +08:00
using JiShe.CollectBus.IoTDB;
2025-04-30 12:36:54 +08:00
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
2025-04-25 17:41:43 +08:00
using JiShe.CollectBus.Kafka;
2025-04-21 09:54:34 +08:00
using JiShe.CollectBus.Mappers;
2025-04-27 09:16:37 +08:00
using JiShe.CollectBus.Protocol;
2025-04-25 17:41:43 +08:00
using JiShe.CollectBus.ScheduledMeterReading;
using Microsoft.Extensions.DependencyInjection;
2025-05-12 14:02:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Channels;
using System.Threading.Tasks;
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.BackgroundWorkers;
using Volo.Abp.BackgroundWorkers.Hangfire;
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-04-15 17:57:47 +08:00
typeof(AbpAutofacModule),
2025-03-14 13:45:29 +08:00
typeof(AbpBackgroundWorkersHangfireModule),
2025-03-17 08:35:19 +08:00
typeof(CollectBusFreeRedisModule),
2025-04-09 14:33:20 +08:00
typeof(CollectBusFreeSqlModule),
typeof(CollectBusKafkaModule),
2025-04-21 10:17:40 +08:00
typeof(CollectBusIoTDbModule),
typeof(CollectBusCassandraModule),
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
context.Services.AddSingleton(new MappingConfiguration()
.Define(new CollectBusMapping()));
// 注册拦截器
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
});
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
{
2024-12-19 16:07:07 +08:00
var assembly = Assembly.GetExecutingAssembly();
2025-04-25 17:41:43 +08:00
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
.ToList();
foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
2025-03-21 11:48:31 +08:00
2025-04-28 16:37:31 +08:00
//Task.Run(() =>
//{
// //默认初始化表计信息
// var dbContext = context.ServiceProvider.GetRequiredService<EnergySystemScheduledMeterReadingService>();
// dbContext.InitAmmeterCacheData();
// //await dbContext.InitWatermeterCacheData();
//}).ConfigureAwait(false);
2025-04-30 12:36:54 +08:00
//下发任务通道构建
DataChannelManage.TaskDataChannel = Channel.CreateUnbounded<ValueTuple<string, List<MeterReadingTelemetryPacketInfo>>>();
2025-04-28 16:37:31 +08:00
2025-05-12 14:02:22 +08:00
// 日志存储通道构建
DataChannelManage.LogSaveChannel = Channel.CreateUnbounded<object>();
// 日志刷新通道构建
DataChannelManage.LogRefreshChannel = Channel.CreateUnbounded<object>();
// 启动通道任务
var _dataChannelManage = context.ServiceProvider.GetRequiredService<DataChannelManageService>();
_ = _dataChannelManage.LogSaveAsync(DataChannelManage.LogSaveChannel.Reader);
2025-04-28 16:37:31 +08:00
//默认初始化表计信息
var dbContext = context.ServiceProvider.GetRequiredService<EnergySystemScheduledMeterReadingService>();
_= dbContext.InitAmmeterCacheData();
2024-12-19 16:07:07 +08:00
}
2025-04-25 17:41:43 +08:00
}