2025-04-14 10:20:48 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
2025-03-21 14:30:11 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
using JiShe.CollectBus.FreeSql;
|
|
|
|
|
|
using JiShe.CollectBus.Kafka;
|
|
|
|
|
|
using JiShe.CollectBus.Kafka.AdminClient;
|
2025-04-07 17:35:37 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
using JiShe.CollectBus.ScheduledMeterReading;
|
2025-04-07 17:35:37 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
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;
|
2025-04-17 20:28:50 +08:00
|
|
|
|
using JiShe.CollectBus.FreeRedis;
|
|
|
|
|
|
using JiShe.CollectBus.IoTDB;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
using Volo.Abp;
|
|
|
|
|
|
using Volo.Abp.Application;
|
2025-04-15 17:57:47 +08:00
|
|
|
|
using Volo.Abp.Autofac;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
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;
|
2025-04-14 10:20:48 +08:00
|
|
|
|
using Volo.Abp.Modularity;
|
2025-04-17 14:12:02 +08:00
|
|
|
|
using Microsoft.Extensions.Options;
|
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),
|
2025-04-14 10:20:48 +08:00
|
|
|
|
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);
|
2025-04-14 10:20:48 +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-14 10:20:48 +08:00
|
|
|
|
{
|
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-16 16:12:38 +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>();
|
2025-04-17 14:12:02 +08:00
|
|
|
|
var kafkaOptions = context.ServiceProvider.GetRequiredService<IOptions<KafkaOptionConfig>>();
|
2025-04-11 17:43:19 +08:00
|
|
|
|
|
|
|
|
|
|
List<string> topics = ProtocolConstExtensions.GetAllTopicNamesByIssued();
|
|
|
|
|
|
topics.AddRange(ProtocolConstExtensions.GetAllTopicNamesByReceived());
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in topics)
|
|
|
|
|
|
{
|
2025-04-17 14:12:02 +08:00
|
|
|
|
await kafkaAdminClient.CreateTopicAsync(item, kafkaOptions.Value.NumPartitions, kafkaOptions.Value.KafkaReplicationFactor);
|
2025-04-11 17:43:19 +08:00
|
|
|
|
}
|
2024-12-19 16:07:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|