2025-03-12 09:58:37 +08:00
|
|
|
|
using System;
|
2025-03-20 16:40:27 +08:00
|
|
|
|
using System.Collections.Generic;
|
2025-03-12 09:58:37 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using DeviceDetectorNET.Parser.Device;
|
|
|
|
|
|
using DotNetCore.CAP;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-03-14 14:28:04 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
2025-03-17 14:23:48 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.MessageIssueds;
|
|
|
|
|
|
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
2025-03-20 16:40:27 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
2025-03-12 09:58:37 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
2025-03-20 16:40:27 +08:00
|
|
|
|
using JiShe.CollectBus.Repository.MeterReadingRecord;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2025-03-12 09:58:37 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using TouchSocket.Sockets;
|
|
|
|
|
|
using Volo.Abp.Caching;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Subscribers
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 定时抄读任务消息消费订阅
|
|
|
|
|
|
/// </summary>
|
2025-03-12 14:57:42 +08:00
|
|
|
|
[Route($"/worker/app/subscriber")]
|
2025-03-12 09:58:37 +08:00
|
|
|
|
public class WorkerSubscriberAppService : CollectBusAppService, IWorkerSubscriberAppService,ICapSubscribe
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<WorkerSubscriberAppService> _logger;
|
|
|
|
|
|
private readonly ITcpService _tcpService;
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2025-03-13 10:51:16 +08:00
|
|
|
|
private readonly IRepository<Device, Guid> _deviceRepository;
|
2025-03-20 16:40:27 +08:00
|
|
|
|
private readonly IMeterReadingRecordRepository _meterReadingRecordsRepository;
|
2025-03-12 09:58:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="WorkerSubscriberAppService"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
|
/// <param name="tcpService">The TCP service.</param>
|
2025-03-18 15:58:37 +08:00
|
|
|
|
/// <param name="deviceRepository">The Device pepository.</param>
|
2025-03-12 09:58:37 +08:00
|
|
|
|
/// <param name="serviceProvider">The service provider.</param>
|
|
|
|
|
|
public WorkerSubscriberAppService(ILogger<WorkerSubscriberAppService> logger,
|
2025-03-13 10:51:16 +08:00
|
|
|
|
ITcpService tcpService,
|
|
|
|
|
|
IRepository<Device, Guid> deviceRepository,
|
2025-03-20 16:40:27 +08:00
|
|
|
|
IMeterReadingRecordRepository meterReadingRecordsRepository,
|
2025-03-13 10:51:16 +08:00
|
|
|
|
IServiceProvider serviceProvider)
|
2025-03-12 09:58:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_tcpService = tcpService;
|
2025-03-13 10:51:16 +08:00
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
|
_deviceRepository = deviceRepository;
|
2025-03-20 16:40:27 +08:00
|
|
|
|
_meterReadingRecordsRepository = meterReadingRecordsRepository;
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
2025-04-08 17:44:42 +08:00
|
|
|
|
#region 电表消息采集
|
2025-03-20 16:40:27 +08:00
|
|
|
|
|
2025-03-13 10:51:16 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一分钟定时抄读任务消息消费订阅
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("ammeter/oneminute/issued-event")]
|
|
|
|
|
|
[CapSubscribe(ProtocolConst.AmmeterSubscriberWorkerOneMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task AmmeterScheduledMeterOneMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-13 10:51:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger.LogInformation("1分钟采集电表数据下行消息消费队列开始处理");
|
|
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError("【1分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-21 15:07:38 +08:00
|
|
|
|
var device = await _deviceRepository.FirstOrDefaultAsync(a => a.Number == receivedMessage.FocusAddress);
|
2025-03-13 10:51:16 +08:00
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5分钟采集电表数据下行消息消费订阅
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("ammeter/fiveminute/issued-event")]
|
2025-03-17 11:34:30 +08:00
|
|
|
|
[CapSubscribe(ProtocolConst.AmmeterSubscriberWorkerFiveMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task AmmeterScheduledMeterFiveMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-13 10:51:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger.LogInformation("5分钟采集电表数据下行消息消费队列开始处理");
|
|
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError("【5分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-21 15:07:38 +08:00
|
|
|
|
var device = await _deviceRepository.FirstOrDefaultAsync(a => a.Number == receivedMessage.FocusAddress);
|
2025-03-13 10:51:16 +08:00
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 15分钟采集电表数据下行消息消费订阅
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("ammeter/fifteenminute/issued-event")]
|
2025-03-17 11:34:30 +08:00
|
|
|
|
[CapSubscribe(ProtocolConst.AmmeterSubscriberWorkerFifteenMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task AmmeterScheduledMeterFifteenMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-13 10:51:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger.LogInformation("15分钟采集电表数据下行消息消费队列开始处理");
|
2025-03-21 11:48:31 +08:00
|
|
|
|
try
|
2025-03-13 10:51:16 +08:00
|
|
|
|
{
|
2025-03-21 11:48:31 +08:00
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
2025-03-13 10:51:16 +08:00
|
|
|
|
{
|
2025-03-21 11:48:31 +08:00
|
|
|
|
_logger.LogError("【15分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-04-08 17:44:42 +08:00
|
|
|
|
{
|
2025-03-21 11:48:31 +08:00
|
|
|
|
var device = await _deviceRepository.FirstOrDefaultAsync(a => a.Number == receivedMessage.FocusAddress);
|
|
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
2025-03-21 11:48:31 +08:00
|
|
|
|
}
|
2025-03-13 10:51:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-21 11:48:31 +08:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
}
|
2025-03-13 10:51:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 水表消息采集
|
2025-03-12 09:58:37 +08:00
|
|
|
|
/// <summary>
|
2025-04-09 14:31:48 +08:00
|
|
|
|
/// 1分钟采集水表数据下行消息消费订阅
|
2025-03-12 09:58:37 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-03-12 14:57:42 +08:00
|
|
|
|
[HttpPost]
|
2025-03-13 10:51:16 +08:00
|
|
|
|
[Route("watermeter/oneminute/issued-event")]
|
|
|
|
|
|
[CapSubscribe(ProtocolConst.WatermeterSubscriberWorkerOneMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task WatermeterScheduledMeterOneMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-12 09:58:37 +08:00
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogInformation("1分钟采集水表数据下行消息消费队列开始处理");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogError("【1分钟采集水表数据下行消息消费队列开始处理】协议不存在!");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
var device = await _deviceRepository.FindAsync(a => a.Number == receivedMessage.FocusAddress);
|
2025-03-13 10:51:16 +08:00
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-09 14:31:48 +08:00
|
|
|
|
/// 5分钟采集水表数据下行消息消费订阅
|
2025-03-12 09:58:37 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-03-12 14:57:42 +08:00
|
|
|
|
[HttpPost]
|
2025-03-13 10:51:16 +08:00
|
|
|
|
[Route("watermeter/fiveminute/issued-event")]
|
2025-04-09 14:31:48 +08:00
|
|
|
|
[CapSubscribe(ProtocolConst.WatermeterSubscriberWorkerFiveMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task WatermeterScheduledMeterFiveMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-12 09:58:37 +08:00
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogInformation("5分钟采集水表数据下行消息消费队列开始处理");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogError("【5分钟采集水表数据下行消息消费队列开始处理】协议不存在!");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
var device = await _deviceRepository.FindAsync(a => a.Number == receivedMessage.FocusAddress);
|
2025-03-13 10:51:16 +08:00
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-09 14:31:48 +08:00
|
|
|
|
/// 15分钟采集水表数据下行消息消费订阅
|
2025-03-12 09:58:37 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="receivedMessage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-03-12 14:57:42 +08:00
|
|
|
|
[HttpPost]
|
2025-03-13 10:51:16 +08:00
|
|
|
|
[Route("watermeter/fifteenminute/issued-event")]
|
2025-04-09 14:31:48 +08:00
|
|
|
|
[CapSubscribe(ProtocolConst.WatermeterSubscriberWorkerFifteenMinuteIssuedEventName)]
|
2025-03-14 17:28:58 +08:00
|
|
|
|
public async Task WatermeterScheduledMeterFifteenMinuteReadingIssuedEvent(ScheduledMeterReadingIssuedEventMessage receivedMessage)
|
2025-03-12 09:58:37 +08:00
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogInformation("15分钟采集水表数据下行消息消费队列开始处理");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
_logger.LogError("【15分钟采集水表数据下行消息消费队列开始处理】协议不存在!");
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
var device = await _deviceRepository.FindAsync(a => a.Number == receivedMessage.FocusAddress);
|
2025-03-13 10:51:16 +08:00
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
2025-03-18 22:43:24 +08:00
|
|
|
|
await _tcpService.SendAsync(device.ClientId, Convert.FromHexString(receivedMessage.MessageHexString));
|
2025-03-13 10:51:16 +08:00
|
|
|
|
}
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-13 10:51:16 +08:00
|
|
|
|
#endregion
|
2025-03-12 09:58:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|