Compare commits

..

No commits in common. "8639fad1400366895addfc5a654a42d94eac8728" and "7a5479f6466219d34faa1c172f1bdb3acbb66b20" have entirely different histories.

4 changed files with 18 additions and 48 deletions

View File

@ -298,8 +298,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.ServicePro.DynamicAna
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.ServicePro.DynamicAnalyzer.Provider", "JiShe.ServicePro\frameworks\src\JiShe.ServicePro.DynamicAnalyzer.Provider\JiShe.ServicePro.DynamicAnalyzer.Provider.csproj", "{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.ServicePro.DynamicAnalyzer.Provider", "JiShe.ServicePro\frameworks\src\JiShe.ServicePro.DynamicAnalyzer.Provider\JiShe.ServicePro.DynamicAnalyzer.Provider.csproj", "{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.ServicePro.EMQXProvider", "JiShe.ServicePro\frameworks\src\JiShe.ServicePro.EMQXProvider\JiShe.ServicePro.EMQXProvider.csproj", "{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -774,10 +772,6 @@ Global
{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Release|Any CPU.Build.0 = Release|Any CPU {516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8}.Release|Any CPU.Build.0 = Release|Any CPU
{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -910,7 +904,6 @@ Global
{539D0149-B52C-7FE1-373D-67EC401D5B47} = {E10B1433-8E8E-4163-AC98-1058004980F9} {539D0149-B52C-7FE1-373D-67EC401D5B47} = {E10B1433-8E8E-4163-AC98-1058004980F9}
{6CDFFB25-15FF-19C2-D4AB-921CF40DB056} = {72493AF2-CDAA-40A7-98AB-B8AA2B05965E} {6CDFFB25-15FF-19C2-D4AB-921CF40DB056} = {72493AF2-CDAA-40A7-98AB-B8AA2B05965E}
{516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8} = {72493AF2-CDAA-40A7-98AB-B8AA2B05965E} {516CAE8B-3EDC-8B5C-D15C-5BF9ABF971D8} = {72493AF2-CDAA-40A7-98AB-B8AA2B05965E}
{6DB1C8C3-E57A-005D-D1D0-2194F6AC6537} = {72493AF2-CDAA-40A7-98AB-B8AA2B05965E}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}

View File

@ -82,8 +82,7 @@
"IsAesEncrypted": false, "IsAesEncrypted": false,
"DistributedMessage": 2, "DistributedMessage": 2,
"SnowflakeWorkerId": 1, "SnowflakeWorkerId": 1,
"DownloadDeviceFirmwareBasicUrl": "http://121.42.175.177:32580/Aggregation/Device/DownloadFirmware?Id=", "DownloadDeviceFirmwareBasicUrl": "http://121.42.175.177:32580/Aggregation/Device/DownloadFirmware?Id="
"MQTTServerType": 1
}, },
"Jwt": { "Jwt": {
"Audience": "JiShe.IoT", "Audience": "JiShe.IoT",

View File

@ -14,7 +14,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
public interface IBusinessSystemAggregationService : IApplicationService public interface IBusinessSystemAggregationService : IApplicationService
{ {
/// <summary> /// <summary>
/// 接收业务系统设置指令信息Msg 字段为 ReceiveCommandInfoDto 实体,操作类型必须有对应的事件上报,进行业务系统回调触发,不能直接使用同步操作。 /// 接收业务系统设置指令信息Msg 字段为 ReceiveCommandInfoDto 实体
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>

View File

@ -73,7 +73,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
return redis.call('HMGET', hashKey, unpack(fieldKeys))"; return redis.call('HMGET', hashKey, unpack(fieldKeys))";
/// <summary> /// <summary>
/// 接收业务系统设置指令信息Msg 字段为 ReceiveCommandInfoDto 实体,操作类型必须有对应的事件上报,进行业务系统回调触发,不能直接使用同步操作。 /// 接收业务系统设置指令信息
/// </summary> /// </summary>
[AllowAnonymous] [AllowAnonymous]
public async Task<HttpDataResult> ReceiveSetCommandInfoAsync(OpenApiRequest input) public async Task<HttpDataResult> ReceiveSetCommandInfoAsync(OpenApiRequest input)
@ -116,7 +116,9 @@ namespace JiShe.IoT.BusinessSystemAggregation
{ {
return HttpDataResultExtensions.Failed("设备不存在", -1041, ResponeResultEnum.Fail); return HttpDataResultExtensions.Failed("设备不存在", -1041, ResponeResultEnum.Fail);
} }
var packetTaskInfo = GetDeviceTelemetryPacketTaskInfo(ioTDBOptions, input, deviceInfo.Adapt<DeviceCacheInfos>(), messageBody.Commands.Serialize());
//将指令存储IoTDB数据库和Redis发布通道 //将指令存储IoTDB数据库和Redis发布通道
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET) if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
{ {
@ -128,7 +130,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
{ {
throw new UserFriendlyException($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。"); throw new UserFriendlyException($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。");
} }
Dictionary<string, object> commands = new Dictionary<string, object>();
foreach (var item in messageBody.Commands) foreach (var item in messageBody.Commands)
{ {
var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.IoTPlatformRawFieldName == item.Key).FirstOrDefault(); var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.IoTPlatformRawFieldName == item.Key).FirstOrDefault();
@ -153,21 +155,12 @@ namespace JiShe.IoT.BusinessSystemAggregation
messageBody.Commands.RemoveAll(d => d.Key == item.Key); messageBody.Commands.RemoveAll(d => d.Key == item.Key);
continue; continue;
} }
commands.Add(tempPlatformThingModelInfo.IoTPlatformRawFieldName, item.Value);
} }
if (commands == null || commands.Count <= 0)
{
_logger.LogError($"业务系统推送设置属性指令时设备{deviceInfo.DeviceAddress}未匹配到具体数据模型,被禁止。");
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("设置属性失败,未匹配到具体数据模型", -108);
}
var packetTaskInfo = GetDeviceTelemetryPacketTaskInfo(ioTDBOptions, input, deviceInfo.Adapt<DeviceCacheInfos>(), commands.Serialize());
//数据写入遥测任务数据存储通道 //数据写入遥测任务数据存储通道
await ioTDBDataChannelManageService.DeviceTelemetryTaskWriterAsync(DataChannelManage.DeviceTelemetryTaskDataChannel.Writer, (DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo)); await ioTDBDataChannelManageService.DeviceTelemetryTaskWriterAsync(DataChannelManage.DeviceTelemetryTaskDataChannel.Writer, (DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo));
await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, input); await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, input);
} }
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing) else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
@ -176,7 +169,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
} }
else else
{ {
return HttpDataResultExtensions.Failed("设置属性指令处理失败,当前设备平台类型异常", -105); return HttpDataResultExtensions.Failed("指令处理失败,当前设备平台类型异常", -105);
} }
return HttpDataResultExtensions.Success("指令下发成功"); return HttpDataResultExtensions.Success("指令下发成功");
@ -206,20 +199,11 @@ namespace JiShe.IoT.BusinessSystemAggregation
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,签名校验异常", -101); return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,签名校验异常", -101);
} }
var messageBody = handleResult.Data; var messageBody = handleResult.Data;
if (messageBody == null || messageBody.Commands == null || messageBody.Commands.Count <= 0 || string.IsNullOrWhiteSpace(messageBody.DeviceAddress)) if (messageBody == null || messageBody.Commands == null || messageBody.Commands.Count <= 0)
{ {
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,设备属性值不能为空", -102, ResponeResultEnum.Fail); return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,设备属性值不能为空", -103, ResponeResultEnum.Fail);
} }
var restrictionKey = string.Format(RedisConst.CacheDeviceOpenApiRestrictionKey,nameof(ReceiveGetCommandInfoAsync), messageBody.DeviceAddress);
var openApiDeviceRequest = FreeRedisProvider.Instance.Get(restrictionKey);
if (openApiDeviceRequest != null)
{
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,设备请求被限制", -103, ResponeResultEnum.Fail);
}
FreeRedisProvider.Instance.Set(restrictionKey,"1",TimeSpan.FromSeconds(5));
//限定来源类型必须为业务系统 //限定来源类型必须为业务系统
if (messageBody.SourceType != DeviceTelemetrySourceTypeEnum.BusinessSystem) if (messageBody.SourceType != DeviceTelemetrySourceTypeEnum.BusinessSystem)
{ {
@ -251,7 +235,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
return HttpDataResultExtensions.Failed<Dictionary<string, object>>($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。", -107, ResponeResultEnum.Fail); return HttpDataResultExtensions.Failed<Dictionary<string, object>>($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。", -107, ResponeResultEnum.Fail);
} }
Dictionary<string, string> commands = new Dictionary<string, string>(); Dictionary<string, object> commands = new Dictionary<string, object>();
foreach (var item in messageBody.Commands) foreach (var item in messageBody.Commands)
{ {
var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.StandardFieldName == item.Key).FirstOrDefault(); var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.StandardFieldName == item.Key).FirstOrDefault();
@ -276,7 +260,8 @@ namespace JiShe.IoT.BusinessSystemAggregation
messageBody.Commands.RemoveAll(d => d.Key == item.Key); messageBody.Commands.RemoveAll(d => d.Key == item.Key);
continue; continue;
} }
commands.Add(tempPlatformThingModelInfo.IoTPlatformRawFieldName,item.Key);
commands.Add(item.Key,item.Value);
} }
if (commands == null || commands.Count <= 0) if (commands == null || commands.Count <= 0)
@ -298,13 +283,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败OneNET平台未返回数据", -109); return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败OneNET平台未返回数据", -109);
} }
Dictionary<string, object> result = new Dictionary<string, object>(); return HttpDataResultExtensions.Success<Dictionary<string, object>>(queryResult);
foreach (var item in commands)
{
result.Add(item.Value, queryResult[item.Key]);
}
return HttpDataResultExtensions.Success<Dictionary<string, object>>(result);
} }
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing) else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
@ -318,15 +297,14 @@ namespace JiShe.IoT.BusinessSystemAggregation
return HttpDataResultExtensions.Success<Dictionary<string, object>>("指令下发成功"); return HttpDataResultExtensions.Success<Dictionary<string, object>>("指令下发成功");
} }
catch (UserFriendlyException ex) catch (UserFriendlyException)
{ {
_logger.LogError(ex, "接收业务系统指令信息时发生异常"); throw; // 重新抛出用户友好异常
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("设备属性数据获取失败,发送异常", -111);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "接收业务系统指令信息时发生异常"); _logger.LogError(ex, "接收业务系统指令信息时发生异常");
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("设备属性数据获取失败,发送异常", -112); return HttpDataResultExtensions.Failed<Dictionary<string, object>>("指令处理失败,发送异常", -111);
} }
} }