增加下发采集项定时任务
This commit is contained in:
parent
02839e58f1
commit
da08522bfd
@ -2,7 +2,7 @@
|
||||
<!-- 定义项目加载属性 -->
|
||||
<PropertyGroup>
|
||||
<!--JiShe.ServicePro版本-->
|
||||
<ServiceProVersion>1.0.5.23</ServiceProVersion>
|
||||
<ServiceProVersion>1.0.5.27</ServiceProVersion>
|
||||
<!--Volo Abp 版本-->
|
||||
<VoloAbpVersion>9.1.1</VoloAbpVersion>
|
||||
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
using JiShe.CollectBus.Ammeters;
|
||||
using Confluent.Kafka;
|
||||
using JiShe.CollectBus.Ammeters;
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Helpers;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.IotSystems.Devices;
|
||||
using JiShe.CollectBus.IotSystems.PrepayModel;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.FreeSqlProvider;
|
||||
using JiShe.ServicePro.Kafka.Internal;
|
||||
using JiShe.ServicePro.Kafka.Producer;
|
||||
@ -14,6 +18,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using TouchSocket.Sockets;
|
||||
using static FreeSql.Internal.GlobalFilter;
|
||||
|
||||
namespace JiShe.CollectBus.Samples;
|
||||
|
||||
@ -26,8 +31,10 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
|
||||
|
||||
private readonly IProducerService _producerService;
|
||||
private readonly ITcpService _tcpService;
|
||||
|
||||
private readonly IFreeRedisProvider _freeRedisProvider;
|
||||
public SampleAppService(IoTDBSessionPoolProvider iotDBProvider, IOptions<IoTDbOptions> options,
|
||||
ILogger<SampleAppService> logger, IRedisDataCacheService redisDataCacheService, IProducerService producerService, ITcpService tcpService)
|
||||
ILogger<SampleAppService> logger, IRedisDataCacheService redisDataCacheService, IProducerService producerService, ITcpService tcpService, IFreeRedisProvider freeRedisProvider)
|
||||
{
|
||||
_iotDBProvider = iotDBProvider;
|
||||
_options = options.Value;
|
||||
@ -35,6 +42,7 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
|
||||
_redisDataCacheService = redisDataCacheService;
|
||||
_producerService = producerService;
|
||||
_tcpService = tcpService;
|
||||
_freeRedisProvider = freeRedisProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -400,5 +408,40 @@ public class SampleAppService : CollectBusAppService, ISampleAppService, IKafkaS
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置集中器采集项
|
||||
/// </summary>
|
||||
/// <param name="focusAddress"></param>
|
||||
/// <param name="meterAddress"></param>
|
||||
/// <param name="cycle">值可选(15,5)</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public async Task<string> AutoCollectionItemsSet(string focusAddress, string meterAddress,int cycle)
|
||||
{
|
||||
var key = $"{RedisConst.CacheAllDeviceInfoHashKey}";
|
||||
List<DeviceCacheInfo> deviceCacheInfos= await _freeRedisProvider.Instance.HGetAsync<List<DeviceCacheInfo>>(key, focusAddress);
|
||||
if (deviceCacheInfos == null || deviceCacheInfos.Count <= 0)
|
||||
{
|
||||
throw new Exception($"未能在缓存中找到设备{focusAddress},缓存key:{key}");
|
||||
}
|
||||
DeviceCacheInfo? deviceCacheInfo = deviceCacheInfos.FirstOrDefault(d => d.MeterAddress == meterAddress);
|
||||
if (deviceCacheInfo == null) {
|
||||
throw new Exception($"未能在缓存中找到设备{focusAddress}下的表{meterAddress},缓存key:{key}");
|
||||
}
|
||||
|
||||
var details = deviceCacheInfo.ItemCodes.Where(n => n.Trim().Substring(0, 3) == "0D_").Select(it => new PnFn(1, Convert.ToInt32(it.Split('_')[1]))).ToList();
|
||||
var bytes = Build3761SendData.BuildAmmeterReportCollectionItemsSetSendCmd(focusAddress, 1, 0, cycle, DateTime.Now,1, details);
|
||||
|
||||
string frame = bytes.ToHexString();
|
||||
await _producerService.ProduceAsync<KafkaSendDto>(KafkaTopicConsts.TESTSENDTOPIC, new KafkaSendDto() {
|
||||
Address = focusAddress,
|
||||
Frame = frame
|
||||
});
|
||||
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Samples;
|
||||
using JiShe.ServicePro.Dto;
|
||||
using JiShe.ServicePro.FreeRedisProvider;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -16,19 +21,21 @@ namespace JiShe.CollectBus.Subscribers
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IoTDBSessionPoolProvider _dbProvider;
|
||||
private readonly IProtocolService _protocolService;
|
||||
|
||||
private readonly IFreeRedisProvider _freeRedisProvider;
|
||||
|
||||
public ServiceCommunicationChannelSubscriberService(ILogger<SubscriberAnalysisAppService> logger,
|
||||
ITcpService tcpService,
|
||||
IServiceProvider serviceProvider,
|
||||
IoTDBSessionPoolProvider dbProvider,
|
||||
IProtocolService protocolService)
|
||||
IProtocolService protocolService,
|
||||
IFreeRedisProvider freeRedisProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_tcpService = tcpService;
|
||||
_serviceProvider = serviceProvider;
|
||||
_dbProvider = dbProvider;
|
||||
_protocolService = protocolService;
|
||||
_freeRedisProvider = freeRedisProvider;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +51,7 @@ namespace JiShe.CollectBus.Subscribers
|
||||
var tempFirstKeyInfo = issuedMessage.FirstOrDefault();
|
||||
if (tempFirstKeyInfo.Value == null)
|
||||
{
|
||||
return SubscribeAck.Fail();
|
||||
return SubscribeAck.Success();
|
||||
}
|
||||
|
||||
ServiceCommunicationTypeEnum serviceCommunication = tempFirstKeyInfo.Key;
|
||||
@ -54,8 +61,31 @@ namespace JiShe.CollectBus.Subscribers
|
||||
case ServiceCommunicationTypeEnum.ArchivalDataIssued:
|
||||
if(!string.IsNullOrWhiteSpace(tempFirstKeyInfo.Value))
|
||||
{
|
||||
FocusCacheInfos focusCacheInfo = tempFirstKeyInfo.Value.Deserialize<FocusCacheInfos>();
|
||||
tempResult = await SendArchivalDataIssued(focusCacheInfo);
|
||||
// 解析数据
|
||||
// 判断电表,水表,气表 下发档案
|
||||
ArchivalDataIssuedInput? input = tempFirstKeyInfo.Value.Deserialize<ArchivalDataIssuedInput>();
|
||||
if (input != null)
|
||||
{
|
||||
switch (input.MeterType)
|
||||
{
|
||||
case MeterTypeEnum.Ammeter:
|
||||
|
||||
break;
|
||||
case MeterTypeEnum.WaterMeter:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
//tempResult = await SendArchivalDataIssued(focusCacheInfo);
|
||||
}
|
||||
break;
|
||||
case ServiceCommunicationTypeEnum.SetItemCodeTask:
|
||||
if(!string.IsNullOrWhiteSpace(tempFirstKeyInfo.Value)){
|
||||
SetItemCodeTaskInput? input = tempFirstKeyInfo.Value!.Deserialize<SetItemCodeTaskInput>();
|
||||
if(input != null)
|
||||
{
|
||||
await AutoCollectionItemsSetAsync(input);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -87,5 +117,55 @@ namespace JiShe.CollectBus.Subscribers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动采集项目设置
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> AutoCollectionItemsSetAsync(SetItemCodeTaskInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = $"{RedisConst.CacheAllDeviceInfoHashKey}";
|
||||
List<DeviceCacheInfo> deviceCacheInfos = await _freeRedisProvider.Instance.HGetAsync<List<DeviceCacheInfo>>(key, input.FocusAddress);
|
||||
if (deviceCacheInfos == null || deviceCacheInfos.Count <= 0)
|
||||
{
|
||||
throw new Exception($"未能在缓存中找到设备{input.FocusAddress},缓存key:{key}");
|
||||
}
|
||||
DeviceCacheInfo? deviceCacheInfo = deviceCacheInfos.FirstOrDefault(d => d.MeterAddress == input.MeterAddress);
|
||||
if (deviceCacheInfo == null)
|
||||
{
|
||||
throw new Exception($"未能在缓存中找到设备{input.FocusAddress}下的表{input.MeterAddress},缓存key:{key}");
|
||||
}
|
||||
|
||||
var details = deviceCacheInfo.ItemCodes.Where(n => n.Trim().Substring(0, 3) == "0D_").Select(it => new PnFn(1, Convert.ToInt32(it.Split('_')[1]))).ToList();
|
||||
var bytes = Build3761SendData.BuildAmmeterReportCollectionItemsSetSendCmd(input.FocusAddress, 1, 0, input.Cycle, DateTime.Now, 1, details);
|
||||
|
||||
string frame = bytes.ToHexString();
|
||||
|
||||
// TODO: 需要插入iotdb 日志
|
||||
|
||||
|
||||
var checkResult = _tcpService.ClientExists(input.FocusAddress);
|
||||
if (checkResult)
|
||||
{
|
||||
await _tcpService.SendAsync(input.FocusAddress, bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1731,7 +1731,7 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
list.AddRange(dA);
|
||||
list.AddRange(dT);
|
||||
|
||||
if (dataUnit != null)
|
||||
if (dataUnit != null && dataUnit.Count > 0)
|
||||
{
|
||||
list.AddRange(dataUnit);
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting.Internal;
|
||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
|
||||
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
|
||||
using Volo.Abp.AspNetCore.Serilog;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Caching.StackExchangeRedis;
|
||||
@ -57,6 +58,13 @@ namespace JiShe.CollectBus.Host
|
||||
.AddDataProtection()
|
||||
.PersistKeysToStackFreeRedis("JiSheCollectBus-Protection-Keys");
|
||||
|
||||
// DOTO:abp swagger调用抽风 提示 The antiforgery token could not be decrypted.
|
||||
Configure<AbpAntiForgeryOptions>(options =>
|
||||
{
|
||||
options.TokenCookie.Expiration = TimeSpan.Zero;
|
||||
options.AutoValidate = false; //表示不验证防伪令牌
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user