Compare commits
4 Commits
6e70b026c9
...
9380c6e6b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9380c6e6b1 | ||
|
|
a75c7d34d7 | ||
|
|
1f2cd7e110 | ||
|
|
000f9752ea |
@ -1 +1 @@
|
||||
Subproject commit cf3eff7465d5f3d89b4f95d372a0a7e797f4dec0
|
||||
Subproject commit ae4ef2a2f28f374199d0b0bc0f61be527f2965f0
|
||||
@ -0,0 +1,46 @@
|
||||
using JiShe.ServicePro;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.CTWingAggregation.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产车间获取CTWing产品列表
|
||||
/// </summary>
|
||||
public class CTWingWorkshopProductListOutput : OpenApiRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 产品数据Id
|
||||
/// </summary>
|
||||
[SwaggerSchema("产品数据Id")]
|
||||
public Guid ProductDataId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品名称
|
||||
/// </summary>
|
||||
[SwaggerSchema("产品名称")]
|
||||
public string ProductName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备访问密钥
|
||||
/// </summary>
|
||||
[SwaggerSchema("设备访问密钥")]
|
||||
public string ProductAccesskey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通讯服务地址
|
||||
/// </summary>
|
||||
[SwaggerSchema("通讯服务地址")]
|
||||
public string CommunicationAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TLS通讯服务地址
|
||||
/// </summary>
|
||||
[SwaggerSchema("TLS通讯服务地址")]
|
||||
public string CommunicationAddressTLS { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
using JiShe.IoT.CTWingAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.ServicePro;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.CTWingAggregation
|
||||
{
|
||||
public interface ICTWingAggregationService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 接收车间生产信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult> ReceiveWorkshopProductionInfoAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取CTWing产品列表
|
||||
/// </summary>
|
||||
Task<HttpDataResult> GetProductListAsync(OpenApiRequest input);
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
/// 产品名称
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.OneNETAggregation.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产设备详情
|
||||
/// </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>
|
||||
public string IoTPlatformProductId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,6 @@ namespace JiShe.IoT.OneNETAggregation
|
||||
/// <summary>
|
||||
/// 获取OneNET产品列表
|
||||
/// </summary>
|
||||
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input);
|
||||
Task<HttpDataResult> GetProductListAsync(OpenApiRequest input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.Workshops
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产设备详情
|
||||
/// </summary>
|
||||
public class ProductionEquipmentMessageBody
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备地址
|
||||
/// </summary>
|
||||
public string DeviceAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物联网平台对应的产品Id
|
||||
/// </summary>
|
||||
public string IoTPlatformProductId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
using JiShe.IoT.CTWingAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.IoT.Workshops;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.CTWingManagement.CTWingDevices;
|
||||
using JiShe.ServicePro.CTWingManagement.CTWingProduct;
|
||||
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.ServerOptions;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace JiShe.IoT.CTWingAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// CTWing聚合服务
|
||||
/// </summary>
|
||||
/// <param name="deviceAppService"></param>
|
||||
/// <param name="ctwingDeviceService"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="logger"></param>
|
||||
public class CTWingAggregationService(IDeviceAppService deviceAppService, ICTWingDeviceService ctwingDeviceService, IOptions<ServerApplicationOptions> options, ILogger<CTWingAggregationService> logger) : IoTAppService, ICTWingAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
|
||||
/// <summary>
|
||||
/// 接收车间生产信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult> ReceiveWorkshopProductionInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
|
||||
if (verifySignatureReult == false)//签名校验失败
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
||||
}
|
||||
|
||||
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("物联网平台产品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()
|
||||
{
|
||||
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
|
||||
PlatformPassword = productInfo.FeatureAccesskey,
|
||||
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
IoTPlatformDeviceOpenInfo = $"{productionEquipmentMessageBody.IoTPlatformProductId}{productionEquipmentMessageBody.DeviceAddress}",
|
||||
DeviceName = productionEquipmentMessageBody.DeviceAddress
|
||||
};
|
||||
|
||||
//创建本地设备信息
|
||||
var insertResult = await deviceAppService.CreateAsync(meterInfoEntity);
|
||||
|
||||
//推送至CTWing平台
|
||||
var pushResult = await ctwingDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
||||
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("推送设备成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(ReceiveWorkshopProductionInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
|
||||
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -107, ResponeResultEnum.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取CTWing产品列表
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
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("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
||||
}
|
||||
|
||||
var pageListQuery = FreeSqlDbContext.Instance.Select<CTWingPrivateProductInfo>()
|
||||
.Where(e => e.IsEnabled == true)
|
||||
.OrderByDescending(e => e.CreationTime);
|
||||
|
||||
var pageList = await pageListQuery.ToListAsync(d => new CTWingWorkshopProductListOutput
|
||||
{
|
||||
ProductDataId = d.Id,
|
||||
ProductName = d.ProductName,
|
||||
CommunicationAddress = d.CommunicationAddress,
|
||||
ProductAccesskey = d.FeatureAccesskey,
|
||||
});
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
|
||||
|
||||
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
|
||||
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == input.IoTPlatformProductId)
|
||||
.Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混
|
||||
.FirstAsync();
|
||||
|
||||
if (productInfo == null)
|
||||
@ -113,6 +113,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
|
||||
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
|
||||
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
|
||||
updateDeviceInput.IsPlatformPushSuccess = true;
|
||||
|
||||
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
||||
if (updateResult == null)
|
||||
@ -124,6 +125,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
//设备数据缓存到Redis
|
||||
DeviceCacheInfos deviceCacheInfos = insertResult.Adapt<DeviceCacheInfos>();
|
||||
deviceCacheInfos.IoTPlatformResponse = updateDeviceInput.IoTPlatformResponse;
|
||||
|
||||
RedisProvider.Instance.HSet<DeviceCacheInfos>(RedisConst.CacheAllDeviceInfoHashKey, insertResult.DeviceAddress, deviceCacheInfos);
|
||||
|
||||
return true;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.IoT.Workshops;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
|
||||
@ -48,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)
|
||||
@ -80,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>();
|
||||
@ -117,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
|
||||
@ -126,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,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
|
||||
@ -147,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)
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -13,7 +13,7 @@ using Volo.Abp.EntityFrameworkCore;
|
||||
namespace JiShe.IoT.Migrations
|
||||
{
|
||||
[DbContext(typeof(IoTDbContext))]
|
||||
[Migration("20250729024912_InitialCreate")]
|
||||
[Migration("20250730091642_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -129,6 +129,24 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("账号名称");
|
||||
|
||||
b.Property<string>("AppId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)")
|
||||
.HasComment("应用 ID");
|
||||
|
||||
b.Property<string>("AppKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("应用 AppKey");
|
||||
|
||||
b.Property<string>("AppSecret")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("应用 AppSecret");
|
||||
|
||||
b.Property<string>("CommunicationAddress")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
@ -276,18 +294,30 @@ namespace JiShe.IoT.Migrations
|
||||
b.Property<int>("DeviceCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("DeviceThingModelUrl")
|
||||
b.Property<string>("DeviceThingModelFileId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)")
|
||||
.HasComment("设备物模型文件Id");
|
||||
|
||||
b.Property<string>("DeviceThingModelFileName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("设备物模型文件管理地址");
|
||||
.HasComment("设备物模型文件名称");
|
||||
|
||||
b.Property<string>("ExtraProperties")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("ExtraProperties")
|
||||
.HasComment("扩展属性,用于存储自定义字段,JSON格式");
|
||||
|
||||
b.Property<int>("IoTPlatformProductId")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("FeatureAccesskey")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("设备访问密钥");
|
||||
|
||||
b.Property<string>("IoTPlatformProductId")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("产品ID");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -296,7 +326,8 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("tinyint(1)")
|
||||
.HasComment("是否启用");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)")
|
||||
@ -307,9 +338,9 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnName("LastModifierId");
|
||||
|
||||
b.Property<string>("MasterKey")
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("varchar(1024)")
|
||||
.HasComment("主密钥");
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("OpenAPI 通信主密钥");
|
||||
|
||||
b.Property<int>("NetworkType")
|
||||
.HasColumnType("int");
|
||||
@ -583,9 +614,7 @@ namespace JiShe.IoT.Migrations
|
||||
.HasComment("物联网平台中对应的产品Id");
|
||||
|
||||
b.Property<string>("IoTPlatformResponse")
|
||||
.IsRequired()
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("varchar(512)")
|
||||
.HasColumnType("text")
|
||||
.HasComment("物联网平台返回的响应信息");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
@ -594,6 +623,9 @@ namespace JiShe.IoT.Migrations
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsPlatformPushSuccess")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)")
|
||||
.HasColumnName("LastModificationTime");
|
||||
@ -1281,7 +1313,8 @@ namespace JiShe.IoT.Migrations
|
||||
.HasComment("手机号码");
|
||||
|
||||
b.Property<int>("ProductCount")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("int")
|
||||
.HasComment("产品数量");
|
||||
|
||||
b.Property<string>("Remark")
|
||||
.HasColumnType("longtext")
|
||||
@ -751,6 +751,12 @@ namespace JiShe.IoT.Migrations
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
AccountId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "账号ID")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
AppId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "应用 ID")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
AppKey = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, comment: "应用 AppKey")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
AppSecret = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, comment: "应用 AppSecret")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
PlatformTenantId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true, comment: "平台租户ID")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CommunicationAddress = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true, comment: "通讯服务地址")
|
||||
@ -792,9 +798,12 @@ namespace JiShe.IoT.Migrations
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CommunicationAddress = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, comment: "通讯服务地址")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
MasterKey = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: true, comment: "主密钥")
|
||||
MasterKey = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true, comment: "OpenAPI 通信主密钥")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
FeatureAccesskey = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true, comment: "设备访问密钥")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IoTPlatformProductId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true, comment: "产品ID")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IoTPlatformProductId = table.Column<int>(type: "int", nullable: false),
|
||||
ProductName = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true, comment: "产品名称")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Protocol = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "通讯协议")
|
||||
@ -817,9 +826,11 @@ namespace JiShe.IoT.Migrations
|
||||
TupDeviceModel = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true, comment: "设备型号")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
DeviceCount = table.Column<int>(type: "int", nullable: false),
|
||||
DeviceThingModelUrl = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true, comment: "设备物模型文件管理地址")
|
||||
DeviceThingModelFileId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "设备物模型文件Id")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
DeviceThingModelFileName = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true, comment: "设备物模型文件名称")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否启用"),
|
||||
ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
@ -863,8 +874,9 @@ namespace JiShe.IoT.Migrations
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IoTPlatformAccountId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "物联网平台中对应的账号Id")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IoTPlatformResponse = table.Column<string>(type: "varchar(512)", maxLength: 512, nullable: false, comment: "物联网平台返回的响应信息")
|
||||
IoTPlatformResponse = table.Column<string>(type: "text", nullable: true, comment: "物联网平台返回的响应信息")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IsPlatformPushSuccess = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
@ -951,7 +963,7 @@ namespace JiShe.IoT.Migrations
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
AccountAccesskey = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, comment: "账户通信密钥,平台可以重置密钥")
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
ProductCount = table.Column<int>(type: "int", nullable: false),
|
||||
ProductCount = table.Column<int>(type: "int", nullable: false, comment: "产品数量"),
|
||||
ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
@ -126,6 +126,24 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("账号名称");
|
||||
|
||||
b.Property<string>("AppId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)")
|
||||
.HasComment("应用 ID");
|
||||
|
||||
b.Property<string>("AppKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("应用 AppKey");
|
||||
|
||||
b.Property<string>("AppSecret")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("应用 AppSecret");
|
||||
|
||||
b.Property<string>("CommunicationAddress")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
@ -273,18 +291,30 @@ namespace JiShe.IoT.Migrations
|
||||
b.Property<int>("DeviceCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("DeviceThingModelUrl")
|
||||
b.Property<string>("DeviceThingModelFileId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)")
|
||||
.HasComment("设备物模型文件Id");
|
||||
|
||||
b.Property<string>("DeviceThingModelFileName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("设备物模型文件管理地址");
|
||||
.HasComment("设备物模型文件名称");
|
||||
|
||||
b.Property<string>("ExtraProperties")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("ExtraProperties")
|
||||
.HasComment("扩展属性,用于存储自定义字段,JSON格式");
|
||||
|
||||
b.Property<int>("IoTPlatformProductId")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("FeatureAccesskey")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("设备访问密钥");
|
||||
|
||||
b.Property<string>("IoTPlatformProductId")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("varchar(128)")
|
||||
.HasComment("产品ID");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -293,7 +323,8 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("tinyint(1)")
|
||||
.HasComment("是否启用");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)")
|
||||
@ -304,9 +335,9 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnName("LastModifierId");
|
||||
|
||||
b.Property<string>("MasterKey")
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("varchar(1024)")
|
||||
.HasComment("主密钥");
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)")
|
||||
.HasComment("OpenAPI 通信主密钥");
|
||||
|
||||
b.Property<int>("NetworkType")
|
||||
.HasColumnType("int");
|
||||
@ -580,9 +611,7 @@ namespace JiShe.IoT.Migrations
|
||||
.HasComment("物联网平台中对应的产品Id");
|
||||
|
||||
b.Property<string>("IoTPlatformResponse")
|
||||
.IsRequired()
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("varchar(512)")
|
||||
.HasColumnType("text")
|
||||
.HasComment("物联网平台返回的响应信息");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
@ -591,6 +620,9 @@ namespace JiShe.IoT.Migrations
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsPlatformPushSuccess")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)")
|
||||
.HasColumnName("LastModificationTime");
|
||||
@ -1278,7 +1310,8 @@ namespace JiShe.IoT.Migrations
|
||||
.HasComment("手机号码");
|
||||
|
||||
b.Property<int>("ProductCount")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("int")
|
||||
.HasComment("产品数量");
|
||||
|
||||
b.Property<string>("Remark")
|
||||
.HasColumnType("longtext")
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
using JiShe.IoT.CTWingAggregation;
|
||||
using JiShe.IoT.CTWingAggregation.Dto;
|
||||
using JiShe.ServicePro;
|
||||
|
||||
namespace JiShe.IoT.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// CTWing聚合服务
|
||||
/// </summary>
|
||||
[Route("/Aggregation/CTWing")]
|
||||
public class CTWingAggregationController : IoTController
|
||||
{
|
||||
private readonly ICTWingAggregationService _ctwingAggregationServiceService;
|
||||
public CTWingAggregationController(ICTWingAggregationService ctwingAggregationServiceService)
|
||||
{
|
||||
_ctwingAggregationServiceService = ctwingAggregationServiceService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收车间生产信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(nameof(ReceiveWorkshopProductionInfoAsync))]
|
||||
[SwaggerOperation(summary: "接收车间生产信息", Tags = new[] { "AggregationCTWing" })]
|
||||
public async Task ReceiveWorkshopProductionInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
await _ctwingAggregationServiceService.ReceiveWorkshopProductionInfoAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取CTWing产品列表
|
||||
/// </summary>
|
||||
[HttpPost(nameof(GetProductListAsync))]
|
||||
[SwaggerOperation(summary: "获取CTWing产品列表", Tags = new[] { "AggregationCTWing" })]
|
||||
public async Task<HttpDataResult> GetProductListAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _ctwingAggregationServiceService.GetProductListAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user