From db96b72482a0008a10f6beb5b48ff007d5e550ef Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 12 Mar 2025 14:57:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E9=87=87=E9=9B=86=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FreeRedisProviderService.cs | 14 +- .../Options/FreeRedisOptions.cs | 2 +- .../CollectBusRemoteServiceConsts.cs | 2 +- ...he.CollectBus.Application.Contracts.csproj | 4 - ...ce.cs => IScheduledMeterReadingService.cs} | 27 ++- .../Ammeters/AmmeterInfo.cs | 99 ----------- .../CollectBusAppService.cs | 24 +-- .../BasicScheduledMeterReadingService.cs | 137 +++++++++++++++ ...nergySystemScheduledMeterReadingService.cs | 103 ++++++++++++ .../Workers/ScheduledMeterReadingService.cs | 27 --- .../Workers/WorkerSubscriberAppService.cs | 8 + .../Consts/FreeRedisConst.cs | 8 +- .../Consts/SystemTypeConst.cs | 24 +++ .../Enums/MeterTypeEnum.cs | 53 ++++++ .../Ammeters/AmmeterInfo.cs | 14 +- .../Watermeter/WatermeterInfo.cs} | 158 ++++++++++-------- 16 files changed, 463 insertions(+), 241 deletions(-) rename src/JiShe.CollectBus.Application.Contracts/Workers/{IWorkerScheduledService.cs => IScheduledMeterReadingService.cs} (51%) delete mode 100644 src/JiShe.CollectBus.Application/Ammeters/AmmeterInfo.cs create mode 100644 src/JiShe.CollectBus.Application/Workers/BasicScheduledMeterReadingService.cs create mode 100644 src/JiShe.CollectBus.Application/Workers/EnergySystemScheduledMeterReadingService.cs delete mode 100644 src/JiShe.CollectBus.Application/Workers/ScheduledMeterReadingService.cs create mode 100644 src/JiShe.CollectBus.Common/Consts/SystemTypeConst.cs create mode 100644 src/JiShe.CollectBus.Common/Enums/MeterTypeEnum.cs rename src/{JiShe.CollectBus.Application.Contracts/Workers/DTO/Energy/EnergyAmmeterInfoDto.cs => JiShe.CollectBus.Domain/Watermeter/WatermeterInfo.cs} (59%) diff --git a/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/FreeRedisProviderService.cs b/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/FreeRedisProviderService.cs index 2556803..79e2037 100644 --- a/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/FreeRedisProviderService.cs +++ b/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/FreeRedisProviderService.cs @@ -1,4 +1,5 @@ using FreeRedis; +using JetBrains.Annotations; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -23,7 +24,14 @@ public class FreeRedisProviderService : IFreeRedisProviderService, ISingletonDep freeRedisOptions = options.Value; } - public IRedisClient FreeRedis { get => GetClient(); } + [NotNull] + public IRedisClient FreeRedis + { + get + { + return GetClient(); + } + } /// /// 获取 FreeRedis 客户端 @@ -31,8 +39,8 @@ public class FreeRedisProviderService : IFreeRedisProviderService, ISingletonDep /// public IRedisClient GetClient() { - - var redisClinet = new RedisClient(freeRedisOptions.ConnectionString); + string connectionString = $"{freeRedisOptions.Configuration},defaultdatabase={freeRedisOptions.DefaultDB}"; + var redisClinet = new RedisClient(connectionString); redisClinet.Serialize = obj => JsonSerializer.Serialize(obj); redisClinet.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type); redisClinet.Notice += (s, e) => Trace.WriteLine(e.Log); diff --git a/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/Options/FreeRedisOptions.cs b/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/Options/FreeRedisOptions.cs index 266c743..9eb7bb9 100644 --- a/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/Options/FreeRedisOptions.cs +++ b/JiShe.CollectBus.FreeRedisProvider/FreeRedisProvider/Options/FreeRedisOptions.cs @@ -11,7 +11,7 @@ public class FreeRedisOptions /// /// 连接字符串 /// - public string? ConnectionString { get; set; } + public string? Configuration { get; set; } /// /// 默认数据库 diff --git a/src/JiShe.CollectBus.Application.Contracts/CollectBusRemoteServiceConsts.cs b/src/JiShe.CollectBus.Application.Contracts/CollectBusRemoteServiceConsts.cs index 396140d..2a7170e 100644 --- a/src/JiShe.CollectBus.Application.Contracts/CollectBusRemoteServiceConsts.cs +++ b/src/JiShe.CollectBus.Application.Contracts/CollectBusRemoteServiceConsts.cs @@ -4,5 +4,5 @@ public class CollectBusRemoteServiceConsts { public const string RemoteServiceName = "CollectBus"; - public const string ModuleName = "collectBus"; + public const string ModuleName = "collectBus"; } diff --git a/src/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj b/src/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj index 6841779..0a28849 100644 --- a/src/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj +++ b/src/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj @@ -22,8 +22,4 @@ - - - - diff --git a/src/JiShe.CollectBus.Application.Contracts/Workers/IWorkerScheduledService.cs b/src/JiShe.CollectBus.Application.Contracts/Workers/IScheduledMeterReadingService.cs similarity index 51% rename from src/JiShe.CollectBus.Application.Contracts/Workers/IWorkerScheduledService.cs rename to src/JiShe.CollectBus.Application.Contracts/Workers/IScheduledMeterReadingService.cs index 6ec0577..7591f3e 100644 --- a/src/JiShe.CollectBus.Application.Contracts/Workers/IWorkerScheduledService.cs +++ b/src/JiShe.CollectBus.Application.Contracts/Workers/IScheduledMeterReadingService.cs @@ -1,28 +1,47 @@ using JiShe.CollectBus.Ammeters; +using JiShe.CollectBus.Watermeter; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.Workers { /// /// 定时任务基础约束 /// - interface IWorkerScheduledService + public interface IScheduledMeterReadingService : IApplicationService { /// /// 获取电表信息 /// + /// 采集端Code /// - Task> GetAmmeterInfoList(); - + Task> GetAmmeterInfoList(string gatherCode = ""); + /// /// 初始化电表缓存数据 /// + /// 采集端Code /// - Task InitAmmeterCacheData(); + Task InitAmmeterCacheData(string gatherCode = ""); + + /// + /// 获取水表信息 + /// + /// 采集端Code + /// + Task> GetWatermeterInfoList(string gatherCode = ""); + + /// + /// 初始化水表缓存数据 + /// + /// 采集端Code + /// + Task InitWatermeterCacheData(string gatherCode = ""); /// /// 1分钟采集电表数据 diff --git a/src/JiShe.CollectBus.Application/Ammeters/AmmeterInfo.cs b/src/JiShe.CollectBus.Application/Ammeters/AmmeterInfo.cs deleted file mode 100644 index e9bc4b5..0000000 --- a/src/JiShe.CollectBus.Application/Ammeters/AmmeterInfo.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace JiShe.CollectBus.Ammeters -{ - public class AmmeterInfo - { - public int ID { get; set; } - public string Name { get; set; } - public int FocusID { get; set; } - public string Address { get; set; } - public string AreaCode { get; set; } - /// - /// 电表类别 (1单相、2三相三线、3三相四线), - /// 07协议: 开合闸指令(1A开闸断电,1C单相表合闸,1B多相表合闸) 645 2007 表 - /// 97协议://true(合闸);false(跳闸) 545 1997 没有单相多相 之分 "true" ? "9966" : "3355" - /// - public int TypeName { get; set; } - /// - /// 跳合闸状态字段: 0 合闸,1 跳闸 - /// 电表:TripState (0 合闸-通电, 1 断开、跳闸); - /// - public int TripState { get; set; } - /// - /// 规约 -电表default(30) 1:97协议,30:07协议 - /// - public int? Protocol { get; set; } - /// - /// 一个集中器下的[MeteringCode]必须唯一。 PN - /// - public int MeteringCode { get; set; } - /// - /// 电表通信地址 - /// - public string AmmerterAddress { get; set; } - /// - /// 波特率 default(2400) - /// - public int Baudrate { get; set; } - /// - /// MeteringPort 端口就几个可以枚举。 - /// - public int MeteringPort { get; set; } - /// - /// 电表密码 - /// - public string Password { get; set; } - /// - /// 采集时间间隔(分钟,如15) - /// - public int TimeDensity { get; set; } - /// - /// 该电表方案下采集项,如:0D_80 - /// - public string ItemCodes { get; set; } - /// - /// State表状态: - /// 0新装(未下发),1运行(档案下发成功时设置状态值1), 2暂停, 100销表(销表后是否重新启用) - /// 特定:State -1 已删除 - /// - public int State { get; set; } - /// - /// 是否自动采集(0:主动采集,1:自动采集) - /// - public int AutomaticReport { get; set; } - /// - /// 该电表方案下采集项编号 - /// - public string DataTypes { get; set; } - /// - /// 品牌型号 - /// - public string BrandType { get; set; } - /// - /// 采集器编号 - /// - public string GatherCode { get; set; } - /// - /// 是否特殊表 - /// - public int Special { get; set; } - /// - /// 费率类型,单、多 (SingleRate :单费率(单相表1),多费率(其他0) ,与TypeName字段无关) - /// SingleRate ? "单" : "复" - /// [SingleRate] --0 复费率 false , 1 单费率 true (与PayPlanID保持一致) - ///对应 TB_PayPlan.Type: 1复费率,2单费率 - /// - public bool SingleRate { get; set; } - public int ProjectID { get; set; } - /// - /// 是否异常集中器 0:正常,1异常 - /// - public int AbnormalState { get; set; } - public DateTime LastTime { get; set; } - } -} diff --git a/src/JiShe.CollectBus.Application/CollectBusAppService.cs b/src/JiShe.CollectBus.Application/CollectBusAppService.cs index c607ec4..f45dda1 100644 --- a/src/JiShe.CollectBus.Application/CollectBusAppService.cs +++ b/src/JiShe.CollectBus.Application/CollectBusAppService.cs @@ -3,7 +3,6 @@ using FreeSql; using JiShe.CollectBus.FreeRedisProvider; using JiShe.CollectBus.FreeSql; using JiShe.CollectBus.Localization; -using JiShe.CollectBus.Workers.DTO.Energy; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; @@ -15,30 +14,11 @@ namespace JiShe.CollectBus; public abstract class CollectBusAppService : ApplicationService { public IFreeSqlProvider SqlProvider => LazyServiceProvider.LazyGetRequiredService(); - protected IRedisClient? FreeRedis => LazyServiceProvider.LazyGetService()?.FreeRedis; + protected IFreeRedisProviderService FreeRedisProvider => LazyServiceProvider.LazyGetService()!; protected CollectBusAppService() { LocalizationResource = typeof(CollectBusResource); ObjectMapperContext = typeof(CollectBusApplicationModule); - } - - - #region 能耗相关 - /// - /// 查找当前采集器下所有电表 - /// - /// 采集端Code - /// - protected async Task> GetAmmetersByGatherCode(string gatherCode = "V4-Gather-8890") - { - string sql = $@"SELECT C.ID,C.Name,C.FocusID,C.SingleRate,C.MeteringCode,C.Code AS BrandType,C.Baudrate,C.Password,C.MeteringPort,C.[Address] AS AmmerterAddress,C.TypeName,C.Protocol,C.TripState,C.[State],B.[Address],B.AreaCode,B.AutomaticReport,D.DataTypes,B.TimeDensity,A.GatherCode,C.Special,C.[ProjectID],B.AbnormalState,B.LastTime - FROM TB_GatherInfo(NOLOCK) AS A - INNER JOIN TB_FocusInfo(NOLOCK) AS B ON A.ID = B.GatherInfoID AND B.RemoveState >= 0 AND B.State>=0 - INNER JOIN TB_AmmeterInfo(NOLOCK) AS C ON B.ID = C.FocusID AND C.State>= 0 AND C.State<100 - INNER JOIN TB_AmmeterGatherItem(NOLOCK) AS D ON C.ID = D.AmmeterID AND D.State>=0 - WHERE A.GatherCode = {gatherCode}"; - return await SqlProvider.Instance.Change(DbEnum.EnergyDB).Select(sql).ToListAsync(); - } - #endregion + } } diff --git a/src/JiShe.CollectBus.Application/Workers/BasicScheduledMeterReadingService.cs b/src/JiShe.CollectBus.Application/Workers/BasicScheduledMeterReadingService.cs new file mode 100644 index 0000000..46dc901 --- /dev/null +++ b/src/JiShe.CollectBus.Application/Workers/BasicScheduledMeterReadingService.cs @@ -0,0 +1,137 @@ +using FreeRedis; +using JiShe.CollectBus.Ammeters; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Watermeter; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace JiShe.CollectBus.Workers +{ + /// + /// 定时采集服务 + /// + public abstract class BasicScheduledMeterReadingService : CollectBusAppService, IScheduledMeterReadingService + { + /// + /// 系统类型 + /// + public abstract string SystemType { get; } + + /// + /// 获取电表信息 + /// + /// 采集端Code + /// + public virtual Task> GetAmmeterInfoList(string gatherCode = "") + { + throw new NotImplementedException($"{nameof(GetAmmeterInfoList)}请根据不同系统类型进行实现"); + } + + /// + /// 初始化电表缓存数据 + /// + /// 采集端Code + /// + public virtual async Task InitAmmeterCacheData(string gatherCode = "") + { + var meterInfos = await GetAmmeterInfoList(gatherCode); + if (meterInfos == null || meterInfos.Count <= 0) + { + throw new NullReferenceException($"{nameof(InitWatermeterCacheData)} 初始化电表缓存数据时,电表数据为空"); + } + + //将表计信息根据集中器分组 + var meterInfoGroup = meterInfos.GroupBy(x => x.FocusAddress).ToList(); + foreach (var item in meterInfoGroup) + { + if (string.IsNullOrWhiteSpace(item.Key)) + { + continue; + } + + var redisCacheKey = $"{string.Format(FreeRedisConst.CacheAmmeterInfoKey, SystemTypeConst.Energy)}{item.Key}"; + Dictionary keyValuePairs = new Dictionary(); + foreach (var subItem in item) + { + + keyValuePairs.TryAdd($"{subItem.ID}", subItem); + } + await FreeRedisProvider.FreeRedis.HSetAsync(redisCacheKey, keyValuePairs); + } + } + + /// + /// 获取水表信息 + /// + /// 采集端Code + /// + public virtual async Task> GetWatermeterInfoList(string gatherCode = "") + { + throw new NotImplementedException($"{nameof(GetWatermeterInfoList)}请根据不同系统类型进行实现"); + } + + /// + /// 初始化水表缓存数据 + /// + /// 采集端Code + /// + public virtual async Task InitWatermeterCacheData(string gatherCode = "") + { + var meterInfos = await GetWatermeterInfoList(gatherCode); + if (meterInfos == null || meterInfos.Count <= 0) + { + throw new NullReferenceException($"{nameof(InitWatermeterCacheData)} 初始化水表缓存数据时,水表数据为空"); + } + + //将表计信息根据集中器分组 + var meterInfoGroup = meterInfos.GroupBy(x => x.FocusAddress).ToList(); + foreach (var item in meterInfoGroup) + { + if (string.IsNullOrWhiteSpace(item.Key)) + { + continue; + } + + var redisCacheKey = $"{string.Format(FreeRedisConst.CacheWatermeterInfoKey, SystemTypeConst.Energy)}{item.Key}"; + Dictionary keyValuePairs = new Dictionary(); + foreach (var subItem in item) + { + + keyValuePairs.TryAdd($"{subItem.ID}", subItem); + } + await FreeRedisProvider.FreeRedis.HSetAsync(redisCacheKey, keyValuePairs); + } + } + + /// + /// 1分钟采集电表数据 + /// + /// + public virtual Task ScheduledMeterOneMinuteReading() + { + throw new NotImplementedException($"{nameof(ScheduledMeterOneMinuteReading)}请根据不同系统类型进行实现"); + } + + /// + /// 5分钟采集电表数据 + /// + /// + public virtual Task ScheduledMeterFiveMinuteReading() + { + throw new NotImplementedException($"{nameof(ScheduledMeterFiveMinuteReading)}请根据不同系统类型进行实现"); + } + + /// + /// 15分钟采集电表数据 + /// + /// + public virtual Task ScheduledMeterFifteenMinuteReading() + { + throw new NotImplementedException($"{nameof(ScheduledMeterFifteenMinuteReading)}请根据不同系统类型进行实现"); + } + } +} diff --git a/src/JiShe.CollectBus.Application/Workers/EnergySystemScheduledMeterReadingService.cs b/src/JiShe.CollectBus.Application/Workers/EnergySystemScheduledMeterReadingService.cs new file mode 100644 index 0000000..92a9861 --- /dev/null +++ b/src/JiShe.CollectBus.Application/Workers/EnergySystemScheduledMeterReadingService.cs @@ -0,0 +1,103 @@ +using FreeRedis; +using JiShe.CollectBus.Ammeters; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.FreeRedisProvider; +using JiShe.CollectBus.FreeSql; +using JiShe.CollectBus.Watermeter; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace JiShe.CollectBus.Workers +{ + /// + /// 能耗系统定时采集服务 + /// + [AllowAnonymous] + //[Route($"/energy/app/scheduled")] + public class EnergySystemScheduledMeterReadingService : BasicScheduledMeterReadingService + { + public sealed override string SystemType => SystemTypeConst.Energy; + + /// + /// 获取电表信息 + /// + /// 采集端Code + /// + //[HttpGet] + //[Route($"ammeter/list")] + public override async Task> GetAmmeterInfoList(string gatherCode = "V4-Gather-8890") + { + string sql = $@"SELECT C.ID,C.Name,C.FocusID,C.SingleRate,C.MeteringCode,C.Code AS BrandType,C.Baudrate,C.Password,C.MeteringPort,C.[Address] AS AmmerterAddress,C.TypeName,C.Protocol,C.TripState,C.[State],B.[Address],B.AreaCode,B.AutomaticReport,D.DataTypes,B.TimeDensity,A.GatherCode,C.Special,C.[ProjectID],B.AbnormalState,B.LastTime,CONCAT(B.AreaCode, B.[Address]) AS FocusAddress + FROM TB_GatherInfo(NOLOCK) AS A + INNER JOIN TB_FocusInfo(NOLOCK) AS B ON A.ID = B.GatherInfoID AND B.RemoveState >= 0 AND B.State>=0 + INNER JOIN TB_AmmeterInfo(NOLOCK) AS C ON B.ID = C.FocusID AND C.State>= 0 AND C.State<100 + INNER JOIN TB_AmmeterGatherItem(NOLOCK) AS D ON C.ID = D.AmmeterID AND D.State>=0 + WHERE 1=1 "; + + if (!string.IsNullOrWhiteSpace(gatherCode)) + { + sql = $@"{sql} A.GatherCode = '{gatherCode}'"; + } + return await SqlProvider.Instance.Change(DbEnum.EnergyDB) + .Ado + .QueryAsync(sql); + } + + /// + /// 获取水表信息 + /// + /// 采集端Code + /// + //[HttpGet] + //[Route($"ammeter/list")] + public override async Task> GetWatermeterInfoList(string gatherCode = "V4-Gather-8890") + { + string sql = $@"SELECT + A.ID, + A.Name, + A.FocusID, + A.MeteringCode, + A.Baudrate, + A.MeteringPort, + A.[Address] AS MeterAddress, + A.[Password], + A.TypeName, + A.Protocol, + A.Code, + A.LinkType, + A.HaveValve, + A.MeterType AS MeterTypeName, + A.MeterBrand, + A.TimesRate, + A.TimeDensity, + A.TripState, + B.[Address], + B.AreaCode, + B.AutomaticReport, + A.[State], + C.GatherCode, + A.[ProjectID], + B.AbnormalState, + B.LastTime + FROM [dbo].[TB_WatermeterInfo](NOLOCK) AS A + INNER JOIN [dbo].[TB_FocusInfo](NOLOCK) AS B ON A.FocusID=B.ID AND B.RemoveState >= 0 AND B.State>=0 + INNER JOIN [dbo].[TB_GatherInfo](NOLOCK) AS C ON B.GatherInfoID=C.ID + WHERE A.State>=0 AND A.State<100 "; + + if (!string.IsNullOrWhiteSpace(gatherCode)) + { + sql = $@"{sql} AND C.GatherCode= '{gatherCode}'"; + } + return await SqlProvider.Instance.Change(DbEnum.EnergyDB) + .Ado + .QueryAsync(sql); + } + + } +} \ No newline at end of file diff --git a/src/JiShe.CollectBus.Application/Workers/ScheduledMeterReadingService.cs b/src/JiShe.CollectBus.Application/Workers/ScheduledMeterReadingService.cs deleted file mode 100644 index 9673490..0000000 --- a/src/JiShe.CollectBus.Application/Workers/ScheduledMeterReadingService.cs +++ /dev/null @@ -1,27 +0,0 @@ -using FreeRedis; -using JiShe.CollectBus.FreeRedisProvider; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; - -namespace JiShe.CollectBus.Workers -{ - /// - /// 定时采集服务 - /// - public class ScheduledMeterReadingService : CollectBusAppService, IScheduledMeterReadingService - { - /// - /// 初始化能耗电表数据 - /// - /// - public async Task InitEnergyAmmeterData() - { - var ammerterList = await GetAmmetersByGatherCode(); - } - } -} \ No newline at end of file diff --git a/src/JiShe.CollectBus.Application/Workers/WorkerSubscriberAppService.cs b/src/JiShe.CollectBus.Application/Workers/WorkerSubscriberAppService.cs index 1ddaeea..6c7bfab 100644 --- a/src/JiShe.CollectBus.Application/Workers/WorkerSubscriberAppService.cs +++ b/src/JiShe.CollectBus.Application/Workers/WorkerSubscriberAppService.cs @@ -8,6 +8,7 @@ using JiShe.CollectBus.Devices; using JiShe.CollectBus.MessageReceiveds; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using TouchSocket.Sockets; @@ -19,6 +20,7 @@ namespace JiShe.CollectBus.Subscribers /// /// 定时抄读任务消息消费订阅 /// + [Route($"/worker/app/subscriber")] public class WorkerSubscriberAppService : CollectBusAppService, IWorkerSubscriberAppService,ICapSubscribe { private readonly ILogger _logger; @@ -45,6 +47,8 @@ namespace JiShe.CollectBus.Subscribers /// /// /// + [HttpPost] + [Route("oneminute/issued-event")] [CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)] public async Task ScheduledMeterOneMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage) { @@ -65,6 +69,8 @@ namespace JiShe.CollectBus.Subscribers /// /// /// + [HttpPost] + [Route("fiveminute/issued-event")] [CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)] public async Task ScheduledMeterFiveMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage) { @@ -85,6 +91,8 @@ namespace JiShe.CollectBus.Subscribers /// /// /// + [HttpPost] + [Route("fifteenminute/issued-event")] [CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)] public async Task ScheduledMeterFifteenMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage) { diff --git a/src/JiShe.CollectBus.Common/Consts/FreeRedisConst.cs b/src/JiShe.CollectBus.Common/Consts/FreeRedisConst.cs index 96661d8..ae37f9d 100644 --- a/src/JiShe.CollectBus.Common/Consts/FreeRedisConst.cs +++ b/src/JiShe.CollectBus.Common/Consts/FreeRedisConst.cs @@ -12,9 +12,15 @@ namespace JiShe.CollectBus.Common.Consts /// 缓存基础目录 /// public const string CacheBasicDirectoryKey = "CollectBus:"; + /// /// 缓存电表信息 /// - public const string CacheAmmeterInfoKey = $"{CacheBasicDirectoryKey}AmmeterInfo:"; + public const string CacheAmmeterInfoKey = $"{CacheBasicDirectoryKey}{"{0}"}:AmmeterInfo:"; + + /// + /// 缓存水表信息 + /// + public const string CacheWatermeterInfoKey = $"{CacheBasicDirectoryKey}{"{0}"}:WatermeterInfo:"; } } diff --git a/src/JiShe.CollectBus.Common/Consts/SystemTypeConst.cs b/src/JiShe.CollectBus.Common/Consts/SystemTypeConst.cs new file mode 100644 index 0000000..fd37fd9 --- /dev/null +++ b/src/JiShe.CollectBus.Common/Consts/SystemTypeConst.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Common.Consts +{ + /// + /// 系统类型常量 + /// + public class SystemTypeConst + { + /// + /// 预付费系统 + /// + public const string Prepay = "Prepay"; + + /// + /// 能耗系统 + /// + public const string Energy = "Energy"; + } +} diff --git a/src/JiShe.CollectBus.Common/Enums/MeterTypeEnum.cs b/src/JiShe.CollectBus.Common/Enums/MeterTypeEnum.cs new file mode 100644 index 0000000..43cfaae --- /dev/null +++ b/src/JiShe.CollectBus.Common/Enums/MeterTypeEnum.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Common.Enums +{ + /// + /// 表计类型 + /// 电表= 1,水表= 2,燃气表= 3,热能表= 4,水表流量计=5,燃气表流量计=6 + /// + public enum MeterTypeEnum + { + /// + /// 电表 + /// + Ammeter = 1, + /// + /// 水表 + /// + WaterMeter = 2, + /// + /// 燃气表 + /// + Gasmeter = 3, + /// + /// 热能表 + /// + HeatMeter = 4, + /// + /// 水表流量计 + /// + WaterMeterFlowmeter = 5, + /// + /// 燃气表流量计 + /// + GasmeterFlowmeter = 6, + /// + /// 特殊电表 + /// + SpecialAmmeter = 7, + /// + /// 传感器 + /// + Sensor = 8, + + /// + /// 采集器 + /// + Collector = 9, + } +} diff --git a/src/JiShe.CollectBus.Domain/Ammeters/AmmeterInfo.cs b/src/JiShe.CollectBus.Domain/Ammeters/AmmeterInfo.cs index aabbd32..7dce8ac 100644 --- a/src/JiShe.CollectBus.Domain/Ammeters/AmmeterInfo.cs +++ b/src/JiShe.CollectBus.Domain/Ammeters/AmmeterInfo.cs @@ -12,6 +12,7 @@ namespace JiShe.CollectBus.Ammeters /// 电表ID /// public int ID { get; set; } + /// /// 电表名称 /// @@ -22,6 +23,11 @@ namespace JiShe.CollectBus.Ammeters /// public int FocusID { get; set; } + /// + /// 集中器地址 + /// + public string FocusAddress { get; set; } + /// /// 集中器地址 /// @@ -129,16 +135,12 @@ namespace JiShe.CollectBus.Ammeters /// 项目ID /// public int ProjectID { get; set; } + /// /// 是否异常集中器 0:正常,1异常 /// public int AbnormalState { get; set; } - public DateTime LastTime { get; set; } - - /// - /// 集中器地址 - /// - public string FocusAddress { get; set; } + public DateTime LastTime { get; set; } } } diff --git a/src/JiShe.CollectBus.Application.Contracts/Workers/DTO/Energy/EnergyAmmeterInfoDto.cs b/src/JiShe.CollectBus.Domain/Watermeter/WatermeterInfo.cs similarity index 59% rename from src/JiShe.CollectBus.Application.Contracts/Workers/DTO/Energy/EnergyAmmeterInfoDto.cs rename to src/JiShe.CollectBus.Domain/Watermeter/WatermeterInfo.cs index 7836840..dd7e125 100644 --- a/src/JiShe.CollectBus.Application.Contracts/Workers/DTO/Energy/EnergyAmmeterInfoDto.cs +++ b/src/JiShe.CollectBus.Domain/Watermeter/WatermeterInfo.cs @@ -1,67 +1,46 @@ -using System; +using JiShe.CollectBus.Common.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace JiShe.CollectBus.Workers.DTO.Energy +namespace JiShe.CollectBus.Watermeter { /// - /// 能耗电表信息数据模型 + /// 水表信息 /// - public class EnergyAmmeterInfoDto + public class WatermeterInfo { /// - /// 电表ID + /// 水表ID /// public int ID { get; set; } + /// - /// 电表名称 + /// 水表名称 /// public string Name { get; set; } + /// + /// 表密码 + /// + public string Password { get; set; } /// /// 集中器ID /// public int FocusID { get; set; } - + /// /// 集中器地址 /// - public string Address { get; set; } - - /// - /// 集中器区域代码 - /// - public string AreaCode { get; set; } - - /// - /// 电表类别 (1单相、2三相三线、3三相四线), - /// 07协议: 开合闸指令(1A开闸断电,1C单相表合闸,1B多相表合闸) 645 2007 表 - /// 97协议://true(合闸);false(跳闸) 545 1997 没有单相多相 之分 "true" ? "9966" : "3355" - /// - public int TypeName { get; set; } - /// - /// 跳合闸状态字段: 0 合闸,1 跳闸 - /// 电表:TripState (0 合闸-通电, 1 断开、跳闸); - /// - public int TripState { get; set; } - - /// - /// 规约 -电表default(30) 1:97协议,30:07协议 - /// - public int? Protocol { get; set; } + public string FocusAddress { get; set; } /// /// 一个集中器下的[MeteringCode]必须唯一。 PN /// public int MeteringCode { get; set; } - /// - /// 电表通信地址 - /// - public string AmmerterAddress { get; set; } - /// /// 波特率 default(2400) /// @@ -73,74 +52,107 @@ namespace JiShe.CollectBus.Workers.DTO.Energy public int MeteringPort { get; set; } /// - /// 电表密码 + /// 水表通信地址 (当protocol=32时,Address为14位字符;否则12位字符) /// - public string Password { get; set; } + public string MeterAddress { get; set; } /// - /// 采集时间间隔(分钟,如15) + /// 水表类别 (水表类型改成“公称口径”) /// - public int TimeDensity { get; set; } + public string TypeName { get; set; } /// - /// 该电表方案下采集项,如:0D_80 + /// 规约 -电表default(30) 1:97协议,30:07协议,32:CJ/T 188—2018协议 /// - public string ItemCodes { get; set; } + public int? Protocol { get; set; } + + public string Code { get; set; } + /// + /// 通讯方案: + /// NB-IOT常德水表、NB-IOT泽联电表、GPRS华立水表、 + /// RS-485、无线、载波 + /// + public string LinkType { get; set; } + + /// + /// HaveValve: 是否带阀 (0 不带阀, 1 带阀) + /// 注意:NULL表示未设置 + /// + public int? HaveValve { get; set; } + + /// + /// 设备类型: 水表\气表、流量计 + /// + public string MeterTypeName { get; set; } + + /// + /// 表计类型 + //// 电表= 1,水表= 2,燃气表= 3,热能表= 4,水表流量计=5,燃气表流量计=6,特殊电表=7 + /// + public MeterTypeEnum MeterType { get; set; } + /// + /// 设备品牌; + /// (当 MeterType = 水表, 如 威铭、捷先 等) + /// (当 MeterType = 流量计, 如 西恩超声波流量计、西恩电磁流量计、涡街流量计 等) + /// + public string MeterBrand { get; set; } + + /// + /// 倍率 + /// + public decimal TimesRate { get; set; } + + /// + /// 集中器地址 + /// + public string Address { get; set; } + + /// + /// 网关地址 + /// + public string GateAddress { get; set; } + /// + /// 集中器区域 + /// + public string AreaCode { get; set; } + /// + /// 通讯状态 + /// 水表:TripState (0 合闸-开阀, 1 关阀);开阀关阀 + /// + public int TripState { get; set; } + /// + /// 是否自动采集 + /// + public int AutomaticReport { get; set; } /// /// State表状态: /// 0新装(未下发),1运行(档案下发成功时设置状态值1), 2暂停, 100销表(销表后是否重新启用) /// 特定:State -1 已删除 /// public int State { get; set; } - /// - /// 是否自动采集(0:主动采集,1:自动采集) + /// 采集时间间隔(分钟,如15) /// - public int AutomaticReport { get; set; } - - /// - /// 该电表方案下采集项编号 - /// - public string DataTypes { get; set; } - - /// - /// 品牌型号 - /// - public string BrandType { get; set; } - + public int TimeDensity { get; set; } /// /// 采集器编号 /// public string GatherCode { get; set; } - - /// - /// 是否特殊表 - /// - public int Special { get; set; } - - /// - /// 费率类型,单、多 (SingleRate :单费率(单相表1),多费率(其他0) ,与TypeName字段无关) - /// SingleRate ? "单" : "复" - /// [SingleRate] --0 复费率 false , 1 单费率 true (与PayPlanID保持一致) - ///对应 TB_PayPlan.Type: 1复费率,2单费率 - /// - public bool SingleRate { get; set; } - + /// /// 项目ID /// public int ProjectID { get; set; } + /// /// 是否异常集中器 0:正常,1异常 /// public int AbnormalState { get; set; } - public DateTime LastTime { get; set; } - /// - /// 集中器地址 + /// 集中器最后在线时间 /// - public string FocusAddress { get; set; } + public DateTime LastTime { get; set; } } }