设备缓存刷新
This commit is contained in:
parent
2da566094f
commit
b2f0bb05b2
@ -1 +1 @@
|
||||
Subproject commit 76379211e6dd49d3c9ad10f7c4766f1fbbd4cde3
|
||||
Subproject commit 717785239911c98e2be567d49e57bcd9ff029516
|
||||
@ -11,11 +11,18 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
public interface IDeviceAggregationService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建设备信息
|
||||
/// 管理后台创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> CreateAsync(CreateDeviceAggregationInput input);
|
||||
Task<bool> CreateDeviceForApiAsync(CreateDeviceAggregationInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 车间创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> CreateDeviceWorkshopAsync(CreateDeviceAggregationInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备信息
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using JiShe.IoT.CTWingAggregation.Dto;
|
||||
using JiShe.IoT.DeviceAggregation;
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.IoT.Workshops;
|
||||
using JiShe.ServicePro;
|
||||
@ -20,11 +22,10 @@ namespace JiShe.IoT.CTWingAggregation
|
||||
/// <summary>
|
||||
/// CTWing聚合服务
|
||||
/// </summary>
|
||||
/// <param name="deviceAppService"></param>
|
||||
/// <param name="ctwingDeviceService"></param>
|
||||
/// <param name="deviceAggregationService">设备聚合服务</param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="logger"></param>
|
||||
public class CTWingAggregationService(IDeviceAppService deviceAppService, ICTWingDeviceService ctwingDeviceService, IOptions<ServerApplicationOptions> options, ILogger<CTWingAggregationService> logger) : IoTAppService, ICTWingAggregationService
|
||||
public class CTWingAggregationService(IDeviceAggregationService deviceAggregationService, IOptions<ServerApplicationOptions> options, ILogger<CTWingAggregationService> logger) : IoTAppService, ICTWingAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
|
||||
@ -48,73 +49,35 @@ namespace JiShe.IoT.CTWingAggregation
|
||||
|
||||
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -102, ResponeResultEnum.Fail);
|
||||
return HttpDataResultExtensions.Failed("CTWing平台产品Id不能为空", -102, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceAddress))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("设备地址不能为空", -103, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
|
||||
var productInfo = await FreeSqlDbContext.Instance.Select<CTWingPrivateProductInfo>()
|
||||
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId)
|
||||
.FirstAsync();
|
||||
|
||||
if (productInfo == null)
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -104, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
CreateDeviceInput meterInfoEntity = new CreateDeviceInput()
|
||||
CreateDeviceAggregationInput deviceInsertInput = new CreateDeviceAggregationInput()
|
||||
{
|
||||
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
|
||||
PlatformPassword = productInfo.FeatureAccesskey,
|
||||
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
IoTPlatformDeviceOpenInfo = $"{productionEquipmentMessageBody.IoTPlatformProductId}{productionEquipmentMessageBody.DeviceAddress}",
|
||||
DeviceName = productionEquipmentMessageBody.DeviceAddress
|
||||
IoTPlatform = IoTPlatformTypeEnum.CTWing,
|
||||
};
|
||||
|
||||
//创建本地设备信息
|
||||
var insertResult = await deviceAppService.CreateAsync(meterInfoEntity);
|
||||
|
||||
//推送至CTWing平台
|
||||
var pushResult = await ctwingDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
||||
//创建设备信息
|
||||
var insertResult = await deviceAggregationService.CreateDeviceWorkshopAsync(deviceInsertInput);
|
||||
if (!insertResult)
|
||||
{
|
||||
//DeviceName = productionEquipmentMessageBody.DeviceOpenInfo,
|
||||
//ProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
//CTWingAccountId = productInfo.CTWingAccountId,
|
||||
//Description = productionEquipmentMessageBody.DeviceOpenInfo,
|
||||
});
|
||||
|
||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("推送设备信息CTWing失败", -105, ResponeResultEnum.Fail);
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 创建设备信息失败:{insertResult.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("CTWing推送设备失败!", -105);
|
||||
}
|
||||
|
||||
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
|
||||
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
|
||||
|
||||
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
||||
if (updateResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} CTWing返回的设备信息更新失败:{input.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("CTWing返回的设备信息更新失败", -106, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
//设备数据缓存到Redis
|
||||
DeviceCacheInfos deviceCacheInfos = insertResult.Adapt<DeviceCacheInfos>();
|
||||
deviceCacheInfos.IoTPlatformResponse = updateDeviceInput.IoTPlatformResponse;
|
||||
|
||||
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, insertResult.DeviceAddress, deviceCacheInfos);
|
||||
|
||||
return HttpDataResultExtensions.Success("推送设备成功!");
|
||||
return HttpDataResultExtensions.Success("CTWing推送设备成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -107, ResponeResultEnum.Exception);
|
||||
return HttpDataResultExtensions.Failed("生产车间推送CTWing数据发生异常", -107, ResponeResultEnum.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,12 +29,41 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
public class DeviceAggregationService(ILogger<DeviceAggregationService> logger, IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService) : IoTAppService, IDeviceAggregationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建设备信息
|
||||
/// 管理后台创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(DeviceManagementPermissions.DeviceInfoManagement.Create)]
|
||||
public async Task<bool> CreateAsync(CreateDeviceAggregationInput input)
|
||||
public async Task<bool> CreateDeviceForApiAsync(CreateDeviceAggregationInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
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>
|
||||
/// 车间创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CreateDeviceWorkshopAsync(CreateDeviceAggregationInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -95,7 +124,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
var insertResult = await deviceAppService.CreateAsync(createDeviceInput);
|
||||
if (insertResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 添加设备信息失败:{input.Serialize()}");
|
||||
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 添加设备信息失败:{input.Serialize()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -110,7 +139,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
|
||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -244,7 +273,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
|
||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
throw new UserFriendlyException($"平台请求失败。");
|
||||
|
||||
}
|
||||
@ -274,7 +303,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
||||
if (updateResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 更新设备信息失败:{input.Serialize()}");
|
||||
logger.LogError($"{nameof(CreateDeviceForApiAsync)} 更新设备信息失败:{input.Serialize()}");
|
||||
throw new UserFriendlyException($"推送结果更新失败。");
|
||||
}
|
||||
|
||||
|
||||
@ -1,32 +1,26 @@
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.IoT.DeviceAggregation;
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.IoT.Workshops;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
|
||||
using JiShe.ServicePro.DeviceManagement.DeviceInfos.Dto;
|
||||
using JiShe.ServicePro.Encrypt;
|
||||
using JiShe.ServicePro.Enums;
|
||||
using JiShe.ServicePro.FreeRedisProvider;
|
||||
using JiShe.ServicePro.Kafka.Consts;
|
||||
using JiShe.ServicePro.Kafka.Producer;
|
||||
using JiShe.ServicePro.OneNETManagement.OneNETDevices;
|
||||
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
|
||||
using JiShe.ServicePro.ServerOptions;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.IO.Pipelines;
|
||||
|
||||
namespace JiShe.IoT.OneNETAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// OneNET聚合服务
|
||||
/// </summary>
|
||||
/// <param name="deviceAppService">设备管理信息服务</param>
|
||||
/// <param name="oneNETDeviceService">OneNET设备操作服务</param>
|
||||
/// <param name="deviceAggregationService">设备聚合服务</param>
|
||||
/// <param name="options">服务配置</param>
|
||||
/// <param name="logger"></param>
|
||||
public class OneNETAggregationService(IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService, IOptions<ServerApplicationOptions> options, ILogger<OneNETAggregationService> logger) : IoTAppService, IOneNETAggregationService
|
||||
public class OneNETAggregationService(IDeviceAggregationService deviceAggregationService, IOptions<ServerApplicationOptions> options, ILogger<OneNETAggregationService> logger) : IoTAppService, IOneNETAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
|
||||
@ -61,65 +55,28 @@ namespace JiShe.IoT.OneNETAggregation
|
||||
}
|
||||
|
||||
|
||||
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
|
||||
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId)
|
||||
.FirstAsync();
|
||||
|
||||
if (productInfo == null)
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -104, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
CreateDeviceInput deviceInsertInput = new CreateDeviceInput()
|
||||
CreateDeviceAggregationInput deviceInsertInput = new CreateDeviceAggregationInput()
|
||||
{
|
||||
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
|
||||
PlatformPassword = productInfo.ProductAccesskey,
|
||||
IoTPlatform = IoTPlatformTypeEnum.OneNET,
|
||||
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
IoTPlatformDeviceOpenInfo = $"{productionEquipmentMessageBody.IoTPlatformProductId}{productionEquipmentMessageBody.DeviceAddress}",
|
||||
DeviceName = productionEquipmentMessageBody.DeviceAddress
|
||||
};
|
||||
|
||||
//创建本地设备信息
|
||||
var insertResult = await deviceAppService.CreateAsync(deviceInsertInput);
|
||||
|
||||
//推送至OneNET平台
|
||||
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
||||
//创建设备信息
|
||||
var insertResult = await deviceAggregationService.CreateDeviceWorkshopAsync(deviceInsertInput);
|
||||
if (!insertResult)
|
||||
{
|
||||
DeviceName = deviceInsertInput.IoTPlatformDeviceOpenInfo,
|
||||
ProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
OneNETAccountId = productInfo.OneNETAccountId,
|
||||
Description = deviceInsertInput.IoTPlatformDeviceOpenInfo,
|
||||
});
|
||||
|
||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("推送设备信息OneNET失败", -105, ResponeResultEnum.Fail);
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} OneNET创建设备信息失败:{insertResult.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("OneNET推送设备失败!", -105);
|
||||
}
|
||||
|
||||
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
|
||||
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
|
||||
|
||||
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
||||
if (updateResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} OneNET返回的设备信息更新失败:{input.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("OneNET返回的设备信息更新失败", -106, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
//设备数据缓存到Redis
|
||||
DeviceCacheInfos deviceCacheInfos = insertResult.Adapt<DeviceCacheInfos>();
|
||||
deviceCacheInfos.IoTPlatformResponse = updateDeviceInput.IoTPlatformResponse;
|
||||
|
||||
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, insertResult.DeviceAddress, deviceCacheInfos);
|
||||
|
||||
return HttpDataResultExtensions.Success("推送设备成功!");
|
||||
return HttpDataResultExtensions.Success("OneNET推送设备成功!");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -107, ResponeResultEnum.Exception);
|
||||
return HttpDataResultExtensions.Failed("生产车间推送OneNET数据发生异常", -107, ResponeResultEnum.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ namespace JiShe.IoT.Controllers
|
||||
[SwaggerOperation(summary: "创建设备信息", Tags = new[] { "AggregationDevice" })]
|
||||
public async Task<bool> CreateAsync(CreateDeviceAggregationInput input)
|
||||
{
|
||||
return await _deviceAggregationService.CreateAsync(input);
|
||||
return await _deviceAggregationService.CreateDeviceForApiAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -32,9 +32,9 @@ namespace JiShe.IoT.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpPost(nameof(ReceiveWorkshopProductionInfoAsync))]
|
||||
[SwaggerOperation(summary: "接收车间生产信息", Tags = new[] { "AggregationOneNET" })]
|
||||
public async Task ReceiveWorkshopProductionInfoAsync(OpenApiRequest input)
|
||||
public async Task<HttpDataResult> ReceiveWorkshopProductionInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
await _oneNETAggregationServiceService.ReceiveWorkshopProductionInfoAsync(input);
|
||||
return await _oneNETAggregationServiceService.ReceiveWorkshopProductionInfoAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user