完善生产车间数据交互

This commit is contained in:
ChenYi 2025-07-30 16:14:32 +08:00
parent 000f9752ea
commit 1f2cd7e110
11 changed files with 88 additions and 118 deletions

@ -1 +1 @@
Subproject commit 5562b1a3c43e34f663b4f58415698b1c9d0190d6
Subproject commit 8abbb9899b01f6bc94a0d699cedc00cfbf2cbd7e

View File

@ -14,16 +14,10 @@ namespace JiShe.IoT.CTWingAggregation.Dto
public class CTWingWorkshopProductListOutput : OpenApiRequest
{
/// <summary>
/// CTWing账户Id
/// 产品数据Id
/// </summary>
[SwaggerSchema("CTWing账户Id")]
public string CTWingAccountId { get; set; }
/// <summary>
/// 物联网平台对应的产品Id
/// </summary>
[SwaggerSchema("物联网平台对应的产品Id")]
public string IoTPlatformProductId { get; set; }
[SwaggerSchema("产品数据Id")]
public Guid ProductDataId { get; set; }
/// <summary>
/// 产品名称
@ -35,7 +29,7 @@ namespace JiShe.IoT.CTWingAggregation.Dto
/// 设备访问密钥
/// </summary>
[SwaggerSchema("设备访问密钥")]
public string FeatureAccesskey { get; set; }
public string ProductAccesskey { get; set; }
/// <summary>
/// 通讯服务地址

View File

@ -21,6 +21,6 @@ namespace JiShe.IoT.CTWingAggregation
/// <summary>
/// 获取CTWing产品列表
/// </summary>
Task<HttpDataResult<List<CTWingWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input);
Task<HttpDataResult> GetProductListAsync(OpenApiRequest input);
}
}

View File

@ -11,19 +11,13 @@ namespace JiShe.IoT.OneNETAggregation.Dto
/// <summary>
/// 生产车间获取OneNET产品列表
/// </summary>
public class OneNetWorkshopProductListOutput: OpenApiRequest
public class OneNetWorkshopProductListOutput
{
/// <summary>
/// OneNET账户Id
/// 产品数据Id
/// </summary>
[SwaggerSchema("OneNET账户Id")]
public string OneNETAccountId { get; set; }
/// <summary>
/// 物联网平台对应的产品Id
/// </summary>
[SwaggerSchema("物联网平台对应的产品Id")]
public string IoTPlatformProductId { get; set; }
[SwaggerSchema("产品数据Id")]
public Guid ProductDataId { get; set; }
/// <summary>
/// 产品名称

View File

@ -24,6 +24,6 @@ namespace JiShe.IoT.OneNETAggregation
/// <summary>
/// 获取OneNET产品列表
/// </summary>
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input);
Task<HttpDataResult> GetProductListAsync(OpenApiRequest input);
}
}

View File

@ -14,24 +14,11 @@ namespace JiShe.IoT.Workshops
/// </summary>
public class ProductionEquipmentMessageBody
{
/// <summary>
/// 表计类型
/// 电表= 1,水表= 2,燃气表= 3,热能表= 4,水表流量计=5燃气表流量计=6,特殊电表=7
/// </summary>
public DeviceTypeEnum? MeterType { get; set; }
/// <summary>
/// 设备地址
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 物联网平台唯一设备标识
/// CTWing唯一设备标识为设备Id=CTWing产品Id+推送的设备序列号(集中器地址)
/// OneNET唯一设备标识为推送的设备名称为了保持统一因此推送的设备名称=OneNET产品Id+推送的设备序列号(集中器地址)
/// </summary>
public string DeviceOpenInfo { get; set; }
/// <summary>
/// 物联网平台对应的产品Id
/// </summary>

View File

@ -1,4 +1,5 @@
using JiShe.IoT.CTWingAggregation.Dto;
using JiShe.IoT.OneNETAggregation.Dto;
using JiShe.IoT.Workshops;
using JiShe.ServicePro;
using JiShe.ServicePro.Core;
@ -45,31 +46,16 @@ namespace JiShe.IoT.CTWingAggregation
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
if (productionEquipmentMessageBody.MeterType.HasValue == false)
{
return HttpDataResultExtensions.Failed("设备类型不能为空", -103, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -104, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -105, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -102, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceAddress))
{
return HttpDataResultExtensions.Failed("设备地址不能为空", -106, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("设备地址不能为空", -103, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceOpenInfo))
{
return HttpDataResultExtensions.Failed("物联网平台唯一设备标识,不能为空", -107, ResponeResultEnum.Fail);
}
var productInfo = await FreeSqlDbContext.Instance.Select<CTWingPrivateProductInfo>()
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId)
@ -77,16 +63,16 @@ namespace JiShe.IoT.CTWingAggregation
if (productInfo == null)
{
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -108, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -104, ResponeResultEnum.Fail);
}
CreateDeviceInput meterInfoEntity = new CreateDeviceInput()
{
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
PlatformPassword = productInfo.MasterKey,
PlatformPassword = productInfo.FeatureAccesskey,
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo,
DeviceName = productionEquipmentMessageBody.DeviceOpenInfo
IoTPlatformDeviceOpenInfo = $"{productionEquipmentMessageBody.IoTPlatformProductId}{productionEquipmentMessageBody.DeviceAddress}",
DeviceName = productionEquipmentMessageBody.DeviceAddress
};
//创建本地设备信息
@ -104,7 +90,7 @@ namespace JiShe.IoT.CTWingAggregation
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 推送设备信息失败:{pushResult.Serialize()}");
return HttpDataResultExtensions.Failed("推送设备信息CTWing失败", -109, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("推送设备信息CTWing失败", -105, ResponeResultEnum.Fail);
}
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
@ -114,7 +100,7 @@ namespace JiShe.IoT.CTWingAggregation
if (updateResult == null)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} CTWing返回的设备信息更新失败{input.Serialize()}");
return HttpDataResultExtensions.Failed("CTWing返回的设备信息更新失败", -110, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("CTWing返回的设备信息更新失败", -106, ResponeResultEnum.Fail);
}
//设备数据缓存到Redis
@ -123,12 +109,12 @@ namespace JiShe.IoT.CTWingAggregation
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, insertResult.DeviceAddress, deviceCacheInfos);
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
return HttpDataResultExtensions.Success("推送设备成功!");
}
catch (Exception ex)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -101, ResponeResultEnum.Exception);
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -107, ResponeResultEnum.Exception);
}
}
@ -136,25 +122,37 @@ namespace JiShe.IoT.CTWingAggregation
/// 获取CTWing产品列表
/// </summary>
[AllowAnonymous]
public async Task<HttpDataResult<List<CTWingWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input)
public async Task<HttpDataResult> GetProductListAsync(OpenApiRequest input)
{
try
{
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
if (verifySignatureReult == false)//签名校验失败
{
return HttpDataResultExtensions.Failed<List<CTWingWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
}
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
var pageListQuery = FreeSqlDbContext.Instance.Select<CTWingPrivateProductInfo>()
.Where(e => e.IsEnabled == true)
.OrderByDescending(e => e.CreationTime);
var pageList = await pageListQuery.ToListAsync<CTWingWorkshopProductListOutput>();
var pageList = await pageListQuery.ToListAsync(d => new CTWingWorkshopProductListOutput
{
ProductDataId = d.Id,
ProductName = d.ProductName,
CommunicationAddress = d.CommunicationAddress,
ProductAccesskey = d.FeatureAccesskey,
});
return HttpDataResultExtensions.Success(pageList);
if (pageList == null || pageList.Count <= 0)
{
return HttpDataResultExtensions.Failed("获取CTWing产品失败", -102, ResponeResultEnum.NotAllowed);
}
var rawMessage = pageList.Serialize();
var signatureResult = EncryptUtil.OpenApiSignature(rawMessage, srverOptions.VerifySignatureToken);
return HttpDataResultExtensions.Success(rawMessage, signatureResult.Item1, signatureResult.Item2);
}
catch (Exception)
{

View File

@ -49,31 +49,17 @@ namespace JiShe.IoT.OneNETAggregation
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
if (productionEquipmentMessageBody.MeterType.HasValue == false)
{
return HttpDataResultExtensions.Failed("设备类型不能为空", -103, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -104, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -105, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -102, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceAddress))
{
return HttpDataResultExtensions.Failed("设备地址不能为空", -106, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("设备地址不能为空", -103, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceOpenInfo))
{
return HttpDataResultExtensions.Failed("物联网平台唯一设备标识,不能为空", -107, ResponeResultEnum.Fail);
}
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId)
@ -81,34 +67,34 @@ namespace JiShe.IoT.OneNETAggregation
if (productInfo == null)
{
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -108, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -104, ResponeResultEnum.Fail);
}
CreateDeviceInput meterInfoEntity = new CreateDeviceInput()
CreateDeviceInput deviceInsertInput = new CreateDeviceInput()
{
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
PlatformPassword = productInfo.ProductAccesskey,
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo,
DeviceName = productionEquipmentMessageBody.DeviceOpenInfo
IoTPlatformDeviceOpenInfo = $"{productionEquipmentMessageBody.IoTPlatformProductId}{productionEquipmentMessageBody.DeviceAddress}",
DeviceName = productionEquipmentMessageBody.DeviceAddress
};
//创建本地设备信息
var insertResult = await deviceAppService.CreateAsync(meterInfoEntity);
var insertResult = await deviceAppService.CreateAsync(deviceInsertInput);
//推送至OneNET平台
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
{
DeviceName = productionEquipmentMessageBody.DeviceOpenInfo,
DeviceName = deviceInsertInput.IoTPlatformDeviceOpenInfo,
ProductId = productionEquipmentMessageBody.IoTPlatformProductId,
OneNETAccountId = productInfo.OneNETAccountId,
Description = productionEquipmentMessageBody.DeviceOpenInfo,
Description = deviceInsertInput.IoTPlatformDeviceOpenInfo,
});
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 推送设备信息失败:{pushResult.Serialize()}");
return HttpDataResultExtensions.Failed("推送设备信息OneNET失败", -109, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("推送设备信息OneNET失败", -105, ResponeResultEnum.Fail);
}
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
@ -118,7 +104,7 @@ namespace JiShe.IoT.OneNETAggregation
if (updateResult == null)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} OneNET返回的设备信息更新失败{input.Serialize()}");
return HttpDataResultExtensions.Failed("OneNET返回的设备信息更新失败", -110, ResponeResultEnum.Fail);
return HttpDataResultExtensions.Failed("OneNET返回的设备信息更新失败", -106, ResponeResultEnum.Fail);
}
//设备数据缓存到Redis
@ -127,12 +113,13 @@ namespace JiShe.IoT.OneNETAggregation
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, insertResult.DeviceAddress, deviceCacheInfos);
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
return HttpDataResultExtensions.Success("推送设备成功!");
}
catch (Exception ex)
{
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -101, ResponeResultEnum.Exception);
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -107, ResponeResultEnum.Exception);
}
}
@ -140,7 +127,7 @@ namespace JiShe.IoT.OneNETAggregation
/// 获取OneNET产品列表
/// </summary>
[AllowAnonymous]
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input)
public async Task<HttpDataResult> GetProductListAsync(OpenApiRequest input)
{
try
@ -148,18 +135,31 @@ namespace JiShe.IoT.OneNETAggregation
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
if (verifySignatureReult == false)//签名校验失败
{
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
}
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
var pageListQuery = FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IsEnabled == true)
.OrderByDescending(e => e.CreationTime);
var pageList = await pageListQuery.ToListAsync<OneNetWorkshopProductListOutput>();
var pageList = await pageListQuery.ToListAsync(d => new OneNetWorkshopProductListOutput
{
ProductDataId = d.Id,
ProductName = d.ProductName,
CommunicationAddress = d.CommunicationAddress,
ProductAccesskey = d.ProductAccesskey,
CommunicationAddressTLS = d.CommunicationAddressTLS
});
return HttpDataResultExtensions.Success(pageList);
if (pageList == null || pageList.Count <= 0)
{
return HttpDataResultExtensions.Failed("获取OneNET产品失败", -102, ResponeResultEnum.NotAllowed);
}
var rawMessage = pageList.Serialize();
var signatureResult = EncryptUtil.OpenApiSignature(rawMessage, srverOptions.VerifySignatureToken);
return HttpDataResultExtensions.Success(rawMessage, signatureResult.Item1, signatureResult.Item2);
}
catch (Exception)
{

View File

@ -21,9 +21,6 @@
# 更新dotnet tools
> dotnet tool update --global dotnet-ef
> 这个项目不能删除,初始化最基础的证书,以及《项目管理》的连接字符串加密都需要这个处理
> 生成SQL语句 Script-Migration -From 20220307064411_handlerMealPackage202203071443 -To 20220311084146_alterDevice202203111636 -Context ConsumerSystemDbContext
> Add-Migration alterAuditLogs202107011013 -c ConsumerSystemDbContext

View File

@ -10,10 +10,10 @@ namespace JiShe.IoT.Controllers
[Route("/Aggregation/CTWing")]
public class CTWingAggregationController : IoTController
{
private readonly ICTWingAggregationService _CTWingAggregationServiceService;
public CTWingAggregationController(ICTWingAggregationService CTWingAggregationServiceService)
private readonly ICTWingAggregationService _ctwingAggregationServiceService;
public CTWingAggregationController(ICTWingAggregationService ctwingAggregationServiceService)
{
_CTWingAggregationServiceService = CTWingAggregationServiceService;
_ctwingAggregationServiceService = ctwingAggregationServiceService;
}
/// <summary>
@ -25,7 +25,7 @@ namespace JiShe.IoT.Controllers
[SwaggerOperation(summary: "接收车间生产信息", Tags = new[] { "AggregationCTWing" })]
public async Task ReceiveWorkshopProductionInfoAsync(OpenApiRequest input)
{
await _CTWingAggregationServiceService.ReceiveWorkshopProductionInfoAsync(input);
await _ctwingAggregationServiceService.ReceiveWorkshopProductionInfoAsync(input);
}
/// <summary>
@ -33,9 +33,9 @@ namespace JiShe.IoT.Controllers
/// </summary>
[HttpPost(nameof(GetProductListAsync))]
[SwaggerOperation(summary: "获取CTWing产品列表", Tags = new[] { "AggregationCTWing" })]
public async Task<HttpDataResult<List<CTWingWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input)
public async Task<HttpDataResult> GetProductListAsync(OpenApiRequest input)
{
return await _CTWingAggregationServiceService.GetProductListAsync(input);
return await _ctwingAggregationServiceService.GetProductListAsync(input);
}
}
}

View File

@ -42,7 +42,7 @@ namespace JiShe.IoT.Controllers
/// </summary>
[HttpPost(nameof(GetProductListAsync))]
[SwaggerOperation(summary: "获取OneNET产品列表", Tags = new[] { "AggregationOneNET" })]
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input)
public async Task<HttpDataResult> GetProductListAsync(OpenApiRequest input)
{
return await _oneNETAggregationServiceService.GetProductListAsync(input);
}