diff --git a/projects/Application/Domain/IoTCenter/IoTData.cs b/projects/Application/Domain/IoTCenter/IoTData.cs index 38879265..52d9e386 100644 --- a/projects/Application/Domain/IoTCenter/IoTData.cs +++ b/projects/Application/Domain/IoTCenter/IoTData.cs @@ -1,8 +1,8 @@ - using Infrastructure.Domain; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json; namespace Application.Domain.Entities { @@ -21,8 +21,14 @@ namespace Application.Domain.Entities [Display(Name = "名称")] public string Name { get; set; } - [Display(Name = "类型")] - public IoTValueType Type { get; set; } + [Display(Name = "数据类型")] + public IoTDataType DataType { get; set; } + + [Display(Name = "数值类型")] + public IoTValueType ValueType { get; set; } + + [Display(Name = "枚举定义")] + public String EnumValues { get; set; } [Display(Name = "单位")] public string Unit { get; set; } @@ -44,17 +50,27 @@ namespace Application.Domain.Entities public List IoTTiggers { get; set; } = new List(); + public Dictionary GetEnumValues() + { + return JsonSerializer.Deserialize>(this.EnumValues); + } + + public void SetEnumValues(Dictionary values) + { + this.EnumValues = JsonSerializer.Serialize(values); + } + public dynamic GetValue() { - if (this.Type == IoTValueType.Int) + if (this.ValueType == IoTValueType.Int) { return Convert.ToInt32(this.Value); } - else if (this.Type == IoTValueType.Float) + else if (this.ValueType == IoTValueType.Float) { return Convert.ToSingle(this.Value); } - else if (this.Type == IoTValueType.Long) + else if (this.ValueType == IoTValueType.Long) { return Convert.ToInt64(this.Value); } diff --git a/projects/Application/Domain/IoTCenter/IoTDataType.cs b/projects/Application/Domain/IoTCenter/IoTDataType.cs index f644931f..a5297ea2 100644 --- a/projects/Application/Domain/IoTCenter/IoTDataType.cs +++ b/projects/Application/Domain/IoTCenter/IoTDataType.cs @@ -1,9 +1,14 @@ -namespace Application.Domain.IoTCenter +using System.ComponentModel.DataAnnotations; + +namespace Application.Domain.Entities { public enum IoTDataType { - Info, - Data, - Event + [Display(Name="设备信息")] + Info=10, + [Display(Name = "设备数据")] + Data=20, + [Display(Name = "设备事件")] + Event=30 } -} +} \ No newline at end of file diff --git a/projects/Application/Domain/IoTCenter/IoTDevice.cs b/projects/Application/Domain/IoTCenter/IoTDevice.cs index 4a926b4c..6a6e0e17 100644 --- a/projects/Application/Domain/IoTCenter/IoTDevice.cs +++ b/projects/Application/Domain/IoTCenter/IoTDevice.cs @@ -89,7 +89,7 @@ namespace Application.Domain.Entities IoTDeviceId = this.Id, Key = key, Value = Convert.ToString(value), - Type = type, + ValueType = type, Name = name, Unit = unit, Description = description, diff --git a/projects/Application/Domain/IoTCenter/IoTValueType.cs b/projects/Application/Domain/IoTCenter/IoTValueType.cs index b553ec20..46c5ac65 100644 --- a/projects/Application/Domain/IoTCenter/IoTValueType.cs +++ b/projects/Application/Domain/IoTCenter/IoTValueType.cs @@ -4,15 +4,23 @@ namespace Application.Domain.Entities { public enum IoTValueType { - [Display(Name = "整数")] + [Display(Name = "整数(32)")] Int = 10, - [Display(Name = "浮点数")] + [Display(Name = "单精度浮点数(32)")] Float = 20, - [Display(Name = "长整数")] - Long = 30, - [Display(Name = "日期")] - Timestamp = 40, + [Display(Name = "双精度浮点数(64)")] + Double = 30, + [Display(Name = "长整数(64)")] + Long = 40, + [Display(Name = "时间戳(String格式UTC毫秒)")] + Timestamp = 50, [Display(Name = "字符串")] - String = 50 + String = 60, + [Display(Name = "枚举(整数)")] + Enum=70, + [Display(Name = "对象(String格式JSON)")] + Object=80, + [Display(Name = "数组(单一其他格式)")] + Array = 90 } } diff --git a/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs b/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs index f5d94a8d..46a4ddce 100644 --- a/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs +++ b/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs @@ -35,12 +35,17 @@ namespace IoT.Shared.Application.Models [Display(Name = "名称")] [ReadOnlyForEdit] [Required(ErrorMessage = nameof(RequiredAttribute))] + public string Name { get; set; } + [Display(Name = "数据类型")] + [ReadOnlyForEdit] + [Required(ErrorMessage = nameof(RequiredAttribute))] + public IoTDataType? DataType { get; set; } - [Display(Name = "类型")] + [Display(Name = "数值类型")] [ReadOnlyForEdit] [Required(ErrorMessage = nameof(RequiredAttribute))] - public IoTValueType? Type { get; set; } + public IoTValueType? ValueType { get; set; } [Display(Name = "单位")] [ReadOnlyForEdit] diff --git a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTDataController.cs b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTDataController.cs index d80e66d9..d9762bf0 100644 --- a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTDataController.cs +++ b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTDataController.cs @@ -42,7 +42,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) .WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key)) .WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Value.Contains(model.Query.Value)) - .WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value) + .WhereIf(model.Query.ValueType.HasValue, o => o.ValueType == model.Query.ValueType.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Unit), o => o.Unit.Contains(model.Query.Unit)) .WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description)) .WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value) diff --git a/projects/IoTNode/db.sql b/projects/IoTNode/db.sql index 19a2b1ff..f3c564c9 100644 --- a/projects/IoTNode/db.sql +++ b/projects/IoTNode/db.sql @@ -88,7 +88,9 @@ CREATE TABLE "iot_IoTData" ( "Key" TEXT NOT NULL, "Value" TEXT NULL, "Name" TEXT NULL, - "Type" INTEGER NOT NULL, + "DataType" INTEGER NOT NULL, + "ValueType" INTEGER NOT NULL, + "EnumValues" TEXT NULL, "Unit" TEXT NULL, "Description" TEXT NULL, "Timestamp" INTEGER NOT NULL, diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs index 4fc35f9b..aaeec07d 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs @@ -66,7 +66,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) .WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key)) .WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Value.Contains(model.Query.Value)) - .WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value) + .WhereIf(model.Query.ValueType.HasValue, o => o.ValueType == model.Query.ValueType.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Unit), o => o.Unit.Contains(model.Query.Unit)) .WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description)) .WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value) diff --git a/projects/Platform/Areas/IoTCenter/Views/IoTData/Details.cshtml b/projects/Platform/Areas/IoTCenter/Views/IoTData/Details.cshtml index 39f9cc11..3c2c091e 100644 --- a/projects/Platform/Areas/IoTCenter/Views/IoTData/Details.cshtml +++ b/projects/Platform/Areas/IoTCenter/Views/IoTData/Details.cshtml @@ -2,7 +2,7 @@ @{ HtmlTitle = "查看" + ViewContext.ViewData.ModelMetadata.ModelType.GetDisplayName(); } -@if (Model.Type == IoTValueType.Int || Model.Type == IoTValueType.Float) +@if (Model.ValueType == IoTValueType.Int || Model.ValueType == IoTValueType.Float) {
查看历史数据 diff --git a/projects/Platform/Controllers/AjaxController.cs b/projects/Platform/Controllers/AjaxController.cs index 2456665b..635cf5ea 100644 --- a/projects/Platform/Controllers/AjaxController.cs +++ b/projects/Platform/Controllers/AjaxController.cs @@ -108,7 +108,7 @@ namespace Platform.Areas.IoTCenter.Controllers var repo = serviceScope.ServiceProvider.GetRequiredService>(); var list = repo.ReadOnlyTable() .Where(o => !o.Hidden && o.IoTDeviceId == parentId) - .Select(o => new { o.Id, Name = $"{o.Name}[{o.Type}]" }) + .Select(o => new { o.Id, Name = $"{o.Name}[{o.ValueType}]" }) .ToList(); return new JsonResult(new SelectList(list, "Id", "Name", selected)); } @@ -120,7 +120,7 @@ namespace Platform.Areas.IoTCenter.Controllers var data = repo.ReadOnlyTable().FirstOrDefault(o => o.Id == parentId); var list = new List(); - if (data.Type != IoTValueType.String) + if (data.ValueType != IoTValueType.String) { list.Add(new SelectListItem { Value = IoTOperationType.GreaterThan.GetValue().ToString(), Text = "大于" }); list.Add(new SelectListItem { Value = IoTOperationType.LessThan.GetValue().ToString(), Text = "小于" }); @@ -309,7 +309,7 @@ namespace Platform.Areas.IoTCenter.Controllers var expression = ""; if (type != IoTOperationType.Other) { - if (data.Type == IoTValueType.String) + if (data.ValueType == IoTValueType.String) { condition = $"\"{condition}\""; } diff --git a/projects/Platform/Services/IoTCenterEventHandler.cs b/projects/Platform/Services/IoTCenterEventHandler.cs index e338b1c1..d07b4af8 100644 --- a/projects/Platform/Services/IoTCenterEventHandler.cs +++ b/projects/Platform/Services/IoTCenterEventHandler.cs @@ -342,7 +342,7 @@ namespace Platform.Services { return; } - if (data.Type != IoTValueType.Int && data.Type != IoTValueType.Float && data.Type != IoTValueType.String) + if (data.ValueType != IoTValueType.Int && data.ValueType != IoTValueType.Float && data.ValueType != IoTValueType.String) { return; } @@ -382,7 +382,7 @@ namespace Platform.Services private object GetDataValue(IoTData model) { - return model.Type switch + return model.ValueType switch { IoTValueType.Int => Convert.ToInt32(model.Value), diff --git a/projects/Platform/Services/IoTCenterHub.cs b/projects/Platform/Services/IoTCenterHub.cs index 0de012e0..8a72987f 100644 --- a/projects/Platform/Services/IoTCenterHub.cs +++ b/projects/Platform/Services/IoTCenterHub.cs @@ -407,7 +407,7 @@ namespace Platform.Services { return; } - if (data.Type != IoTValueType.Int && data.Type != IoTValueType.Float) + if (data.ValueType != IoTValueType.Int && data.ValueType != IoTValueType.Float) { return; } @@ -439,7 +439,7 @@ namespace Platform.Services private object GetDataValue(IoTData model) { - return model.Type switch + return model.ValueType switch { IoTValueType.Int => Convert.ToInt32(model.Value), diff --git a/projects/Platform/db.sql b/projects/Platform/db.sql index ae862b1e..09d7a254 100644 --- a/projects/Platform/db.sql +++ b/projects/Platform/db.sql @@ -381,7 +381,9 @@ CREATE TABLE "iot_IoTData" ( "Key" TEXT NOT NULL, "Value" TEXT NULL, "Name" TEXT NULL, - "Type" INTEGER NOT NULL, + "DataType" INTEGER NOT NULL, + "ValueType" INTEGER NOT NULL, + "EnumValues" TEXT NULL, "Unit" TEXT NULL, "Description" TEXT NULL, "Timestamp" INTEGER NOT NULL,