701 lines
28 KiB
C#
Raw Normal View History

using JiShe.IoT.DeviceAggregation.Dto;
using JiShe.ServicePro;
2025-09-19 11:36:17 +08:00
using JiShe.ServicePro.ApacheIoTDB.Provider.Options;
using JiShe.ServicePro.Core;
2025-09-19 11:36:17 +08:00
using JiShe.ServicePro.DataChannelManages;
2025-07-25 17:27:21 +08:00
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
using JiShe.ServicePro.DeviceManagement.DeviceInfos.Dto;
using JiShe.ServicePro.DeviceManagement.Permissions;
2025-08-04 17:29:47 +08:00
using JiShe.ServicePro.Dto;
2025-08-04 11:59:07 +08:00
using JiShe.ServicePro.Enums;
using JiShe.ServicePro.FreeRedisProvider;
2025-09-19 11:36:17 +08:00
using JiShe.ServicePro.IoTDBManagement.DataChannels;
using JiShe.ServicePro.IoTDBManagement.TableModels;
using JiShe.ServicePro.OneNETManagement.OneNETDevices;
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
using Mapster;
using Microsoft.Extensions.Logging;
2025-09-19 11:36:17 +08:00
using Microsoft.Extensions.Options;
using Volo.Abp;
namespace JiShe.IoT.DeviceAggregation
{
/// <summary>
/// 设备聚合服务
/// </summary>
/// <param name="logger"></param>
/// <param name="deviceAppService">设备服务</param>
/// <param name="oneNETDeviceService">OneNET设备服务</param>
2025-08-21 11:34:16 +08:00
/// <param name="redisPubSubService">Redis发布订阅服务</param>
2025-09-19 11:36:17 +08:00
/// <param name="ioTDBDataChannelManageService">数据通道</param>
/// <param name="_ioTDBOptions">IoTDBOptions</param>
public class DeviceAggregationService(ILogger<DeviceAggregationService> logger, IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService, IReliableRedisPubSubService redisPubSubService, IIoTDBDataChannelManageService ioTDBDataChannelManageService,IOptions<IoTDBOptions> _ioTDBOptions) : IoTAppService, IDeviceAggregationService
{
2025-09-19 11:36:17 +08:00
IoTDBOptions ioTDBOptions = _ioTDBOptions.Value;
/// <summary>
2025-08-01 14:59:11 +08:00
/// 管理后台创建设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
2025-07-25 11:54:19 +08:00
[Authorize(DeviceManagementPermissions.DeviceInfoManagement.Create)]
2025-08-01 14:59:11 +08:00
public async Task<bool> CreateDeviceForApiAsync(CreateDeviceAggregationInput input)
{
try
{
2025-08-04 11:59:07 +08:00
input.DeviceSourceTypeEnum = ServicePro.Enums.DeviceSourceTypeEnum.AdminSystem;
2025-08-01 14:59:11 +08:00
if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
return await CTWingDeviceCreateAsync(input);
}
else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
return await OneNETDeviceCreateAsync(input);
}
throw new UserFriendlyException($"不支持的物联网平台");
}
catch (Exception)
{
throw;
}
}
2025-08-04 11:59:07 +08:00
/// <summary>
/// 管理后台批量创建设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> BatchCreateDeviceForApiAsync(BatchCreateDeviceAggregationInput input)
{
try
{
if (input.AddressList == null || input.AddressList.Count <= 0)
{
throw new UserFriendlyException($"批量创建设备失败,设备信息不能为空。");
}
if (input.AddressList.Count > 100)
{
throw new UserFriendlyException($"批量创建设备失败设备信息不能超过100个。");
}
input.DeviceSourceTypeEnum = ServicePro.Enums.DeviceSourceTypeEnum.AdminSystem;
if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
return await CTWingDeviceBatchCreateAsync(input);
}
else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
return await OneNETDeviceBatchCreateAsync(input);
}
throw new UserFriendlyException($"不支持的物联网平台");
}
catch (Exception)
{
throw;
}
}
2025-08-01 14:59:11 +08:00
/// <summary>
/// 车间创建设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> CreateDeviceWorkshopAsync(CreateDeviceAggregationInput input)
{
try
{
2025-08-04 11:59:07 +08:00
input.DeviceSourceTypeEnum = DeviceSourceTypeEnum.Workshop;
if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
return await CTWingDeviceCreateAsync(input);
}
else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
return await OneNETDeviceCreateAsync(input);
}
throw new UserFriendlyException($"不支持的物联网平台");
}
catch (Exception)
{
throw;
}
}
/// <summary>
2025-08-04 11:59:07 +08:00
/// 车间批量创建设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
2025-08-04 11:59:07 +08:00
public async Task<bool> BatchCreateDeviceWorkshopAsync(BatchCreateDeviceAggregationInput input)
{
try
{
2025-08-04 11:59:07 +08:00
if (input.AddressList == null || input.AddressList.Count <= 0)
{
2025-08-04 11:59:07 +08:00
throw new UserFriendlyException($"批量创建设备失败,设备信息不能为空。");
}
2025-08-04 11:59:07 +08:00
if (input.AddressList.Count > 100)
{
2025-08-04 11:59:07 +08:00
throw new UserFriendlyException($"批量创建设备失败设备信息不能超过100个。");
}
2025-08-04 11:59:07 +08:00
input.DeviceSourceTypeEnum = DeviceSourceTypeEnum.Workshop;
2025-08-04 11:59:07 +08:00
if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
2025-08-04 11:59:07 +08:00
return await CTWingDeviceBatchCreateAsync(input);
}
2025-08-04 11:59:07 +08:00
else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
2025-08-04 11:59:07 +08:00
return await OneNETDeviceBatchCreateAsync(input);
}
2025-08-04 11:59:07 +08:00
throw new UserFriendlyException($"不支持的物联网平台");
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 删除设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
2025-07-25 11:54:19 +08:00
[Authorize(DeviceManagementPermissions.DeviceInfoManagement.Delete)]
public async Task<bool> DeleteAsync(IdInput input)
{
2025-08-04 11:59:07 +08:00
//检查设备信息是不是已经存在
var existsDeviceInfo = await deviceAppService.FindByIdAsync(input);
if (existsDeviceInfo == null)
{
throw new UserFriendlyException($"删除设备失败,未找到对应设备信息。");
}
//根据设备平台调用删除接口
if (existsDeviceInfo.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
return await DeleteDeviceInfoToOneNET(existsDeviceInfo);
}
else if (existsDeviceInfo.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
return await DeleteDeviceInfoToCTWing(existsDeviceInfo);
}
2025-08-04 11:59:07 +08:00
throw new UserFriendlyException($"不支持的物联网平台");
}
/// <summary>
/// 根据设备ID查询设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<DeviceManagementInfoDto> FindByIdAsync(IdInput input)
{
return await deviceAppService.FindByIdAsync(input);
}
/// <summary>
/// 重新推送设备信息到物联网平台
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<DeviceManagementInfoDto> RepushDeviceInfoToIoTPlatform(IdInput input)
{
try
{
var entityDevice = await FreeSqlDbContext.Instance.Select<DeviceManagementInfo>().Where(f => f.Id == input.Id).FirstAsync<DeviceManagementInfoDto>();
if (entityDevice == null)
{
throw new UserFriendlyException($"推送失败,未找到设备数据");
}
if (entityDevice.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
return await RepushDeviceInfoToCTWing(entityDevice);
}
else if (entityDevice.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET)
{
return await RepushDeviceInfoToOneNET(entityDevice);
}
throw new UserFriendlyException($"推送失败,异常的物联网平台");
}
catch (Exception)
{
throw;
}
}
/// <summary>
2025-08-04 11:59:07 +08:00
/// 更新设备信息并处理缓存
/// </summary>
/// <param name="input"></param>
2025-08-04 11:59:07 +08:00
/// <param name="pushResult"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
2025-08-04 11:59:07 +08:00
private async Task<DeviceManagementInfoDto> DeviceUpdateHandler(DeviceManagementInfoDto input, HttpDataResult pushResult)
{
UpdateDeviceInput updateDeviceInput = input.Adapt<UpdateDeviceInput>();
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
updateDeviceInput.IsPlatformPushSuccess = true;
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
if (updateResult == null)
{
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 更新设备信息失败:{input.Serialize()}");
throw new UserFriendlyException($"推送结果更新失败。");
}
//设备数据缓存到Redis
DeviceCacheInfos deviceCacheInfos = input.Adapt<DeviceCacheInfos>();
deviceCacheInfos.IoTPlatformResponse = null;
deviceCacheInfos.PlatformPassword = null;
FreeRedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, input.DeviceAddress, deviceCacheInfos);
2025-08-04 11:59:07 +08:00
2025-08-04 11:59:07 +08:00
return input.Adapt<DeviceManagementInfoDto>();
}
2025-08-04 17:29:47 +08:00
/// <summary>
/// 发送设备指令信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> DeviceCommandForApiAsync(DeviceCommandForApiInput input)
{
try
{
var deviceInfo = await deviceAppService.FindByIdAsync(input);
2025-09-19 11:36:17 +08:00
if (deviceInfo == null)
{
throw new UserFriendlyException($"设备不存在");
}
2025-08-04 17:29:47 +08:00
//将指令存储Kafka的OneNET主题中
var commandRequest = new OpenApiRequest()
{
Message = new ReceiveCommandInfoDto()
{
DeviceAddress = deviceInfo.DeviceAddress,
2025-08-04 17:29:47 +08:00
Commands = input.CommandContent.Deserialize<Dictionary<string,object>>(),
2025-09-19 11:36:17 +08:00
DeviceType = input.DeviceType ?? DeviceTypeEnum.Focus,//todo 设备类型 需要跟设备统一什么情况下知道具体设备类型
2025-08-04 17:29:47 +08:00
SourceType = DeviceTelemetrySourceTypeEnum.AdminSystem,
2025-09-19 11:36:17 +08:00
TelemetryType = input.TelemetryType ?? DeviceTelemetryCommandTypeEnum.,
IoTPlatform = deviceInfo.IoTPlatform,
2025-08-04 17:29:47 +08:00
}.Serialize(),
};
2025-09-19 11:36:17 +08:00
var packetTaskInfo = GetDeviceTelemetryPacketTaskInfo(ioTDBOptions, commandRequest, deviceInfo.Adapt<DeviceCacheInfos>(), commandRequest.Message);
//数据写入遥测任务数据存储通道
await ioTDBDataChannelManageService.DeviceTelemetryTaskWriterAsync(DataChannelManage.DeviceTelemetryTaskDataChannel.Writer, (DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo));
2025-08-04 17:29:47 +08:00
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
{
2025-09-19 11:36:17 +08:00
return await DeviceCommandInfoToOneNET(deviceInfo, packetTaskInfo);
2025-08-04 17:29:47 +08:00
}
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
{
await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.CTWingAepCommandIssuedEventName,commandRequest);
2025-08-04 17:29:47 +08:00
return true;
}
else
{
throw new UserFriendlyException($"创建设备失败,未找到对应的产品配置信息。");
}
}
catch (Exception)
{
throw;
}
}
2025-08-04 11:59:07 +08:00
#region OneNET
/// <summary>
/// OneNET设备创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
protected async Task<bool> OneNETDeviceCreateAsync(CreateDeviceAggregationInput input)
{
try
{
2025-08-04 11:59:07 +08:00
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混
.WhereIf(input.DeviceSourceTypeEnum == DeviceSourceTypeEnum.Workshop, e => e.IsEnabled == true)
.FirstAsync();
if (productInfo == null)
{
throw new UserFriendlyException($"创建设备失败,未找到对应的产品配置信息。");
}
createDeviceInput.DeviceName = input.DeviceAddress;
createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId;
createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{input.DeviceAddress}";
createDeviceInput.PlatformPassword = productInfo.ProductAccesskey;
createDeviceInput.IoTPlatformProductName = productInfo.ProductName;
createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber;
var insertResult = await deviceAppService.CreateAsync(createDeviceInput);
if (insertResult == null)
{
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 添加设备信息失败:{input.Serialize()}");
return false;
}
//推送至OneNET平台
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
{
DeviceName = createDeviceInput.IoTPlatformDeviceOpenInfo,
ProductId = productInfo.IoTPlatformProductId,
OneNETAccountId = productInfo.OneNETAccountId,
Description = input.DeviceAddress,
});
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}");
return false;
}
await DeviceUpdateHandler(insertResult, pushResult);
return true;
}
catch (Exception)
{
throw;
}
}
2025-08-04 11:59:07 +08:00
/// <summary>
/// OneNET设备批量创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
protected async Task<bool> OneNETDeviceBatchCreateAsync(BatchCreateDeviceAggregationInput input)
{
try
{
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混
.WhereIf(input.DeviceSourceTypeEnum == DeviceSourceTypeEnum.Workshop, e => e.IsEnabled == true)
.FirstAsync();
if (productInfo == null)
{
throw new UserFriendlyException($"批量创建设备失败,未找到对应的产品配置信息。");
}
BatchCreateDeviceInput batchCreateDeviceInput = new BatchCreateDeviceInput()
{
IoTPlatform = input.IoTPlatform,
AddressList = input.AddressList,
DeviceInputs = new List<CreateDeviceInput>()
};
foreach (var item in input.AddressList)
{
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
createDeviceInput.DeviceName = item;
createDeviceInput.DeviceAddress = item;
2025-08-04 11:59:07 +08:00
createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId;
createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{item}";
createDeviceInput.PlatformPassword = productInfo.ProductAccesskey;
createDeviceInput.IoTPlatformProductName = productInfo.ProductName;
createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber;
createDeviceInput.DeviceSourceTypeEnum = input.DeviceSourceTypeEnum.Value;
batchCreateDeviceInput.DeviceInputs.Add(createDeviceInput);
2025-08-04 11:59:07 +08:00
}
var insertResult = await deviceAppService.BatchCreateAsync(batchCreateDeviceInput);
if (insertResult == null)
{
logger.LogError($"{nameof(OneNETDeviceBatchCreateAsync)} OneNET设备批量创建添加设备信息失败{input.Serialize()}");
return false;
}
//推送至OneNET平台
var oneNETBatchCreateDeviceInfoInput = new BatchCreateDeviceInfoInput()
{
ProductId = productInfo.IoTPlatformProductId,
OneNETAccountId = productInfo.OneNETAccountId,
DeviceList = new List<string>()
2025-08-04 11:59:07 +08:00
};
oneNETBatchCreateDeviceInfoInput.DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList();
2025-08-04 11:59:07 +08:00
var pushResult = await oneNETDeviceService.BatchCreateDeviceInfoAsync(oneNETBatchCreateDeviceInfoInput);
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}");
return false;
}
foreach (var item in insertResult)
{
var successEntity = pushResult.Data.Successlist.Where(d => d.DeviceName == item.IoTPlatformDeviceOpenInfo).FirstOrDefault();
if (successEntity != null)
{
await DeviceUpdateHandler(item, HttpDataResultExtensions.Success(successEntity));
}
}
return true;
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 重新推送设备信息到OneNET物联网平台
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<DeviceManagementInfoDto> RepushDeviceInfoToOneNET(DeviceManagementInfoDto input)
{
try
{
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)
.FirstAsync();
if (productInfo == null)
{
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平台
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
{
DeviceName = input.IoTPlatformDeviceOpenInfo,
ProductId = productInfo.IoTPlatformProductId,
OneNETAccountId = productInfo.OneNETAccountId,
Description = input.DeviceAddress,
});
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
2025-08-01 14:59:11 +08:00
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}");
throw new UserFriendlyException($"平台请求失败。");
}
return await DeviceUpdateHandler(input, pushResult);
}
catch (Exception)
{
throw;
}
}
/// <summary>
2025-08-04 11:59:07 +08:00
/// 删除OneNET平台设备
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
2025-08-04 11:59:07 +08:00
public async Task<bool> DeleteDeviceInfoToOneNET(DeviceManagementInfoDto input)
{
2025-08-04 11:59:07 +08:00
try
{
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
2025-08-04 17:29:47 +08:00
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)
2025-08-04 11:59:07 +08:00
.FirstAsync();
2025-08-04 11:59:07 +08:00
if (productInfo == null)
{
throw new UserFriendlyException($"删除失败,未找到对应的产品配置信息。");
}
//删除OneNET平台设备信息
var deleteResult = await oneNETDeviceService.DeleteDeviceInfoAsync(new DeleteDeviceInfoInput()
{
DeviceName = input.IoTPlatformDeviceOpenInfo,
ProductId = productInfo.IoTPlatformProductId,
OneNETAccountId = productInfo.OneNETAccountId,
2025-08-04 11:59:07 +08:00
});
if (deleteResult == null || deleteResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 删除设备信息失败:{deleteResult.Serialize()}");
throw new UserFriendlyException($"删除设备平台请求失败。");
}
var localDeleteReult = await deviceAppService.DeleteAsync(new IdInput() { Id = input.Id });
if (localDeleteReult == false)
{
throw new UserFriendlyException($"平台设备信息删除成功,系统删除设备失败。");
}
return localDeleteReult;
}
catch (Exception)
{
2025-08-04 11:59:07 +08:00
throw;
}
2025-08-04 11:59:07 +08:00
}
/// <summary>
/// 发送OneNET平台设备指令
/// </summary>
/// <param name="deviceInfo"></param>
2025-09-19 11:36:17 +08:00
/// <param name="packetTaskInfo"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
2025-09-19 11:36:17 +08:00
public async Task<bool> DeviceCommandInfoToOneNET(DeviceManagementInfoDto deviceInfo, DeviceTelemetryPacketTaskInfo packetTaskInfo)
{
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("设备不在线");
}
2025-09-19 11:36:17 +08:00
await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo);
return true;
}
catch (Exception)
{
throw;
}
}
2025-08-04 11:59:07 +08:00
#endregion
2025-08-04 11:59:07 +08:00
#region CTWing
/// <summary>
/// CTWing 设备创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
protected async Task<bool> CTWingDeviceCreateAsync(CreateDeviceAggregationInput input)
{
throw new UserFriendlyException($"CTWing 设备创建失败,功能未实现。");
}
2025-08-04 11:59:07 +08:00
/// <summary>
/// CTWing 批量设备创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
protected async Task<bool> CTWingDeviceBatchCreateAsync(BatchCreateDeviceAggregationInput input)
{
try
{
throw new UserFriendlyException($"CTWing 批量设备创建失败CTWing暂未实现。");
}
catch (Exception)
{
2025-08-04 11:59:07 +08:00
throw;
}
}
/// <summary>
/// 重新推送设备信息到CTWing物联网平台
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<DeviceManagementInfoDto> RepushDeviceInfoToCTWing(DeviceManagementInfoDto input)
{
try
{
throw new UserFriendlyException($"推送失败CTWing暂未实现。");
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 删除CTWing平台设备
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<bool> DeleteDeviceInfoToCTWing(DeviceManagementInfoDto input)
{
try
{
throw new UserFriendlyException($"删除失败CTWing暂未实现。");
}
catch (Exception)
{
throw;
}
}
2025-08-04 11:59:07 +08:00
#endregion
}
}