2025-07-24 17:06:54 +08:00
|
|
|
|
using JiShe.IoT.DeviceAggregation.Dto;
|
|
|
|
|
|
using JiShe.IoT.OneNETAggregation.Dto;
|
|
|
|
|
|
using JiShe.ServicePro.Core;
|
2025-07-25 17:27:21 +08:00
|
|
|
|
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
|
|
|
|
|
|
using JiShe.ServicePro.DeviceManagement.DeviceInfos.Dto;
|
2025-07-24 17:06:54 +08:00
|
|
|
|
using JiShe.ServicePro.DeviceManagement.Permissions;
|
|
|
|
|
|
using JiShe.ServicePro.OneNETManagement.OneNETDevices;
|
|
|
|
|
|
using Mapster;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.IoT.DeviceAggregation
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设备聚合服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
|
/// <param name="deviceAppService">设备服务</param>
|
|
|
|
|
|
/// <param name="oneNETDeviceService">OneNET设备服务</param>
|
|
|
|
|
|
public class DeviceAggregationService(ILogger<DeviceAggregationService> logger, IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService) : IoTAppService, IDeviceAggregationService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建设备信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-25 11:54:19 +08:00
|
|
|
|
[Authorize(DeviceManagementPermissions.DeviceInfoManagement.Create)]
|
2025-07-24 17:06:54 +08:00
|
|
|
|
public async Task<bool> CreateAsync(CreateDeviceAggregationInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
|
|
|
|
|
|
|
|
|
|
|
|
var insertResult = await deviceAppService.CreateAsync(createDeviceInput);
|
|
|
|
|
|
if (insertResult == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError($"{nameof(CreateAsync)} 添加设备信息失败:{input.Serialize()}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//推送至OneNET平台
|
|
|
|
|
|
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceName = $"{input.IoTPlatformProductId}{input.DeviceAddress}",
|
|
|
|
|
|
ProductId = input.IoTPlatformProductId,
|
|
|
|
|
|
OneNETAccountId = input.IoTPlatformAccountId,
|
|
|
|
|
|
Description = input.DeviceAddress,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError($"{nameof(CreateAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
|
|
|
|
|
|
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
|
|
|
|
|
|
|
|
|
|
|
|
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
|
|
|
|
|
if (updateResult == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError($"{nameof(CreateAsync)} 更新设备信息失败:{input.Serialize()}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
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)]
|
2025-07-24 17:06:54 +08:00
|
|
|
|
public async Task<bool> DeleteAsync(IdInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await deviceAppService.DeleteAsync(input);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|