Compare commits
2 Commits
7a5479f646
...
8639fad140
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8639fad140 | ||
|
|
295baad480 |
@ -298,6 +298,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.ServicePro.DynamicAna
|
||||
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}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -772,6 +774,10 @@ Global
|
||||
{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.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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -904,6 +910,7 @@ Global
|
||||
{539D0149-B52C-7FE1-373D-67EC401D5B47} = {E10B1433-8E8E-4163-AC98-1058004980F9}
|
||||
{6CDFFB25-15FF-19C2-D4AB-921CF40DB056} = {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
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}
|
||||
|
||||
@ -82,7 +82,8 @@
|
||||
"IsAesEncrypted": false,
|
||||
"DistributedMessage": 2,
|
||||
"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": {
|
||||
"Audience": "JiShe.IoT",
|
||||
|
||||
@ -14,7 +14,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
public interface IBusinessSystemAggregationService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 接收业务系统设置指令信息,Msg 字段为 ReceiveCommandInfoDto 实体
|
||||
/// 接收业务系统设置指令信息,Msg 字段为 ReceiveCommandInfoDto 实体,操作类型必须有对应的事件上报,进行业务系统回调触发,不能直接使用同步操作。
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@ -73,7 +73,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
return redis.call('HMGET', hashKey, unpack(fieldKeys))";
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统设置指令信息
|
||||
/// 接收业务系统设置指令信息,Msg 字段为 ReceiveCommandInfoDto 实体,操作类型必须有对应的事件上报,进行业务系统回调触发,不能直接使用同步操作。
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult> ReceiveSetCommandInfoAsync(OpenApiRequest input)
|
||||
@ -117,8 +117,6 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
return HttpDataResultExtensions.Failed("设备不存在", -1041, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
var packetTaskInfo = GetDeviceTelemetryPacketTaskInfo(ioTDBOptions, input, deviceInfo.Adapt<DeviceCacheInfos>(), messageBody.Commands.Serialize());
|
||||
|
||||
//将指令存储IoTDB数据库和Redis发布通道
|
||||
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
|
||||
{
|
||||
@ -130,7 +128,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
{
|
||||
throw new UserFriendlyException($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。");
|
||||
}
|
||||
|
||||
Dictionary<string, object> commands = new Dictionary<string, object>();
|
||||
foreach (var item in messageBody.Commands)
|
||||
{
|
||||
var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.IoTPlatformRawFieldName == item.Key).FirstOrDefault();
|
||||
@ -155,12 +153,21 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
messageBody.Commands.RemoveAll(d => d.Key == item.Key);
|
||||
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 redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, input);
|
||||
}
|
||||
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
|
||||
@ -169,7 +176,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpDataResultExtensions.Failed("指令处理失败,当前设备平台类型异常", -105);
|
||||
return HttpDataResultExtensions.Failed("设置属性指令处理失败,当前设备平台类型异常", -105);
|
||||
}
|
||||
|
||||
return HttpDataResultExtensions.Success("指令下发成功");
|
||||
@ -199,11 +206,20 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,签名校验异常", -101);
|
||||
}
|
||||
var messageBody = handleResult.Data;
|
||||
if (messageBody == null || messageBody.Commands == null || messageBody.Commands.Count <= 0)
|
||||
if (messageBody == null || messageBody.Commands == null || messageBody.Commands.Count <= 0 || string.IsNullOrWhiteSpace(messageBody.DeviceAddress))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,设备属性值不能为空", -103, ResponeResultEnum.Fail);
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,设备属性值不能为空", -102, 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)
|
||||
{
|
||||
@ -235,7 +251,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>($"业务系统推送指令时设备{deviceInfo.DeviceAddress}的平台端物模型信息不存在。", -107, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
Dictionary<string, object> commands = new Dictionary<string, object>();
|
||||
Dictionary<string, string> commands = new Dictionary<string, string>();
|
||||
foreach (var item in messageBody.Commands)
|
||||
{
|
||||
var tempPlatformThingModelInfo = platformThingModelInfo.Where(d => d.StandardFieldName == item.Key).FirstOrDefault();
|
||||
@ -260,8 +276,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
messageBody.Commands.RemoveAll(d => d.Key == item.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
commands.Add(item.Key,item.Value);
|
||||
commands.Add(tempPlatformThingModelInfo.IoTPlatformRawFieldName,item.Key);
|
||||
}
|
||||
|
||||
if (commands == null || commands.Count <= 0)
|
||||
@ -283,7 +298,13 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("获取数据失败,OneNET平台未返回数据", -109);
|
||||
}
|
||||
|
||||
return HttpDataResultExtensions.Success<Dictionary<string, object>>(queryResult);
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
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)
|
||||
@ -297,14 +318,15 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
|
||||
return HttpDataResultExtensions.Success<Dictionary<string, object>>("指令下发成功");
|
||||
}
|
||||
catch (UserFriendlyException)
|
||||
catch (UserFriendlyException ex)
|
||||
{
|
||||
throw; // 重新抛出用户友好异常
|
||||
_logger.LogError(ex, "接收业务系统指令信息时发生异常");
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("设备属性数据获取失败,发送异常", -111);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "接收业务系统指令信息时发生异常");
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("指令处理失败,发送异常", -111);
|
||||
return HttpDataResultExtensions.Failed<Dictionary<string, object>>("设备属性数据获取失败,发送异常", -112);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user