104 lines
4.3 KiB
C#
104 lines
4.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using DeviceDetectorNET.Parser.Device;
|
|||
|
|
using DotNetCore.CAP;
|
|||
|
|
using JiShe.CollectBus.Common.Enums;
|
|||
|
|
using JiShe.CollectBus.Common.Models;
|
|||
|
|
using JiShe.CollectBus.Devices;
|
|||
|
|
using JiShe.CollectBus.MessageReceiveds;
|
|||
|
|
using JiShe.CollectBus.Protocol.Contracts;
|
|||
|
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
|||
|
|
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>
|
|||
|
|
public class WorkerSubscriberAppService : CollectBusAppService, IWorkerSubscriberAppService,ICapSubscribe
|
|||
|
|
{
|
|||
|
|
private readonly ILogger<WorkerSubscriberAppService> _logger;
|
|||
|
|
private readonly ITcpService _tcpService;
|
|||
|
|
private readonly IServiceProvider _serviceProvider;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <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>
|
|||
|
|
/// <param name="serviceProvider">The service provider.</param>
|
|||
|
|
public WorkerSubscriberAppService(ILogger<WorkerSubscriberAppService> logger,
|
|||
|
|
ITcpService tcpService, IServiceProvider serviceProvider)
|
|||
|
|
{
|
|||
|
|
_logger = logger;
|
|||
|
|
_tcpService = tcpService;
|
|||
|
|
_serviceProvider = serviceProvider;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 一分钟定时抄读任务消息消费订阅
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="receivedMessage"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)]
|
|||
|
|
public async Task ScheduledMeterOneMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage)
|
|||
|
|
{
|
|||
|
|
_logger.LogInformation("1分钟采集电表数据下行消息消费队列开始处理");
|
|||
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|||
|
|
if (protocolPlugin == null)
|
|||
|
|
{
|
|||
|
|
_logger.LogError("【1分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
await _tcpService.SendAsync(receivedMessage.ClientId, receivedMessage.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 5分钟采集电表数据下行消息消费订阅
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="receivedMessage"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)]
|
|||
|
|
public async Task ScheduledMeterFiveMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage)
|
|||
|
|
{
|
|||
|
|
_logger.LogInformation("5分钟采集电表数据下行消息消费队列开始处理");
|
|||
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|||
|
|
if (protocolPlugin == null)
|
|||
|
|
{
|
|||
|
|
_logger.LogError("【5分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
await _tcpService.SendAsync(receivedMessage.ClientId, receivedMessage.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 15分钟采集电表数据下行消息消费订阅
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="receivedMessage"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[CapSubscribe(ProtocolConst.SubscriberWorkerOneMinuteIssuedEventName)]
|
|||
|
|
public async Task ScheduledMeterFifteenMinuteReadingIssuedEvent(IssuedEventMessage receivedMessage)
|
|||
|
|
{
|
|||
|
|
_logger.LogInformation("15分钟采集电表数据下行消息消费队列开始处理");
|
|||
|
|
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
|||
|
|
if (protocolPlugin == null)
|
|||
|
|
{
|
|||
|
|
_logger.LogError("【15分钟采集电表数据下行消息消费队列开始处理】协议不存在!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
await _tcpService.SendAsync(receivedMessage.ClientId, receivedMessage.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|