JiShe.CollectBus/src/JiShe.CollectBus.Application/CollectBusApplicationModule.cs

83 lines
3.0 KiB
C#
Raw Normal View History

using JiShe.CollectBus.Common.Consts;
2025-03-21 14:30:11 +08:00
using JiShe.CollectBus.Common.Extensions;
using JiShe.CollectBus.FreeRedisProvider;
using JiShe.CollectBus.FreeSql;
2025-04-02 17:46:33 +08:00
using JiShe.CollectBus.IoTDBProvider;
using JiShe.CollectBus.Kafka;
using JiShe.CollectBus.Kafka.AdminClient;
2025-04-07 17:35:37 +08:00
using JiShe.CollectBus.Protocol.Contracts;
using JiShe.CollectBus.ScheduledMeterReading;
2025-04-07 17:35:37 +08:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
2025-04-15 17:57:47 +08:00
using System.Threading.Tasks;
using JiShe.CollectBus.Cassandra;
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;
2025-04-09 14:33:20 +08:00
using Volo.Abp.EventBus;
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-15 17:57:47 +08:00
typeof(CollectBusIoTDBModule),
typeof(CollectBusCassandraModule)
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>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<CollectBusApplicationModule>(validate: true);
});
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)
{
2024-12-19 16:07:07 +08:00
var assembly = Assembly.GetExecutingAssembly();
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface).ToList();
foreach (var type in types)
{
2025-04-15 17:57:47 +08:00
await context.AddBackgroundWorkerAsync(type);
2024-12-19 16:07:07 +08:00
}
2025-03-21 11:48:31 +08:00
//默认初始化表计信息
2025-04-11 17:43:19 +08:00
var dbContext = context.ServiceProvider.GetRequiredService<EnergySystemScheduledMeterReadingService>();
2025-04-15 17:57:47 +08:00
await dbContext.InitAmmeterCacheData();
2025-04-15 18:01:30 +08:00
//await dbContext.InitWatermeterCacheData();
2025-04-11 17:43:19 +08:00
//初始化主题信息
var kafkaAdminClient = context.ServiceProvider.GetRequiredService<IAdminClientService>();
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
List<string> topics = ProtocolConstExtensions.GetAllTopicNamesByIssued();
topics.AddRange(ProtocolConstExtensions.GetAllTopicNamesByReceived());
foreach (var item in topics)
{
2025-04-15 17:57:47 +08:00
await kafkaAdminClient.CreateTopicAsync(item, configuration.GetValue<int>(CommonConst.NumPartitions), configuration.GetValue<short>(CommonConst.KafkaReplicationFactor));
2025-04-11 17:43:19 +08:00
}
2024-12-19 16:07:07 +08:00
}
}