Compare commits
3 Commits
fd30054a8b
...
45e52b9f1f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45e52b9f1f | ||
|
|
8f78a15cbc | ||
|
|
ff8fd898f6 |
@ -1 +1 @@
|
|||||||
Subproject commit 8df0a54f551a1f894014c9b0e8eca5d7c5c4f51b
|
Subproject commit db06f880158a1bb85996b0f7e08153943fd9e40c
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using JiShe.ServicePro.Enums;
|
using JiShe.ServicePro.Core;
|
||||||
|
using JiShe.ServicePro.Enums;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace JiShe.IoT.DeviceAggregation
|
namespace JiShe.IoT.DeviceAggregation
|
||||||
@ -7,26 +8,8 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备命令
|
/// 设备命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DeviceCommandForApiInput
|
public class DeviceCommandForApiInput:IdInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 表通信地址
|
|
||||||
/// </summary>
|
|
||||||
[Required(ErrorMessage = "设备地址不能为空")]
|
|
||||||
public string DeviceAddress { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 物联网平台类型
|
|
||||||
/// </summary>
|
|
||||||
[Required(ErrorMessage = "物联网平台类型不能为空")]
|
|
||||||
public IoTPlatformTypeEnum IoTPlatform { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设备在物联网平台中对应的产品Id
|
|
||||||
/// </summary>
|
|
||||||
[Required(ErrorMessage = "产品Id不能为空")]
|
|
||||||
public string IoTPlatformProductId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备在物联网平台中发送的命令内容,JSON格式
|
/// 设备在物联网平台中发送的命令内容,JSON格式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -267,6 +267,8 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
|
|
||||||
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, input.DeviceAddress, deviceCacheInfos);
|
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, input.DeviceAddress, deviceCacheInfos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return input.Adapt<DeviceManagementInfoDto>();
|
return input.Adapt<DeviceManagementInfoDto>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,13 +281,13 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var deviceInfo = await deviceAppService.FindByDeviceAddressAsync(input.DeviceAddress);
|
var deviceInfo = await deviceAppService.FindByIdAsync(input);
|
||||||
//将指令存储Kafka的OneNET主题中
|
//将指令存储Kafka的OneNET主题中
|
||||||
var commandRequest = new OpenApiRequest()
|
var commandRequest = new OpenApiRequest()
|
||||||
{
|
{
|
||||||
Message = new ReceiveCommandInfoDto()
|
Message = new ReceiveCommandInfoDto()
|
||||||
{
|
{
|
||||||
DeviceAddress = input.DeviceAddress,
|
DeviceAddress = deviceInfo.DeviceAddress,
|
||||||
Commands = input.CommandContent.Deserialize<Dictionary<string,object>>(),
|
Commands = input.CommandContent.Deserialize<Dictionary<string,object>>(),
|
||||||
DeviceType = DeviceTypeEnum.Focus,//todo 设备类型 需要跟设备统一什么情况下知道具体设备类型
|
DeviceType = DeviceTypeEnum.Focus,//todo 设备类型 需要跟设备统一什么情况下知道具体设备类型
|
||||||
SourceType = DeviceTelemetrySourceTypeEnum.AdminSystem,
|
SourceType = DeviceTelemetrySourceTypeEnum.AdminSystem,
|
||||||
@ -294,8 +296,7 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
|
|
||||||
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
|
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
|
||||||
{
|
{
|
||||||
await producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", commandRequest);
|
return await DeviceCommandInfoToOneNET(deviceInfo, commandRequest);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
|
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
|
||||||
{
|
{
|
||||||
@ -406,11 +407,15 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
{
|
{
|
||||||
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
|
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
|
||||||
createDeviceInput.DeviceName = item;
|
createDeviceInput.DeviceName = item;
|
||||||
|
createDeviceInput.DeviceAddress = item;
|
||||||
createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId;
|
createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId;
|
||||||
createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{item}";
|
createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{item}";
|
||||||
createDeviceInput.PlatformPassword = productInfo.ProductAccesskey;
|
createDeviceInput.PlatformPassword = productInfo.ProductAccesskey;
|
||||||
createDeviceInput.IoTPlatformProductName = productInfo.ProductName;
|
createDeviceInput.IoTPlatformProductName = productInfo.ProductName;
|
||||||
createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber;
|
createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber;
|
||||||
|
createDeviceInput.DeviceSourceTypeEnum = input.DeviceSourceTypeEnum.Value;
|
||||||
|
|
||||||
|
batchCreateDeviceInput.DeviceInputs.Add(createDeviceInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -426,9 +431,11 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
{
|
{
|
||||||
ProductId = productInfo.IoTPlatformProductId,
|
ProductId = productInfo.IoTPlatformProductId,
|
||||||
OneNETAccountId = productInfo.OneNETAccountId,
|
OneNETAccountId = productInfo.OneNETAccountId,
|
||||||
DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList(),
|
DeviceList = new List<string>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
oneNETBatchCreateDeviceInfoInput.DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList();
|
||||||
|
|
||||||
var pushResult = await oneNETDeviceService.BatchCreateDeviceInfoAsync(oneNETBatchCreateDeviceInfoInput);
|
var pushResult = await oneNETDeviceService.BatchCreateDeviceInfoAsync(oneNETBatchCreateDeviceInfoInput);
|
||||||
|
|
||||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||||
@ -466,9 +473,8 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
|
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
|
||||||
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == input.IoTPlatformProductId)
|
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
|
||||||
if (productInfo == null)
|
if (productInfo == null)
|
||||||
@ -476,6 +482,18 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
throw new UserFriendlyException($"推送失败,未找到对应的产品配置信息。");
|
throw new UserFriendlyException($"推送失败,未找到对应的产品配置信息。");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检查OneNET平台设备是否已经存在
|
||||||
|
var oneNETDeviceInfoResult = await oneNETDeviceService.DeviceInfoDetailAsync(new DeviceInfoDetailInput()
|
||||||
|
{
|
||||||
|
DeviceName = input.IoTPlatformDeviceOpenInfo,
|
||||||
|
ProductId = productInfo.IoTPlatformProductId,
|
||||||
|
OneNETAccountId = productInfo.OneNETAccountId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (oneNETDeviceInfoResult != null && oneNETDeviceInfoResult.Code == ServicePro.Enums.ResponeResultEnum.Success)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"推送失败,OneNET账号{productInfo.AccountPhoneNumber}的产品下{productInfo.ProductName}已经存在该设备{input.DeviceAddress}。");
|
||||||
|
}
|
||||||
|
|
||||||
//推送至OneNET平台
|
//推送至OneNET平台
|
||||||
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
||||||
@ -528,7 +546,6 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
DeviceName = input.IoTPlatformDeviceOpenInfo,
|
DeviceName = input.IoTPlatformDeviceOpenInfo,
|
||||||
ProductId = productInfo.IoTPlatformProductId,
|
ProductId = productInfo.IoTPlatformProductId,
|
||||||
OneNETAccountId = productInfo.OneNETAccountId,
|
OneNETAccountId = productInfo.OneNETAccountId,
|
||||||
Description = input.DeviceAddress,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (deleteResult == null || deleteResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
if (deleteResult == null || deleteResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||||
@ -552,6 +569,45 @@ namespace JiShe.IoT.DeviceAggregation
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送OneNET平台设备指令
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceInfo"></param>
|
||||||
|
/// <param name="commandRequest"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
|
public async Task<bool> DeviceCommandInfoToOneNET(DeviceManagementInfoDto deviceInfo, OpenApiRequest commandRequest)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//检查下设备是否在线
|
||||||
|
var deviceOnlineStatus = await oneNETDeviceService.DeviceInfoDetailAsync(new DeviceInfoDetailInput()
|
||||||
|
{
|
||||||
|
DeviceName = deviceInfo.IoTPlatformDeviceOpenInfo,
|
||||||
|
OneNETAccountId = deviceInfo.IoTPlatformAccountId,
|
||||||
|
ProductId = deviceInfo.IoTPlatformProductId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (deviceOnlineStatus == null || deviceOnlineStatus.Code != ResponeResultEnum.Success)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("获取平台设备信息失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceOnlineStatus.Data.Status != 1)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("设备不在线");
|
||||||
|
}
|
||||||
|
|
||||||
|
await producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", commandRequest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CTWing 设备操作
|
#region CTWing 设备操作
|
||||||
|
|||||||
@ -83,6 +83,13 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers
|
|||||||
return SubscribeAck.Fail();
|
return SubscribeAck.Fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新设备数据缓存到Redis
|
||||||
|
DeviceCacheInfos deviceCacheInfos = deviceEntity.Adapt<DeviceCacheInfos>();
|
||||||
|
deviceCacheInfos.IoTPlatformResponse = null;
|
||||||
|
deviceCacheInfos.PlatformPassword = null;
|
||||||
|
|
||||||
|
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, deviceEntity.DeviceAddress, deviceCacheInfos);
|
||||||
|
|
||||||
return SubscribeAck.Success();
|
return SubscribeAck.Success();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
@ -66,11 +66,25 @@ namespace JiShe.IoT.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("RepushDeviceInfoToIoTPlatform")]
|
[HttpPost(nameof(RepushDeviceInfoToIoTPlatform))]
|
||||||
[SwaggerOperation(summary: "重新推送设备信息到物联网平台", Tags = new[] { "AggregationDevice" })]
|
[SwaggerOperation(summary: "重新推送设备信息到物联网平台", Tags = new[] { "AggregationDevice" })]
|
||||||
public Task<DeviceManagementInfoDto> RepushDeviceInfoToIoTPlatform(IdInput input)
|
public Task<DeviceManagementInfoDto> RepushDeviceInfoToIoTPlatform(IdInput input)
|
||||||
{
|
{
|
||||||
return _deviceAggregationService.RepushDeviceInfoToIoTPlatform(input);
|
return _deviceAggregationService.RepushDeviceInfoToIoTPlatform(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送设备指令信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(nameof(DeviceCommandForApiAsync))]
|
||||||
|
[SwaggerOperation(summary: "发送设备指令信息", Tags = new[] { "AggregationDevice" })]
|
||||||
|
public Task<bool> DeviceCommandForApiAsync(DeviceCommandForApiInput input)
|
||||||
|
{
|
||||||
|
return _deviceAggregationService.DeviceCommandForApiAsync(input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user