2025-07-24 17:06:54 +08:00
|
|
|
|
using JiShe.IoT.OneNETAggregation.Dto;
|
|
|
|
|
|
using JiShe.ServicePro;
|
2025-08-04 17:29:47 +08:00
|
|
|
|
using JiShe.ServicePro.Core;
|
|
|
|
|
|
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
|
|
|
|
|
|
using JiShe.ServicePro.Dto;
|
2025-07-24 17:06:54 +08:00
|
|
|
|
using JiShe.ServicePro.Encrypt;
|
|
|
|
|
|
using JiShe.ServicePro.Enums;
|
|
|
|
|
|
using JiShe.ServicePro.Kafka.Consts;
|
|
|
|
|
|
using JiShe.ServicePro.Kafka.Producer;
|
|
|
|
|
|
using JiShe.ServicePro.ServerOptions;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.IoT.BusinessSystemAggregation
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 业务系统聚合服务
|
|
|
|
|
|
/// </summary>
|
2025-08-04 17:29:47 +08:00
|
|
|
|
public class BusinessSystemAggregationService(IOptions<ServerApplicationOptions> options, IKafkaProducerService _producerService, IDeviceAppService deviceAppService) : IoTAppService, IBusinessSystemAggregationService
|
2025-07-24 17:06:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
ServerApplicationOptions srverOptions = options.Value;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 接收业务系统指令信息,缓存进Kafka
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
|
|
|
|
|
|
if (verifySignatureReult == false)//签名校验失败
|
|
|
|
|
|
{
|
2025-08-04 17:29:47 +08:00
|
|
|
|
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
2025-07-24 17:06:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(input.Message))
|
|
|
|
|
|
{
|
2025-08-04 17:29:47 +08:00
|
|
|
|
return HttpDataResultExtensions.Failed("指令下发内容不能为空", -102, ResponeResultEnum.Fail);
|
2025-07-24 17:06:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-04 17:29:47 +08:00
|
|
|
|
//查询设备信息,判断设备在哪个平台
|
|
|
|
|
|
var messageBody = input.Message.Deserialize<ReceiveCommandInfoDto>();
|
|
|
|
|
|
|
|
|
|
|
|
//限定来源类型必须为业务系统
|
|
|
|
|
|
if (messageBody.SourceType != DeviceTelemetrySourceTypeEnum.BusinessSystem)
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed("设备指令来源类型错误,业务系统传固定值2", -103, ResponeResultEnum.Fail);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var deviceInfo = await deviceAppService.FindByDeviceAddressAsync(messageBody.DeviceAddress);
|
|
|
|
|
|
|
|
|
|
|
|
//将指令存储Kafka的OneNET主题中
|
|
|
|
|
|
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", input);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _producerService.ProduceAsync(KafkaTopicConsts.CTWingAepCommandIssuedEventName, $"{GuidGenerator.Create()}", input);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed("指令处理失败,当前设备平台类型异常",-104);
|
|
|
|
|
|
}
|
2025-07-24 17:06:54 +08:00
|
|
|
|
|
|
|
|
|
|
return HttpDataResultExtensions.Success("指令下发Kafka成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|