完善设备端物模型指令管理和数据上报解析时数据分类异常的问题。获取所有平台端物模型信息
This commit is contained in:
parent
d7d4ea0408
commit
91437a600f
@ -100,7 +100,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
throw new UserFriendlyException($"业务系统推送指令时设备{deviceInfo.DeviceAddress}平台端物模型属性标识符{item.Key}是升级指令操作,被禁止。");
|
||||
}
|
||||
|
||||
if (deviceInfo.IsNeedConfigDevicMdoel && deviceInfo.DeviceThingModelDataId.HasValue && item.Key.ToLowerInvariant() == ThingModelFixedTypeConst.SpecialCommand.ToLowerInvariant())
|
||||
if (deviceInfo.IsNeedConfigDeviceModel && deviceInfo.DeviceThingModelDataId.HasValue && item.Key.ToLowerInvariant() == ThingModelFixedTypeConst.SpecialCommand.ToLowerInvariant())
|
||||
{
|
||||
throw new UserFriendlyException($"业务系统推送指令时设备{deviceInfo.DeviceAddress}平台端物模型属性标识符{item.Key}是特殊指令操作,被禁止。");
|
||||
}
|
||||
|
||||
@ -1075,7 +1075,7 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
//检查设备是否有配置设备端物模型信息
|
||||
//如果有配置,就检查指令字典中是否有SpecialCommand标识符
|
||||
//如果有就需要构建 SpecialCommand 的特别指令
|
||||
if (deviceInfo.IsNeedConfigDevicMdoel && deviceInfo.DeviceThingModelDataId.HasValue && input.Commands.ContainsKey(ThingModelFixedTypeConst.SpecialCommand))
|
||||
if (deviceInfo.IsNeedConfigDeviceModel && deviceInfo.DeviceThingModelDataId.HasValue && input.Commands.ContainsKey(ThingModelFixedTypeConst.SpecialCommand))
|
||||
{
|
||||
var propertyInfo = await oneNETProductService.GetProductThingModelSpecialCommandDataTypeListAsync(new IdInput<string>() { Id = deviceInfo.IoTPlatformProductId });
|
||||
|
||||
@ -1118,9 +1118,9 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
logger.LogError($"{nameof(DeviceCommandInfoToOneNET)} 发送OneNET设备指令信息发生异常,设备地址:{deviceInfo.DeviceAddress},异常信息:{ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -1316,22 +1316,76 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
return deviceDataResult.Data;
|
||||
}
|
||||
|
||||
var platformUpdatePropertyInfo = platformThingModelInfo.Where(d => d.StandardFieldName.ToLowerInvariant() == ThingModelFixedTypeConst.FIRMWARE_VERSION.ToLowerInvariant()).FirstOrDefault();
|
||||
//抄读结果如果有固件版本号,则更新固件版本号到设备信息中
|
||||
var firmwareVersionKey = platformUpdatePropertyInfo?.IoTPlatformRawFieldName.ToLowerInvariant();
|
||||
List<string> updateKeys = new List<string>()
|
||||
{
|
||||
ThingModelFixedTypeConst.FIRMWARE_VERSION.ToLowerInvariant(),
|
||||
ThingModelFixedTypeConst.ReadingMode.ToLowerInvariant()
|
||||
};
|
||||
|
||||
var platformUpdatePropertyInfos = platformThingModelInfo.Where(d => updateKeys.Contains(d.StandardFieldName.ToLowerInvariant())).ToList();
|
||||
if (platformUpdatePropertyInfos == null || platformUpdatePropertyInfos.Count <= 0)
|
||||
{
|
||||
return deviceDataResult.Data;
|
||||
}
|
||||
|
||||
//根据抄读结果(单个或多个属性)更新设备信息,统一收集后只调用一次 UpdateDeviceInfos
|
||||
bool needUpdate = false;
|
||||
|
||||
//抄读结果如果有固件版本号,则更新固件版本号到设备信息中
|
||||
var firmwareVersionKey = platformUpdatePropertyInfos.FirstOrDefault(d => d.StandardFieldName?.ToLowerInvariant() == ThingModelFixedTypeConst.FIRMWARE_VERSION.ToLowerInvariant())?.IoTPlatformRawFieldName;
|
||||
if (!string.IsNullOrWhiteSpace(firmwareVersionKey) && deviceDataResult.Data.ContainsKey(firmwareVersionKey))
|
||||
{
|
||||
deviceInfo.FirmwareVersion = deviceDataResult.Data[firmwareVersionKey].ToString();
|
||||
await deviceAppService.UpdateDeviceFirmwareVersion(deviceInfo);
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
//抄读结果如果有抄读模式,则更新抄读模式到设备信息中
|
||||
var readModeKey = platformUpdatePropertyInfos.FirstOrDefault(d => d.StandardFieldName?.ToLowerInvariant() == ThingModelFixedTypeConst.ReadingMode.ToLowerInvariant())?.IoTPlatformRawFieldName;
|
||||
if (!string.IsNullOrWhiteSpace(readModeKey) && deviceDataResult.Data.ContainsKey(readModeKey))
|
||||
{
|
||||
var readModeValue = deviceDataResult.Data[readModeKey];
|
||||
|
||||
// 兼容 JsonElement / 字符串 / 数值 三种情况
|
||||
int readModeInt;
|
||||
if (readModeValue is System.Text.Json.JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement.ValueKind == System.Text.Json.JsonValueKind.Number && jsonElement.TryGetInt32(out var num))
|
||||
{
|
||||
readModeInt = num;
|
||||
}
|
||||
else
|
||||
{
|
||||
readModeInt = Convert.ToInt32(jsonElement.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readModeInt = Convert.ToInt32(readModeValue);
|
||||
}
|
||||
|
||||
deviceInfo.ReadingMode = (DeviceReadingModeEnum)readModeInt;
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (needUpdate)
|
||||
{
|
||||
await deviceAppService.UpdateDeviceInfos(deviceInfo);
|
||||
}
|
||||
|
||||
return deviceDataResult.Data;
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
if (input.PropertyList.Contains(ThingModelFixedTypeConst.SpecialCommand))
|
||||
{
|
||||
ex = new UserFriendlyException("请检查设备是否已经采集数据");
|
||||
throw ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
4303
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128012938_updatedevicethingmodel.Designer.cs
generated
Normal file
4303
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128012938_updatedevicethingmodel.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.IoT.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatedevicethingmodel : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsEnable",
|
||||
table: "ServiceProDeviceThingModelCommandInfo",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false,
|
||||
comment: "是否启用");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsEnable",
|
||||
table: "ServiceProDeviceThingModelCommandInfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
4309
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128015625_updatedeviceinfo20260128.Designer.cs
generated
Normal file
4309
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128015625_updatedeviceinfo20260128.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.IoT.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatedeviceinfo20260128 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ReadingMode",
|
||||
table: "ServiceProDeviceInfo",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 1,
|
||||
comment: "抄读模式");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ReadingMode",
|
||||
table: "ServiceProDeviceInfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
4309
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128020928_updatedeviceinfo202601281007.Designer.cs
generated
Normal file
4309
src/JiShe.IoT.EntityFrameworkCore/Migrations/20260128020928_updatedeviceinfo202601281007.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.IoT.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatedeviceinfo202601281007 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "IsNeedConfigDevicMdoel",
|
||||
table: "ServiceProDeviceInfo",
|
||||
newName: "IsNeedConfigDeviceModel");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "IsNeedConfigDeviceModel",
|
||||
table: "ServiceProDeviceInfo",
|
||||
newName: "IsNeedConfigDevicMdoel");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -794,7 +794,7 @@ namespace JiShe.IoT.Migrations
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsNeedConfigDevicMdoel")
|
||||
b.Property<bool>("IsNeedConfigDeviceModel")
|
||||
.HasColumnType("boolean")
|
||||
.HasComment("是否需要配置设备模型");
|
||||
|
||||
@ -836,6 +836,12 @@ namespace JiShe.IoT.Migrations
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasComment("物联网平台设备密码");
|
||||
|
||||
b.Property<int>("ReadingMode")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasComment("抄读模式");
|
||||
|
||||
b.Property<string>("Remark")
|
||||
.HasColumnType("text")
|
||||
.HasComment("备注");
|
||||
@ -1204,6 +1210,10 @@ namespace JiShe.IoT.Migrations
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("IsDeleted");
|
||||
|
||||
b.Property<bool>("IsEnable")
|
||||
.HasColumnType("boolean")
|
||||
.HasComment("是否启用");
|
||||
|
||||
b.Property<string>("IssueCommand")
|
||||
.IsRequired()
|
||||
.HasMaxLength(512)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user